12 std::vector<std::uint8_t> fullData{};
13 if (!dataFieldHeader.empty()) {
14 fullData.insert(fullData.end(), dataFieldHeader.begin(), dataFieldHeader.end());
21 return m_applicationData;
25 return m_dataPacketSize - getDataFieldUsedBytesSize();
29 return m_dataPacketSize;
33 return m_applicationData.size();
38 if (!getDataFieldHeaderFlag()) {
39 return m_applicationData.size();
41 if (m_secondaryHeader !=
nullptr) {
42 return m_applicationData.size() + m_secondaryHeader->getSize();
49 return m_secondaryHeader;
53 if (!m_dataFieldHeaderUpdated && m_enableDataFieldUpdate) {
54 if (m_secondaryHeaderFactory.typeIsRegistered(m_dataFieldHeaderType)) {
55 m_secondaryHeader->update(
this);
57 m_dataFieldHeaderUpdated =
true;
65 "Application data field exceeds available size");
67 if (!m_applicationData.empty()) {
68 printf(
"[ CCSDS Data ] Warning: Data field is not empty, it has been overwritten.");
70 m_applicationData.assign(pData, pData + sizeData);
71 m_dataFieldHeaderUpdated =
false;
77 "Application data field exceeds available size.");
78 m_applicationData = applicationData;
79 m_dataFieldHeaderUpdated =
false;
87 "Secondary header data exceeds available size.");
89 std::vector<std::uint8_t> data;
90 data.assign(pData, pData + sizeData);
96 const std::string &pType) {
100 "Secondary header type is not registered: " + pType);
102 if (m_secondaryHeaderFactory.typeIsRegistered(pType)) {
103 std::vector<std::uint8_t> data;
104 data.assign(pData, pData + sizeData);
108 m_dataFieldHeaderType = pType;
110 m_dataFieldHeaderUpdated =
false;
115 const std::string &pType) {
117 "Secondary header data exceeds available size");
119 "Secondary header type is not registered: " + pType);
121 auto header = m_secondaryHeaderFactory.create(pType);
123 if (!header->variableLength) {
125 "Secondary header data size mismatch for type: " + pType);
128 m_secondaryHeader = std::move(header);
131 m_dataFieldHeaderType = pType;
133 m_dataFieldHeaderUpdated =
false;
139 "Secondary header data exceeds available size");
142 m_secondaryHeader = std::make_shared<BufferHeader>(dataFieldHeader);
143 FORWARD_RESULT( m_secondaryHeader->deserialize(dataFieldHeader) );
145 m_dataFieldHeaderType = m_secondaryHeader->getType(); ;
146 m_dataFieldHeaderUpdated =
false;
153 "Config: Missing string field: secondary_header_type");
157 "Secondary header type is not registered: " + type);
159 m_secondaryHeader = m_secondaryHeaderFactory.create(type);
161 "Failed to create secondary header of type: " + type);
162 m_secondaryHeader->loadFromConfig(cfg);
163 m_dataFieldHeaderType = m_secondaryHeader->getType();
169 m_secondaryHeader = std::move(header);
170 m_dataFieldHeaderType = m_secondaryHeader->getType();
171 m_dataFieldHeaderUpdated =
false;
178 if (m_secondaryHeader) {
179 return m_secondaryHeader->serialize();
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
#define ASSIGN_OR_PRINT(var, result)
Macro to assign a result value or print an error message.
#define FORWARD_RESULT(result)
Macro to return a result as-is (for functions returning Result<T>).
std::vector< std::uint8_t > serialize()
Retrieves the full data field by combining the data field header and application data.
std::shared_ptr< SecondaryHeaderAbstract > getSecondaryHeader()
retrieves the known PUS type
std::uint16_t getDataFieldUsedBytesSize() const
Retrieves the used size of the data field in bytes.
void setDataPacketSize(const std::uint16_t &value)
Sets the maximum data packet size for the CCSDS DataField.
ResultBool setDataFieldHeader(const std::uint8_t *pData, const size_t &sizeData)
Sets the secondary header data for the data field.
std::uint16_t getDataFieldAbsoluteBytesSize() const
Retrieves the absolute size of the data field in bytes.
void update()
Updates the data field header based on the current application data size.
std::vector< std::uint8_t > getDataFieldHeaderBytes()
Retrieves the secondary header data as a vector of bytes.
std::uint16_t getApplicationDataBytesSize() const
Retrieves the size of the application data stored in the data field.
std::vector< std::uint8_t > getApplicationData()
Retrieves the application data from the data field.
std::vector< std::uint8_t > m_applicationData
Application data buffer.
ResultBool setApplicationData(const std::vector< std::uint8_t > &applicationData)
Sets the application data using a vector of bytes.
std::uint16_t getDataFieldAvailableBytesSize() const
Retrieves the available size of the data field in bytes.
Encapsulates a result that can hold either a value or an Error.
Parses and stores config values from custom file format.
bool isKey(const std::string &key) const
CCSDS::Result< T > get(const std::string &key) const
Get value by key and type.
@ INVALID_APPLICATION_DATA
Application data is invalid.
@ CONFIG_FILE_ERROR
Configuration file error.
@ INVALID_SECONDARY_HEADER_DATA
Secondary header data is invalid.
@ NULL_POINTER
Null pointer encountered.