CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
PusServices.h
Go to the documentation of this file.
1// Copyright 2025-2026 ExoSpaceLabs
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef PUS_SERVICES_H
5#define PUS_SERVICES_H
6
9#include "CCSDSResult.h"
10
11//exclude includes when building for MCU
12#ifndef CCSDS_MCU
13 #include "CCSDSConfig.h"
14#endif //CCSDS_MCU
27 class PusA final : public CCSDS::SecondaryHeaderAbstract {
28 public:
29 PusA() = default;
30
39 explicit PusA(const std::uint8_t version, const std::uint8_t serviceType, const std::uint8_t serviceSubtype,
40 const std::uint8_t sourceID, const std::uint32_t dataLength) : m_version(version & 0x7),
41 m_serviceType(serviceType),
42 m_serviceSubType(serviceSubtype),
43 m_sourceID(sourceID), m_dataLength(dataLength) {
44 }
45
46 [[nodiscard]] std::uint8_t getVersion() const { return m_version; }
47 [[nodiscard]] std::uint8_t getServiceType() const { return m_serviceType; }
48 [[nodiscard]] std::uint8_t getServiceSubtype() const { return m_serviceSubType; }
49 [[nodiscard]] std::uint8_t getSourceID() const { return m_sourceID; }
50 [[nodiscard]] std::uint16_t getDataLength() const { return m_dataLength; }
51 [[nodiscard]] std::uint16_t getSize() const override { return m_size; }
52 [[nodiscard]] std::string getType() const override { return m_type; }
53
54 [[nodiscard]] std::vector<std::uint8_t> serialize() const override;
55 [[nodiscard]] CCSDS::ResultBool deserialize( const std::vector<std::uint8_t> &data ) override;
56 void update(CCSDS::DataField* dataField) override;
57
58#ifndef CCSDS_MCU
59 CCSDS::ResultBool loadFromConfig(const ::Config &cfg) override;
60#endif
61
62
63 private: // Field Size (bits) Description
64 std::uint8_t m_version{}; // Version 3 Version of the PUS standard
65 std::uint8_t m_serviceType{}; // Service Type 8 Type of service (e.g., 0x01 for telemetry)
66 std::uint8_t m_serviceSubType{}; // Service Subtype 8 Subtype of the service (e.g., specific telemetry type)
67 std::uint8_t m_sourceID{}; // Source ID 8 ID of the source (e.g., satellite or sensor)
68 std::uint16_t m_dataLength{}; // Data Length 16 Length of the telemetry data in bytes
69
70 const std::string m_type = "PusA"; // Static registration (automatically called when the program starts)
71 const std::uint16_t m_size = 6; // bytes
72 };
73
87 class PusB final : public CCSDS::SecondaryHeaderAbstract {
88 public:
89 PusB() = default;
90
100 explicit PusB(const std::uint8_t version, const std::uint8_t serviceType, const std::uint8_t serviceSubtype,
101 const std::uint8_t sourceID, const std::uint16_t eventID, const std::uint16_t dataLength) : m_version(version & 0x7),
102 m_serviceType(serviceType), m_serviceSubType(serviceSubtype), m_sourceID(sourceID), m_eventID(eventID),
103 m_dataLength(dataLength) {
104 }
105
106 [[nodiscard]] std::uint8_t getVersion() const { return m_version; }
107 [[nodiscard]] std::uint8_t getServiceType() const { return m_serviceType; }
108 [[nodiscard]] std::uint8_t getServiceSubtype() const { return m_serviceSubType; }
109 [[nodiscard]] std::uint8_t getSourceID() const { return m_sourceID; }
110 [[nodiscard]] std::uint16_t getEventID() const { return m_eventID; }
111 [[nodiscard]] std::uint16_t getDataLength() const { return m_dataLength; }
112 [[nodiscard]] std::uint16_t getSize() const override { return m_size; }
113 [[nodiscard]] std::string getType() const override { return m_type; }
114
115 [[nodiscard]] std::vector<std::uint8_t> serialize() const override;
116 [[nodiscard]] CCSDS::ResultBool deserialize( const std::vector<std::uint8_t> &data ) override;
117 void update(CCSDS::DataField* dataField) override;
118
119#ifndef CCSDS_MCU
120 CCSDS::ResultBool loadFromConfig(const ::Config &cfg) override;
121#endif
122
123 private: // Field Size (bits) Description
124 std::uint8_t m_version{}; // Version 3 Version of the PUS standard
125 std::uint8_t m_serviceType{}; // Service Type 8 Type of service (e.g., 0x02 for event reporting)
126 std::uint8_t m_serviceSubType{}; // Service Subtype 8 Subtype of the service (e.g., specific event type)
127 std::uint8_t m_sourceID{}; // Source ID 8 ID of the source (e.g., satellite or sensor)
128 std::uint16_t m_eventID{}; // Event ID 16 ID of the event being reported
129 std::uint16_t m_dataLength{}; // Data Length 16 Length of the event data in bytes
130
131 const std::string m_type = "PusB"; // Static registration (automatically called when the program starts)
132 const std::uint16_t m_size = 8; // bytes
133 };
134
149 public:
151
161 explicit PusC(const std::uint8_t version, const std::uint8_t serviceType, const std::uint8_t serviceSubtype,
162 const std::uint8_t sourceID, const std::vector<std::uint8_t>& timeCode,
163 const std::uint16_t dataLength) : m_version(version & 0x7), m_serviceType(serviceType),
164 m_serviceSubType(serviceSubtype), m_sourceID(sourceID),
165 m_timeCode(timeCode), m_dataLength(dataLength) {
166 variableLength=true;
167 }
168
169 [[nodiscard]] std::uint8_t getVersion() const { return m_version; }
170 [[nodiscard]] std::uint8_t getServiceType() const { return m_serviceType; }
171 [[nodiscard]] std::uint8_t getServiceSubtype() const { return m_serviceSubType; }
172 [[nodiscard]] std::uint8_t getSourceID() const { return m_sourceID; }
173 [[nodiscard]] std::vector<std::uint8_t> getTimeCode() const { return m_timeCode; }
174 [[nodiscard]] std::uint16_t getDataLength() const { return m_dataLength; }
175 [[nodiscard]] std::uint16_t getSize() const override { return m_size + m_timeCode.size(); }
176 [[nodiscard]] std::string getType() const override { return m_type; }
177
178 [[nodiscard]] std::vector<std::uint8_t> serialize() const override;
179 [[nodiscard]] CCSDS::ResultBool deserialize( const std::vector<std::uint8_t> &data ) override;
180 void update(CCSDS::DataField* dataField) override;
181
182#ifndef CCSDS_MCU
183 CCSDS::ResultBool loadFromConfig(const ::Config &cfg) override;
184#endif
185
186 private: // Field Size (bits) Description
187 std::uint8_t m_version{}; // Version 3 Version of the PUS standard
188 std::uint8_t m_serviceType{}; // Service Type 8 Type of service (e.g., 0x03 for time code)
189 std::uint8_t m_serviceSubType{}; // Service Subtype 8 Subtype of the service (e.g., specific time type
190 std::uint8_t m_sourceID{}; // Source ID 8 ID of the source (e.g., satellite or sensor)
191 std::vector<std::uint8_t> m_timeCode{}; // Time Code 16 Time code value, depending on the system
192 std::uint16_t m_dataLength{}; // Data Length 16 Length of the time data in bytes
193
194 const std::string m_type = "PusC"; // Static registration (automatically called when the program starts)
195 const std::uint16_t m_size = 6; // bytes minimum size
196
197 };
198
199
200#endif //PUS_SERVICES_H
Represents the data field of a CCSDS packet.
Encapsulates a result that can hold either a value or an Error.
Definition CCSDSResult.h:85
Abstract base class for a (Packet Utilization Standard) header.
std::uint16_t getSize() const override
Gets the size of the header in bytes.
Definition PusServices.h:51
std::uint16_t getDataLength() const
Definition PusServices.h:50
std::uint8_t getServiceSubtype() const
Definition PusServices.h:48
std::uint8_t getSourceID() const
Definition PusServices.h:49
std::uint8_t getServiceType() const
Definition PusServices.h:47
PusA()=default
std::uint8_t getVersion() const
Definition PusServices.h:46
PusA(const std::uint8_t version, const std::uint8_t serviceType, const std::uint8_t serviceSubtype, const std::uint8_t sourceID, const std::uint32_t dataLength)
Constructs a PusA object with all fields explicitly set.
Definition PusServices.h:39
std::string getType() const override
Retrieves the name of the packet.
Definition PusServices.h:52
Represents a PUS Type B (Event Reporting) header.
Definition PusServices.h:87
const std::string m_type
std::uint8_t getSourceID() const
std::uint8_t m_serviceSubType
CCSDS::ResultBool deserialize(const std::vector< std::uint8_t > &data) override
takes a buffer if data (vector std::uint8) and creates the header
std::vector< std::uint8_t > serialize() const override
Retrieves the serialized representation of the header.
std::uint8_t m_serviceType
std::uint8_t m_sourceID
std::uint16_t m_eventID
PusB(const std::uint8_t version, const std::uint8_t serviceType, const std::uint8_t serviceSubtype, const std::uint8_t sourceID, const std::uint16_t eventID, const std::uint16_t dataLength)
Constructs a PusB object with all fields explicitly set.
std::uint16_t getEventID() const
std::uint8_t getServiceSubtype() const
std::uint16_t m_dataLength
std::string getType() const override
Retrieves the name of the packet.
std::uint8_t getVersion() const
std::uint8_t m_version
std::uint8_t getServiceType() const
const std::uint16_t m_size
void update(CCSDS::DataField *dataField) override
Defines how the packet secondary header is updated using the data field as reference.
std::uint16_t getSize() const override
Gets the size of the header in bytes.
PusB()=default
CCSDS::ResultBool loadFromConfig(const ::Config &cfg) override
std::uint16_t getDataLength() const
Represents a PUS Type C (Time Code) header.
std::uint16_t getSize() const override
Gets the size of the header in bytes.
std::uint8_t getVersion() const
std::uint16_t getDataLength() const
const std::uint16_t m_size
CCSDS::ResultBool deserialize(const std::vector< std::uint8_t > &data) override
takes a buffer if data (vector std::uint8) and creates the header
std::vector< std::uint8_t > m_timeCode
std::uint8_t m_serviceType
PusC(const std::uint8_t version, const std::uint8_t serviceType, const std::uint8_t serviceSubtype, const std::uint8_t sourceID, const std::vector< std::uint8_t > &timeCode, const std::uint16_t dataLength)
Constructs a PusC object with all fields explicitly set.
std::uint8_t m_sourceID
std::vector< std::uint8_t > serialize() const override
Retrieves the serialized representation of the header.
const std::string m_type
CCSDS::ResultBool loadFromConfig(const ::Config &cfg) override
std::vector< std::uint8_t > getTimeCode() const
std::uint8_t getSourceID() const
std::string getType() const override
Retrieves the name of the packet.
std::uint16_t m_dataLength
std::uint8_t m_serviceSubType
void update(CCSDS::DataField *dataField) override
Defines how the packet secondary header is updated using the data field as reference.
std::uint8_t getServiceSubtype() const
std::uint8_t getServiceType() const
std::uint8_t m_version