6 #include <satcat5/eth_dispatch.h>
11 namespace eth = satcat5::eth;
16 static const unsigned DEBUG_VERBOSE = 0;
20 constexpr
unsigned ETH_HEADER_BYTES = SATCAT5_VLAN_ENABLE ? 18 : 14;
29 , m_reply_dstaddr(eth::MACADDR_NONE)
30 , m_reply_srcaddr(eth::MACADDR_NONE)
31 , m_reply_type(eth::ETYPE_NONE)
32 , m_reply_vtag(eth::VTAG_NONE)
33 , m_default_vid(eth::VTAG_NONE)
38 #if SATCAT5_ALLOW_DELETION
50 if (DEBUG_VERBOSE > 1) {
51 if (SATCAT5_VLAN_ENABLE) {
61 if (SATCAT5_VLAN_ENABLE) {
66 return open_write(m_reply_srcaddr, etype, vtag);
79 if (DEBUG_VERBOSE > 0)
83 if (dst == satcat5::eth::MACADDR_NONE)
return 0;
87 if (type.
value < 1536)
return 0;
93 SATCAT5_CLOCK->busywait_usec(20);
104 if (SATCAT5_VLAN_ENABLE && vtag.
value) {
105 m_dst->
write_obj(satcat5::eth::ETYPE_VTAG);
123 bool pending = m_src->
read_obj(hdr);
125 if (DEBUG_VERBOSE > 0)
126 log::Log(log::DEBUG,
"EthDispatch: data_rcvd ").
write(pending ?
"OK" :
"Error");
129 m_reply_dstaddr = hdr.
dst;
130 m_reply_srcaddr = hdr.
src;
131 m_reply_type = hdr.
type;
135 #if SATCAT5_VLAN_ENABLE
137 if (pending && hdr.
vtag.
vid()) {
152 if (pending && DEBUG_VERBOSE > 1)
Implemention of "net::Dispatch" for Ethernet frames.
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
void set_macaddr(const satcat5::eth::MacAddr &macaddr)
Set the local MAC-address.
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
satcat5::io::Writeable * open_reply(const satcat5::net::Type &type, unsigned len) override
Send a reply to the most recent received frame.
satcat5::io::Writeable * open_write(const satcat5::eth::MacAddr &dst, const satcat5::eth::MacType &type, satcat5::eth::VlanTag vtag=satcat5::eth::VTAG_NONE)
Send a frame to the designated Ethernet address/VLAN.
Abstract API for reading byte-streams and packets.
bool read_obj(T &t)
Templated wrapper for any object with the following method: bool read_from(satcat5::io::Readable* rd)...
virtual void read_finalize()
Consume any remaining bytes in this frame, if applicable.
virtual void set_callback(satcat5::io::EventListener *callback)
Update registered callback for data_rcvd() events.
virtual unsigned get_read_ready() const =0
How many bytes can be read without blocking?
Abstract API for writing byte-streams and packets.
virtual unsigned get_write_space() const =0
How many bytes can be written without blocking?
void write_obj(const T &obj)
Templated wrapper for any object with the following method: void write_to(satcat5::io::Writeable* wr)...
The Log class creates and formats one log message.
Log & write(const char *str)
Formatting methods for various data types.
Dispatch()
Constructor and destructor access restricted to children.
bool deliver(const satcat5::net::Type &type, satcat5::io::Readable *src, unsigned len)
Deliver current message by calling Protocol::frame_rcvd(...).
I/O interface core definitions.
Diagnostic logging to UART and/or Ethernet ports.
An Ethernet MAC address (with serializable interface).
EtherType field (uint16) is used a protocol-ID [1536..65535].
u16 value
The 16-bit value is stored in processor-native order.
Header contents for an 802.1Q Virtual-LAN tag.
u16 value
The 16-bit value holds VID, DEI, and PCP fields.
u16 vid() const
Accessors for each individual field.
Multipurpose filter for matching fields in network packets.
u16 as_u16() const
Accessors for m_value.
void as_pair(u16 &a, u16 &b) const
Sets the given parameter to m_value.
u32 as_u32() const
Accessors for m_value.
TimeRef and TimeVal define the API for monotonic timers.