6 #include <satcat5/eth_chat.h>
7 #include <satcat5/eth_dispatch.h>
10 namespace eth = satcat5::eth;
11 namespace log = satcat5::log;
12 namespace net = satcat5::net;
23 : eth::
Protocol(dispatch, eth::ETYPE_CHAT_TEXT, vtag)
24 , m_reply_type(vtag.value, eth::ETYPE_CHAT_TEXT.value)
25 , m_username(username)
26 , m_userlen(strlen(username))
30 if (dispatch->macaddr() == eth::MACADDR_NONE)
return;
41 if (wr) {wr->write_u16((u16)msg_bytes);}
48 eth::MACADDR_BROADCAST,
49 eth::ETYPE_CHAT_HEARTBEAT,
59 const eth::MacAddr& dst,
unsigned nbytes,
const char* msg)
61 Writeable* wr = open_inner(dst, eth::ETYPE_CHAT_TEXT, nbytes);
70 const eth::MacAddr& dst,
unsigned nbytes,
const void* msg)
72 Writeable* wr = open_inner(dst, eth::ETYPE_CHAT_DATA, nbytes);
83 if (wr) wr->write_u16(len);
89 return open_inner(dst, eth::ETYPE_CHAT_TEXT, len);
105 if (!m_callback)
return;
109 unsigned len = src.read_u16();
134 const char* pstr = log::priority_label(priority);
135 unsigned plen = strlen(pstr);
136 unsigned total = plen + nbytes + 1;
155 #if SATCAT5_ALLOW_DELETION
156 ChatEcho::~ChatEcho()
Service for echoing ChatProto text messages.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
ChatEcho(satcat5::eth::ChatProto *service)
Bind to the designated ChatProto object.
Protocol handler for a simple text-messaging protocol This class implements a simple as-hoc text-mess...
void send_data(const satcat5::eth::MacAddr &dst, unsigned nbytes, const void *msg)
Send machine-readable data.
satcat5::io::Writeable * open_reply(unsigned len)
Open a reply to the sender of the most recent message.
void send_text(const satcat5::eth::MacAddr &dst, unsigned nbytes, const char *msg)
Send a human-readable text message.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
void set_callback(satcat5::net::Protocol *callback)
Set callback for processing incoming messages.
void timer_event() override
Child class MUST override this method.
satcat5::eth::MacAddr local_mac() const
Get the local device's source MAC address.
void send_heartbeat()
Send a heartbeat message indicating our presence on the LAN.
satcat5::eth::MacAddr reply_mac() const
Source MAC address of the most recent received message.
satcat5::io::Writeable * open_text(const satcat5::eth::MacAddr &dst, unsigned len)
As "open_reply", but to any destination address.
Implemention of "net::Dispatch" for Ethernet frames.
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.
Service for forwarding Log events as text messages.
void log_event(s8 priority, unsigned nbytes, const char *msg) override
Event handler for the log::EventHandler API.
LogToChat(satcat5::eth::ChatProto *dst, const satcat5::eth::MacAddr &addr=satcat5::eth::MACADDR_BROADCAST)
Bind to the designated ChatProto object.
Accept incoming Ethernet packets by EtherType.
satcat5::eth::Dispatch *const m_iface
Parent interface (e.g., for address and I/O)
Limited read of next N bytes.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
unsigned copy_to(satcat5::io::Writeable *dst)
Copy data to a Writeable object, without finalizing.
Abstract API for writing byte-streams and packets.
virtual void write_bytes(unsigned nbytes, const void *src)
Write 0 or more bytes from a buffer.
void write_u8(u8 data)
One of many functions for writing integer/floating point values, see details.
void write_str(const char *str)
Write the contents of a null-terminated string.
virtual bool write_finalize()
Mark end of frame and release temporary working data.
virtual void frame_rcvd(satcat5::io::LimitedRead &src)=0
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
void timer_every(unsigned msec)
Configure a repeating notification every X milliseconds.
An Ethernet MAC address (with serializable interface).
EtherType field (uint16) is used a protocol-ID [1536..65535].
Header contents for an 802.1Q Virtual-LAN tag.