10 #include <hal_posix/chat_printer.h>
12 #include <satcat5/eth_chat.h>
18 : satcat5::net::Protocol(satcat5::net::TYPE_NONE)
20 , m_loopback(loopback)
25 ChatPrinter::~ChatPrinter()
34 msg.push_back((
char)rd.
read_u8());
43 std::string from_str = satcat5::log::format(from);
44 printf(
"From: %s\n%s\n\n", from_str.c_str(), msg.c_str());
51 m_chat->
send_text(satcat5::eth::MACADDR_BROADCAST,
52 msg.length(), msg.c_str());
57 if (m_line.length() > 0) {
Protocol handler for a simple text-messaging protocol This class implements a simple as-hoc text-mess...
void send_text(const satcat5::eth::MacAddr &dst, unsigned nbytes, const char *msg)
Send a human-readable text message.
void set_callback(satcat5::net::Protocol *callback)
Set callback for processing incoming messages.
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.
Limited read of next N bytes.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
u8 read_u8()
One of many functions for reading integer/floating point values, see details.
Callback object that prints incoming messages.
void write_next(u8 ch)
Writeable endpoint: Accumulate characters from input stream.
bool write_finalize() override
Writeable endpoint: Accumulate characters from input stream.
void print_message(const satcat5::eth::MacAddr &from, const std::string &msg)
Pretty formatting for incoming or outgoing messages.
void frame_rcvd(satcat5::io::LimitedRead &rd) override
Handle incoming data from eth::ChatProto.
void send_message(const std::string &msg)
Send a message string to all other chat clients.
unsigned get_write_space() const override
Writeable endpoint: Accumulate characters from input stream.
Miscellaneous POSIX wrappers (e.g., heap allocation, log to console...)
An Ethernet MAC address (with serializable interface).