22 #include <satcat5/pkt_buffer.h>
28 constexpr u32 VERSION_MASK = 0xE0000000u;
29 constexpr u32 TYPE_MASK = 0x10000000u;
30 constexpr u32 SEC_HDR_FLAG = 0x08000000u;
31 constexpr u32 APID_MASK = 0x07FF0000u;
32 constexpr u32 SEQF_MASK = 0x0000C000u;
33 constexpr u32 SEQC_MASK = 0x00003FFFu;
34 constexpr u32 VERSION_1 = (0 << 29);
35 constexpr u32 TYPE_CMD = (1 << 28);
36 constexpr u32 TYPE_TLM = (0 << 28);
37 constexpr u32 SEQF_CONTINUE = (0 << 14);
38 constexpr u32 SEQF_FIRST = (1 << 14);
39 constexpr u32 SEQF_LAST = (2 << 14);
40 constexpr u32 SEQF_UNSEG = (3 << 14);
43 constexpr u16 APID_IDLE = 0x7FF;
56 {
return (u32(
apid) << 16) & APID_MASK; }
59 {
return u32(
seqc) & SEQC_MASK; }
63 {
return value & VERSION_MASK; }
65 {
return (value & TYPE_MASK) == TYPE_CMD; }
67 {
return (value & TYPE_MASK) == TYPE_TLM; }
69 {
return !!(value & SEC_HDR_FLAG); }
71 {
return u16((value & APID_MASK) >> 16); }
73 {
return value & SEQF_MASK; }
75 {
return u16(value & SEQC_MASK); }
78 void set(
bool cmd, u16
apid, u16 seq);
138 u8* buff,
unsigned rxbytes,
unsigned rxpkt,
156 template<
unsigned SIZE=1600>
161 :
Packetizer(m_raw, SIZE, 32, src), m_raw{} {}
173 : m_iface(
iface), m_dst{0} {}
178 { m_dst.
set(cmd, apid, 0); }
183 void close()
override;
184 bool ready()
const override;
222 {
return m_rcvd_hdr; }
264 bool cmd, u16 apid,
unsigned max_chunk = 256);
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...
constexpr Address(satcat5::ccsds_spp::Dispatch *iface)
Attach this address to a specified interface.
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...
bool reply_is_multicast() const override
Was the parent interface's incoming message sent to a multicast address? (i.e., Could that message ha...
bool is_multicast() const override
Is the destination a broadcast or multicast address? Child MUST override these method.
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.
satcat5::io::BufferedStream * strm()
Access the inner io::BufferedStream.
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.
void set_timeout(unsigned timeout_msec)
If sync is lost, rely on idle periods to resync.
unsigned m_rem
Bytes remaining in current packet.
unsigned m_timeout
User-configurable resync timeout.
satcat5::io::Writeable * packet()
Write-access with CCSDS-SPP packetization.
u16 m_sreg
Packet header working buffer.
satcat5::io::PacketBuffer m_buff
Output buffer.
satcat5::io::Writeable * bypass()
Direct write-access to the internal buffer.
satcat5::io::EventListener * listen()
Access the event-listener used for read/pull mode.
u8 m_wridx
Packet header write pointer.
satcat5::io::Counter & counter()
Access the internal statistics counters.
Packetizer variant with a statically-allocated buffer.
PacketizerStatic(satcat5::io::Readable *src=nullptr)
Optionally link this object to a source byte-stream.
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.
BufferedCopy copies from any Readable source to any Writeable sink.
Copy bytes from a Readable source to a network address.
Define a generic API for reporting traffic statistics.
Event-handler interface for newly received data.
Limited read of next N bytes.
The PacketBuffer class is a wrapper for a circular buffer, with optional logic to support retention o...
Abstract API for reading byte-streams and packets.
Wrapper class for forwarding reads to another object.
Abstract API for writing byte-streams and packets.
Defines a generic API for sending data to a specific destination, such as a MAC address,...
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Dispatch()
Constructor and destructor access restricted to children.
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Timer objects are polled after a fixed delay or at a regular interval.
Buffered I/O wrappers for PacketBuffer.
Generic network Dispatch API.
Multipurpose filter for matching fields in network packets.