SatCat5
satcat5::eth::ChatProto Class Referencefinal

Detailed Description

Protocol handler for a simple text-messaging protocol This class implements a simple as-hoc text-messaging protocol using raw Ethernet frames.

This is used by some SatCat5 example designs, such as "examples/arty_managed" and "test/chat_client". This class implements both transmit and receive functions.

Definition at line 25 of file eth_chat.h.

#include <eth_chat.h>

Inheritance diagram for satcat5::eth::ChatProto:
[legend]
Collaboration diagram for satcat5::eth::ChatProto:
[legend]

Public Member Functions

 ChatProto (satcat5::eth::Dispatch *dispatch, const char *username, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
 Bind this handler to a specified Ethernet interface.
 
void set_callback (satcat5::net::Protocol *callback)
 Set callback for processing incoming messages.
 
void send_heartbeat ()
 Send a heartbeat message indicating our presence on the LAN.
 
void send_text (const satcat5::eth::MacAddr &dst, unsigned nbytes, const char *msg)
 Send a human-readable text message.
 
void send_data (const satcat5::eth::MacAddr &dst, unsigned nbytes, const void *msg)
 Send machine-readable data. More...
 
satcat5::io::Writeableopen_reply (unsigned len)
 Open a reply to the sender of the most recent message.
 
satcat5::io::Writeableopen_text (const satcat5::eth::MacAddr &dst, unsigned len)
 As "open_reply", but to any destination address.
 
satcat5::eth::MacAddr local_mac () const
 Get the local device's source MAC address.
 
satcat5::eth::MacAddr reply_mac () const
 Source MAC address of the most recent received message.
 
void timer_once (unsigned msec)
 Configure a one-time notification after X milliseconds.
 
void timer_every (unsigned msec)
 Configure a repeating notification every X milliseconds.
 
void timer_stop ()
 Stop all future notifications.
 
unsigned timer_interval () const
 Accessor for recurring timer interval, if one is set.
 
unsigned timer_remaining () const
 Accessor for time to next event, if one is set.
 

Static Public Member Functions

static unsigned count_timer ()
 Count all objects of this type, including idle timers.
 

Protected Member Functions

satcat5::io::Writeableopen_inner (const satcat5::eth::MacAddr &dst, const satcat5::eth::MacType &typ, unsigned msg_bytes)
 
void frame_rcvd (satcat5::io::LimitedRead &src) override
 Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value. More...
 
void timer_event () override
 Child class MUST override this method.
 

Protected Attributes

const satcat5::net::Type m_reply_type
 
const char *const m_username
 
const unsigned m_userlen
 
const satcat5::eth::VlanTag m_vtag
 
satcat5::net::Protocolm_callback
 
satcat5::eth::Dispatch *const m_iface
 Parent interface (e.g., for address and I/O)
 
const satcat5::eth::MacType m_etype
 
satcat5::net::Type m_filter
 Incoming packet filter.
 

Private Member Functions

void query (unsigned elapsed_msec)
 

Private Attributes

satcat5::net::Protocolm_next
 Linked list of Protocols.
 
unsigned m_trem
 
unsigned m_tnext
 

Member Function Documentation

◆ frame_rcvd()

void ChatProto::frame_rcvd ( satcat5::io::LimitedRead src)
overrideprotectedvirtual

Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.

The child class SHOULD read the frame contents from the provided "src" object, which is only valid until the function returns.

To send a reply:

  • Call m_iface->open_reply() to obtain a Writable object. (This also writes out any applicable frame headers.)
  • Write frame contents, then call write_finalize().

The child class MUST override this method.

Implements satcat5::net::Protocol.

Definition at line 102 of file eth_chat.cc.

◆ send_data()

void ChatProto::send_data ( const satcat5::eth::MacAddr dst,
unsigned  nbytes,
const void *  msg 
)

Send machine-readable data.

In example designs, this is used for throughput stress-tests with data that isn't suitable for human-readable displays.

Definition at line 69 of file eth_chat.cc.


The documentation for this class was generated from the following files: