SatCat5
codec_slip.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/io_buffer.h>
26 #include <satcat5/pkt_buffer.h>
27 
28 // Default size parameters
29 // (Must be large enough for one full-size Ethernet frame + metadata,
30 // larger sizes are fine if you have the memory for it.)
31 #ifndef SATCAT5_SLIP_BUFFSIZE
32 #define SATCAT5_SLIP_BUFFSIZE 1600 // One full-size Ethernet frame
33 #endif
34 
35 #ifndef SATCAT5_SLIP_PACKETS
36 #define SATCAT5_SLIP_PACKETS 32 // ...or many smaller frames
37 #endif
38 
39 namespace satcat5 {
40  namespace io {
43  public:
45  explicit SlipEncoder(satcat5::io::Writeable* dst);
46 
47  // Implement required API from Writeable:
48  unsigned get_write_space() const override;
49  bool write_finalize() override;
50  void write_overflow() override;
51 
52  private:
53  // Implement required API from Writeable:
54  void write_next(u8 data) override;
55 
56  // Internal state:
57  satcat5::io::Writeable* const m_dst; // Output object
58  bool m_overflow;
59  };
60 
63  public:
65  explicit SlipDecoder(satcat5::io::Writeable* dst);
66 
67  // Implement required API from Writeable:
68  unsigned get_write_space() const override;
69 
70  private:
71  // Implement required API from Writeable:
72  void write_next(u8 data) override;
73  void write_overflow() override;
74 
75  // Internal state:
76  enum class State {SLIP_RDY, SLIP_ESC, SLIP_EOF, SLIP_ERR};
77  satcat5::io::Writeable* const m_dst; // Output object
78  satcat5::io::SlipDecoder::State m_state; // Decoder state
79  };
80 
90  class SlipCodec
93  {
94  public:
97  SlipCodec(
100 
101  protected:
105  u8 m_rawbuff[SATCAT5_SLIP_BUFFSIZE];
106  };
107 
116  : public satcat5::io::SlipDecoder
118  {
119  public:
124  satcat5::io::Readable* src);
125 
126  protected:
130  u8 m_rawbuff[SATCAT5_SLIP_BUFFSIZE];
131  };
132  }
133 }
BufferedCopy copies from any Readable source to any Writeable sink.
Definition: io_buffer.h:68
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
Buffered SLIP encoder / decoder pair.
Definition: codec_slip.h:93
satcat5::io::SlipDecoder m_decode
Decoder object.
Definition: codec_slip.h:103
satcat5::io::PacketBuffer m_buff
Decoder writes to buffer.
Definition: codec_slip.h:102
SlipCodec(satcat5::io::Writeable *dst, satcat5::io::Readable *src)
Constructor links to specified source and destination.
Definition: codec_slip.cc:134
satcat5::io::BufferedCopy m_copy
Push/pull adapter.
Definition: codec_slip.h:104
u8 m_rawbuff[SATCAT5_SLIP_BUFFSIZE]
Working buffer for m_rx.
Definition: codec_slip.h:105
Buffered SLIP encoder / decoder pair with opposite polarity.
Definition: codec_slip.h:118
u8 m_rawbuff[SATCAT5_SLIP_BUFFSIZE]
Working buffer for m_rx.
Definition: codec_slip.h:130
SlipCodecInverse(satcat5::io::Writeable *dst, satcat5::io::Readable *src)
Constructor links to specified source and destination.
Definition: codec_slip.cc:144
satcat5::io::BufferedCopy m_copy
Push/pull adapter.
Definition: codec_slip.h:129
satcat5::io::PacketBuffer m_buff
Encoder writes to buffer.
Definition: codec_slip.h:127
satcat5::io::SlipEncoder m_encode
Encoder object.
Definition: codec_slip.h:128
Inline SLIP decoder.
Definition: codec_slip.h:62
unsigned get_write_space() const override
How many bytes can be written without blocking?
Definition: codec_slip.cc:89
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
Definition: codec_slip.cc:95
SlipDecoder(satcat5::io::Writeable *dst)
Permanently link this encoder to an output object.
Definition: codec_slip.cc:82
void write_overflow() override
Optional error handling for write overflow.
Definition: codec_slip.cc:126
Inline SLIP encoder.
Definition: codec_slip.h:42
void write_overflow() override
Optional error handling for write overflow.
Definition: codec_slip.cc:65
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
Definition: codec_slip.cc:70
SlipEncoder(satcat5::io::Writeable *dst)
Permanently link this encoder to an output object.
Definition: codec_slip.cc:29
bool write_finalize() override
Mark end of frame and release temporary working data.
Definition: codec_slip.cc:49
unsigned get_write_space() const override
How many bytes can be written without blocking?
Definition: codec_slip.cc:36
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Buffered I/O wrappers for PacketBuffer.