2#ifdef USE_PACKET_INTERFACE_BASIC_ADDRESSING
16 "Basic Addressing on '%s':\n"
30 if (!data.is_contiguous()) {
31 ESP_LOGW(TAG,
"%s: Packet split across buffers is not supported", this->
link_->
get_name());
34 auto packet = data.as_span();
36 ESP_LOGV(TAG,
"%s: Packet of %zu bytes is shorter than the address header, dropped", this->
link_->
get_name(),
46 for (
auto *port : this->
ports_) {
47 if (port->destination_ == source) {
50 broadcast_port = port;
56 if (broadcast_port !=
nullptr && (destination ==
BROADCAST_ADDRESS || source_port ==
nullptr))
57 target = broadcast_port;
58 if (target ==
nullptr) {
59 ESP_LOGV(TAG,
"%s: Packet from 0x%04X dropped", this->
link_->
get_name(), source);
71 addressing_(addressing),
72 destination_(destination) {
85 if (chosen != 0 && chosen != destination) {
91 "%s: Packet for 0x%04X refused; only the broadcast port sends to a chosen address, and not to "
104 "Addressing Port '%s':\n"
105 " Max Packet Size: %zu",
108 ESP_LOGCONFIG(TAG,
" Destination: broadcast");
110 ESP_LOGCONFIG(TAG,
" Destination: 0x%04X", this->
destination_);
The bottom of the stack of layers for one destination, or for broadcast, on an addressed channel.
bool send_to_interface(const PacketBuffer &data, const PacketMetaData &meta_data) override
Sends to the port's destination.
BasicAddressing * addressing_
const uint16_t destination_
AddressingPort(BasicAddressing *addressing, uint16_t destination, bool only_port)
With only_port, the port is the top of the link, so top() on the link reaches this port's stack.
void dump_config() override
An addressing layer for channels shared by several devices, such as an RS485 bus or a LoRa radio.
static constexpr size_t HEADER_SIZE
Destination and source addresses.
PacketInterface * get_link() const
bool send(const PacketBuffer &data, const PacketMetaData &meta_data, uint16_t destination)
Sends data to destination, which the port has checked.
void add_port(AddressingPort *port)
void receive_(const PacketBuffer &data, const PacketMetaData &meta_data)
void dump_config() override
StaticVector< AddressingPort *, PACKET_INTERFACE_ADDRESSING_PORT_COUNT > ports_
static constexpr uint16_t BROADCAST_ADDRESS
uint16_t get_address() const
A buffer class that efficiently represents a composite buffer with three sections:
A class that will transport data to and from an abstract channel.
const char * get_name() const
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.
void add_packet_interface_listener(F &&callback)
Add a listener that will be called when data is received.
void inherit_from_(PacketInterface *lower, Capability capability)
Takes the name and capabilities of lower without becoming its top, for one of several stacks on a lin...
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")
constexpr size_t remaining_packet_size(size_t size, size_t used)
The room left for a packet of size bytes after used bytes, or 0 if it is too small.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
constexpr uint8_t * put_le16(uint8_t *dst, uint16_t value)