SatCat5
crc16_checksum.h
Go to the documentation of this file.
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
28 
29 #pragma once
30 
31 #include <satcat5/io_checksum.h>
32 
33 namespace satcat5 {
34  namespace crc16 {
37  u16 kermit(unsigned nbytes, const void* data);
40  u16 xmodem(unsigned nbytes, const void* data);
41 
45  class KermitTx : public satcat5::io::ChecksumTx<u16,2> {
46  public:
47  explicit KermitTx(satcat5::io::Writeable* dst, u16 init = 0, u16 xorout = 0);
48  bool write_finalize() override;
49  private:
50  void write_next(u8 data) override;
51  const u16 m_xorout;
52  };
53 
56  class KermitRx : public satcat5::io::ChecksumRx<u16,2> {
57  public:
58  explicit KermitRx(satcat5::io::Writeable* dst, u16 init = 0, u16 xorout = 0);
59  bool write_finalize() override;
60  private:
61  void write_next(u8 data) override;
62  const u16 m_xorout;
63  };
64 
67  class XmodemTx : public satcat5::io::ChecksumTx<u16,2> {
68  public:
69  explicit XmodemTx(satcat5::io::Writeable* dst, u16 init = 0, u16 xorout = 0);
70  bool write_finalize() override;
71  private:
72  void write_next(u8 data) override;
73  const u16 m_xorout;
74  };
75 
78  class XmodemRx : public satcat5::io::ChecksumRx<u16,2> {
79  public:
80  explicit XmodemRx(satcat5::io::Writeable* dst, u16 init = 0, u16 xorout = 0);
81  bool write_finalize() override;
82  private:
83  void write_next(u8 data) override;
84  const u16 m_xorout;
85  };
86  }
87 }
Check and remove FCS from each incoming frame ("KERMIT" variant).
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.
Append FCS to each outgoing frame ("KERMIT" variant).
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.
Check and remove FCS from each incoming frame ("XMODEM" variant).
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.
Append FCS to each outgoing frame ("XMODEM" variant).
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.
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
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
u16 xmodem(unsigned nbytes, const void *data)
Directly calculate CRC16 on a block of data.
u16 kermit(unsigned nbytes, const void *data)
Directly calculate CRC16 on a block of data.
Inline checksum insertion (ChecksumTx) and verification (ChecksumRx).