mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 19:06:37 +00:00
[core] Add format_hex_pretty_to buffer helper and reduce code duplication (#12687)
This commit is contained in:
@@ -123,10 +123,11 @@ void ZWaveProxy::process_uart_() {
|
||||
}
|
||||
|
||||
void ZWaveProxy::dump_config() {
|
||||
char hex_buf[format_hex_pretty_size(ZWAVE_HOME_ID_SIZE)];
|
||||
ESP_LOGCONFIG(TAG,
|
||||
"Z-Wave Proxy:\n"
|
||||
" Home ID: %s",
|
||||
format_hex_pretty(this->home_id_.data(), this->home_id_.size(), ':', false).c_str());
|
||||
format_hex_pretty_to(hex_buf, this->home_id_.data(), this->home_id_.size()));
|
||||
}
|
||||
|
||||
void ZWaveProxy::api_connection_authenticated(api::APIConnection *conn) {
|
||||
@@ -167,7 +168,8 @@ bool ZWaveProxy::set_home_id(const uint8_t *new_home_id) {
|
||||
return false; // No change
|
||||
}
|
||||
std::memcpy(this->home_id_.data(), new_home_id, this->home_id_.size());
|
||||
ESP_LOGI(TAG, "Home ID: %s", format_hex_pretty(this->home_id_.data(), this->home_id_.size(), ':', false).c_str());
|
||||
char hex_buf[format_hex_pretty_size(ZWAVE_HOME_ID_SIZE)];
|
||||
ESP_LOGI(TAG, "Home ID: %s", format_hex_pretty_to(hex_buf, this->home_id_.data(), this->home_id_.size()));
|
||||
this->home_id_ready_ = true;
|
||||
return true; // Home ID was changed
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
namespace esphome::zwave_proxy {
|
||||
|
||||
static constexpr size_t MAX_ZWAVE_FRAME_SIZE = 257; // Maximum Z-Wave frame size
|
||||
static constexpr size_t ZWAVE_HOME_ID_SIZE = 4; // Z-Wave Home ID size in bytes
|
||||
|
||||
enum ZWaveResponseTypes : uint8_t {
|
||||
ZWAVE_FRAME_TYPE_ACK = 0x06,
|
||||
@@ -73,8 +74,8 @@ class ZWaveProxy : public uart::UARTDevice, public Component {
|
||||
|
||||
// Pre-allocated message - always ready to send
|
||||
api::ZWaveProxyFrame outgoing_proto_msg_;
|
||||
std::array<uint8_t, MAX_ZWAVE_FRAME_SIZE> buffer_; // Fixed buffer for incoming data
|
||||
std::array<uint8_t, 4> home_id_{0, 0, 0, 0}; // Fixed buffer for home ID
|
||||
std::array<uint8_t, MAX_ZWAVE_FRAME_SIZE> buffer_; // Fixed buffer for incoming data
|
||||
std::array<uint8_t, ZWAVE_HOME_ID_SIZE> home_id_{}; // Fixed buffer for home ID
|
||||
|
||||
// Pointers and 32-bit values (aligned together)
|
||||
api::APIConnection *api_connection_{nullptr}; // Current subscribed client
|
||||
|
||||
Reference in New Issue
Block a user