2#ifdef USE_PACKET_INTERFACE_LZSS
11 size_t dictionary_size, uint8_t check, uint8_t *buffers, uint16_t *chains)
12 :
PacketInterface(max_packet_size != 0 ? max_packet_size : packet_size(lower->get_max_packet_size())),
13 check_(check & HEADER_CHECK_MASK),
15 codec_(dictionary, dictionary_size),
24 LOG_STR(
"max_packet_size too small for the configured layers")))
27 LOG_STR(
"Not enough memory for the packet buffers")))
37 "LZSS Compression on '%s':\n"
38 " Max Packet Size: %zu\n"
39 " Dictionary Size: %zu\n"
40 " Dictionary Check: 0x%02X",
53 ESP_LOGW(TAG,
"%s: Packet of %zu bytes is larger than %zu", this->
name_, size, this->
max_packet_size_);
58 in = data.as_span().data();
68 ESP_LOGV(TAG,
"%s: Packet of %zu bytes compressed to %zu", this->
name_, size,
length);
73 ESP_LOGW(TAG,
"%s: Packet of %zu bytes does not compress to %zu", this->
name_, size, room);
76 uint8_t header = this->
check_;
82 if (!data.is_contiguous()) {
83 ESP_LOGW(TAG,
"%s: Packet split across buffers is not supported", this->
name_);
87 auto packet = data.as_span();
89 ESP_LOGV(TAG,
"%s: Packet of %zu bytes with another dictionary dropped", this->
name_, packet.size());
97 ESP_LOGV(TAG,
"%s: Packet of %zu bytes is larger than %zu", this->
name_, size, this->
max_packet_size_);
106 if (length == SIZE_MAX) {
107 ESP_LOGV(TAG,
"%s: Malformed packet of %zu bytes dropped", this->
name_, packet.size());
bool ESPHOME_ALWAYS_INLINE setup_check(bool ok)
Marks the component failed with message (default "Communication failed") unless ok; returns ok.
size_t compress(const uint8_t *in, size_t size, uint8_t *out, size_t capacity, uint16_t *chains) const
Compress size bytes into out, which holds capacity bytes, using chains (CHAIN_WORDS words) as working...
size_t dictionary_size() const
size_t expand(const uint8_t *in, size_t size, uint8_t *out, size_t capacity) const
Expand size bytes into out, which holds capacity bytes; returns the length, or SIZE_MAX if the data i...
static constexpr uint8_t HEADER_COMPRESSED
The bit flagging compressed data, and the dictionary check in the bits below it.
bool send_to_interface(const PacketBuffer &data, const PacketMetaData &meta_data) override
void dump_config() override
void receive_(const PacketBuffer &data, const PacketMetaData &meta_data)
static constexpr uint8_t HEADER_CHECK_MASK
static constexpr size_t HEADER_SIZE
bool send_(const PacketBuffer &data, const PacketMetaData &meta_data)
LzssCompression(PacketInterface *lower, size_t max_packet_size, const uint8_t *dictionary, size_t dictionary_size, uint8_t check, uint8_t *buffers, uint16_t *chains)
A buffer class that efficiently represents a composite buffer with three sections:
size_t size() const
Get the total size of the buffer.
bool is_contiguous() const
Check if all the data is held in the pre-buffer, so it can be read as one span.
A class that will transport data to and from an abstract channel.
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.
void stack_on_(PacketInterface *lower, Capability capability)
Called by a layer's constructor to record itself as the layer above lower, adding its own capability.
virtual bool send_to_interface(const PacketBuffer &data, const PacketMetaData &meta_data)=0
Method to be implemented by child classes to send data to the interface.
bool send_exclusive_(F &&send)
For a layer that sends from a buffer of its own: runs send, or returns false if a send through this l...
void add_packet_interface_listener(F &&callback)
Add a listener that will be called when data is received.
const size_t max_packet_size_
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...
ESPHOME_LOG_TAG(TAG, "packet_interface.addressing")
T clamp_at_most(T value, U max)