ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
packet_interface_transport.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "packet_interface.transport");
7
9 PacketTransport::setup();
10 this->interface_ = this->interface_->top();
12 [this](const PacketBuffer &data, const PacketMetaData &) { this->receive_(data); });
13}
14
16 // Packet interface layers deliver packets in one piece
17 if (!data.is_contiguous()) {
18 ESP_LOGW(TAG, "Packet split across buffers is not supported");
19 return;
20 }
21 this->process_(data.as_span());
22}
23
24void PacketInterfaceTransport::send_packet(const std::vector<uint8_t> &buf) const {
25 if (!this->interface_->send_to_interface(PacketBuffer(buf), {}))
26 ESP_LOGD(TAG, "Failed to send packet of %zu bytes", buf.size());
27}
28
29} // namespace esphome::packet_interface
A buffer class that efficiently represents a composite buffer with three sections:
std::span< const uint8_t > as_span() const
Get the data as one span.
PacketInterface * top()
The topmost layer stacked on this one, or this one if nothing is stacked on it.
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.
void add_packet_interface_listener(F &&callback)
Add a listener that will be called when data is received.
void send_packet(const std::vector< uint8_t > &buf) const override
A struct to hold metadata about a packet.
void process_(std::span< const uint8_t > data)
Process a received packet.
ESPHOME_LOG_TAG(TAG, "packet_interface.session")