SatCat5
satcat5::io::ChecksumRx< T, N > Class Template Referenceabstract

Detailed Description

template<class T, unsigned N>
class satcat5::io::ChecksumRx< T, N >

Check and remove FCS from each incoming frame.

Inline checksum insertion (ChecksumTx) and verification (ChecksumRx). Many frame formats consist of frame data followed by a checksum. io::ChecksumTx and io::ChecksumRx define two templates for working with such streams. The templates are able to work with any byte-aligned checksum with byte-aligned inputs, including most CRC types and many other formats.

Each template accepts data using the io::Writeable interface and writes modified data to a designated io::Writeable pointer:

  • ChecksumTx: For each incoming frame, append the calculated checksum.
  • ChecksumRx: For each incoming frame, strip the last N bytes and compare against the calculated checksum. If it is a match call write_finalize(), and otherwise call write_abort().

Because checksum validation is often tied to a network interface, these classes include the io::Counter API for counting sent and received frames.

In all child classes of either template, the user MUST override the methods write_next() and write_finalize() to calculate and format the checksum. For child classes of io::ChecksumTx, the implementation of write_finalize() MUST call chk_finalize(). For example usage, refer to eth::ChecksumTx and eth::ChecksumRx.

Template type T stores the checksum (u8/u16/u32/u64). Template value N is the checksum length in bytes.

Child class is responsible for the following:

Definition at line 149 of file io_checksum.h.

#include <io_checksum.h>

Inheritance diagram for satcat5::io::ChecksumRx< T, N >:
[legend]
Collaboration diagram for satcat5::io::ChecksumRx< T, N >:
[legend]

Public Member Functions

void error_incr ()
 Increment the internal error counter. More...
 
void error_incr (unsigned incr)
 
unsigned get_write_space () const override
 How many bytes can be written without blocking? More...
 
void write_abort () override
 If possible, abort the current partially-written packet. More...
 
unsigned byte_count (bool reset=true) override
 Bytes transferred since the last query.
 
unsigned frame_count (bool reset=true) override
 Frames transferred since the last query.
 
unsigned error_count (bool reset=true) override
 (Optional) Error events since the last query.
 
void byte_incr (unsigned incr)
 Increment any of the internal counters.
 
void frame_incr (unsigned incr)
 
void write_u8 (u8 data)
 One of many functions for writing integer/floating point values, see details. More...
 
virtual void write_bytes (unsigned nbytes, const void *src)
 Write 0 or more bytes from a buffer. More...
 
void write_str (const char *str)
 Write the contents of a null-terminated string. More...
 
virtual bool write_finalize ()
 Mark end of frame and release temporary working data. More...
 
template<class T >
void write_obj (const T &obj)
 Templated wrapper for any object with the following method: void write_to(satcat5::io::Writeable* wr) const;
 

Protected Member Functions

 ChecksumRx (satcat5::io::Writeable *dst, T init)
 Only the child class has access to the constructor.
 
void chk_reset () override
 Reset checksum calculation to its initial state.
 
bool sreg_match (T fcs)
 Child class MUST call sreg_match(...) during write_finalize(). More...
 
bool sreg_push (u8 &data)
 Child class MUST call sreg_push(...) during write_next(). More...
 
virtual void write_next (u8 data)=0
 Write the next byte to the underlying buffer or device. More...
 
virtual void write_overflow ()
 Optional error handling for write overflow. More...
 

Protected Attributes

m_chk
 Checksum state.
 
const T m_init
 State after reset.
 
m_sreg
 Big-endian input buffer.
 
satcat5::io::Writeable *const m_dst
 Output object.
 
unsigned m_byte_ct
 Cumulative byte count.
 
unsigned m_err_ct
 Cumulative error count.
 
unsigned m_frm_ct
 Cumulative frame count.
 
unsigned m_frm_len
 Length of current frame.
 
friend LimitedWrite
 
friend WriteableBroadcast
 
friend WriteableRedirect
 

Member Function Documentation

◆ error_incr()

void satcat5::io::ChecksumRxCommon::error_incr ( )
inlineinherited

Increment the internal error counter.

Some systems use the checksum error counter to consolidate tracking of multiple frame-error types.

See also
ccsds_aos.h.

Definition at line 118 of file io_checksum.h.

◆ get_write_space()

unsigned ChecksumRxCommon::get_write_space ( ) const
overridevirtualinherited

How many bytes can be written without blocking?

Child objects of io::Writeable MUST override this method.

Implements satcat5::io::Writeable.

Definition at line 38 of file io_checksum.cc.

◆ sreg_match()

template<class T , unsigned N>
bool satcat5::io::ChecksumRx< T, N >::sreg_match ( fcs)
inlineprotected

Child class MUST call sreg_match(...) during write_finalize().

The child provides the FCS in a format that matches SREG.

Definition at line 164 of file io_checksum.h.

◆ sreg_push()

template<class T , unsigned N>
bool satcat5::io::ChecksumRx< T, N >::sreg_push ( u8 &  data)
inlineprotected

Child class MUST call sreg_push(...) during write_next().

If it returns true, update the checksum state appropriately.

Definition at line 186 of file io_checksum.h.

◆ write_abort()

void ChecksumRxCommon::write_abort ( )
overridevirtualinherited

If possible, abort the current partially-written packet.

Child objects of io::Writeable SHOULD override this method if it is practical to prevent in-progress data from being relayed downstream.

Reimplemented from satcat5::io::Writeable.

Definition at line 42 of file io_checksum.cc.

◆ write_bytes()

void Writeable::write_bytes ( unsigned  nbytes,
const void *  src 
)
virtualinherited

◆ write_finalize()

◆ write_next()

◆ write_overflow()

void Writeable::write_overflow ( )
protectedvirtualinherited

◆ write_str()

void Writeable::write_str ( const char *  str)
inherited

Write the contents of a null-terminated string.

Note: Null-termination is not copied to the output.

Definition at line 180 of file io_writeable.cc.

◆ write_u8()

void Writeable::write_u8 ( u8  data)
inherited

One of many functions for writing integer/floating point values, see details.

Several functions are provided for reading and writing scalar types to/from io::Readable and io::Writeable instances. Since there are many of these that are frequently inherited, they are hidden from documentation. These functions follow a shared template:

  • read_ or write_ prefix.
  • u for unsigned, s for signed, f for floating-point.
  • Data-type width in bits.
    • Available widths for ints: 8/16/24/32/48/64.
    • Available widths for floats: 32/64.
  • l suffix if little-endian, no suffix if big-endian.

Example: write_s48l is "Write 48 bits (6 bytes) to this io::Writeable as a signed value in little-endian order".

Definition at line 20 of file io_writeable.cc.


The documentation for this class was generated from the following file: