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::DataField Class Reference

Represents the data field of a CCSDS packet. More...

#include <CCSDSDataField.h>

Collaboration diagram for CCSDS::DataField:
[legend]

Public Member Functions

 DataField ()
 
 ~DataField ()=default
 
ResultBool setApplicationData (const std::vector< uint8_t > &applicationData)
 Sets the application data using a vector of bytes.
 
ResultBool setApplicationData (const uint8_t *pData, const size_t &sizeData)
 Sets the application data for the data field.
 
ResultBool setDataFieldHeader (const uint8_t *pData, const size_t &sizeData)
 Sets the secondary header data for the data field.
 
ResultBool setDataFieldHeader (const uint8_t *pData, const size_t &sizeData, const std::string &pType)
 Sets the secondary header for the data field using a PUS Type.
 
ResultBool setDataFieldHeader (const std::vector< uint8_t > &data, const std::string &pType)
 Sets the data field header for the CCSDS DataField with a specific PUS type.
 
ResultBool setDataFieldHeader (const std::vector< uint8_t > &dataFieldHeader)
 Sets the data field header for the CCSDS DataField.
 
void setDataFieldHeader (std::shared_ptr< SecondaryHeaderAbstract > header)
 Sets the secondary header for the data field using a PUS-A header.
 
SecondaryHeaderFactorygetDataFieldHeaderFactory ()
 returns the secondary header factory
 
SecondaryHeaderAbstractgetDataFieldHeader ()
 returns the secondary header A SecondaryHeaderAbstract derived object containing the header data.
 
void setDataPacketSize (const uint16_t &value)
 Sets the maximum data packet size for the CCSDS DataField.
 
void setDataFieldHeaderAutoUpdateStatus (const bool enable)
 Sets The auto update variable, if disabled the data size in the header field will not be updated.
 
uint16_t getDataFieldAbsoluteBytesSize ()
 Retrieves the absolute size of the data field in bytes.
 
uint16_t getDataFieldUsedBytesSize ()
 Retrieves the used size of the data field in bytes.
 
uint16_t getDataFieldAvailableBytesSize ()
 Retrieves the available size of the data field in bytes.
 
std::vector< uint8_t > getDataFieldHeaderBytes ()
 Retrieves the secondary header data as a vector of bytes.
 
std::vector< uint8_t > getFullDataFieldBytes ()
 Retrieves the full data field by combining the data field header and application data.
 
std::vector< uint8_t > getApplicationData ()
 Retrieves the application data from the data field.
 
bool getDataFieldHeaderAutoUpdateStatus () const
 returns true if auto update has been enabled for the secondary header
 
bool getDataFieldHeaderFlag () const
 retrieves true if a known secondary header has been set
 
std::shared_ptr< SecondaryHeaderAbstractgetSecondaryHeader ()
 retrieves the known PUS type
 
void update ()
 Updates the data field header based on the current application data size.
 

Private Attributes

std::shared_ptr< SecondaryHeaderAbstractm_secondaryHeader {}
 Shared pointer to the secondary header class.
 
SecondaryHeaderFactory m_secondaryHeaderFactory
 secondary header dispatcher factory
 
std::vector< uint8_t > m_applicationData {}
 Application data buffer.
 
std::string m_dataFieldHeaderType {}
 Data field Header type.
 
uint16_t m_dataPacketSize {2024}
 Data field maximum size in bytes.
 
bool m_dataFieldHeaderUpdated {false}
 Boolean for secondary header updated status.
 
bool m_enableDataFieldUpdate {true}
 Boolean for secondary header update enable.
 

Detailed Description

Represents the data field of a CCSDS packet.

This class encapsulates the structure and operations for handling the data field of a CCSDS (Consultative Committee for Space Data Systems) packet. It allows for setting and retrieving application data, data field headers, and calculating the full data field. Additionally, it provides methods for managing the data field's size and printing its content.

The data field consists of headers and application data, and the class supports different header types (PusA, PusB, PusC). It also allows setting and getting the data packet size, as well as managing the data field header flag.

Definition at line 26 of file CCSDSDataField.h.

Constructor & Destructor Documentation

◆ DataField()

CCSDS::DataField::DataField ( )
inline

Definition at line 28 of file CCSDSDataField.h.

28 {
29 m_secondaryHeaderFactory.registerType(std::make_shared<BufferHeader>());
30 m_secondaryHeaderFactory.registerType(std::make_shared<PusA>());
31 m_secondaryHeaderFactory.registerType(std::make_shared<PusB>());
32 m_secondaryHeaderFactory.registerType(std::make_shared<PusC>());
33 };
SecondaryHeaderFactory m_secondaryHeaderFactory
secondary header dispatcher factory
void registerType(std::shared_ptr< SecondaryHeaderAbstract > header)
Registers a new header type with its creation function.
Here is the call graph for this function:

◆ ~DataField()

CCSDS::DataField::~DataField ( )
default

Member Function Documentation

◆ getApplicationData()

std::vector< uint8_t > CCSDS::DataField::getApplicationData ( )

Retrieves the application data from the data field.

This method returns a vector containing the raw application data stored in the data field.

Returns
A vector containing the application data bytes.

Definition at line 18 of file CCSDSDataField.cpp.

18 {
19 update();
20 return m_applicationData;
21}
std::vector< uint8_t > m_applicationData
Application data buffer.
void update()
Updates the data field header based on the current application data size.
Here is the caller graph for this function:

◆ getDataFieldAbsoluteBytesSize()

uint16_t CCSDS::DataField::getDataFieldAbsoluteBytesSize ( )

Retrieves the absolute size of the data field in bytes.

This method returns the total allocated size for the data field, including both the header and application data.

Returns
The absolute size of the data field in bytes.

Definition at line 28 of file CCSDSDataField.cpp.

28 {
29 update();
30 return m_dataPacketSize;
31}
uint16_t m_dataPacketSize
Data field maximum size in bytes.

◆ getDataFieldAvailableBytesSize()

uint16_t CCSDS::DataField::getDataFieldAvailableBytesSize ( )

Retrieves the available size of the data field in bytes.

This method calculates and returns the remaining free space within the data field that can be utilized.

Returns
The available size of the data field in bytes.

Definition at line 23 of file CCSDSDataField.cpp.

23 {
24 update();
26}
uint16_t getDataFieldUsedBytesSize()
Retrieves the used size of the data field in bytes.

◆ getDataFieldHeader()

SecondaryHeaderAbstract & CCSDS::DataField::getDataFieldHeader ( )
inline

returns the secondary header A SecondaryHeaderAbstract derived object containing the header data.

Returns
std::shared_ptr<SecondaryHeaderAbstract>& .

Definition at line 149 of file CCSDSDataField.h.

149{return *m_secondaryHeader;}
std::shared_ptr< SecondaryHeaderAbstract > m_secondaryHeader
Shared pointer to the secondary header class.

◆ getDataFieldHeaderAutoUpdateStatus()

bool CCSDS::DataField::getDataFieldHeaderAutoUpdateStatus ( ) const
inline

returns true if auto update has been enabled for the secondary header

Definition at line 226 of file CCSDSDataField.h.

226{ return m_enableDataFieldUpdate; }
bool m_enableDataFieldUpdate
Boolean for secondary header update enable.

◆ getDataFieldHeaderBytes()

std::vector< uint8_t > CCSDS::DataField::getDataFieldHeaderBytes ( )

Retrieves the secondary header data as a vector of bytes.

If the header type is not OTHER or NA, retrieves the data from the corresponding PUS header object.

Returns
A vector containing the header data bytes.

Definition at line 153 of file CCSDSDataField.cpp.

153 {
154 update();
155 if (m_secondaryHeader) {
156 return m_secondaryHeader->serialize();
157 }
158 return {};
159}
Here is the caller graph for this function:

◆ getDataFieldHeaderFactory()

SecondaryHeaderFactory & CCSDS::DataField::getDataFieldHeaderFactory ( )
inline

returns the secondary header factory

Returns
SecondaryHeaderFactory& .

Definition at line 141 of file CCSDSDataField.h.

◆ getDataFieldHeaderFlag()

bool CCSDS::DataField::getDataFieldHeaderFlag ( ) const
inline

retrieves true if a known secondary header has been set

Returns
boolean

Definition at line 233 of file CCSDSDataField.h.

233 {
234 return m_secondaryHeader != nullptr;
235 }
Here is the caller graph for this function:

◆ getDataFieldUsedBytesSize()

uint16_t CCSDS::DataField::getDataFieldUsedBytesSize ( )

Retrieves the used size of the data field in bytes.

This method returns the amount of space currently occupied by valid data within the data field.

Returns
The used size of the data field in bytes.

Definition at line 33 of file CCSDSDataField.cpp.

33 {
34 update();
36 return m_applicationData.size();
37 }
38 if (m_secondaryHeader != nullptr) {
39 return m_applicationData.size() + m_secondaryHeader->getSize();
40 }
41 return 0;
42}
bool getDataFieldHeaderFlag() const
retrieves true if a known secondary header has been set

◆ getFullDataFieldBytes()

std::vector< uint8_t > CCSDS::DataField::getFullDataFieldBytes ( )

Retrieves the full data field by combining the data field header and application data.

Combines the secondary header (if present) and application data into a single vector. Ensures that the total size does not exceed the maximum allowed data packet size.

Returns
A vector containing the full data field (header + application data).

Definition at line 7 of file CCSDSDataField.cpp.

7 {
8 update();
9 const auto &dataFieldHeader = getDataFieldHeaderBytes();
10 std::vector<uint8_t> fullData{};
11 if (!dataFieldHeader.empty()) {
12 fullData.insert(fullData.end(), dataFieldHeader.begin(), dataFieldHeader.end());
13 }
14 fullData.insert(fullData.end(), m_applicationData.begin(), m_applicationData.end());
15 return fullData;
16}
std::vector< uint8_t > getDataFieldHeaderBytes()
Retrieves the secondary header data as a vector of bytes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSecondaryHeader()

std::shared_ptr< CCSDS::SecondaryHeaderAbstract > CCSDS::DataField::getSecondaryHeader ( )

retrieves the known PUS type

Returns
std::shared_ptr<SecondaryHeaderAbstract>

Definition at line 44 of file CCSDSDataField.cpp.

44 {
45 return m_secondaryHeader;
46}

◆ setApplicationData() [1/2]

CCSDS::ResultBool CCSDS::DataField::setApplicationData ( const std::vector< uint8_t > &  applicationData)

Sets the application data using a vector of bytes.

Replaces the current application data with the given vector and updates the header.

Parameters
applicationDataA vector containing the application data bytes.
Note
The method will log an error to standard error and ErrorCode is returned by ResultBool if provided data exceeds available size.
Returns
ResultBool.

Definition at line 71 of file CCSDSDataField.cpp.

71 {
73 "Application data field exceeds available size.");
74 m_applicationData = applicationData;
76 return true;
77}
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
uint16_t getDataFieldAvailableBytesSize()
Retrieves the available size of the data field in bytes.
bool m_dataFieldHeaderUpdated
Boolean for secondary header updated status.
@ INVALID_APPLICATION_DATA
Application data is invalid.
Definition CCSDSResult.h:26

◆ setApplicationData() [2/2]

CCSDS::ResultBool CCSDS::DataField::setApplicationData ( const uint8_t *  pData,
const size_t &  sizeData 
)

Sets the application data for the data field.

Validates and assigns the given application data to the data field. Ensures the data size is within acceptable limits and does not exceed

Parameters
pDataA pointer to the application data.
sizeDataThe size of the application data in bytes.
Note
The method will log an error to standard error and ErrorCode is returned by ResultBool if provided data is invalid.
Returns
ResultBool.

Definition at line 57 of file CCSDSDataField.cpp.

57 {
58 RET_IF_ERR_MSG(!pData, ErrorCode::NULL_POINTER, "Application data is nullptr");
59 RET_IF_ERR_MSG(sizeData < 1, ErrorCode::INVALID_APPLICATION_DATA, "Application data size cannot be < 1");
61 "Application data field exceeds available size");
62
63 if (!m_applicationData.empty()) {
64 std::cerr << "[ CCSDS Data ] Warning: Data field is not empty, it has been overwritten." << std::endl;
65 }
66 m_applicationData.assign(pData, pData + sizeData);
68 return true;
69}
@ NULL_POINTER
Null pointer encountered.
Definition CCSDSResult.h:27

◆ setDataFieldHeader() [1/5]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const std::vector< uint8_t > &  data,
const std::string &  pType 
)

Sets the data field header for the CCSDS DataField with a specific PUS type.

This method configures the data field header based on the provided data and the specified Packet Utilization Standard (PUS) type. It validates the header size to ensure it does not exceed the maximum allowed packet size and creates the appropriate header object based on the PUS type.

Parameters
dataA vector containing the data for the data field header.
pTypeThe PUS type (PUS_A, PUS_B, PUS_C, or OTHER) indicating the header format.
Note
If the PUS type is OTHER, the data is passed to the overloaded setDataFieldHeader method. The method will log an error to standard error and ErrorCode is returned by ResultBool if provided data is invalid.

Definition at line 110 of file CCSDSDataField.cpp.

111 {
113 "Secondary header data exceeds available size");
115 "Secondary header type is not registered: " + pType);
116
117 auto header = m_secondaryHeaderFactory.create(pType);
118
119 RET_IF_ERR_MSG(data.size() != header->getSize(), ErrorCode::INVALID_SECONDARY_HEADER_DATA,
120 "Secondary header data size mismatch for type: " + pType);
121
122
123 m_secondaryHeader = std::move(header);
124 FORWARD_RESULT(m_secondaryHeader->deserialize(data));
125
126 m_dataFieldHeaderType = pType;
127
129 return true;
130}
#define FORWARD_RESULT(result)
Macro to return a result as-is (for functions returning Result<T>).
std::string m_dataFieldHeaderType
Data field Header type.
std::shared_ptr< SecondaryHeaderAbstract > create(const std::string &type)
Creates an instance of a registered header type.
bool typeIsRegistered(const std::string &type)
Checks if a header type is registered.
@ INVALID_SECONDARY_HEADER_DATA
Secondary header data is invalid.
Definition CCSDSResult.h:25

◆ setDataFieldHeader() [2/5]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const std::vector< uint8_t > &  dataFieldHeader)

Sets the data field header for the CCSDS DataField.

This method updates the data field header with the provided vector of bytes. If the existing data field header is not empty, it clears the current contents and logs a warning to indicate that the header has been overwritten.

Parameters
dataFieldHeaderA vector containing the new data field header.
Note
The m_dataFieldHeaderType is set to OTHER after the header is updated. If the current data field header is not empty, it will be cleared. The method will log an error to standard error and ErrorCode is returned by ResultBool if provided data is invalid.

Definition at line 132 of file CCSDSDataField.cpp.

132 {
134 "Secondary header data exceeds available size");
135
136 BufferHeader header;
137 m_secondaryHeader = std::make_shared<BufferHeader>(dataFieldHeader);
138 FORWARD_RESULT( m_secondaryHeader->deserialize(dataFieldHeader) );
139
142 return true;
143}

◆ setDataFieldHeader() [3/5]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const uint8_t *  pData,
const size_t &  sizeData 
)

Sets the secondary header data for the data field.

Validates and assigns the given secondary header data to the data field. Ensures the data size is within acceptable limits and does not exceed the remaining packet size after accounting for the header.

Parameters
pDataA pointer to the application data.
sizeDataThe size of the application data in bytes.
Note
The method will log an error to standard error and ErrorCode is returned by ResultBool if provided data is invalid.
Returns
ResultBool.

Definition at line 79 of file CCSDSDataField.cpp.

79 {
80 RET_IF_ERR_MSG(!pData, ErrorCode::NULL_POINTER, "Secondary header data is nullptr");
81 RET_IF_ERR_MSG(sizeData < 1, ErrorCode::INVALID_SECONDARY_HEADER_DATA, "Secondary header data size cannot be < 1");
83 "Secondary header data exceeds available size.");
84
85 std::vector<uint8_t> data;
86 data.assign(pData, pData + sizeData);
88 return true;
89}
ResultBool setDataFieldHeader(const uint8_t *pData, const size_t &sizeData)
Sets the secondary header data for the data field.

◆ setDataFieldHeader() [4/5]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const uint8_t *  pData,
const size_t &  sizeData,
const std::string &  pType 
)

Sets the secondary header for the data field using a PUS Type.

Validates and assigns the given header data to the secondary header field. Ensures the header size is within acceptable limits and does not exceed the remaining packet size after accounting for the application data.

Parameters
pDataA pointer to the header data.
sizeDataThe size of the header data in bytes.
pTypeenum of type PUSType to select
Note
If the PUS type is OTHER, the data is passed to the overloaded setDataFieldHeader method. The method will log an error to standard error and ErrorCode is returned by ResultBool if provided data is invalid.
Returns
ResultBool.

Definition at line 91 of file CCSDSDataField.cpp.

92 {
93 RET_IF_ERR_MSG(!pData, ErrorCode::NULL_POINTER, "Secondary header data is nullptr");
94
96 "Secondary header type is not registered: " + pType);
97
99 std::vector<uint8_t> data;
100 data.assign(pData, pData + sizeData);
102 } else {
103 FORWARD_RESULT(setDataFieldHeader(pData, sizeData));
104 m_dataFieldHeaderType = pType;
105 }
107 return true;
108}

◆ setDataFieldHeader() [5/5]

void CCSDS::DataField::setDataFieldHeader ( std::shared_ptr< SecondaryHeaderAbstract header)

Sets the secondary header for the data field using a PUS-A header.

Parameters
headerA SecondaryHeaderAbstract derived object containing the header data.
Returns
None.

Definition at line 145 of file CCSDSDataField.cpp.

145 {
146 m_secondaryHeader = std::move(header);
149}

◆ setDataFieldHeaderAutoUpdateStatus()

void CCSDS::DataField::setDataFieldHeaderAutoUpdateStatus ( const bool  enable)
inline

Sets The auto update variable, if disabled the data size in the header field will not be updated.

Parameters
enable

Definition at line 166 of file CCSDSDataField.h.

166{ m_enableDataFieldUpdate = enable; }

◆ setDataPacketSize()

void CCSDS::DataField::setDataPacketSize ( const uint16_t &  value)

Sets the maximum data packet size for the CCSDS DataField.

This method updates the maximum allowed size for the data packet. The data packet size is used to validate that the combined size of the header and application data does not exceed this limit.

Parameters
valueThe maximum size of the data packet, in bytes.

Definition at line 151 of file CCSDSDataField.cpp.

151{ m_dataPacketSize = value; }

◆ update()

void CCSDS::DataField::update ( )

Updates the data field header based on the current application data size.

Updates the length field in the secondary header to match the size of the application data. Ensures the header reflects the most recent data state.

Returns
None.

Definition at line 48 of file CCSDSDataField.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_applicationData

std::vector<uint8_t> CCSDS::DataField::m_applicationData {}
private

Application data buffer.

Definition at line 257 of file CCSDSDataField.h.

257{};

◆ m_dataFieldHeaderType

std::string CCSDS::DataField::m_dataFieldHeaderType {}
private

Data field Header type.

Definition at line 258 of file CCSDSDataField.h.

258{};

◆ m_dataFieldHeaderUpdated

bool CCSDS::DataField::m_dataFieldHeaderUpdated {false}
private

Boolean for secondary header updated status.

Definition at line 260 of file CCSDSDataField.h.

260{false};

◆ m_dataPacketSize

uint16_t CCSDS::DataField::m_dataPacketSize {2024}
private

Data field maximum size in bytes.

Definition at line 259 of file CCSDSDataField.h.

259{2024};

◆ m_enableDataFieldUpdate

bool CCSDS::DataField::m_enableDataFieldUpdate {true}
private

Boolean for secondary header update enable.

Definition at line 261 of file CCSDSDataField.h.

261{true};

◆ m_secondaryHeader

std::shared_ptr<SecondaryHeaderAbstract> CCSDS::DataField::m_secondaryHeader {}
private

Shared pointer to the secondary header class.

Definition at line 255 of file CCSDSDataField.h.

255{};

◆ m_secondaryHeaderFactory

SecondaryHeaderFactory CCSDS::DataField::m_secondaryHeaderFactory
private

secondary header dispatcher factory

Definition at line 256 of file CCSDSDataField.h.


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