arduino-audio-tools
|
High-Level Data Link Control (HDLC) is a bit-oriented code-transparent synchronous data link layer protocol for reliable, framed, and error-checked communication. More...
#include <HDLCStream.h>
Public Member Functions | |
HDLCStream (Print &stream, size_t maxFrameSize) | |
Construct a new HDLCStream object using a Print for output only. | |
HDLCStream (Stream &stream, size_t maxFrameSize) | |
Construct a new HDLCStream object using a Stream for input and output. | |
int | available () override |
Get the number of bytes available to read from the frame buffer. | |
virtual int | availableForWrite () |
void | flush () override |
Flush the output buffer of the underlying stream. | |
operator bool () | |
int | peek () override |
Not supported. | |
int | read () override |
Not supported. | |
size_t | readBytes (uint8_t *buffer, size_t length) override |
Read a full frame from the stream into a buffer. | |
size_t | write (const uint8_t *data, size_t len) override |
Write multiple bytes to the stream. | |
size_t | write (uint8_t b) override |
Not supported. | |
Protected Types | |
enum | RxState { IDLE , RECEIVING , ESCAPED } |
Protected Member Functions | |
uint16_t | _crc16 (uint8_t data, uint16_t crc) |
Calculate CRC-CCITT (16-bit) | |
void | _processInput () |
Process incoming bytes, detect frames, validate CRC and prepare data for reading. | |
void | _writeEscaped (uint8_t b) |
Write a byte with proper HDLC byte stuffing if needed. | |
size_t | writeFrame (const uint8_t *data, size_t len) |
Write a complete HDLC frame with proper framing and CRC. | |
Protected Attributes | |
size_t | _frameLen = 0 |
bool | _frameReady = false |
const size_t | _maxFrameSize |
Vector< uint8_t > | _rxBuffer |
size_t | _rxLen = 0 |
size_t | _rxPos = 0 |
enum audio_tools::HDLCStream::RxState | _rxState = IDLE |
int | _timeout = 10 |
Print * | p_print = nullptr |
Stream * | p_stream = nullptr |
SingleBuffer< uint8_t > | rx_frame_buffer |
SingleBuffer< uint8_t > | tx_frame_buffer |
Static Protected Attributes | |
static constexpr uint8_t | HDLC_ESC = 0x7D |
static constexpr uint8_t | HDLC_ESC_XOR = 0x20 |
static constexpr uint8_t | HDLC_FLAG = 0x7E |
High-Level Data Link Control (HDLC) is a bit-oriented code-transparent synchronous data link layer protocol for reliable, framed, and error-checked communication.
This class implements HDLC framing with:
|
inline |
Construct a new HDLCStream object using a Stream for input and output.
stream | The underlying Stream for both reading and writing |
maxFrameSize | Maximum size of a single HDLC frame |
|
inline |
Construct a new HDLCStream object using a Print for output only.
stream | The underlying Print for writing |
maxFrameSize | Maximum size of a single HDLC frame |
|
inlineprotected |
Calculate CRC-CCITT (16-bit)
data | Byte to include in CRC calculation |
crc | Current CRC value |
|
inlineprotected |
Write a byte with proper HDLC byte stuffing if needed.
b | Byte to write |
|
inlineoverridevirtual |
Get the number of bytes available to read from the frame buffer.
Reimplemented from Stream.
|
inlinevirtualinherited |
Reimplemented in RTSPOutput, UDPStream, A2DPStream, AudioFFTBase, I2SCodecStream, Equalizer3Bands, Equalizer3BandsPerChannel, AbstractURLStream, URLStreamESP32, I2SStream, OutputMixer< T >, MeasuringStream, ProgressStream, FrequencyDetectorAutoCorrelation, FrequencyDetectorZeroCrossing, and VolumeStream.
|
inlineoverridevirtual |
Flush the output buffer of the underlying stream.
Reimplemented from Print.
|
inlineoverride |
Not supported.
|
inlineoverride |
Not supported.
|
inlineoverridevirtual |
Read a full frame from the stream into a buffer.
buffer | Destination buffer to hold the data |
length | Maximum number of bytes to read |
Reimplemented from Stream.
|
inlineoverridevirtual |
Write multiple bytes to the stream.
data | Pointer to the data buffer |
len | Number of bytes to write |
Reimplemented from Print.
|
inlineoverride |
Not supported.
b | The byte to write |
|
inlineprotected |
Write a complete HDLC frame with proper framing and CRC.
data | Data to be framed |
len | Length of data |