11inline uint64_t
read_be(
const uint8_t *p,
size_t n) {
13 for (
size_t i = 0; i < n; i++)
29 const uint64_t energy_raw = std::min<uint64_t>(
read_be(&frame[3], 7), 999900);
30 const uint8_t hours = std::min<uint8_t>(frame[14], 99);
31 const uint8_t minutes = std::min<uint8_t>(frame[15], 59);
32 const uint8_t seconds = std::min<uint8_t>(frame[16], 59);
33 return {power_raw / 1000.0f, energy_raw / 1000.0f, hours * 60.0f + minutes + seconds / 60.0f, frame[17]};
54static constexpr size_t MAX_FRAME_LEN = 260;
77 esp_ble_gattc_cb_param_t *param)
override;
78 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
override;
94 SUB_NUMBER(max_current)
96 SUB_TEXT_SENSOR(fw_version)
97 SUB_TEXT_SENSOR(bt_fw_version)
98 SUB_TEXT_SENSOR(model_name)
99 SUB_TEXT_SENSOR(error_code)
100 void set_charging_state(
bool state);
120 void halt_(
const LogString *reason);
This class simplifies creating components that periodically check a state.
StringRef is a reference to a string owned by something else.
espbt::ClientState node_state
void write_frame_(const uint8_t *frame, size_t len)
void set_max_current(float current)
void halt_(const LogString *reason)
void set_time_id(time::RealTimeClock *time_id)
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
void dump_config() override
uint8_t max_current_limit_
void set_pin(uint32_t pin)
SUB_SENSOR(power) SUB_SENSOR(energy) SUB_SENSOR(charging_time) SUB_SENSOR(charger_state) SUB_SENSOR(max_current) SUB_NUMBER(max_current) SUB_TEXT_SENSOR(serial_number) SUB_TEXT_SENSOR(fw_version) SUB_TEXT_SENSOR(bt_fw_version) SUB_TEXT_SENSOR(model_name) SUB_TEXT_SENSOR(error_code) void set_charging_state(bool state)
void advance_to_(DeltaState next)
void send_next_state_command_()
void handle_frame_(const uint8_t *frame, size_t len)
bool pairing_in_progress_
std::array< uint8_t, MAX_FRAME_LEN > rx_buffer_
void drop_rx_bytes_(size_t count)
uint8_t pairing_attempts_
void send_frame_(const uint8_t *body, size_t len)
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
time::RealTimeClock * time_id_
DeltaWallbox(const char *user, const char *password)
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
uint64_t read_be(const uint8_t *p, size_t n)
@ DELTA_STATE_GET_LOGIN_RESULT
@ DELTA_STATE_GET_BT_FW_VERSION
@ DELTA_STATE_GET_CHARGER_FW_VERSION
@ DELTA_STATE_GET_LOGIN_USER
@ DELTA_STATE_CHECK_PAIRING
@ DELTA_STATE_GET_SERIAL_NUMBER
@ DELTA_STATE_GET_LOGIN_RESULT0
@ DELTA_STATE_SEND_LOGIN_CREDENTIALS
@ DELTA_STATE_GET_LOGIN_ROLE
ChargingInfo decode_charging_info(const uint8_t *frame)
constexpr T encode_value(const uint8_t *bytes)
Encode a value from its constituent bytes (from most to least significant) in an array with length si...