CCSDS
Public Types | Public Member Functions | Static Public Member Functions | List of all members
CCSDS::SpacePacket Class Reference

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...
 

Detailed Description

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.

Member Typedef Documentation

◆ TSpCallback

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.

Parameters
p_SpContextThe pointer to the context which has to be used
u8_PacketTypeThe packet type (TM or TC)
u8_SequenceFlagsThe sequence flags (Continuation, First, Last Segment or Unsegmented)
u16_APIDThe target application ID
u16_SequenceCountThe channel-specific frame count
b_SecHeaderA flag which indicates the presence of a secondary space packet header
pu8_PacketDataA pointer to the data block which holds the content of the package
u16_PacketDataLengthThe size of the data block in bytes

Member Enumeration Documentation

◆ PacketType

The package type defines if a space packet contains a telecommand (TC) or telemetry (TM).

Enumerator
TM 

Telemetry (downlink)

TC 

Telecommand (uplink)

◆ SequenceFlags

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.

Enumerator
ContinuationSegment 

If the package belongs to a sequence of packages, this flag identifies that this package is somewhere in the middle.

FirstSegment 

The first package of a sequence of packages mus be identified with this flag.

LastSegment 

This flag identifies the last package of a sequence.

Unsegmented 

If the package is completly within one source packet, this flag is used.

Constructor & Destructor Documentation

◆ SpacePacket()

CCSDS::SpacePacket::SpacePacket ( void *  p_SpContext = NULL,
TSpCallback p_SpCallback = NULL 
)

Construct a new SpacePacket object.

Parameters
p_SpContextA pointer to the context which has to be used when a space packet is received
p_SpCallbackThis callback is called when a space packet is received

Member Function Documentation

◆ create() [1/2]

uint32_t CCSDS::SpacePacket::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 
)
static

Creates a Space Packet and writes it into the given buffer.

Parameters
pu8_BufferA pointer to the buffer where the space packet shall be stored
u32_BufferSizeThe available size of the buffer
e_PacketTypeIdentifies the type of Space Packet (SpacePacket::TM or SpacePacket::TC)
e_SequenceFlagsIdentifies that a packet belongs to a sequence of packets (one of SpacePacket::Unsegmented, SpacePacket::FirstSegment, SpacePacket::ContinuationSegment, SpacePacket::LastSegment)
u16_APIDThe Application Identifier where this packet belongs to
u16_SequenceCountThe 14-bit sequence counter is handeled by the calling context and must be specific for each APID
pu8_PacketDataA pointer to the data block which shall be wrapped
u16_PacketDataLengthThe size of the data block in bytes
Return values
0No packet could be created
Returns
The size of the created packet in bytes as uint32_t

◆ create() [2/2]

uint32_t CCSDS::SpacePacket::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 
)
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.

Parameters
pu8_BufferA pointer to the buffer where the space packet shall be stored
u32_BufferSizeThe available size of the buffer
e_PacketTypeIdentifies the type of Space Packet (SpacePacket::TM or SpacePacket::TC)
e_SequenceFlagsIdentifies that a packet belongs to a sequence of packets (one of SpacePacket::Unsegmented, SpacePacket::FirstSegment, SpacePacket::ContinuationSegment, SpacePacket::LastSegment)
u16_APIDThe application identifier (APID) defines where this packet belongs to
u16_SequenceCountThe 14-bit sequence counter is handeled by the calling context and must be specific for each APID.
pu8_SecondaryHeaderDataA pointer to the secondary header
u16_SecondaryHeaderLengthThe size of the secondary header
pu8_PacketDataA pointer to the data block which shall be wrapped
u16_PacketDataLengthThe size of the data block in bytes; the secondary header and the packet data must both fit into 65535 bytes.
Return values
0No packet could be created
Returns
The size of the created packet in bytes as uint32_t

◆ createIdle()

uint32_t CCSDS::SpacePacket::createIdle ( uint8_t *  pu8_Buffer,
const uint32_t  u32_BufferSize,
const uint16_t  u16_SequenceCount,
const uint16_t  u16_TargetPacketSize 
)
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.

Parameters
pu8_BufferA pointer to the buffer where the idle space packet shall be stored
u32_BufferSizeThe available size of the buffer
u16_SequenceCountThe 14-bit sequence counter is handeled by the calling context and must be specific also for idle frames.
u16_TargetPacketSizeThe requested size of the packet (usually the remaining size within the transfer frame)
Return values
0No packet could be created
Returns
The size of the created packet in bytes as uint32_t

◆ getOverflowErrorCount()

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.

Returns
Number of overflow errors as uint16_t

◆ getSyncErrorCount()

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.

Returns
Number of sync errors as uint16_t

◆ process()

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.

Parameters
pu8_BufferThe data buffer which is to parse
u32_BufferSizeThe size of the data buffer
Return values
0If the buffer was parsed
-1If fhe u32_BufferSize is 0 or the pu8_Buffer is NULL

◆ reset()

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.

◆ setCallback()

void CCSDS::SpacePacket::setCallback ( void *  p_SpContext,
TSpCallback p_SpCallback 
)

Overwrites the context pointer and callback which were set using the constructor.

Parameters
p_SpContextA pointer to the context which has to be used when a space packet is received
p_SpCallbackThis callback is called when a space packet is received

The documentation for this class was generated from the following files: