16 #ifndef SATCAT5_HDLC_DEFAULT_ACTRL
17 #define SATCAT5_HDLC_DEFAULT_ACTRL 0
20 #ifndef SATCAT5_HDLC_DEFAULT_CRC32
21 #define SATCAT5_HDLC_DEFAULT_CRC32 1
24 static constexpr u8 HDLC_END = 0x7E;
25 static constexpr u8 HDLC_ESC = 0x7D;
26 static constexpr u8 HDLC_MASK = 0x20;
27 static constexpr u16 HDLC_ABORT = 256*HDLC_ESC + HDLC_END;
33 , m_crc16(&m_bstuff, 0xFFFF, 0xFFFF)
44 write_dst(mode32 ? dst32 : dst16);
49 , m_actrl(SATCAT5_HDLC_DEFAULT_ACTRL)
66 m_dst->write_u16(HDLC_ABORT);
81 if (data == HDLC_END || data == HDLC_ESC) {
85 }
else if (m_actrl && data < HDLC_MASK) {
97 , m_crc16(dst, 0xFFFF, 0xFFFF)
98 , m_state(State::HDLC_EOF)
99 , m_actrl(SATCAT5_HDLC_DEFAULT_ACTRL)
116 m_crc = mode32 ? dst32 : dst16;
122 if (data == HDLC_END) {
125 if (m_state == State::HDLC_RDY) {
127 }
else if (m_state != State::HDLC_EOF) {
130 m_state = State::HDLC_EOF;
131 }
else if (m_state == State::HDLC_ERR) {
133 }
else if (m_actrl && data < HDLC_MASK) {
135 }
else if (data == HDLC_ESC) {
136 m_state = State::HDLC_ESC;
137 }
else if (m_state == State::HDLC_ESC) {
139 m_state = State::HDLC_RDY;
142 m_state = State::HDLC_RDY;
149 m_state = State::HDLC_ERR;
Inline HDLC decoder (framing layer only).
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
void set_mode_crc32(bool mode32)
Select CRC16 or CRC32 checksum?
unsigned get_write_space() const override
How many bytes can be written without blocking?
void write_overflow() override
Optional error handling for write overflow.
HdlcDecoder(satcat5::io::Writeable *dst)
Permanently link this encoder to an output object.
unsigned get_write_space() const override
How many bytes can be written without blocking?
void write_abort() override
If possible, abort the current partially-written packet.
bool write_finalize() override
Mark end of frame and release temporary working data.
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
Inline HDLC encoder (framing layer only).
void set_mode_crc32(bool mode32)
Select CRC16 or CRC32 checksum?
Abstract API for writing byte-streams and packets.
virtual unsigned get_write_space() const =0
How many bytes can be written without blocking?
virtual void write_abort()
If possible, abort the current partially-written packet.
void write_u8(u8 data)
One of many functions for writing integer/floating point values, see details.
virtual bool write_finalize()
Mark end of frame and release temporary working data.
Wrapper class for forwarding writes to another object.
Inline HDLC encoder and decoder objects.