CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
PusServices.cpp
Go to the documentation of this file.
1
2#include "PusServices.h"
3#include "CCSDSDataField.h"
4#include "CCSDSUtils.h"
5
6CCSDS::ResultBool PusA::deserialize(const std::vector<std::uint8_t> &data) {
8 "PUS-A header not correct size (size != 6 bytes)");
9
10 m_version = data[0] & 0x7;
11 m_serviceType = data[1];
12 m_serviceSubType = data[2];
13 m_sourceID = data[3];
14 m_dataLength = data[4] << 8 | data[5];
15 return true;
16}
17
18std::vector<std::uint8_t> PusA::serialize() const {
19 std::vector data{
20 static_cast<std::uint8_t>(m_version & 0x7),
24 static_cast<std::uint8_t>(m_dataLength >> 8 & 0xFF),
25 static_cast<std::uint8_t>(m_dataLength & 0xFF),
26 };
27
28 return data;
29}
30
34
35CCSDS::ResultBool PusB::deserialize(const std::vector<std::uint8_t> &data) {
37 "PUS-B header not correct size (size != 8 bytes)");
38 m_version = data[0] & 0x7;
39 m_serviceType = data[1];
40 m_serviceSubType = data[2];
41 m_sourceID = data[3];
42 m_eventID = data[4] << 8 | data[5];
43 m_dataLength = data[6] << 8 | data[7];
44 return true;
45}
46
47std::vector<std::uint8_t> PusB::serialize() const {
48 std::vector data{
49 static_cast<std::uint8_t>(m_version & 0x7),
53 static_cast<std::uint8_t>(m_eventID >> 8 & 0xFF),
54 static_cast<std::uint8_t>(m_eventID & 0xFF),
55 static_cast<std::uint8_t>(m_dataLength >> 8 & 0xFF),
56 static_cast<std::uint8_t>(m_dataLength & 0xFF),
57 };
58
59 return data;
60}
61
65
66
67CCSDS::ResultBool PusC::deserialize(const std::vector<std::uint8_t> &data) {
69 "PUS-C header not correct size (size <= 6 bytes)");
70 m_version = data[0] & 0x7;
71 m_serviceType = data[1];
72 m_serviceSubType = data[2];
73 m_sourceID = data[3];
74 m_dataLength = data[data.size()-2] << 8 | data[data.size()-1];
75 if (data.size() > 6) {
76 m_timeCode.assign(data.begin() + 4, data.end()-2);
77 }
78 return true;
79}
80
81std::vector<std::uint8_t> PusC::serialize() const {
82 std::vector<std::uint8_t> data;
83 data.reserve(4 + m_timeCode.size() + 2);
84 data.push_back(static_cast<std::uint8_t>(m_version & 0x7));
85 data.push_back(m_serviceType);
86 data.push_back(m_serviceSubType);
87 data.push_back(m_sourceID);
88
89 if (!m_timeCode.empty()) {
90 const auto* p = m_timeCode.data();
91 const auto n = m_timeCode.size();
92 data.insert(data.end(), p, p + n);
93 }
94 data.push_back(m_dataLength >> 8 & 0xFF);
95 data.push_back(m_dataLength & 0xFF);
96
97 return data;
98}
99
102}
103
104#ifndef CCSDS_MCU
105
107 std::uint8_t version = 0;
108 std::uint8_t serviceType = 0;
109 std::uint8_t serviceSubType = 0;
110 std::uint8_t sourceId = 0;
111
112 RET_IF_ERR_MSG(!cfg.isKey("pus_version"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_version");
113 RET_IF_ERR_MSG(!cfg.isKey("pus_service_type"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_service_type");
114 RET_IF_ERR_MSG(!cfg.isKey("pus_service_sub_type"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_service_sub_type");
115 RET_IF_ERR_MSG(!cfg.isKey("pus_source_id"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_source_id");
116
117 ASSIGN_OR_PRINT(version, cfg.get<int>("pus_version"));
118 ASSIGN_OR_PRINT(serviceType, cfg.get<int>("pus_service_type"));
119 ASSIGN_OR_PRINT(serviceSubType,cfg.get< int>("pus_service_sub_type"));
120 ASSIGN_OR_PRINT(sourceId,cfg.get<int>("pus_source_id"));
121
122 m_version = version & 0x7;
123 m_serviceType = serviceType & 0xFF;
124 m_serviceSubType = serviceSubType & 0xFF;
125 m_sourceID = sourceId & 0xFF;
126
127 return true;
128}
129
131 std::uint8_t version = 0;
132 std::uint8_t serviceType = 0;
133 std::uint8_t serviceSubType = 0;
134 std::uint8_t sourceId = 0;
135 std::uint8_t eventId = 0;
136
137 RET_IF_ERR_MSG(!cfg.isKey("pus_version"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_version");
138 RET_IF_ERR_MSG(!cfg.isKey("pus_service_type"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_service_type");
139 RET_IF_ERR_MSG(!cfg.isKey("pus_service_sub_type"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_service_sub_type");
140 RET_IF_ERR_MSG(!cfg.isKey("pus_source_id"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_source_id");
141 RET_IF_ERR_MSG(!cfg.isKey("pus_event_id"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_event_id");
142
143 ASSIGN_OR_PRINT(version, cfg.get<int>("pus_version"));
144 ASSIGN_OR_PRINT(serviceType, cfg.get<int>("pus_service_type"));
145 ASSIGN_OR_PRINT(serviceSubType,cfg.get< int>("pus_service_sub_type"));
146 ASSIGN_OR_PRINT(sourceId,cfg.get<int>("pus_source_id"));
147 ASSIGN_OR_PRINT(eventId,cfg.get<int>("pus_event_id"));
148
149 m_version = version & 0x7;
150 m_serviceType = serviceType & 0xFF;
151 m_serviceSubType = serviceSubType & 0xFF;
152 m_sourceID = sourceId & 0xFF;
153 m_eventID = eventId & 0xFFFF;
154
155 return true;
156}
157
159 std::uint8_t version = 0;
160 std::uint8_t serviceType = 0;
161 std::uint8_t serviceSubType = 0;
162 std::uint8_t sourceId = 0;
163 std::vector<std::uint8_t> timeCode{};
164
165 RET_IF_ERR_MSG(!cfg.isKey("pus_version"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_version");
166 RET_IF_ERR_MSG(!cfg.isKey("pus_service_type"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_service_type");
167 RET_IF_ERR_MSG(!cfg.isKey("pus_service_sub_type"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_service_sub_type");
168 RET_IF_ERR_MSG(!cfg.isKey("pus_source_id"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_source_id");
169 RET_IF_ERR_MSG(!cfg.isKey("pus_time_code"), CCSDS::ErrorCode::CONFIG_FILE_ERROR,"Config: Missing string field: pus_time_code");
170
171 ASSIGN_OR_PRINT(version, cfg.get<int>("pus_version"));
172 ASSIGN_OR_PRINT(serviceType, cfg.get<int>("pus_service_type"));
173 ASSIGN_OR_PRINT(serviceSubType,cfg.get< int>("pus_service_sub_type"));
174 ASSIGN_OR_PRINT(sourceId,cfg.get<int>("pus_source_id"));
175 ASSIGN_OR_PRINT(timeCode,cfg.get<std::vector<std::uint8_t>>("pus_time_code"));
176
177 m_version = version & 0x7;
178 m_serviceType = serviceType & 0xFF;
179 m_serviceSubType = serviceSubType & 0xFF;
180 m_sourceID = sourceId & 0xFF;
181 m_timeCode = timeCode;
182
183 return true;
184}
185
186#endif
#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.
Represents the data field of a CCSDS packet.
std::uint16_t getApplicationDataBytesSize() const
Retrieves the size of the application data stored in the data field.
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
bool isKey(const std::string &key) const
CCSDS::Result< T > get(const std::string &key) const
Get value by key and type.
Definition CCSDSConfig.h:20
std::uint8_t m_serviceType
Definition PusServices.h:62
std::uint8_t m_serviceSubType
Definition PusServices.h:63
std::uint8_t m_sourceID
Definition PusServices.h:64
std::vector< std::uint8_t > serialize() const override
Retrieves the serialized representation of the header.
void update(CCSDS::DataField *dataField) override
Defines how the packet secondary header is updated using the data field as reference.
const std::uint16_t m_size
Definition PusServices.h:68
CCSDS::ResultBool loadFromConfig(const ::Config &cfg) override
std::uint8_t m_version
Definition PusServices.h:61
CCSDS::ResultBool deserialize(const std::vector< std::uint8_t > &data) override
takes a buffer if data (vector std::uint8) and creates the header
std::uint16_t m_dataLength
Definition PusServices.h:65
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
std::uint16_t m_dataLength
std::uint8_t m_version
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.
CCSDS::ResultBool loadFromConfig(const ::Config &cfg) override
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
std::uint8_t m_sourceID
std::vector< std::uint8_t > serialize() const override
Retrieves the serialized representation of the header.
CCSDS::ResultBool loadFromConfig(const ::Config &cfg) override
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 m_version
@ CONFIG_FILE_ERROR
Configuration file error.
Definition CCSDSResult.h:34
@ INVALID_SECONDARY_HEADER_DATA
Secondary header data is invalid.
Definition CCSDSResult.h:26