10static const char *
const TAG =
"zwave_proxy";
12static constexpr uint8_t ZWAVE_COMMAND_GET_NETWORK_IDS = 0x20;
14static constexpr uint8_t ZWAVE_COMMAND_TYPE_RESPONSE = 0x01;
15static constexpr uint8_t ZWAVE_MIN_GET_NETWORK_IDS_LENGTH = 9;
16static constexpr uint32_t HOME_ID_TIMEOUT_MS = 100;
18static uint8_t calculate_frame_checksum(
const uint8_t *data, uint8_t
length) {
23 for (uint8_t i = 1; i <
length - 1; i++) {
49 ESP_LOGV(TAG,
"Handled response during setup");
63 ESP_LOGW(TAG,
"Timeout reading Home ID during setup");
72 ESP_LOGV(TAG,
"Handled late response");
75 ESP_LOGW(TAG,
"Subscriber disconnected");
98 if (this->
buffer_[3] == ZWAVE_COMMAND_GET_NETWORK_IDS && this->
buffer_[2] == ZWAVE_COMMAND_TYPE_RESPONSE &&
102 std::memcpy(this->
home_id_.data(), this->buffer_.data() + 4, this->home_id_.size());
104 ESP_LOGI(TAG,
"Home ID: %s",
107 ESP_LOGV(TAG,
"Sending to client: %s", YESNO(this->
api_connection_ !=
nullptr));
129 ESP_LOGE(TAG,
"Only one API subscription is allowed at a time");
133 ESP_LOGV(TAG,
"API connection is now subscribed");
137 ESP_LOGV(TAG,
"API connection is not subscribed");
143 ESP_LOGW(TAG,
"Unknown request type: %d",
type);
150 ESP_LOGV(TAG,
"Skipping sending duplicate response: 0x%02X", data[0]);
161 uint8_t cmd[] = {0x01, 0x03, 0x00, command_id, 0x00};
162 cmd[4] = calculate_frame_checksum(cmd,
sizeof(cmd));
167 bool frame_completed =
false;
175 ESP_LOGW(TAG,
"Invalid LENGTH: %u",
byte);
179 ESP_LOGVV(TAG,
"Received LENGTH: %u",
byte);
187 ESP_LOGVV(TAG,
"Received TYPE: 0x%02X",
byte);
192 ESP_LOGVV(TAG,
"Received COMMAND ID: 0x%02X",
byte);
197 ESP_LOGVV(TAG,
"Received PAYLOAD: 0x%02X",
byte);
204 auto checksum = calculate_frame_checksum(this->
buffer_.data(), this->buffer_index_);
205 ESP_LOGVV(TAG,
"CHECKSUM Received: 0x%02X - Calculated: 0x%02X",
byte,
checksum);
207 ESP_LOGW(TAG,
"Bad checksum: expected 0x%02X, got 0x%02X",
checksum,
byte);
212 frame_completed =
true;
221 frame_completed =
true;
228 ESP_LOGW(TAG,
"Bad parsing state; resetting");
232 return frame_completed;
240 ESP_LOGVV(TAG,
"Received START");
242 ESP_LOGD(TAG,
"Exited bootloader mode");
249 ESP_LOGVV(TAG,
"Received BL_MENU");
251 ESP_LOGD(TAG,
"Entered bootloader mode");
258 ESP_LOGVV(TAG,
"Received BL_BEGIN_UPLOAD");
261 ESP_LOGVV(TAG,
"Received ACK");
264 ESP_LOGW(TAG,
"Received NAK");
267 ESP_LOGW(TAG,
"Received CAN");
270 ESP_LOGW(TAG,
"Unrecognized START: 0x%02X",
byte);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
bool is_connection_setup() override
bool send_message(const ProtoMessage &msg, uint8_t message_type)
static constexpr uint8_t MESSAGE_TYPE
bool read_byte(uint8_t *data)
void write_byte(uint8_t data)
void write_array(const uint8_t *data, size_t len)
void zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type)
api::ZWaveProxyFrame outgoing_proto_msg_
void send_frame(const uint8_t *data, size_t length)
bool parse_byte_(uint8_t byte)
void parse_start_(uint8_t byte)
void send_simple_command_(uint8_t command_id)
bool can_proceed() override
ZWaveParsingState parsing_state_
std::array< uint8_t, MAX_ZWAVE_FRAME_SIZE > buffer_
void dump_config() override
std::array< uint8_t, 4 > home_id_
api::APIConnection * api_connection_
float get_setup_priority() const override
@ ZWAVE_PROXY_REQUEST_TYPE_SUBSCRIBE
@ ZWAVE_PROXY_REQUEST_TYPE_UNSUBSCRIBE
const float BEFORE_CONNECTION
For components that should be initialized after WiFi and before API is connected.
@ ZWAVE_FRAME_TYPE_BL_MENU
@ ZWAVE_FRAME_TYPE_BL_BEGIN_UPLOAD
@ ZWAVE_PARSING_STATE_WAIT_COMMAND_ID
@ ZWAVE_PARSING_STATE_WAIT_LENGTH
@ ZWAVE_PARSING_STATE_WAIT_CHECKSUM
@ ZWAVE_PARSING_STATE_WAIT_PAYLOAD
@ ZWAVE_PARSING_STATE_SEND_ACK
@ ZWAVE_PARSING_STATE_SEND_NAK
@ ZWAVE_PARSING_STATE_READ_BL_MENU
@ ZWAVE_PARSING_STATE_WAIT_TYPE
@ ZWAVE_PARSING_STATE_SEND_CAN
@ ZWAVE_PARSING_STATE_WAIT_START
ZWaveProxy * global_zwave_proxy
Providing packet encoding functions for exchanging data with a remote host.
bool api_is_connected()
Return whether the node has at least one client connected to the native API.
std::string format_hex_pretty(const uint8_t *data, size_t length, char separator, bool show_length)
Format a byte array in pretty-printed, human-readable hex format.
Application App
Global storage of Application pointer - only one Application can exist.