Router#
pw_hdlc: Simple, robust, and efficient serial communication
pw_hdlc::Router
is an experimental asynchronous HDLC router using
pw_channel
.
It sends and receives HDLC packets using an external byte-oriented channel and routes the decoded packets to local datagram-oriented channels.
API#
-
class Router#
A router that multiplexes multiple datagram-oriented
Channel
s over a single byte-orientedChannel
using HDLC framing.Public Functions
-
inline Router(pw::channel::ByteReaderWriter &io_channel, ByteSpan decode_buffer)#
Constructs a
Router
- Parameters:
io_channel – [in] The channel on which to send and receive encoded HDLC packets.
decode_buffer – [in] The memory to use for storing partially-decoded HDLC frames. This buffer should be at least
Decoder::RequiredBufferSizeForFrameSize(frame_size)
bytes in order to ensure that HDLC frames of sizeframe_size
can be successfully decoded.
-
Status AddChannel(pw::channel::DatagramReaderWriter &channel, uint64_t receive_address, uint64_t send_address)#
Registers a
Channel
tied to the provided addresses.All incoming HDLC messages received on
io_channel
with HDLC addressreceive_address
will be decoded and routed to the providedchannel
.Data read from
channel
will be HDLC-encoded and sent toio_channel
.Note that a non-writeable channel will exert backpressure on the entire router, so channels should strive to consume or discard incoming data as quickly as possible in order to prevent starvation of other channels.
- Parameters:
receive_address – [in] Incoming HDLC messages received on the external
io_channel
with an address matchingreceive_address
will be decoded and written tochannel
.send_address – [in] Data read from
channel
will be written toio_channel
with the HDLC addresssend_address
.
- Returns:
Code
Description
Channel
was successfully registered.A registration already exists for either
channel
,receive_address
, orsend_address
. Channels may not be registered with multiple addresses, nor may addresses be used with multiple channels.
-
Status RemoveChannel(pw::channel::DatagramReaderWriter &channel, uint64_t receive_address, uint64_t send_address)#
Removes a previously registered
Channel
tied to the provided addresses.- Returns:
-
pw::async2::Poll Pend(pw::async2::Context &cx)#
Progress the router as far as possible, waking the provided
cx
when more progress can be made.This will only return
Ready
ifio_channel
has been observed as closed, after which all messages have been flushed to the remaining channels and the channels have been closed.
-
inline Router(pw::channel::ByteReaderWriter &io_channel, ByteSpan decode_buffer)#