CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
CCSDSHeader.h
Go to the documentation of this file.
1// Copyright 2025-2026 ExoSpaceLabs
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef CCSDS_HEADER_H
5#define CCSDS_HEADER_H
6
7#include <CCSDSResult.h>
8#include <cstdint>
9#include <vector>
10
11namespace CCSDS {
28
45 // version and packet identification 16 bit 4 hex
46 std::uint8_t versionNumber{};
47 std::uint8_t type{};
48 std::uint8_t dataFieldHeaderFlag{};
49 std::uint16_t APID{};
50
51 //packet sequence control 16 bit 4 hex
52 std::uint8_t sequenceFlags{};
53 std::uint16_t sequenceCount{};
54
55 // data packet length
56 std::uint16_t dataLength{};
57
69 PrimaryHeader(const std::uint8_t versionNumber_value, const std::uint8_t type_value, const std::uint8_t dataFieldHeaderFlag_value,
70 const std::uint16_t APID_value, const std::uint8_t sequenceFlag_value, const std::uint16_t sequenceCount_value,
71 const std::uint16_t dataLength_value) : versionNumber(versionNumber_value), type(type_value),
72 dataFieldHeaderFlag(dataFieldHeaderFlag_value),
73 APID(APID_value), sequenceFlags(sequenceFlag_value),
74 sequenceCount(sequenceCount_value),
75 dataLength(dataLength_value) {
76 }
77 };
78
83 class Header {
84 public:
85 Header() = default;
86
87 [[nodiscard]] std::uint8_t getVersionNumber() const { return m_versionNumber; }
88 [[nodiscard]] std::uint8_t getType() const { return m_type; }
89 [[nodiscard]] std::uint8_t getDataFieldHeaderFlag() const { return m_dataFieldHeaderFlag; }
90 [[nodiscard]] std::uint16_t getAPID() const { return m_APID; }
91 [[nodiscard]] std::uint8_t getSequenceFlags() const { return m_sequenceFlags; }
92 [[nodiscard]] std::uint16_t getSequenceCount() const { return m_sequenceCount; }
93 [[nodiscard]] std::uint16_t getDataLength() const { return m_dataLength; }
94
101 std::vector<std::uint8_t> serialize();
102
111 std::uint64_t getFullHeader() {
114 m_APID;
115 return (static_cast<std::uint64_t>(m_packetIdentificationAndVersion) << 32) | (
116 static_cast<std::uint32_t>(m_packetSequenceControl) << 16) | m_dataLength;
117 }
118
119 void setVersionNumber ( const std::uint8_t &value ) { m_versionNumber = value & 0x0007; }
120 void setType ( const std::uint8_t &value ) { m_type = value & 0x0001; }
121 void setDataFieldHeaderFlag( const std::uint8_t &value ) { m_dataFieldHeaderFlag = value & 0x0001; }
122 void setAPID ( const std::uint16_t &value ) { m_APID = value & 0x07FF; }
123 void setSequenceFlags ( const std::uint8_t &value ) { m_sequenceFlags = value & 0x0003; }
124 void setSequenceCount ( const std::uint16_t &value ) { m_sequenceCount = value & 0x3FFF; }
125 void setDataLength ( const std::uint16_t &value ) { m_dataLength = value; }
126
138 [[nodiscard]] ResultBool setData(const std::uint64_t &data);
139
151 [[nodiscard]] ResultBool deserialize(const std::vector<std::uint8_t> &data);
152
153
163 void setData(const PrimaryHeader &data);
164
165 private:
166 // version and packet identification 16 bit 4 hex
167 std::uint8_t m_versionNumber{};
168
169 // packet identification 4 hex
170 std::uint8_t m_type{};
171 std::uint8_t m_dataFieldHeaderFlag{};
172 std::uint16_t m_APID{};
173
174 // packet sequence control 16 bit 4 hex
176 std::uint16_t m_sequenceCount{};
177
178 // full packet size 48 bit fixed 6 byes
180 std::uint16_t m_packetSequenceControl{};
181 std::uint16_t m_dataLength{};
182 };
183}
184#endif // CCSDS_HEADER_H
Manages the decomposition and manipulation of CCSDS primary headers.
Definition CCSDSHeader.h:83
void setType(const std::uint8_t &value)
1 bits
void setVersionNumber(const std::uint8_t &value)
3 bits
std::vector< std::uint8_t > serialize()
decomposes the Primary header class and returns it as a vector of bytes.
void setDataLength(const std::uint16_t &value)
16 bits
std::uint8_t m_type
1 bit second of packet identification
void setAPID(const std::uint16_t &value)
11 bits
void setSequenceCount(const std::uint16_t &value)
14 bits
std::uint16_t m_sequenceCount
14 bit last of sequence control
void setDataFieldHeaderFlag(const std::uint8_t &value)
1 bits
std::uint8_t m_sequenceFlags
2 bit first of sequence control / ESequenceFlag enum.
std::uint16_t getAPID() const
11 bits
Definition CCSDSHeader.h:90
std::uint64_t getFullHeader()
Computes and retrieves the full header as a 64-bit value.
std::uint8_t getType() const
1 bits
Definition CCSDSHeader.h:88
std::uint16_t m_dataLength
data packet length 16 bits 4 hex
std::uint8_t getSequenceFlags() const
2 bits
Definition CCSDSHeader.h:91
std::uint8_t m_versionNumber
3 bit first of packet identification
std::uint16_t getSequenceCount() const
14 bits
Definition CCSDSHeader.h:92
std::uint8_t getVersionNumber() const
3 bits
Definition CCSDSHeader.h:87
ResultBool deserialize(const std::vector< std::uint8_t > &data)
Sets the header data from a 64-bit integer representation.
ResultBool setData(const std::uint64_t &data)
Sets the header data from a 64-bit integer representation.
Header()=default
std::uint16_t m_packetSequenceControl
packet sequence control 16 bit 4 hex
std::uint8_t getDataFieldHeaderFlag() const
1 bits
Definition CCSDSHeader.h:89
std::uint16_t m_APID
11 bit last of packet identification
std::uint16_t m_packetIdentificationAndVersion
packet id and version 16 bit 4 hex
void setSequenceFlags(const std::uint8_t &value)
2 bits
std::uint8_t m_dataFieldHeaderFlag
1 bit third of packet identification
std::uint16_t getDataLength() const
16 bits
Definition CCSDSHeader.h:93
Encapsulates a result that can hold either a value or an Error.
Definition CCSDSResult.h:85
Contains definitions and classes for handling CCSDS headers.
ESequenceFlag
Represents the sequence flags used in CCSDS telemetry transfer frames.
Definition CCSDSHeader.h:22
@ LAST_SEGMENT
10 Last segment of a multi-frame packet.
Definition CCSDSHeader.h:25
@ UNSEGMENTED
11 Complete packet in a single frame.
Definition CCSDSHeader.h:26
@ CONTINUING_SEGMENT
00 Intermediate segment of a packet.
Definition CCSDSHeader.h:23
@ FIRST_SEGMENT
01 First segment of a new packet.
Definition CCSDSHeader.h:24
Represents the primary header of a CCSDS packet.
Definition CCSDSHeader.h:44
std::uint16_t dataLength
16 bits
Definition CCSDSHeader.h:56
std::uint16_t sequenceCount
14 bit last of sequence control
Definition CCSDSHeader.h:53
std::uint16_t APID
11 bit last of packet identification
Definition CCSDSHeader.h:49
std::uint8_t sequenceFlags
2 bit first of sequence control
Definition CCSDSHeader.h:52
PrimaryHeader(const std::uint8_t versionNumber_value, const std::uint8_t type_value, const std::uint8_t dataFieldHeaderFlag_value, const std::uint16_t APID_value, const std::uint8_t sequenceFlag_value, const std::uint16_t sequenceCount_value, const std::uint16_t dataLength_value)
Constructs a PrimaryHeader with specified field values.
Definition CCSDSHeader.h:69
std::uint8_t versionNumber
3 bit first of packet identification
Definition CCSDSHeader.h:46
std::uint8_t type
1 bit second of packet identification
Definition CCSDSHeader.h:47
std::uint8_t dataFieldHeaderFlag
1 bit third of packet identification
Definition CCSDSHeader.h:48