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 <cstdint>
25#include <vector>
26#include "CCSDSHeader.h"
27#include "CCSDSDataField.h"
28
33namespace CCSDS {
34
36 struct CRC16Config {
37 uint16_t polynomial = 0x1021;
38 uint16_t initialValue = 0xFFFF;
39 uint16_t finalXorValue = 0x0000;
40 };
41
42
60 class Packet {
61 public:
62 Packet() = default;
63
74
85 [[nodiscard]] ResultBool setPrimaryHeader(uint64_t data);
86
97 [[nodiscard]] ResultBool setPrimaryHeader(const std::vector<uint8_t> &data);
98
107 void setPrimaryHeader(const Header &header);
108
118 void setDataFieldHeader(const std::shared_ptr<SecondaryHeaderAbstract> &header);
119
133 [[nodiscard]] ResultBool setDataFieldHeader(const std::vector<uint8_t> &data, const std::string &headerType);
134
149 [[nodiscard]] ResultBool setDataFieldHeader(const uint8_t *pData, size_t sizeData, const std::string &headerType);
150
162 [[nodiscard]] ResultBool setDataFieldHeader(const std::vector<uint8_t> &data);
163
176 [[nodiscard]] ResultBool setDataFieldHeader(const uint8_t *pData, size_t sizeData);
177
189 [[nodiscard]] ResultBool setApplicationData(const std::vector<uint8_t> &data);
190
203 [[nodiscard]] ResultBool setApplicationData(const uint8_t *pData, size_t sizeData);
204
215
217 [[nodiscard]] ResultBool setSequenceCount(uint16_t count);
218
228 void setDataFieldSize(uint16_t size);
229
234 void setUpdatePacketEnable(bool enable);
235
237 [[nodiscard]] ResultBool deserialize(const std::vector<uint8_t> &data);
238
240 [[nodiscard]] ResultBool deserialize(const std::vector<uint8_t> &data, const std::string& headerType);
241
243 [[nodiscard]] ResultBool deserialize(const std::vector<uint8_t> &data, uint16_t headerDataSizeBytes);
244
246 [[nodiscard]] ResultBool deserialize(const std::vector<uint8_t> &headerData, const std::vector<uint8_t> &data);
247
257 uint64_t getPrimaryHeader64bit();
258
263 uint16_t getFullPacketLength();
264
276 std::vector<uint8_t> serialize();
277
287 std::vector<uint8_t> getPrimaryHeaderBytes();
288
294 std::vector<uint8_t> getDataFieldHeaderBytes();
295
301 std::vector<uint8_t> getApplicationDataBytes();
302
308 std::vector<uint8_t> getFullDataFieldBytes();
309
318 std::vector<uint8_t> getCRCVectorBytes();
319
329 uint16_t getCRC();
330
332 uint16_t getDataFieldMaximumSize();
333
336
339
342
354 void setCrcConfig(const CRC16Config crcConfig) {m_CRC16Config = crcConfig;}
355
356
370 void setCrcConfig(const uint16_t polynomial, const uint16_t initialValue, const uint16_t finalXorValue) {m_CRC16Config = {polynomial, initialValue, finalXorValue};}
371
379 void update();
380
381 private:
384 uint16_t m_CRC16{};
386 bool m_updateStatus{false};
388 uint16_t m_sequenceCounter{0};
389 };
390}
391#endif // CCSDS_PACKET_H
Represents the data field of a CCSDS packet.
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:60
uint16_t m_CRC16
Cyclic Redundancy check 16 bits.
ResultBool setSequenceCount(uint16_t count)
Sets the sequence count for the packet.
std::vector< uint8_t > serialize()
Retrieves the full packet as 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 > &data)
Deserializes a vector of bytes into a CCSDS packet.
void update()
Updates Primary headers data field size.
ResultBool setApplicationData(const std::vector< uint8_t > &data)
Sets the application data for the packet.
void setUpdatePacketEnable(bool enable)
needs to be called as soon as possible, probably also from constructor.
void setCrcConfig(const uint16_t polynomial, const uint16_t initialValue, const uint16_t finalXorValue)
Sets the crc configuration of the crc calculation.
void setDataFieldSize(uint16_t size)
Sets the maximum data packet size for the CCSDS DataField.
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.
Header m_primaryHeader
6 bytes / 48 bits / 12 hex
uint64_t getPrimaryHeader64bit()
Retrieves the primary header of the packet.
DataField m_dataField
variable
uint16_t getCRC()
Computes and retrieves the CRC-16 checksum of the packet.
void setSequenceFlags(ESequenceFlag flags)
Sets the sequence flags for the packet's primary header.
std::vector< uint8_t > getApplicationDataBytes()
Retrieves the application data from the data field.
std::vector< uint8_t > getFullDataFieldBytes()
Retrieves the full data field data.
void setPrimaryHeader(PrimaryHeader data)
Sets the primary header using the provided PrimaryHeader object.
std::vector< uint8_t > getCRCVectorBytes()
Retrieves the CRC-16 checksum as a vector of bytes.
uint16_t m_sequenceCounter
uint16_t getFullPacketLength()
Retrieves the current size of the CCSDS Packet.
CCSDS::Header & getPrimaryHeader()
returns the CCSDS packet's Primary Header.
uint16_t getDataFieldMaximumSize()
returns the maximum data field size
CCSDS::DataField & getDataField()
returns the CCSDS packet's DataField.
bool m_enableUpdatePacket
Enables primary header and secondary header update.
std::vector< uint8_t > getDataFieldHeaderBytes()
Retrieves the secondary header data from the data field.
std::vector< uint8_t > getPrimaryHeaderBytes()
Retrieves the primary header of the packet as a vector of bytes.
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:81
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:36
uint16_t finalXorValue
Definition CCSDSPacket.h:39
uint16_t initialValue
Definition CCSDSPacket.h:38
Represents the primary header of a CCSDS packet.
Definition CCSDSHeader.h:41