15 #ifndef SATCAT5_DEFAULT_PKTBUFF
16 #define SATCAT5_DEFAULT_PKTBUFF 1600
70 constexpr
PacketBuffer(
void* buff,
unsigned nbytes,
unsigned max_pkt=0)
71 :
m_buff(static_cast<u8*>(buff) + 2*max_pkt)
72 ,
m_buff_size((buff && nbytes >= 2*max_pkt) ? (nbytes - 2*max_pkt) : 0)
91 unsigned byte_count(
bool reset =
true)
override;
102 void write_bytes(
unsigned nbytes,
const void* src)
override;
118 bool read_bytes(
unsigned nbytes,
void* dst)
override;
128 const u8*
peek(
unsigned nbytes)
const;
146 bool can_read_internal(
unsigned nbytes)
const;
147 void consume_internal(
unsigned nbytes);
197 template<
unsigned SIZE = SATCAT5_DEFAULT_PKTBUFF>
222 template<
unsigned SIZE = SATCAT5_DEFAULT_PKTBUFF>
Define a generic API for reporting traffic statistics.
The PacketBuffer class is a wrapper for a circular buffer, with optional logic to support retention o...
const u8 * peek(unsigned nbytes) const
Peek nbytes into the circular buffer.
void clear()
Reset buffer contents.
unsigned m_next_wrpos
Working state for writes (write domain)
unsigned frame_count(bool reset=true) override
Frames transferred since the last query.
unsigned m_total_bytes
Cumulative total-bytes and total-frames statistics counters.
unsigned byte_count(bool reset=true) override
Bytes transferred since the last query.
unsigned get_write_partial() const
Get number of bytes in a partial packet, or -1 on overflow.
unsigned get_peek_ready() const
Find the longest available contiguous segment that can be requested by peek().
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.
unsigned m_pkt_rdidx
Store packet lengths in an auxiliary buffer (read domain)
u8 read_next() override
Read the next byte from the underlying buffer or device.
bool read_bytes(unsigned nbytes, void *dst) override
Read 0 or more bytes into a buffer.
unsigned get_write_space() const override
How many bytes can be written without blocking?
volatile unsigned m_shared_pktcount
Shared state is constant except for cross-domain events.
void zcw_write(unsigned nbytes)
Zero-copy write (zcw) mode, required for UART interface.
void write_bytes(unsigned nbytes, const void *src) override
Write 0 or more bytes from a buffer.
void write_overflow() override
Optional error handling for write overflow.
volatile unsigned m_shared_rdavail
Shared state is constant except for cross-domain events.
u8 *const m_buff
State for the main circular buffer (read domain)
constexpr PacketBuffer(void *buff, unsigned nbytes, unsigned max_pkt=0)
Configure this object and link to the underlying working memory.
unsigned m_total_frames
Cumulative total-bytes and total-frames statistics counters.
u8 * get_buff_dtor() const
Accessor for children that need to delete underlying buffer.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
bool read_consume(unsigned nbytes) override
Read and discard 0 or more bytes.
const unsigned m_pkt_maxct
Store packet lengths in an auxiliary buffer (read domain)
unsigned get_buff_size() const
Accessor for children that need to delete underlying buffer.
unsigned m_buff_rdcount
State for the main circular buffer (read domain)
unsigned m_buff_rdidx
State for the main circular buffer (read domain)
unsigned zcw_maxlen() const
Max contiguous write length (ZCW).
unsigned m_next_wrlen
Working state for writes (write domain)
void write_abort() override
If possible, abort the current partially-written packet.
const unsigned m_buff_size
State for the main circular buffer (read domain)
void read_finalize() override
Consume any remaining bytes in this frame, if applicable.
u8 get_percent_full() const
Get overall buffer occupancy as percentage full (0-100%).
u8 * zcw_start()
Pointer to a contiguous buffer (ZCW).
u16 *const m_pkt_lbuff
Store packet lengths in an auxiliary buffer (read domain)
Packet buffer with statically-allocated working memory.
PacketBufferStatic(unsigned max_pkt=32)
Link the parent object to the statically allocated buffer.
Abstract API for reading byte-streams and packets.
Stream buffer with statically-allocated working memory.
StreamBufferStatic()
Link the parent object to the statically allocated buffer.
Abstract API for writing byte-streams and packets.
I/O interface core definitions.
Inline byte and packet counters for statistics and diagnostics.
Basic type aliases and prototypes used throughout SatCat5.