SatCat5
io_checksum.cc
1 // Copyright 2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 
6 #include <satcat5/io_checksum.h>
7 
11 
12 void ChecksumTxCommon::write_overflow() {
13  m_ovr = true; // Flag persists until end-of-frame
14 }
15 
17  if (m_frm_len) ++m_err_ct; // Count this as an error?
18  chk_reset(); // Reset internal state
19  m_ovr = false;
20  m_frm_len = 0;
21  m_dst->write_abort(); // Forward error event
22 }
23 
25  bool ok = !m_ovr; // Overflow error?
26  if (ok) {
28  ++m_frm_ct;
29  } else {
30  m_dst->write_abort();
31  }
32  chk_reset(); // Reset internal state
33  m_ovr = false;
34  m_frm_len = 0;
35  return ok; // Continue finalize event?
36 }
37 
39  return m_dst->get_write_space();
40 }
41 
43  if (m_frm_len) ++m_err_ct; // Count this as an error?
44  chk_reset(); // Reset internal state
45  m_frm_len = 0;
46  m_dst->write_abort(); // Forward error event
47 }
Parent class for non-template elements of ChecksumRx.
Definition: io_checksum.h:113
satcat5::io::Writeable *const m_dst
Output object.
Definition: io_checksum.h:135
void write_abort() override
If possible, abort the current partially-written packet.
Definition: io_checksum.cc:42
unsigned get_write_space() const override
How many bytes can be written without blocking?
Definition: io_checksum.cc:38
Parent class for non-template elements of ChecksumTx.
Definition: io_checksum.h:46
virtual void chk_reset()=0
Reset the checksum calculation to its initial state.
void write_abort() override
If possible, abort the current partially-written packet.
Definition: io_checksum.cc:16
bool m_ovr
Overflow flag.
Definition: io_checksum.h:69
bool chk_finalize()
Reset internal state and return true if the frame is valid.
Definition: io_checksum.cc:24
satcat5::io::Writeable *const m_dst
Output object.
Definition: io_checksum.h:68
unsigned m_err_ct
Cumulative error count.
Definition: io_counter.h:70
unsigned m_frm_ct
Cumulative frame count.
Definition: io_counter.h:71
unsigned m_frm_len
Length of current frame.
Definition: io_counter.h:72
unsigned m_byte_ct
Cumulative byte count.
Definition: io_counter.h:69
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.
Inline checksum insertion (ChecksumTx) and verification (ChecksumRx).
Data structure for combined transmit and receive statistics.
Definition: io_counter.h:94