27 #define DEBUG_VERBOSE 0
29 void Header::set(
bool cmd, u16 apid, u16 seq) {
30 value = VERSION_1 | SEQF_UNSEG
31 | (cmd ? TYPE_CMD : TYPE_TLM)
37 u32 old_hdr = u32(value & ~SEQC_MASK);
38 u16 old_seq = u16(value & SEQC_MASK);
44 : ReadableRedirect(&m_buff)
46 , m_buff(buff, rxbytes, rxpkt)
62 if (src) src->read_finalize();
73 Log(WARNING,
"CCSDS-SDS packetizer timeout.");
88 if (DEBUG_VERBOSE > 0 && !ok)
89 Log(DEBUG,
"ccsds_spp::Packetizer overflow");
116 return !!m_dst.value;
136 #if SATCAT5_ALLOW_DELETION
137 Dispatch::~Dispatch() {
152 if (!m_dst)
return nullptr;
153 if (DEBUG_VERBOSE > 1)
158 if (len < 1)
return 0;
162 m_dst->write_u32(hdr.value);
163 m_dst->write_u16(len - 1);
169 u32 len = 0;
bool ok =
false;
171 m_rcvd_hdr.value = src->read_u32();
172 len = 1 + u32(src->read_u16());
174 && (m_rcvd_hdr.
apid() != APID_IDLE);
178 if (DEBUG_VERBOSE > 1 && ok)
183 if (ok)
deliver(typ, src, len);
198 #if SATCAT5_ALLOW_DELETION
199 Protocol::~Protocol() {
205 bool cmd, u16 apid,
unsigned max_chunk)
207 , m_strm(src, &m_dst, max_chunk)
CCSDS Space Packet Protocol.
Implemention of "net::Address" API for CCSDS-SPP packets.
bool ready() const override
Is this address object ready for use? Child MUST override this method.
void close() override
Close any open connections and revert to idle.
void connect(bool cmd, u16 apid)
Set the packet type and APID.
void save_reply_address() override
Bind this Address object to the parent interface's current reply address, as provided in net::Dispatc...
satcat5::net::Dispatch * iface() const override
Fetch a pointer to the underlying interface.
satcat5::io::Writeable * open_write(unsigned len) override
Open a new frame to the designated address and type.
bool matches_reply_address() const override
Does this Address object match the parent interface's current reply address? Multicast destinations s...
Convert a raw byte-stream by inserting CCSDS-SPP headers.
BytesToSpp(satcat5::io::Readable *src, satcat5::ccsds_spp::Dispatch *dst, bool cmd, u16 apid, unsigned max_chunk=256)
Set source, destination, APID, and chunk-size.
Implemention of "net::Dispatch" API for CCSDS-SPP packets.
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
satcat5::io::Writeable * open_write(const satcat5::ccsds_spp::Header &hdr, unsigned len)
Write CCSDS-SPP frame header and get Writeable object.
satcat5::io::Writeable * open_reply(const satcat5::net::Type &type, unsigned len) override
Write CCSDS-SPP frame header and get Writeable object.
const satcat5::ccsds_spp::Header & rcvd_hdr() const
Fetch the last received CCSDS-SPP header.
Find packet boundaries in a raw CCSDS-SPP byte-stream.
void timer_event() override
Child class MUST override this method.
satcat5::io::BufferedCopy m_copy
Push-pull adapter.
void reset()
Full reset of buffer and synchronization state.
void flush()
Reset partial packets and synchronization state.
unsigned get_write_space() const override
How many bytes can be written without blocking?
Packetizer(u8 *buff, unsigned rxbytes, unsigned rxpkt, satcat5::io::Readable *src=nullptr)
Child class must provide a working buffer.
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
unsigned m_rem
Bytes remaining in current packet.
unsigned m_timeout
User-configurable resync timeout.
u16 m_sreg
Packet header working buffer.
satcat5::io::PacketBuffer m_buff
Output buffer.
u8 m_wridx
Packet header write pointer.
Implemention of "net::Protocol" API for CCSDS-SPP packets.
satcat5::ccsds_spp::Dispatch *const m_iface
Pointer to the parent interface.
Protocol(satcat5::ccsds_spp::Dispatch *iface, u16 apid)
Constructor and destructor access restricted to children.
Convert a CCSDS-SPP packet stream by removing CCSDS-SPP headers.
void frame_rcvd(satcat5::io::LimitedRead &src) override
For each SPP frame, remove header and forward data.
SppToBytes(satcat5::ccsds_spp::Dispatch *src, satcat5::io::Writeable *dst, u16 apid)
Set source, destination, and APID.
satcat5::io::Readable * src()
Other accessors.
Limited read of next N bytes.
void clear()
Reset buffer contents.
bool write_finalize() override
Mark end of frame and release temporary working data.
unsigned get_write_space() const override
How many bytes can be written without blocking?
void write_abort() override
If possible, abort the current partially-written packet.
Abstract API for reading byte-streams and packets.
virtual void read_finalize()
Consume any remaining bytes in this frame, if applicable.
bool copy_and_finalize(satcat5::io::Writeable *dst, satcat5::io::CopyMode mode=CopyMode::PACKET)
Copy data to a Writeable object, then finalize.
virtual void set_callback(satcat5::io::EventListener *callback)
Update registered callback for data_rcvd() events.
virtual unsigned get_read_ready() const =0
How many bytes can be read without blocking?
Abstract API for writing byte-streams and packets.
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.
void write_u8(u8 data)
One of many functions for writing integer/floating point values, see details.
The Log class creates and formats one log message.
Log & write10(s32 val)
Print integer as a decimal value with no leading zeros.
Log & write(const char *str)
Formatting methods for various data types.
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
void add(satcat5::net::Protocol *proto)
Register a Protocol object.
Dispatch()
Constructor and destructor access restricted to children.
bool deliver(const satcat5::net::Type &type, satcat5::io::Readable *src, unsigned len)
Deliver current message by calling Protocol::frame_rcvd(...).
void remove(satcat5::net::Protocol *proto)
Unregister a Protocol object.
void timer_stop()
Stop all future notifications.
void timer_once(unsigned msec)
Configure a one-time notification after X milliseconds.
Diagnostic logging to UART and/or Ethernet ports.
constexpr s8 WARNING
Define basic priority codes for log messages.
constexpr s8 DEBUG
Define basic priority codes for log messages.
Multipurpose filter for matching fields in network packets.
Miscellaneous mathematical utility functions.
constexpr unsigned min_unsigned(unsigned a, unsigned b)
Min and max functions.