ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
basic_addressing.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef USE_PACKET_INTERFACE_BASIC_ADDRESSING
6#include "packet_interface.h"
7
9
10class AddressingPort;
11
25class BasicAddressing : public Component {
26 public:
27 static constexpr uint16_t BROADCAST_ADDRESS = 0xFFFF;
29 static constexpr size_t HEADER_SIZE = 4;
30
32
33 void setup() override;
34 void dump_config() override;
35
36 PacketInterface *get_link() const { return this->link_; }
37 uint16_t get_address() const { return this->address_; }
38 void add_port(AddressingPort *port) { this->ports_.push_back(port); }
40 bool send(const PacketBuffer &data, const PacketMetaData &meta_data, uint16_t destination);
41
42 protected:
43 void receive_(const PacketBuffer &data, const PacketMetaData &meta_data);
44
46 const uint16_t address_;
48};
49
52 public:
54 AddressingPort(BasicAddressing *addressing, uint16_t destination, bool only_port);
55
56 void dump_config() override;
62 bool send_to_interface(const PacketBuffer &data, const PacketMetaData &meta_data) override;
63 size_t get_send_capacity() const override { return this->addressing_->get_link()->get_send_capacity(); }
64 uint16_t get_destination() const { return this->destination_; }
65
66 protected:
67 friend class BasicAddressing;
68
69 // First, so it fills the spare byte at the end of PacketInterface
72 const uint16_t destination_;
73};
74
75} // namespace esphome::packet_interface
76#endif
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:323
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.
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.
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.
bool send(const PacketBuffer &data, const PacketMetaData &meta_data, uint16_t destination)
Sends data to destination, which the port has checked.
void receive_(const PacketBuffer &data, const PacketMetaData &meta_data)
StaticVector< AddressingPort *, PACKET_INTERFACE_ADDRESSING_PORT_COUNT > ports_
BasicAddressing(PacketInterface *link, uint16_t address)
A buffer class that efficiently represents a composite buffer with three sections:
A class that will transport data to and from an abstract channel.
virtual size_t get_send_capacity() const
How many packets send_to_interface() would accept now, so a layer above can tell before sending a ser...
A struct to hold metadata about a packet.