CCSDS
|
Class for handling the Space Packets as described in CCSDS 133.0-B-2. More...
#include <ccsds_spacepacket.h>
Public Types | |
enum | PacketType { TM = 0 , TC = 1 } |
enum | SequenceFlags { ContinuationSegment = 0x0 , FirstSegment = 0x1 , LastSegment = 0x2 , Unsegmented = 0x3 } |
typedef void() | TSpCallback(void *p_SpContext, const uint8_t u8_PacketType, const uint8_t u8_SequenceFlags, const uint16_t u16_APID, const uint16_t u16_SequenceCount, const bool b_SecHeader, const uint8_t *pu8_PacketData, const uint16_t u16_PacketDataLength) |
Declaration of the callback which shall be called if a complete space packet was received. More... | |
Public Member Functions | |
SpacePacket (void *p_SpContext=NULL, TSpCallback *mp_SpCallback=NULL) | |
Construct a new SpacePacket object. More... | |
void | setCallback (void *p_SpContext, TSpCallback *mp_SpCallback) |
Overwrites the context pointer and callback which were set using the constructor. More... | |
int32_t | process (const uint8_t *pu8_Buffer, const uint32_t u32_BufferSize) |
The given upstream data is parsed for SpacePackets. More... | |
int32_t | reset (void) |
Resets the scanning for a space packet. More... | |
uint16_t | getSyncErrorCount (void) |
Returns the number of sync errors. More... | |
uint16_t | getOverflowErrorCount (void) |
Returns the number of overflow errors. More... | |
void | clearErrorCounters (void) |
Clears all error counters (Sync Error and Overflow Error) | |
Static Public Member Functions | |
static uint32_t | create (uint8_t *pu8_Buffer, const uint32_t u32_BufferSize, const PacketType e_PacketType, const SequenceFlags e_SequenceFlags, const uint16_t u16_APID, const uint16_t u16_SequenceCount, const uint8_t *pu8_PacketData, const uint16_t u16_PacketDataLength) |
Creates a Space Packet and writes it into the given buffer. More... | |
static uint32_t | create (uint8_t *pu8_Buffer, const uint32_t u32_BufferSize, const PacketType e_PacketType, const SequenceFlags e_SequenceFlags, const uint16_t u16_APID, const uint16_t u16_SequenceCount, const uint8_t *pu8_SecondaryHeaderData, const uint16_t u16_SecondaryHeaderLength, const uint8_t *pu8_PacketData, const uint16_t u16_PacketDataLength) |
Creates a Space Packet with Secondary Header and writes it into the given buffer. More... | |
static uint32_t | createIdle (uint8_t *pu8_Buffer, const uint32_t u32_BufferSize, const uint16_t u16_SequenceCount, const uint16_t u16_TargetPacketSize) |
Creates an Idle Space Packet and writes into the given buffer. More... | |
Class for handling the Space Packets as described in CCSDS 133.0-B-2.
Space Packets are used to transfer data from one specific application to another which are identified by the Application ID (APID), corresponding to OSI layer 4. Even thouth Space Packets have a sequence counter, there is no mechanism for resending packets. This means, if a connection is expected to be disturbed and unreliable, Space Packes should be wrapped in Transfer Frames.
The size of the Space Package may vary and depends on the information which are to be transfered. The maximum size is limmited to 65536 bytes by the protocol, but typically the maximum size is configured to be much smaller, depending on the needs and the available memory for processing the packages on the controller board.
CCSDS::SpacePacket::TSpCallback |
Declaration of the callback which shall be called if a complete space packet was received.
The implementation of this callback shall handle the space packet. It shall implement the fowarding to the corresponding application (or the further processing of the content.
p_SpContext | The pointer to the context which has to be used |
u8_PacketType | The packet type (TM or TC) |
u8_SequenceFlags | The sequence flags (Continuation, First, Last Segment or Unsegmented) |
u16_APID | The target application ID |
u16_SequenceCount | The channel-specific frame count |
b_SecHeader | A flag which indicates the presence of a secondary space packet header |
pu8_PacketData | A pointer to the data block which holds the content of the package |
u16_PacketDataLength | The size of the data block in bytes |
If the data to be sent is more than it can be handeled in one single space packet, than these flags are used to identify the first and the last package.
CCSDS::SpacePacket::SpacePacket | ( | void * | p_SpContext = NULL , |
TSpCallback * | p_SpCallback = NULL |
||
) |
Construct a new SpacePacket object.
p_SpContext | A pointer to the context which has to be used when a space packet is received |
p_SpCallback | This callback is called when a space packet is received |
|
static |
Creates a Space Packet and writes it into the given buffer.
pu8_Buffer | A pointer to the buffer where the space packet shall be stored |
u32_BufferSize | The available size of the buffer |
e_PacketType | Identifies the type of Space Packet (SpacePacket::TM or SpacePacket::TC) |
e_SequenceFlags | Identifies that a packet belongs to a sequence of packets (one of SpacePacket::Unsegmented, SpacePacket::FirstSegment, SpacePacket::ContinuationSegment, SpacePacket::LastSegment) |
u16_APID | The Application Identifier where this packet belongs to |
u16_SequenceCount | The 14-bit sequence counter is handeled by the calling context and must be specific for each APID |
pu8_PacketData | A pointer to the data block which shall be wrapped |
u16_PacketDataLength | The size of the data block in bytes |
0 | No packet could be created |
|
static |
Creates a Space Packet with Secondary Header and writes it into the given buffer.
The secondary header is not standardized. It can for example hold a time stamp in a telemetry packet. It also can hold additional information about the sender/receiver if SpacecraftID and the ApplicationID is not enough.
pu8_Buffer | A pointer to the buffer where the space packet shall be stored |
u32_BufferSize | The available size of the buffer |
e_PacketType | Identifies the type of Space Packet (SpacePacket::TM or SpacePacket::TC) |
e_SequenceFlags | Identifies that a packet belongs to a sequence of packets (one of SpacePacket::Unsegmented, SpacePacket::FirstSegment, SpacePacket::ContinuationSegment, SpacePacket::LastSegment) |
u16_APID | The application identifier (APID) defines where this packet belongs to |
u16_SequenceCount | The 14-bit sequence counter is handeled by the calling context and must be specific for each APID. |
pu8_SecondaryHeaderData | A pointer to the secondary header |
u16_SecondaryHeaderLength | The size of the secondary header |
pu8_PacketData | A pointer to the data block which shall be wrapped |
u16_PacketDataLength | The size of the data block in bytes; the secondary header and the packet data must both fit into 65535 bytes. |
0 | No packet could be created |
|
static |
Creates an Idle Space Packet and writes into the given buffer.
An Idle Frame is a Space Packet with APID 0x7ff; The content of the packet is all 0xff. Idle frames are used to fill up telemetry transfer frames.
pu8_Buffer | A pointer to the buffer where the idle space packet shall be stored |
u32_BufferSize | The available size of the buffer |
u16_SequenceCount | The 14-bit sequence counter is handeled by the calling context and must be specific also for idle frames. |
u16_TargetPacketSize | The requested size of the packet (usually the remaining size within the transfer frame) |
0 | No packet could be created |
uint16_t CCSDS::SpacePacket::getOverflowErrorCount | ( | void | ) |
Returns the number of overflow errors.
Overflow errors occur if the space packet is bigger than the internal memory of this class used for storing the space packet; A wrong package alignment or a incorrect size given within the space packet can also lead to an overflow error.
If the number of overflow errors exceeds 65535, the method returns 65535.
uint16_t CCSDS::SpacePacket::getSyncErrorCount | ( | void | ) |
Returns the number of sync errors.
Sync Errors occur if the parsing engine is resettet while a space packet is currently processed. The reset can only be triggered from outside (for example by the transferframe class after detecting a wrong checksum or an uncontinuous TF frame counter which cannot be resolved)
If the number of sync errors exceeds 65535, the method returns 65535.
int32_t CCSDS::SpacePacket::process | ( | const uint8_t * | pu8_Buffer, |
const uint32_t | u32_BufferSize | ||
) |
The given upstream data is parsed for SpacePackets.
The method can handle continuously incoming data as well as complete data blocks. If a complete SpacePacket is processed, the callback function p_SpCallback is called.
pu8_Buffer | The data buffer which is to parse |
u32_BufferSize | The size of the data buffer |
0 | If the buffer was parsed |
-1 | If fhe u32_BufferSize is 0 or the pu8_Buffer is NULL |
int32_t CCSDS::SpacePacket::reset | ( | void | ) |
Resets the scanning for a space packet.
A partly received space packet is discarded; In this case, the SyncErrorCounter is increased.
void CCSDS::SpacePacket::setCallback | ( | void * | p_SpContext, |
TSpCallback * | p_SpCallback | ||
) |
Overwrites the context pointer and callback which were set using the constructor.
p_SpContext | A pointer to the context which has to be used when a space packet is received |
p_SpCallback | This callback is called when a space packet is received |