Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Comms
  5. pw_hdlc
Loading...
Searching...
No Matches
pw_hdlc

Overview

Simple, robust, and efficient serial communication.

Classes

class  pw::hdlc::Frame
 
class  pw::hdlc::Decoder
 
class  pw::hdlc::DecoderBuffer< kSizeBytes >
 Declares a buffer along with a Decoder. More...
 
class  pw::hdlc::Encoder
 Encodes and writes HDLC frames. More...
 
class  pw::hdlc::Router
 

Functions

Status pw::hdlc::WriteUIFrame (uint64_t address, ConstByteSpan payload, stream::Writer &writer)
 Writes an HDLC unnumbered information frame (UI frame) to the provided pw::stream writer.
 
constexpr pw::hdlc::Encoder::Encoder (stream::Writer &output)
 Constructs an encoder which will write data to output.
 
Status pw::hdlc::Encoder::StartUnnumberedFrame (uint64_t address)
 
Status pw::hdlc::Encoder::WriteData (ConstByteSpan data)
 
Status pw::hdlc::Encoder::FinishFrame ()
 Finishes a frame. Writes the frame check sequence and a terminating flag.
 

Function Documentation

◆ StartUnnumberedFrame()

Status pw::hdlc::Encoder::StartUnnumberedFrame ( uint64_t  address)
inline

Writes the header for a U-frame. After successfully calling StartUnnumberedFrame(), WriteData() may be called any number of times.

◆ WriteData()

Status pw::hdlc::Encoder::WriteData ( ConstByteSpan  data)

Writes data for an ongoing frame. Must only be called after a successful StartInformationFrame() call, and prior to a FinishFrame() call.

◆ WriteUIFrame()

Status pw::hdlc::WriteUIFrame ( uint64_t  address,
ConstByteSpan  payload,
stream::Writer &  writer 
)

Writes an HDLC unnumbered information frame (UI frame) to the provided pw::stream writer.

This function is a convenience alias for the more general Encoder type and set of functions.

Parameters
addressThe frame address.
payloadThe frame data to encode.
writerThe pw::stream to write the frame to. The frame contains the following bytes. See Design for more information.
  • HDLC flag byte (0x7e)
  • Address (variable length, up to 10 bytes)
  • UI-frame control (metadata) byte
  • Payload (0 or more bytes)
  • Frame check sequence (CRC-32, 4 bytes)
  • HDLC flag byte (0x7e)
Returns
  • OK: The write finished successfully.
  • RESOURCE_EXHAUSTED: The write failed because the size of the frame would be larger than the writer's conservative limit.
  • INVALID_ARGUMENT: The start of the write failed. Check for problems in your address argument's value.