CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
CCSDSUtils.h
Go to the documentation of this file.
1#ifndef CCSDS_UTILS_H
2#define CCSDS_UTILS_H
3
4#include <CCSDSPacket.h>
5#include <CCSDSManager.h>
6#include <string>
7#include <cstdint>
8#include <vector>
9
10// free functions
20uint16_t crc16(const std::vector<uint8_t> &data,
21 uint16_t polynomial = 0x1021,
22 uint16_t initialValue = 0xFFFF,
23 uint16_t finalXorValue = 0x0000
24);
25
31void printPacket(CCSDS::Packet &packet);
32
38void printPackets(CCSDS::Manager & manager);
39
47std::string getBinaryString(uint32_t value, int bits);
48
55std::string getBitsSpaces(int num);
56
63void printBufferData(const std::vector<uint8_t> &buffer, int limitBytes = 20);
64
73void printData(CCSDS::DataField dataField);
74
84void printHeader(CCSDS::Header &header);
85
93
102void printDataField(CCSDS::Packet &packet);
103
112CCSDS::ResultBool writeBinaryFile(const std::vector<uint8_t>& data, const std::string& filename);
113
120CCSDS::ResultBuffer readBinaryFile(const std::string& filename);
121
128bool fileExists(const std::string &fileName);
129
138bool stringEndsWith(const std::string& str, const std::string& suffix);
139
140/* Classes */
141
142
143
145class Config {
146public:
147 using ConfigValue = std::variant<std::string, int, float, bool, std::vector<uint8_t>>;
148
150 CCSDS::ResultBool load(const std::string &filename);
151
153 template<typename T>
154 CCSDS::Result<T> get(const std::string& key) const {
155 auto it = values.find(key);
156 RET_IF_ERR_MSG(it == values.end(), CCSDS::ErrorCode::NO_DATA,"Config: No data found for key: " + key);
157 return std::get<T>(values.at(key));
158 }
159
160 bool isKey(const std::string& key) const;
161
162private:
163 std::unordered_map<std::string, ConfigValue> values;
164
166 static std::tuple<std::string, std::string, std::string> parseLine(const std::string& line);
167
169 static CCSDS::ResultBuffer parseBytes(const std::string &valueStr);
170};
171
172
173
174
175#endif // CCSDS_UTILS_H
#define RET_IF_ERR_MSG(condition, errorCode, message)
Macro to return an error with an error message if a condition is met.
bool fileExists(const std::string &fileName)
filesystem check fore file existence prepared for both windows and linux.
void printPacket(CCSDS::Packet &packet)
Prints to console a CCSDS Packets, breaking it down to Primary header and Data field.
std::string getBinaryString(uint32_t value, int bits)
Converts a given value to its binary representation as a string, with spaces every 4 bits.
bool stringEndsWith(const std::string &str, const std::string &suffix)
Tests if str ends with suffix.
CCSDS::ResultBool printPrimaryHeader(CCSDS::Packet &packet)
Prints to console the primary header of a provided CCSDS packet.
uint16_t crc16(const std::vector< uint8_t > &data, uint16_t polynomial=0x1021, uint16_t initialValue=0xFFFF, uint16_t finalXorValue=0x0000)
Computes the CRC-16 checksum for a given data vector with configurable parameters.
void printData(CCSDS::DataField dataField)
Prints the data field details, including the secondary header and application data.
CCSDS::ResultBuffer readBinaryFile(const std::string &filename)
Read a specified binary file and return its contents as a buffer.
std::string getBitsSpaces(int num)
Generates a string of spaces for formatting binary outputs.
void printHeader(CCSDS::Header &header)
Prints the header fields and their binary or hexadecimal representations.
CCSDS::ResultBool writeBinaryFile(const std::vector< uint8_t > &data, const std::string &filename)
This function takes in a buffer of data and a file name.
void printPackets(CCSDS::Manager &manager)
Prints to console a series of CCSDS Packets contained in the manager.
void printDataField(CCSDS::Packet &packet)
Prints the data field and the CRC-16 checksum of the packet.
void printBufferData(const std::vector< uint8_t > &buffer, int limitBytes=20)
Prints to console the HEX data from the bytes vector.
Represents the data field of a CCSDS packet.
Manages the decomposition and manipulation of CCSDS primary headers.
Definition CCSDSHeader.h:80
Manages CCSDS packets and their templates.
Represents a CCSDS (Consultative Committee for Space Data Systems) packet.
Definition CCSDSPacket.h:60
Encapsulates a result that can hold either a value or an Error.
Definition CCSDSResult.h:81
Parses and stores config values from custom file format.
Definition CCSDSUtils.h:145
std::variant< std::string, int, float, bool, std::vector< uint8_t > > ConfigValue
Definition CCSDSUtils.h:147
bool isKey(const std::string &key) const
static CCSDS::ResultBuffer parseBytes(const std::string &valueStr)
Parse string "[1,2,3]" into vector<uint8_t>
std::unordered_map< std::string, ConfigValue > values
Definition CCSDSUtils.h:163
CCSDS::ResultBool load(const std::string &filename)
Load config file.
CCSDS::Result< T > get(const std::string &key) const
Get value by key and type.
Definition CCSDSUtils.h:154
static std::tuple< std::string, std::string, std::string > parseLine(const std::string &line)
Parse a single line from config.
@ NO_DATA
No data available.
Definition CCSDSResult.h:22