CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
CCSDSPacket.h
Go to the documentation of this file.
1#ifndef CCSDS_PACKET_H
2#define CCSDS_PACKET_H
3
23#include <CCSDSResult.h>
24#include <vector>
25#include "CCSDSHeader.h"
26#include "CCSDSDataField.h"
27
32namespace CCSDS {
33
35 struct CRC16Config {
36 std::uint16_t polynomial = 0x1021;
37 std::uint16_t initialValue = 0xFFFF;
38 std::uint16_t finalXorValue = 0x0000;
39 };
40
41
59 class Packet {
60 public:
61 Packet() = default;
62
73
84 [[nodiscard]] ResultBool setPrimaryHeader(std::uint64_t data);
85
96 [[nodiscard]] ResultBool setPrimaryHeader(const std::vector<std::uint8_t> &data);
97
106 void setPrimaryHeader(const Header &header);
107
117 void setDataFieldHeader(const std::shared_ptr<SecondaryHeaderAbstract> &header);
118
127 template <typename T>
132
146 [[nodiscard]] ResultBool setDataFieldHeader(const std::vector<std::uint8_t> &data, const std::string &headerType);
147
162 [[nodiscard]] ResultBool setDataFieldHeader(const std::uint8_t *pData, size_t sizeData, const std::string &headerType);
163
175 [[nodiscard]] ResultBool setDataFieldHeader(const std::vector<std::uint8_t> &data);
176
189 [[nodiscard]] ResultBool setDataFieldHeader(const std::uint8_t *pData, size_t sizeData);
190
202 [[nodiscard]] ResultBool setApplicationData(const std::vector<std::uint8_t> &data);
203
216 [[nodiscard]] ResultBool setApplicationData(const std::uint8_t *pData, size_t sizeData);
217
228
230 [[nodiscard]] ResultBool setSequenceCount(std::uint16_t count);
231
241 void setDataFieldSize(std::uint16_t size);
242
247 void setUpdatePacketEnable(bool enable);
248
250 [[nodiscard]] ResultBool deserialize(const std::vector<std::uint8_t> &data);
251
253 [[nodiscard]] ResultBool deserialize(const std::vector<std::uint8_t> &data, const std::string& headerType, std::int32_t headerSize = -1);
254
256 [[nodiscard]] ResultBool deserialize(const std::vector<uint8_t> &data, std::uint16_t headerDataSizeBytes);
257
259 [[nodiscard]] ResultBool deserialize(const std::vector<uint8_t> &headerData, const std::vector<uint8_t> &data);
260
270 std::uint64_t getPrimaryHeader64bit();
271
276 std::uint16_t getFullPacketLength();
277
289 std::vector<uint8_t> serialize();
290
300 std::vector<uint8_t> getPrimaryHeaderBytes();
301
307 std::vector<uint8_t> getDataFieldHeaderBytes();
308
314 std::vector<uint8_t> getApplicationDataBytes();
315
321 std::vector<uint8_t> getFullDataFieldBytes();
322
331 std::vector<uint8_t> getCRCVectorBytes();
332
342 std::uint16_t getCRC();
343
345 std::uint16_t getDataFieldMaximumSize() const;
346
349
352
355
367 void setCrcConfig(const CRC16Config crcConfig) {m_CRC16Config = crcConfig;}
368
369
383 void setCrcConfig(const std::uint16_t polynomial, const std::uint16_t initialValue, const std::uint16_t finalXorValue) {m_CRC16Config = {polynomial, initialValue, finalXorValue};}
384
392 void update();
393
400 ResultBool loadFromConfigFile(const std::string &configPath);
401
408#ifndef CCSDS_MCU
409 ResultBool loadFromConfig(const Config &cfg);
410#endif
411
412 private:
415 std::uint16_t m_CRC16{};
417 bool m_updateStatus{false};
419 std::uint16_t m_sequenceCounter{0};
420 };
421}
422#endif // CCSDS_PACKET_H
#define FORWARD_RESULT(result)
Macro to return a result as-is (for functions returning Result<T>).
Represents the data field of a CCSDS packet.
ResultBool RegisterSecondaryHeader()
Registers a new header type with its creation function.
Manages the decomposition and manipulation of CCSDS primary headers.
Definition CCSDSHeader.h:80
Represents a CCSDS (Consultative Committee for Space Data Systems) packet.
Definition CCSDSPacket.h:59
ResultBool setDataFieldHeader(const std::vector< std::uint8_t > &data, const std::string &headerType)
Sets the data field header for the packet using a vector of bytes.
bool m_updateStatus
When setting data thus value should be set to false.
Packet()=default
ResultBool deserialize(const std::vector< uint8_t > &headerData, const std::vector< uint8_t > &data)
Deserializes a CCSDS packet using separate header and data vectors.
std::vector< uint8_t > getPrimaryHeaderBytes()
Retrieves the primary header of the packet as a vector of bytes.
void setCrcConfig(const std::uint16_t polynomial, const std::uint16_t initialValue, const std::uint16_t finalXorValue)
Sets the crc configuration of the crc calculation.
void update()
Updates Primary headers data field size.
std::vector< uint8_t > getCRCVectorBytes()
Retrieves the CRC-16 checksum as a vector of bytes.
void setUpdatePacketEnable(bool enable)
needs to be called as soon as possible, probably also from constructor.
ResultBool setSequenceCount(std::uint16_t count)
Sets the sequence count for the packet.
ResultBool setPrimaryHeader(const std::vector< std::uint8_t > &data)
Sets the primary header using the provided vector of std::uint8_tdata.
bool getDataFieldHeaderFlag()
@ returns the data field header flag
void setDataFieldHeader(const std::shared_ptr< SecondaryHeaderAbstract > &header)
Sets the data field header using the provided SecondaryHeaderAbstract derived header.
std::uint16_t m_sequenceCounter
Header m_primaryHeader
6 bytes / 48 bits / 12 hex
std::uint64_t getPrimaryHeader64bit()
Retrieves the primary header of the packet.
DataField m_dataField
variable
ResultBool loadFromConfig(const Config &cfg)
Loads a packet from a configuration object, including secondary header if present.
std::uint16_t getCRC()
Computes and retrieves the CRC-16 checksum of the packet.
std::uint16_t getDataFieldMaximumSize() const
returns the maximum data field size
void setSequenceFlags(ESequenceFlag flags)
Sets the sequence flags for the packet's primary header.
std::vector< uint8_t > getFullDataFieldBytes()
Retrieves the full data field data.
std::vector< uint8_t > serialize()
Retrieves the full packet as a vector of bytes.
ResultBool loadFromConfigFile(const std::string &configPath)
Loads a packet from a configuration file, including secondary header if present.
ResultBool setApplicationData(const std::vector< std::uint8_t > &data)
Sets the application data for the packet.
std::uint16_t m_CRC16
Cyclic Redundancy check 16 bits.
std::vector< uint8_t > getDataFieldHeaderBytes()
Retrieves the secondary header data from the data field.
void setPrimaryHeader(PrimaryHeader data)
Sets the primary header using the provided PrimaryHeader object.
ResultBool deserialize(const std::vector< std::uint8_t > &data)
Deserializes a vector of bytes into a CCSDS packet.
std::uint16_t getFullPacketLength()
Retrieves the current size of the CCSDS Packet.
ResultBool RegisterSecondaryHeader()
Registers a new header type with the data field secondary header creation function.
Header & getPrimaryHeader()
returns the CCSDS packet's Primary Header.
ResultBool setDataFieldHeader(const std::vector< std::uint8_t > &data)
Sets the data field header using the provided vector of bytes.
std::vector< uint8_t > getApplicationDataBytes()
Retrieves the application data from the data field.
DataField & getDataField()
returns the CCSDS packet's DataField.
bool m_enableUpdatePacket
Enables primary header and secondary header update.
ResultBool deserialize(const std::vector< uint8_t > &data, std::uint16_t headerDataSizeBytes)
Deserializes a CCSDS packet using a vector and a header data size.
void setDataFieldSize(std::uint16_t size)
Sets the maximum data packet size for the CCSDS DataField.
CRC16Config m_CRC16Config
structure holding configuration of crc calculation.
void setCrcConfig(const CRC16Config crcConfig)
Sets the crc configuration of the crc calculation.
Encapsulates a result that can hold either a value or an Error.
Definition CCSDSResult.h:82
Parses and stores config values from custom file format.
Definition CCSDSConfig.h:11
Contains definitions and classes for handling CCSDS headers.
ESequenceFlag
Represents the sequence flags used in CCSDS telemetry transfer frames.
Definition CCSDSHeader.h:19
Configuration structure for CRC16 calculation parameters.
Definition CCSDSPacket.h:35
std::uint16_t initialValue
Definition CCSDSPacket.h:37
std::uint16_t polynomial
Definition CCSDSPacket.h:36
std::uint16_t finalXorValue
Definition CCSDSPacket.h:38
Represents the primary header of a CCSDS packet.
Definition CCSDSHeader.h:41