ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
packet_interface.cpp
Go to the documentation of this file.
1#include "packet_interface.h"
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "packet_interface");
7
8// Packets in a row that cannot be understood before the mismatch is logged
9static constexpr uint8_t MISMATCH_COUNT = 10;
10
12 ESP_LOGCONFIG(TAG,
13 "Packet Interface '%s':\n"
14 " Max Packet Size: %zu",
15 this->name_, this->get_max_packet_size());
16}
17
19#ifdef ESPHOME_LOG_HAS_VERBOSE
20 static constexpr size_t LOG_BYTES = 24;
21 uint8_t head[LOG_BYTES];
22 size_t len = data.copy_to(head, LOG_BYTES);
23 ESP_LOGV_HEX(TAG, head, len, LOG_BYTES, "%s: received %zu bytes %s", this->name_, data.size());
24#endif
25 this->callback_.call(data, meta_data);
26}
27
28void PacketInterface::note_received_(bool understood) {
29 if (understood) {
30 this->not_understood_count_ = 0;
31 } else if (this->not_understood_count_ < MISMATCH_COUNT) {
33 if (this->not_understood_count_ == MISMATCH_COUNT) {
34 ESP_LOGW(TAG, "%s: %u packets in a row could not be understood; check that both ends have the same layers",
35 this->name_, MISMATCH_COUNT);
36 }
37 }
38}
39} // namespace esphome::packet_interface
A buffer class that efficiently represents a composite buffer with three sections:
size_t size() const
Get the total size of the buffer.
size_t get_max_packet_size() const
The largest packet this layer accepts; fixed when the layer is constructed.
void note_received_(bool understood)
Called by a layer for each received packet it understood, or could not make sense of.
LazyCallbackManager< void(const PacketBuffer &, const PacketMetaData &)> callback_
void on_receive_from_interface_(const PacketBuffer &data, const PacketMetaData &meta_data)
This function should be called by implementing classes with received data to be passed to any listene...
A struct to hold metadata about a packet.
ESPHOME_LOG_TAG(TAG, "packet_interface.session")
const void size_t len
Definition hal.h:68