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>
|
| 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.
|
|
|
enum | RxState { IDLE
, RECEIVING
, ESCAPED
} |
|
|
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.
|
|
|
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 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:
- Frame delimiter (0x7E) for marking frame boundaries
- Byte stuffing to escape special characters in the data
- 16-bit CRC-CCITT for error detection
- Transparent Stream interface for easy integration
- Author
- Phil Schatzmann
◆ HDLCStream() [1/2]
Construct a new HDLCStream object using a Stream for input and output.
- Parameters
-
stream | The underlying Stream for both reading and writing |
maxFrameSize | Maximum size of a single HDLC frame |
◆ HDLCStream() [2/2]
Construct a new HDLCStream object using a Print for output only.
- Parameters
-
stream | The underlying Print for writing |
maxFrameSize | Maximum size of a single HDLC frame |
◆ _crc16()
uint16_t _crc16 |
( |
uint8_t |
data, |
|
|
uint16_t |
crc |
|
) |
| |
|
inlineprotected |
Calculate CRC-CCITT (16-bit)
- Parameters
-
data | Byte to include in CRC calculation |
crc | Current CRC value |
- Returns
- uint16_t Updated CRC value
◆ _writeEscaped()
void _writeEscaped |
( |
uint8_t |
b | ) |
|
|
inlineprotected |
Write a byte with proper HDLC byte stuffing if needed.
- Parameters
-
◆ available()
Get the number of bytes available to read from the frame buffer.
- Returns
- int Number of bytes available
Reimplemented from Stream.
◆ availableForWrite()
virtual int availableForWrite |
( |
| ) |
|
|
inlinevirtualinherited |
Reimplemented in RTSPOutput, UDPStream, A2DPStream, AudioFFTBase, I2SCodecStream, AbstractURLStream, URLStreamESP32, I2SStream, OutputMixer< T >, MeasuringStream, ProgressStream, FrequencyDetectorAutoCorrelation, FrequencyDetectorZeroCrossing, and VolumeStream.
◆ flush()
Flush the output buffer of the underlying stream.
Reimplemented from Print.
◆ peek()
◆ read()
◆ readBytes()
size_t readBytes |
( |
uint8_t * |
buffer, |
|
|
size_t |
length |
|
) |
| |
|
inlineoverridevirtual |
Read a full frame from the stream into a buffer.
- Parameters
-
buffer | Destination buffer to hold the data |
length | Maximum number of bytes to read |
- Returns
- size_t Actual number of bytes read
Reimplemented from Stream.
◆ write() [1/2]
size_t write |
( |
const uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
|
inlineoverridevirtual |
Write multiple bytes to the stream.
- Parameters
-
data | Pointer to the data buffer |
len | Number of bytes to write |
- Returns
- size_t Number of bytes written
Reimplemented from Print.
◆ write() [2/2]
size_t write |
( |
uint8_t |
b | ) |
|
|
inlineoverride |
Not supported.
- Parameters
-
- Returns
- 0
◆ writeFrame()
size_t writeFrame |
( |
const uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
|
inlineprotected |
Write a complete HDLC frame with proper framing and CRC.
- Parameters
-
data | Data to be framed |
len | Length of data |
- Returns
- size_t Number of bytes in the original data
The documentation for this class was generated from the following file: