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
 
template<typename T >
ResultBool RegisterSecondaryHeader ()
 Registers a new header type with its creation function.
 
ResultBool setApplicationData (const std::vector< std::uint8_t > &applicationData)
 Sets the application data using a vector of bytes.
 
ResultBool setApplicationData (const std::uint8_t *pData, const size_t &sizeData)
 Sets the application data for the data field.
 
ResultBool setDataFieldHeader (const std::uint8_t *pData, const size_t &sizeData)
 Sets the secondary header data for the data field.
 
ResultBool setDataFieldHeader (const std::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< std::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< std::uint8_t > &dataFieldHeader)
 Sets the data field header for the CCSDS DataField.
 
ResultBool setDataFieldHeader (const Config &cfg)
 Sets the data field header using a configuration file as reference.
 
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 std::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.
 
std::uint16_t getDataFieldAbsoluteBytesSize () const
 Retrieves the absolute size of the data field in bytes.
 
std::uint16_t getApplicationDataBytesSize () const
 Retrieves the size of the application data stored in the data field.
 
std::uint16_t getDataFieldUsedBytesSize () const
 Retrieves the used size of the data field in bytes.
 
std::uint16_t getDataFieldAvailableBytesSize () const
 Retrieves the available size of the data field in bytes.
 
std::vector< std::uint8_t > getDataFieldHeaderBytes ()
 Retrieves the secondary header data as a vector of bytes.
 
std::vector< std::uint8_t > serialize ()
 Retrieves the full data field by combining the data field header and application data.
 
std::vector< std::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< std::uint8_t > m_applicationData {}
 Application data buffer.
 
std::string m_dataFieldHeaderType {}
 Data field Header type.
 
std::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 25 of file CCSDSDataField.h.

Constructor & Destructor Documentation

◆ DataField()

CCSDS::DataField::DataField ( )
inline

Definition at line 27 of file CCSDSDataField.h.

27 {
28 bool noError = true;
29 ASSIGN_OR_PRINT(noError, m_secondaryHeaderFactory.registerType(std::make_shared<BufferHeader>()));
30 ASSIGN_OR_PRINT(noError, m_secondaryHeaderFactory.registerType(std::make_shared<PusA>()));
31 ASSIGN_OR_PRINT(noError, m_secondaryHeaderFactory.registerType(std::make_shared<PusB>()));
32 ASSIGN_OR_PRINT(noError, m_secondaryHeaderFactory.registerType(std::make_shared<PusC>()));
33 if (!noError) {
34 printf("[CCSDS DataField] Unable to Create Data field, secondary header registration failed.");
35 }
36 };
#define ASSIGN_OR_PRINT(var, result)
Macro to assign a result value or print an error message.
SecondaryHeaderFactory m_secondaryHeaderFactory
secondary header dispatcher factory
ResultBool 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< std::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 17 of file CCSDSDataField.cpp.

17 {
18 return m_applicationData;
19}
std::vector< std::uint8_t > m_applicationData
Application data buffer.
Here is the caller graph for this function:

◆ getApplicationDataBytesSize()

uint16_t CCSDS::DataField::getApplicationDataBytesSize ( ) const

Retrieves the size of the application data stored in the data field.

Returns
The size of the application data in bytes

Definition at line 29 of file CCSDSDataField.cpp.

29 {
30 return m_applicationData.size();
31}
Here is the caller graph for this function:

◆ getDataFieldAbsoluteBytesSize()

uint16_t CCSDS::DataField::getDataFieldAbsoluteBytesSize ( ) const

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 25 of file CCSDSDataField.cpp.

25 {
26 return m_dataPacketSize;
27}
std::uint16_t m_dataPacketSize
Data field maximum size in bytes.

◆ getDataFieldAvailableBytesSize()

uint16_t CCSDS::DataField::getDataFieldAvailableBytesSize ( ) const

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 21 of file CCSDSDataField.cpp.

21 {
23}
std::uint16_t getDataFieldUsedBytesSize() const
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 182 of file CCSDSDataField.h.

182{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 266 of file CCSDSDataField.h.

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

◆ getDataFieldHeaderBytes()

std::vector< std::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 173 of file CCSDSDataField.cpp.

173 {
174 update();
175 if (m_secondaryHeader) {
176 return m_secondaryHeader->serialize();
177 }
178 return {};
179}
void update()
Updates the data field header based on the current application data size.
Here is the caller graph for this function:

◆ getDataFieldHeaderFactory()

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

returns the secondary header factory

Returns
SecondaryHeaderFactory& .

Definition at line 174 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 273 of file CCSDSDataField.h.

273 {
274 return m_secondaryHeader != nullptr;
275 }
Here is the caller graph for this function:

◆ getDataFieldUsedBytesSize()

uint16_t CCSDS::DataField::getDataFieldUsedBytesSize ( ) const

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 34 of file CCSDSDataField.cpp.

34 {
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

◆ 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 update();
46 return m_secondaryHeader;
47}

◆ RegisterSecondaryHeader()

template<typename T >
ResultBool CCSDS::DataField::RegisterSecondaryHeader ( )
inline

Registers a new header type with its creation function.

This function adds a new header type to the factory by associating the header's type string with a shared pointer to the header.

Parameters
headerA shared pointer to a SecondaryHeaderAbstract object to register.
Returns
ResultBool.

Definition at line 49 of file CCSDSDataField.h.

49 {
50
52
53 return true;
54 }
#define FORWARD_RESULT(result)
Macro to return a result as-is (for functions returning Result<T>).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ serialize()

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

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 6 of file CCSDSDataField.cpp.

6 {
7 update();
8 const auto &dataFieldHeader = getDataFieldHeaderBytes();
9 std::vector<std::uint8_t> fullData{};
10 if (!dataFieldHeader.empty()) {
11 fullData.insert(fullData.end(), dataFieldHeader.begin(), dataFieldHeader.end());
12 }
13 fullData.insert(fullData.end(), m_applicationData.begin(), m_applicationData.end());
14 return fullData;
15}
std::vector< std::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:

◆ setApplicationData() [1/2]

CCSDS::ResultBool CCSDS::DataField::setApplicationData ( const std::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 58 of file CCSDSDataField.cpp.

58 {
59 RET_IF_ERR_MSG(!pData, ErrorCode::NULL_POINTER, "Application data is nullptr");
60 RET_IF_ERR_MSG(sizeData < 1, ErrorCode::INVALID_APPLICATION_DATA, "Application data size cannot be < 1");
62 "Application data field exceeds available size");
63
64 if (!m_applicationData.empty()) {
65 printf( "[ CCSDS Data ] Warning: Data field is not empty, it has been overwritten.");
66 }
67 m_applicationData.assign(pData, pData + sizeData);
69 return true;
70}
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
bool m_dataFieldHeaderUpdated
Boolean for secondary header updated status.
std::uint16_t getDataFieldAvailableBytesSize() const
Retrieves the available size of the data field in bytes.
@ INVALID_APPLICATION_DATA
Application data is invalid.
Definition CCSDSResult.h:27
@ NULL_POINTER
Null pointer encountered.
Definition CCSDSResult.h:28

◆ setApplicationData() [2/2]

CCSDS::ResultBool CCSDS::DataField::setApplicationData ( const std::vector< std::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 72 of file CCSDSDataField.cpp.

72 {
74 "Application data field exceeds available size.");
75 m_applicationData = applicationData;
77 return true;
78}

◆ setDataFieldHeader() [1/6]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const Config cfg)

Sets the data field header using a configuration file as reference.

Note
The config file must contain all required parameter for the interested secondary header, including the secondary_header_type string indicating which registered secondary header to be parsed.
Parameters
cfgconfiguration file parser object.
Returns
ResultBool

Definition at line 148 of file CCSDSDataField.cpp.

148 {
149 RET_IF_ERR_MSG(!cfg.isKey("secondary_header_type"), ErrorCode::CONFIG_FILE_ERROR,
150 "Config: Missing string field: secondary_header_type");
151 std::string type{};
152 ASSIGN_OR_PRINT(type, cfg.get<std::string>("secondary_header_type"));
154 "Secondary header type is not registered: " + type);
155
158 "Failed to create secondary header of type: " + type);
159 m_secondaryHeader->loadFromConfig(cfg);
161 return true;
162}
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.
bool isKey(const std::string &key) const
CCSDS::Result< T > get(const std::string &key) const
Get value by key and type.
Definition CCSDSConfig.h:20
@ CONFIG_FILE_ERROR
Configuration file error.
Definition CCSDSResult.h:34
@ INVALID_SECONDARY_HEADER_DATA
Secondary header data is invalid.
Definition CCSDSResult.h:26
Here is the call graph for this function:

◆ setDataFieldHeader() [2/6]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const std::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 80 of file CCSDSDataField.cpp.

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

◆ setDataFieldHeader() [3/6]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const std::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 92 of file CCSDSDataField.cpp.

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

◆ setDataFieldHeader() [4/6]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const std::vector< std::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 111 of file CCSDSDataField.cpp.

112 {
114 "Secondary header data exceeds available size");
116 "Secondary header type is not registered: " + pType);
117
118 auto header = m_secondaryHeaderFactory.create(pType);
119
120 if (!header->variableLength) {
121 RET_IF_ERR_MSG(data.size() != header->getSize(), ErrorCode::INVALID_SECONDARY_HEADER_DATA,
122 "Secondary header data size mismatch for type: " + pType);
123 }
124
125 m_secondaryHeader = std::move(header);
126 FORWARD_RESULT(m_secondaryHeader->deserialize(data));
127
128 m_dataFieldHeaderType = pType;
129
131 return true;
132}

◆ setDataFieldHeader() [5/6]

CCSDS::ResultBool CCSDS::DataField::setDataFieldHeader ( const std::vector< std::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.
Returns
ResultBool

Definition at line 134 of file CCSDSDataField.cpp.

134 {
136 "Secondary header data exceeds available size");
137
138 BufferHeader header;
139 m_secondaryHeader = std::make_shared<BufferHeader>(dataFieldHeader);
140 FORWARD_RESULT( m_secondaryHeader->deserialize(dataFieldHeader) );
141
144 return true;
145}

◆ setDataFieldHeader() [6/6]

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 165 of file CCSDSDataField.cpp.

165 {
166 m_secondaryHeader = std::move(header);
169}

◆ 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 199 of file CCSDSDataField.h.

199{ m_enableDataFieldUpdate = enable; }

◆ setDataPacketSize()

void CCSDS::DataField::setDataPacketSize ( const std::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 171 of file CCSDSDataField.cpp.

171{ 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 49 of file CCSDSDataField.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_applicationData

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

Application data buffer.

Definition at line 297 of file CCSDSDataField.h.

297{};

◆ m_dataFieldHeaderType

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

Data field Header type.

Definition at line 298 of file CCSDSDataField.h.

298{};

◆ m_dataFieldHeaderUpdated

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

Boolean for secondary header updated status.

Definition at line 300 of file CCSDSDataField.h.

300{false};

◆ m_dataPacketSize

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

Data field maximum size in bytes.

Definition at line 299 of file CCSDSDataField.h.

299{2024};

◆ m_enableDataFieldUpdate

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

Boolean for secondary header update enable.

Definition at line 301 of file CCSDSDataField.h.

301{true};

◆ m_secondaryHeader

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

Shared pointer to the secondary header class.

Definition at line 295 of file CCSDSDataField.h.

295{};

◆ m_secondaryHeaderFactory

SecondaryHeaderFactory CCSDS::DataField::m_secondaryHeaderFactory
private

secondary header dispatcher factory

Definition at line 296 of file CCSDSDataField.h.


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