SatCat5
eth_checksum.h
Go to the documentation of this file.
1 // Copyright 2021-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
22 
23 #pragma once
24 
25 #include <satcat5/codec_slip.h>
26 #include <satcat5/io_buffer.h>
27 #include <satcat5/io_checksum.h>
28 
29 namespace satcat5 {
30  namespace eth {
32  u32 crc32(unsigned nbytes, const void* data);
33 
35  u32 crc32(satcat5::io::Readable* src);
36 
38  class ChecksumTx : public satcat5::io::ChecksumTx<u32,4> {
39  public:
41  explicit ChecksumTx(satcat5::io::Writeable* dst);
42 
43  // Implement required API from Writeable:
44  bool write_finalize() override;
45 
46  private:
47  // Implement required API from Writeable:
48  void write_next(u8 data) override;
49  };
50 
52  class ChecksumRx : public satcat5::io::ChecksumRx<u32,4> {
53  public:
55  explicit ChecksumRx(satcat5::io::Writeable* dst);
56 
57  // Implement required API from Writeable:
58  bool write_finalize() override;
59 
60  private:
61  // Implement required API from Writeable:
62  void write_next(u8 data) override;
63  };
64 
71  class SlipCodec
74  {
75  public:
78  SlipCodec(
81 
84  { return satcat5::io::TrafficStats::query(m_rx_fcs, *this); }
85 
86  protected:
92  u8 m_rawbuff[SATCAT5_SLIP_BUFFSIZE];
93  };
94 
104  , public satcat5::io::SlipDecoder
105  {
106  public:
111  satcat5::io::Readable* src);
112 
116 
117  protected:
123  u8 m_rawbuff[SATCAT5_SLIP_BUFFSIZE];
124  };
125  }
126 }
Check and remove FCS from each incoming frame.
Definition: eth_checksum.h:52
bool write_finalize() override
Mark end of frame and release temporary working data.
ChecksumRx(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.
Append FCS to each outgoing frame.
Definition: eth_checksum.h:38
ChecksumTx(satcat5::io::Writeable *dst)
Permanently link this encoder to an output object.
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.
Buffered SLIP encoder / decoder pair with Ethernet FCS.
Definition: eth_checksum.h:74
satcat5::io::SlipDecoder m_rx_slip
SLIP decoder object.
Definition: eth_checksum.h:89
satcat5::io::BufferedCopy m_rx_copy
Push/pull adapter.
Definition: eth_checksum.h:88
satcat5::io::SlipEncoder m_tx_slip
SLIP encoder object.
Definition: eth_checksum.h:87
satcat5::eth::ChecksumRx m_rx_fcs
Verify received checksums.
Definition: eth_checksum.h:90
u8 m_rawbuff[SATCAT5_SLIP_BUFFSIZE]
Working buffer for m_rx_buff.
Definition: eth_checksum.h:92
satcat5::io::TrafficStats stats()
Report packet statistics since the previous query.
Definition: eth_checksum.h:83
satcat5::io::PacketBuffer m_rx_buff
Decoder writes to buffer.
Definition: eth_checksum.h:91
SlipCodec(satcat5::io::Writeable *dst, satcat5::io::Readable *src)
Constructor links to specified source and destination.
Inverted SLIP encoder / decoder pair with Ethernet FCS.
Definition: eth_checksum.h:105
satcat5::io::TrafficStats stats()
Report packet statistics since the previous query.
Definition: eth_checksum.h:114
satcat5::io::PacketBuffer m_tx_buff
Decoder writes to buffer.
Definition: eth_checksum.h:122
SlipCodecInverse(satcat5::io::Writeable *dst, satcat5::io::Readable *src)
Constructor links to specified source and destination.
satcat5::io::BufferedCopy m_tx_copy
Push/pull adapter.
Definition: eth_checksum.h:119
satcat5::eth::ChecksumRx m_rx_fcs
Verify received checksums.
Definition: eth_checksum.h:118
satcat5::eth::ChecksumTx m_tx_fcs
Append outgoing checksums.
Definition: eth_checksum.h:120
u8 m_rawbuff[SATCAT5_SLIP_BUFFSIZE]
Working buffer for m_tx_buff.
Definition: eth_checksum.h:123
satcat5::io::SlipEncoder m_tx_slip
SLIP encoder object.
Definition: eth_checksum.h:121
BufferedCopy copies from any Readable source to any Writeable sink.
Definition: io_buffer.h:68
Check and remove FCS from each incoming frame.
Definition: io_checksum.h:149
Inline checksum insertion, appends FCS to each outgoing frame.
Definition: io_checksum.h:83
The PacketBuffer class is a wrapper for a circular buffer, with optional logic to support retention o...
Definition: pkt_buffer.h:66
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Wrapper class for forwarding reads to another object.
Definition: io_readable.h:299
Inline SLIP decoder.
Definition: codec_slip.h:62
Inline SLIP encoder.
Definition: codec_slip.h:42
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Inline SLIP encoder and decoder objects.
u32 crc32(unsigned nbytes, const void *data)
Directly calculate CRC32 on a block of data.
Buffered I/O wrappers for PacketBuffer.
Inline checksum insertion (ChecksumTx) and verification (ChecksumRx).
Data structure for combined transmit and receive statistics.
Definition: io_counter.h:94
static TrafficStats query(satcat5::io::Counter &rx, satcat5::io::Counter &tx)
Read updated statistics from a transmit/receive pair.
Definition: io_counter.cc:58