CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
CCSDS::Header Class Reference

Manages the decomposition and manipulation of CCSDS primary headers. More...

#include <CCSDSHeader.h>

Public Member Functions

 Header ()=default
 
uint8_t getVersionNumber () const
 3 bits
 
uint8_t getType () const
 1 bits
 
uint8_t getDataFieldHeaderFlag () const
 1 bits
 
uint16_t getAPID () const
 11 bits
 
uint8_t getSequenceFlags () const
 2 bits
 
uint16_t getSequenceCount () const
 14 bits
 
uint16_t getDataLength () const
 16 bits
 
std::vector< uint8_t > serialize ()
 decomposes the Primary header class and returns it as a vector of bytes.
 
uint64_t getFullHeader ()
 Computes and retrieves the full header as a 64-bit value.
 
void setVersionNumber (const uint8_t &value)
 3 bits
 
void setType (const uint8_t &value)
 1 bits
 
void setDataFieldHeaderFlag (const uint8_t &value)
 1 bits
 
void setAPID (const uint16_t &value)
 11 bits
 
void setSequenceFlags (const uint8_t &value)
 2 bits
 
void setSequenceCount (const uint16_t &value)
 14 bits
 
void setDataLength (const uint16_t &value)
 16 bits
 
ResultBool setData (const uint64_t &data)
 Sets the header data from a 64-bit integer representation.
 
ResultBool deserialize (const std::vector< uint8_t > &data)
 Sets the header data from a 64-bit integer representation.
 
void setData (const PrimaryHeader &data)
 Sets the header data from a PrimaryHeader structure.
 

Private Attributes

uint8_t m_versionNumber {}
 3 bit first of packet identification
 
uint8_t m_type {}
 1 bit second of packet identification
 
uint8_t m_dataFieldHeaderFlag {}
 1 bit third of packet identification
 
uint16_t m_APID {}
 11 bit last of packet identification
 
uint8_t m_sequenceFlags {UNSEGMENTED}
 2 bit first of sequence control / ESequenceFlag enum.
 
uint16_t m_sequenceCount {}
 14 bit last of sequence control
 
uint16_t m_packetIdentificationAndVersion {}
 packet id and version 16 bit 4 hex
 
uint16_t m_packetSequenceControl {}
 packet sequence control 16 bit 4 hex
 
uint16_t m_dataLength {}
 data packet length 16 bits 4 hex
 

Detailed Description

Manages the decomposition and manipulation of CCSDS primary headers.

Definition at line 80 of file CCSDSHeader.h.

Constructor & Destructor Documentation

◆ Header()

CCSDS::Header::Header ( )
default

Member Function Documentation

◆ deserialize()

CCSDS::ResultBool CCSDS::Header::deserialize ( const std::vector< uint8_t > &  data)

Sets the header data from a 64-bit integer representation.

Decomposes the 64-bit input data into various header fields, including the version number, type, data field header flag, APID, sequence flags, sequence count, and data length.

Note
returns an error code if the provided data exceeds maximum available value (max 6 bytes i.e. elements).
Parameters
datareference to an uint8_t vector.
Returns
ResultBool.

Definition at line 4 of file CCSDSHeader.cpp.

4 {
5 RET_IF_ERR_MSG(data.size() != 6, ErrorCode::INVALID_HEADER_DATA, "Invalid Header Data provided: size != 6");
6
7 uint64_t headerData = 0;
8 for (int i = 0; i < 6; ++i) {
9 headerData |= static_cast<uint64_t>(data[i]) << (40 - i * 8); // Combine MSB to LSB
10 }
11 FORWARD_RESULT(setData(headerData));
12 return true;
13}
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
#define FORWARD_RESULT(result)
Macro to return a result as-is (for functions returning Result<T>).
ResultBool setData(const uint64_t &data)
Sets the header data from a 64-bit integer representation.
@ INVALID_HEADER_DATA
Header data is invalid.
Definition CCSDSResult.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAPID()

uint16_t CCSDS::Header::getAPID ( ) const
inline

11 bits

Definition at line 87 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ getDataFieldHeaderFlag()

uint8_t CCSDS::Header::getDataFieldHeaderFlag ( ) const
inline

1 bits

Definition at line 86 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ getDataLength()

uint16_t CCSDS::Header::getDataLength ( ) const
inline

16 bits

Definition at line 90 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ getFullHeader()

uint64_t CCSDS::Header::getFullHeader ( )
inline

Computes and retrieves the full header as a 64-bit value.

Combines individual header fields into a single 64-bit representation.

Note
if data has not been set it is initialized as all 0s.
Returns
The full header as a 64-bit integer.

Definition at line 108 of file CCSDSHeader.h.

108 {
111 m_APID;
112 return (static_cast<uint64_t>(m_packetIdentificationAndVersion) << 32) | (
113 static_cast<uint32_t>(m_packetSequenceControl) << 16) | m_dataLength;
114 }
uint8_t m_sequenceFlags
2 bit first of sequence control / ESequenceFlag enum.
uint8_t m_dataFieldHeaderFlag
1 bit third of packet identification
uint16_t m_sequenceCount
14 bit last of sequence control
uint16_t m_packetSequenceControl
packet sequence control 16 bit 4 hex
uint8_t m_versionNumber
3 bit first of packet identification
uint16_t m_APID
11 bit last of packet identification
uint8_t m_type
1 bit second of packet identification
uint16_t m_packetIdentificationAndVersion
packet id and version 16 bit 4 hex
uint16_t m_dataLength
data packet length 16 bits 4 hex
Here is the caller graph for this function:

◆ getSequenceCount()

uint16_t CCSDS::Header::getSequenceCount ( ) const
inline

14 bits

Definition at line 89 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ getSequenceFlags()

uint8_t CCSDS::Header::getSequenceFlags ( ) const
inline

2 bits

Definition at line 88 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ getType()

uint8_t CCSDS::Header::getType ( ) const
inline

1 bits

Definition at line 85 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ getVersionNumber()

uint8_t CCSDS::Header::getVersionNumber ( ) const
inline

3 bits

Definition at line 84 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ serialize()

std::vector< uint8_t > CCSDS::Header::serialize ( )

decomposes the Primary header class and returns it as a vector of bytes.

Note
if data has not been set it is initialized as all 0s.
Returns
std::vector<uint8_t>

Definition at line 35 of file CCSDSHeader.cpp.

35 {
36 m_packetSequenceControl = (static_cast<uint16_t>(m_sequenceFlags) << 14) | m_sequenceCount;
37 m_packetIdentificationAndVersion = (static_cast<uint16_t>(m_versionNumber) << 13) | (m_type << 12) | static_cast<
38 uint16_t>((m_dataFieldHeaderFlag) << 11) | m_APID;
39
40 std::vector data{
41 static_cast<unsigned char>(m_packetIdentificationAndVersion >> 8),
42 static_cast<unsigned char>(m_packetIdentificationAndVersion & 0xFF),
43 static_cast<unsigned char>(m_packetSequenceControl >> 8),
44 static_cast<unsigned char>(m_packetSequenceControl & 0xFF),
45 static_cast<unsigned char>(m_dataLength >> 8),
46 static_cast<unsigned char>(m_dataLength & 0xFF),
47 };
48 return data;
49}

◆ setAPID()

void CCSDS::Header::setAPID ( const uint16_t &  value)
inline

11 bits

Definition at line 119 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ setData() [1/2]

void CCSDS::Header::setData ( const PrimaryHeader data)

Sets the header data from a PrimaryHeader structure.

Assigns values from a PrimaryHeader structure to the internal header fields. Combines certain fields into their packed representations for efficient storage.

Parameters
dataA PrimaryHeader structure containing the header data.
Returns
none.

Definition at line 51 of file CCSDSHeader.cpp.

51 {
52 m_versionNumber = data.versionNumber & 0x0007;
53 m_type = data.type & 0x0001;
54 m_dataFieldHeaderFlag = data.dataFieldHeaderFlag & 0x0001;
55 m_APID = data.APID & 0x07FF;
56 m_sequenceFlags = data.sequenceFlags & 0x0003;
57 m_sequenceCount = data.sequenceCount & 0x3FFF;
58 m_dataLength = data.dataLength;
59
60 m_packetSequenceControl = (static_cast<uint16_t>(m_sequenceFlags) << 14) | m_sequenceCount;
61 m_packetIdentificationAndVersion = (static_cast<uint16_t>(m_versionNumber) << 13) | (m_type << 12) | static_cast<
62 uint16_t>((m_dataFieldHeaderFlag) << 11) | m_APID;
63}

◆ setData() [2/2]

CCSDS::ResultBool CCSDS::Header::setData ( const uint64_t &  data)

Sets the header data from a 64-bit integer representation.

Decomposes the 64-bit input data into various header fields, including the version number, type, data field header flag, APID, sequence flags, sequence count, and data length.

Note
returns an error code if the provided data exceeds maximum available value (max 6 bytes).
Parameters
dataThe 64-bit integer representing the header data.
Returns
ResultBool.

Definition at line 15 of file CCSDSHeader.cpp.

15 {
17 "Input data exceeds expected bit size for version or size.");
18 // Decompose data using mask and shifts
19 m_dataLength = (data & 0xFFFF); // last 16 bits
20 m_packetSequenceControl = (data >> 16) & 0xFFFF; // middle 16 bits
21 m_packetIdentificationAndVersion = (data >> 32); // first 16 bits
22
23 // decompose packet identifier
24 m_versionNumber = (m_packetIdentificationAndVersion >> 13); // First 3 bits for version
25 m_type = (m_packetIdentificationAndVersion >> 12) & 0x1; // Next 1 bit
26 m_dataFieldHeaderFlag = (m_packetIdentificationAndVersion >> 11) & 0x1; // Next 1 bit
27 m_APID = (m_packetIdentificationAndVersion & 0x07FF); // Last 11 bits
28
29 // decompose sequence control
30 m_sequenceFlags = (m_packetSequenceControl >> 14); // first 2 bits
31 m_sequenceCount = (m_packetSequenceControl & 0x3FFF); // Last 14 bits.
32 return true;
33}
Here is the caller graph for this function:

◆ setDataFieldHeaderFlag()

void CCSDS::Header::setDataFieldHeaderFlag ( const uint8_t &  value)
inline

1 bits

Definition at line 118 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ setDataLength()

void CCSDS::Header::setDataLength ( const uint16_t &  value)
inline

16 bits

Definition at line 122 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ setSequenceCount()

void CCSDS::Header::setSequenceCount ( const uint16_t &  value)
inline

14 bits

Definition at line 121 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ setSequenceFlags()

void CCSDS::Header::setSequenceFlags ( const uint8_t &  value)
inline

2 bits

Definition at line 120 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ setType()

void CCSDS::Header::setType ( const uint8_t &  value)
inline

1 bits

Definition at line 117 of file CCSDSHeader.h.

Here is the caller graph for this function:

◆ setVersionNumber()

void CCSDS::Header::setVersionNumber ( const uint8_t &  value)
inline

3 bits

Definition at line 116 of file CCSDSHeader.h.

Here is the caller graph for this function:

Member Data Documentation

◆ m_APID

uint16_t CCSDS::Header::m_APID {}
private

11 bit last of packet identification

Definition at line 169 of file CCSDSHeader.h.

169{};

◆ m_dataFieldHeaderFlag

uint8_t CCSDS::Header::m_dataFieldHeaderFlag {}
private

1 bit third of packet identification

Definition at line 168 of file CCSDSHeader.h.

168{};

◆ m_dataLength

uint16_t CCSDS::Header::m_dataLength {}
private

data packet length 16 bits 4 hex

Definition at line 178 of file CCSDSHeader.h.

178{};

◆ m_packetIdentificationAndVersion

uint16_t CCSDS::Header::m_packetIdentificationAndVersion {}
private

packet id and version 16 bit 4 hex

Definition at line 176 of file CCSDSHeader.h.

176{};

◆ m_packetSequenceControl

uint16_t CCSDS::Header::m_packetSequenceControl {}
private

packet sequence control 16 bit 4 hex

Definition at line 177 of file CCSDSHeader.h.

177{};

◆ m_sequenceCount

uint16_t CCSDS::Header::m_sequenceCount {}
private

14 bit last of sequence control

Definition at line 173 of file CCSDSHeader.h.

173{};

◆ m_sequenceFlags

uint8_t CCSDS::Header::m_sequenceFlags {UNSEGMENTED}
private

2 bit first of sequence control / ESequenceFlag enum.

Definition at line 172 of file CCSDSHeader.h.

172{UNSEGMENTED};
@ UNSEGMENTED
11 Complete packet in a single frame.
Definition CCSDSHeader.h:23

◆ m_type

uint8_t CCSDS::Header::m_type {}
private

1 bit second of packet identification

Definition at line 167 of file CCSDSHeader.h.

167{};

◆ m_versionNumber

uint8_t CCSDS::Header::m_versionNumber {}
private

3 bit first of packet identification

Definition at line 164 of file CCSDSHeader.h.

164{};

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