CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
PusC Class Referencefinal

Represents a PUS Type C (Time Code) header. More...

#include <PusServices.h>

Inheritance diagram for PusC:
[legend]
Collaboration diagram for PusC:
[legend]

Public Member Functions

 PusC ()
 
 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 getVersion () const
 
std::uint8_t getServiceType () const
 
std::uint8_t getServiceSubtype () const
 
std::uint8_t getSourceID () const
 
std::vector< std::uint8_t > getTimeCode () const
 
std::uint16_t getDataLength () const
 
std::uint16_t getSize () const override
 Gets the size of the header in bytes.
 
std::string getType () const override
 Retrieves the name of the packet.
 
std::vector< std::uint8_t > serialize () const override
 Retrieves the serialized representation of the header.
 
CCSDS::ResultBool deserialize (const std::vector< std::uint8_t > &data) override
 takes a buffer if data (vector std::uint8) and creates the header
 
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
 
- Public Member Functions inherited from CCSDS::SecondaryHeaderAbstract
virtual ~SecondaryHeaderAbstract ()=default
 
virtual ResultBool loadFromConfig (const Config &config)=0
 
void setVariableLength (const bool bEnable)
 

Private Attributes

std::uint8_t m_version {}
 
std::uint8_t m_serviceType {}
 
std::uint8_t m_serviceSubType {}
 
std::uint8_t m_sourceID {}
 
std::vector< std::uint8_t > m_timeCode {}
 
std::uint16_t m_dataLength {}
 
const std::string m_type = "PusC"
 
const std::uint16_t m_size = 6
 

Additional Inherited Members

- Public Attributes inherited from CCSDS::SecondaryHeaderAbstract
bool variableLength {false}
 

Detailed Description

Represents a PUS Type C (Time Code) header.

Contains fields used for time synchronization.

Field Summary:

Definition at line 145 of file PusServices.h.

Constructor & Destructor Documentation

◆ PusC() [1/2]

PusC::PusC ( )
inline

Definition at line 147 of file PusServices.h.

◆ PusC() [2/2]

PusC::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 
)
inlineexplicit

Constructs a PusC object with all fields explicitly set.

Parameters
versionPUS version (3 bits).
serviceTypeService type (8 bits).
serviceSubtypeService subtype (8 bits).
sourceIDSource identifier (8 bits).
timeCodeTime code value (variable).
dataLengthLength of the time data (16 bits).

Definition at line 158 of file PusServices.h.

160 : m_version(version & 0x7), m_serviceType(serviceType),
161 m_serviceSubType(serviceSubtype), m_sourceID(sourceID),
162 m_timeCode(timeCode), m_dataLength(dataLength) {
163 variableLength=true;
164 }
std::vector< std::uint8_t > m_timeCode
std::uint8_t m_serviceType
std::uint8_t m_sourceID
std::uint16_t m_dataLength
std::uint8_t m_serviceSubType
std::uint8_t m_version

Member Function Documentation

◆ deserialize()

CCSDS::ResultBool PusC::deserialize ( const std::vector< std::uint8_t > &  data)
overridevirtual

takes a buffer if data (vector std::uint8) and creates the header

Returns
Boolean true on success or Error.

Implements CCSDS::SecondaryHeaderAbstract.

Definition at line 67 of file PusServices.cpp.

67 {
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}
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
const std::uint16_t m_size
@ INVALID_SECONDARY_HEADER_DATA
Secondary header data is invalid.
Definition CCSDSResult.h:26

◆ getDataLength()

std::uint16_t PusC::getDataLength ( ) const
inline

Definition at line 171 of file PusServices.h.

171{ return m_dataLength; }

◆ getServiceSubtype()

std::uint8_t PusC::getServiceSubtype ( ) const
inline

Definition at line 168 of file PusServices.h.

168{ return m_serviceSubType; }

◆ getServiceType()

std::uint8_t PusC::getServiceType ( ) const
inline

Definition at line 167 of file PusServices.h.

167{ return m_serviceType; }

◆ getSize()

std::uint16_t PusC::getSize ( ) const
inlineoverridevirtual

Gets the size of the header in bytes.

Returns
The size of the header in bytes.

Implements CCSDS::SecondaryHeaderAbstract.

Definition at line 172 of file PusServices.h.

172{ return m_size + m_timeCode.size(); }

◆ getSourceID()

std::uint8_t PusC::getSourceID ( ) const
inline

Definition at line 169 of file PusServices.h.

169{ return m_sourceID; }

◆ getTimeCode()

std::vector< std::uint8_t > PusC::getTimeCode ( ) const
inline

Definition at line 170 of file PusServices.h.

170{ return m_timeCode; }

◆ getType()

std::string PusC::getType ( ) const
inlineoverridevirtual

Retrieves the name of the packet.

Returns
A vector containing the header bytes. (does not include data field)

Implements CCSDS::SecondaryHeaderAbstract.

Definition at line 173 of file PusServices.h.

173{ return m_type; }
const std::string m_type

◆ getVersion()

std::uint8_t PusC::getVersion ( ) const
inline

Definition at line 166 of file PusServices.h.

166{ return m_version; }

◆ loadFromConfig()

CCSDS::ResultBool PusC::loadFromConfig ( const ::Config cfg)
override

Definition at line 158 of file PusServices.cpp.

158 {
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}
#define ASSIGN_OR_PRINT(var, result)
Macro to assign a result value or print an error message.
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
@ CONFIG_FILE_ERROR
Configuration file error.
Definition CCSDSResult.h:34
Here is the call graph for this function:

◆ serialize()

std::vector< std::uint8_t > PusC::serialize ( ) const
overridevirtual

Retrieves the serialized representation of the header.

Returns
A vector containing the header bytes. (does not include data field)

Implements CCSDS::SecondaryHeaderAbstract.

Definition at line 81 of file PusServices.cpp.

81 {
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}

◆ update()

void PusC::update ( CCSDS::DataField dataField)
overridevirtual

Defines how the packet secondary header is updated using the data field as reference.

This method is called every time a data get is performed from the packet, that is if update is enabled and method successfully registered.

Parameters
dataField

Implements CCSDS::SecondaryHeaderAbstract.

Definition at line 100 of file PusServices.cpp.

100 {
102}
std::uint16_t getApplicationDataBytesSize() const
Retrieves the size of the application data stored in the data field.
Here is the call graph for this function:

Member Data Documentation

◆ m_dataLength

std::uint16_t PusC::m_dataLength {}
private

Definition at line 189 of file PusServices.h.

189{}; // Data Length 16 Length of the time data in bytes

◆ m_serviceSubType

std::uint8_t PusC::m_serviceSubType {}
private

Definition at line 186 of file PusServices.h.

186{}; // Service Subtype 8 Subtype of the service (e.g., specific time type

◆ m_serviceType

std::uint8_t PusC::m_serviceType {}
private

Definition at line 185 of file PusServices.h.

185{}; // Service Type 8 Type of service (e.g., 0x03 for time code)

◆ m_size

const std::uint16_t PusC::m_size = 6
private

Definition at line 192 of file PusServices.h.

◆ m_sourceID

std::uint8_t PusC::m_sourceID {}
private

Definition at line 187 of file PusServices.h.

187{}; // Source ID 8 ID of the source (e.g., satellite or sensor)

◆ m_timeCode

std::vector<std::uint8_t> PusC::m_timeCode {}
private

Definition at line 188 of file PusServices.h.

188{}; // Time Code 16 Time code value, depending on the system

◆ m_type

const std::string PusC::m_type = "PusC"
private

Definition at line 191 of file PusServices.h.

◆ m_version

std::uint8_t PusC::m_version {}
private

Definition at line 184 of file PusServices.h.

184{}; // Version 3 Version of the PUS standard

The documentation for this class was generated from the following files: