ESPHome 2025.10.0-dev
Loading...
Searching...
No Matches
zwave_proxy.h
Go to the documentation of this file.
1#pragma once
2
8
9#include <array>
10
11namespace esphome {
12namespace zwave_proxy {
13
14static constexpr size_t MAX_ZWAVE_FRAME_SIZE = 257; // Maximum Z-Wave frame size
15
24
37
38enum ZWaveProxyFeature : uint32_t {
40};
41
42class ZWaveProxy : public uart::UARTDevice, public Component {
43 public:
44 ZWaveProxy();
45
46 void setup() override;
47 void loop() override;
48 void dump_config() override;
49 float get_setup_priority() const override;
50 bool can_proceed() override;
51
54
56 uint32_t get_home_id() {
57 return encode_uint32(this->home_id_[0], this->home_id_[1], this->home_id_[2], this->home_id_[3]);
58 }
59
60 void send_frame(const uint8_t *data, size_t length);
61
62 protected:
63 void send_simple_command_(uint8_t command_id);
64 bool parse_byte_(uint8_t byte); // Returns true if frame parsing was completed (a frame is ready in the buffer)
65 void parse_start_(uint8_t byte);
66 bool response_handler_();
67 void process_uart_(); // Process all available UART data
68
69 // Pre-allocated message - always ready to send
71 std::array<uint8_t, MAX_ZWAVE_FRAME_SIZE> buffer_; // Fixed buffer for incoming data
72 std::array<uint8_t, 4> home_id_{0, 0, 0, 0}; // Fixed buffer for home ID
73
74 // Pointers and 32-bit values (aligned together)
75 api::APIConnection *api_connection_{nullptr}; // Current subscribed client
76 uint32_t setup_time_{0}; // Time when setup() was called
77
78 // 8-bit values (grouped together to minimize padding)
79 uint8_t buffer_index_{0}; // Index for populating the data buffer
80 uint8_t end_frame_after_{0}; // Payload reception ends after this index
81 uint8_t last_response_{0}; // Last response type sent
83 bool in_bootloader_{false}; // True if the device is detected to be in bootloader mode
84 bool home_id_ready_{false}; // True when home ID has been received from Z-Wave module
85};
86
87extern ZWaveProxy *global_zwave_proxy; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
88
89} // namespace zwave_proxy
90} // namespace esphome
void zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type)
api::ZWaveProxyFrame outgoing_proto_msg_
Definition zwave_proxy.h:70
void send_frame(const uint8_t *data, size_t length)
uint32_t get_feature_flags() const
Definition zwave_proxy.h:55
void send_simple_command_(uint8_t command_id)
api::APIConnection * get_api_connection()
Definition zwave_proxy.h:53
ZWaveParsingState parsing_state_
Definition zwave_proxy.h:82
std::array< uint8_t, MAX_ZWAVE_FRAME_SIZE > buffer_
Definition zwave_proxy.h:71
std::array< uint8_t, 4 > home_id_
Definition zwave_proxy.h:72
api::APIConnection * api_connection_
Definition zwave_proxy.h:75
float get_setup_priority() const override
uint8_t type
ZWaveProxy * global_zwave_proxy
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
Definition helpers.h:182
uint16_t length
Definition tt21100.cpp:0