17 #ifndef SATCAT5_COBS_LOG_ERROR
18 #define SATCAT5_COBS_LOG_ERROR 1
21 static constexpr u8 COBS_END = 0x00;
22 static constexpr u8 COBS_MAX = 0xFE;
23 static constexpr u8 BLK_EMPTY = 0x00;
24 static constexpr u8 BLK_DATA = 0x01;
25 static constexpr u8 BLK_TERM = 0x02;
40 unsigned rem = 3 + unsigned(m_ctr) + dst / 254;
41 if (m_ovr || dst <= rem)
70 if (m_ctr == COBS_MAX) {
74 if (data == COBS_END) {
77 m_buf[m_ctr++] = data;
81 void CobsEncoder::flush_segment() {
104 if (data == COBS_END && m_ctr) {
106 if (SATCAT5_COBS_LOG_ERROR)
112 }
else if (data == COBS_END) {
126 if (m_blk == BLK_TERM) m_dst->
write_u8(COBS_END);
127 m_blk = (data == 0xFF) ? BLK_DATA : BLK_TERM;
141 , m_buff(m_rawbuff, SATCAT5_COBS_BUFFSIZE, SATCAT5_COBS_PACKETS)
143 , m_copy(src, &m_decode)
151 , m_buff(m_rawbuff, SATCAT5_COBS_BUFFSIZE, 0)
153 , m_copy(src, &m_encode)
Buffered COBS encoder / decoder pair.
CobsCodec(satcat5::io::Writeable *dst, satcat5::io::Readable *src)
Constructor links to specified source and destination.
Buffered COBS encoder / decoder pair with opposite polarity.
CobsCodecInverse(satcat5::io::Writeable *dst, satcat5::io::Readable *src)
Constructor links to specified source and destination.
unsigned get_write_space() const override
How many bytes can be written without blocking?
CobsDecoder(satcat5::io::Writeable *dst)
Permanently link this encoder to an output object.
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
void write_overflow() override
Optional error handling for write overflow.
void write_overflow() override
Optional error handling for write overflow.
unsigned get_write_space() const override
How many bytes can be written without blocking?
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
bool write_finalize() override
Mark end of frame and release temporary working data.
Abstract API for reading byte-streams and packets.
Wrapper class for forwarding reads to another object.
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_bytes(unsigned nbytes, const void *src)
Write 0 or more bytes from a buffer.
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.
The Log class creates and formats one log message.
Inline COBS encoder and decoder objects.
Diagnostic logging to UART and/or Ethernet ports.