1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

Merge branch 'packet_transport_hex' into integration

This commit is contained in:
J. Nick Koston
2025-12-31 21:54:21 -10:00

View File

@@ -1,11 +1,15 @@
#include "esphome/core/log.h"
#include "esphome/core/application.h"
#include "esphome/core/helpers.h"
#include "packet_transport.h"
#include "esphome/components/xxtea/xxtea.h"
namespace esphome {
namespace packet_transport {
// Maximum bytes to log in hex output (168 * 3 = 504, under TX buffer size of 512)
static constexpr size_t PACKET_MAX_LOG_BYTES = 168;
/**
* Structure of a data packet; everything is little-endian
*
@@ -263,7 +267,10 @@ void PacketTransport::flush_() {
xxtea::encrypt((uint32_t *) (encode_buffer.data() + header_len), len / 4,
(uint32_t *) this->encryption_key_.data());
}
ESP_LOGVV(TAG, "Sending packet %s", format_hex_pretty(encode_buffer.data(), encode_buffer.size()).c_str());
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
char hex_buf[format_hex_pretty_size(PACKET_MAX_LOG_BYTES)];
#endif
ESP_LOGVV(TAG, "Sending packet %s", format_hex_pretty_to(hex_buf, encode_buffer.data(), encode_buffer.size()));
this->send_packet(encode_buffer);
}
@@ -505,8 +512,9 @@ void PacketTransport::process_(const std::vector<uint8_t> &data) {
}
if (decoder.get(byte) == DECODE_OK) {
ESP_LOGW(TAG, "Unknown key %X", byte);
char hex_buf[format_hex_pretty_size(PACKET_MAX_LOG_BYTES)];
ESP_LOGD(TAG, "Buffer pos: %zu contents: %s", data.size() - decoder.get_remaining_size(),
format_hex_pretty(data).c_str());
format_hex_pretty_to(hex_buf, data.data(), data.size()));
}
break;
}