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
4CCSDS::ResultBool PusA::deserialize(const std::vector<uint8_t> &data) {
6 "PUS-A header not correct size (size != 6 bytes)");
7
8 m_version = data[0] & 0x5;
9 m_serviceType = data[1];
10 m_serviceSubType = data[2];
11 m_sourceID = data[3];
12 m_dataLength = data[4] << 8 | data[5];
13 return true;
14}
15
16std::vector<uint8_t> PusA::serialize() const {
17 std::vector data{
18 static_cast<uint8_t>(m_version & 0x7),
22 static_cast<uint8_t>(m_dataLength >> 8 & 0xFF),
23 static_cast<uint8_t>(m_dataLength & 0xFF),
24 };
25
26 return data;
27}
28
29CCSDS::ResultBool PusB::deserialize(const std::vector<uint8_t> &data) {
31 "PUS-B header not correct size (size != 8 bytes)");
32 m_version = data[0] & 0x7;
33 m_serviceType = data[1];
34 m_serviceSubType = data[2];
35 m_sourceID = data[3];
36 m_eventID = data[4] << 8 | data[5];
37 m_dataLength = data[6] << 8 | data[7];
38 return true;
39}
40
41std::vector<uint8_t> PusB::serialize() const {
42 std::vector data{
43 static_cast<uint8_t>(m_version & 0x7),
47 static_cast<uint8_t>(m_eventID >> 8 & 0xFF),
48 static_cast<uint8_t>(m_eventID & 0xFF),
49 static_cast<uint8_t>(m_dataLength >> 8 & 0xFF),
50 static_cast<uint8_t>(m_dataLength & 0xFF),
51 };
52
53 return data;
54}
55
56CCSDS::ResultBool PusC::deserialize(const std::vector<uint8_t> &data) {
58 "PUS-C header not correct size (size != 8 bytes)");
59
60 m_version = data[0] & 0x7;
61 m_serviceType = data[1];
62 m_serviceSubType = data[2];
63 m_sourceID = data[3];
64 m_timeCode = data[4] << 8 | data[5];
65 m_dataLength = data[6] << 8 | data[7];
66 return true;
67}
68
69std::vector<uint8_t> PusC::serialize() const {
70 std::vector data{
71 static_cast<uint8_t>(m_version & 0x7),
75 static_cast<uint8_t>(m_timeCode >> 8 & 0xFF),
76 static_cast<uint8_t>(m_timeCode & 0xFF),
77 static_cast<uint8_t>(m_dataLength >> 8 & 0xFF),
78 static_cast<uint8_t>(m_dataLength & 0xFF),
79 };
80
81 return data;
82}
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
Encapsulates a result that can hold either a value or an Error.
Definition CCSDSResult.h:81
std::vector< uint8_t > serialize() const override
Retrieves the serialized representation of the header.
uint16_t m_dataLength
Definition PusServices.h:56
uint8_t m_serviceSubType
Definition PusServices.h:54
CCSDS::ResultBool deserialize(const std::vector< uint8_t > &data) override
takes a buffer if data (vector uint8) and creates the header
uint8_t m_sourceID
Definition PusServices.h:55
uint8_t m_version
Definition PusServices.h:52
uint8_t m_serviceType
Definition PusServices.h:53
const uint16_t m_size
Definition PusServices.h:59
uint8_t m_serviceType
uint16_t m_dataLength
uint8_t m_version
std::vector< uint8_t > serialize() const override
Retrieves the serialized representation of the header.
uint16_t m_eventID
uint8_t m_sourceID
const uint16_t m_size
CCSDS::ResultBool deserialize(const std::vector< uint8_t > &data) override
takes a buffer if data (vector uint8) and creates the header
uint8_t m_serviceSubType
uint8_t m_version
uint16_t m_timeCode
const uint16_t m_size
CCSDS::ResultBool deserialize(const std::vector< uint8_t > &data) override
takes a buffer if data (vector uint8) and creates the header
uint16_t m_dataLength
uint8_t m_serviceSubType
std::vector< uint8_t > serialize() const override
Retrieves the serialized representation of the header.
uint8_t m_sourceID
uint8_t m_serviceType
@ INVALID_SECONDARY_HEADER_DATA
Secondary header data is invalid.
Definition CCSDSResult.h:25