9 std::vector<std::uint8_t> fullData{};
10 if (!dataFieldHeader.empty()) {
11 fullData.insert(fullData.end(), dataFieldHeader.begin(), dataFieldHeader.end());
18 return m_applicationData;
22 return m_dataPacketSize - getDataFieldUsedBytesSize();
26 return m_dataPacketSize;
30 return m_applicationData.size();
35 if (!getDataFieldHeaderFlag()) {
36 return m_applicationData.size();
38 if (m_secondaryHeader !=
nullptr) {
39 return m_applicationData.size() + m_secondaryHeader->getSize();
46 return m_secondaryHeader;
50 if (!m_dataFieldHeaderUpdated && m_enableDataFieldUpdate) {
51 if (m_secondaryHeaderFactory.typeIsRegistered(m_dataFieldHeaderType)) {
52 m_secondaryHeader->update(
this);
54 m_dataFieldHeaderUpdated =
true;
62 "Application data field exceeds available size");
64 if (!m_applicationData.empty()) {
65 printf(
"[ CCSDS Data ] Warning: Data field is not empty, it has been overwritten.");
67 m_applicationData.assign(pData, pData + sizeData);
68 m_dataFieldHeaderUpdated =
false;
74 "Application data field exceeds available size.");
75 m_applicationData = applicationData;
76 m_dataFieldHeaderUpdated =
false;
84 "Secondary header data exceeds available size.");
86 std::vector<std::uint8_t> data;
87 data.assign(pData, pData + sizeData);
93 const std::string &pType) {
97 "Secondary header type is not registered: " + pType);
99 if (m_secondaryHeaderFactory.typeIsRegistered(pType)) {
100 std::vector<std::uint8_t> data;
101 data.assign(pData, pData + sizeData);
105 m_dataFieldHeaderType = pType;
107 m_dataFieldHeaderUpdated =
false;
112 const std::string &pType) {
114 "Secondary header data exceeds available size");
116 "Secondary header type is not registered: " + pType);
118 auto header = m_secondaryHeaderFactory.create(pType);
120 if (!header->variableLength) {
122 "Secondary header data size mismatch for type: " + pType);
125 m_secondaryHeader = std::move(header);
128 m_dataFieldHeaderType = pType;
130 m_dataFieldHeaderUpdated =
false;
136 "Secondary header data exceeds available size");
139 m_secondaryHeader = std::make_shared<BufferHeader>(dataFieldHeader);
140 FORWARD_RESULT( m_secondaryHeader->deserialize(dataFieldHeader) );
142 m_dataFieldHeaderType = m_secondaryHeader->getType(); ;
143 m_dataFieldHeaderUpdated =
false;
150 "Config: Missing string field: secondary_header_type");
154 "Secondary header type is not registered: " + type);
156 m_secondaryHeader = m_secondaryHeaderFactory.create(type);
158 "Failed to create secondary header of type: " + type);
159 m_secondaryHeader->loadFromConfig(cfg);
160 m_dataFieldHeaderType = m_secondaryHeader->getType();
166 m_secondaryHeader = std::move(header);
167 m_dataFieldHeaderType = m_secondaryHeader->getType();
168 m_dataFieldHeaderUpdated =
false;
175 if (m_secondaryHeader) {
176 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.