CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
CCSDSManager.h
Go to the documentation of this file.
1#ifndef CCSDS_MANAGER_H
2#define CCSDS_MANAGER_H
3
4#include <utility>
5#include "CCSDSPacket.h"
6#include "CCSDSResult.h"
7#include "CCSDSValidator.h"
8
9namespace CCSDS {
18 class Manager {
19 public:
23 Manager() = default;
24
30 explicit Manager(Packet packet) : m_templatePacket(std::move(packet)) {
31 m_templateIsSet = true;
34 m_validator.configure(true, true, true);
35
36 }
37
44 void setSyncPattern(std::uint32_t syncPattern);
45
51 std::uint32_t getSyncPattern() const;
52
58 void setSyncPatternEnable(bool enable);
59
65 bool getSyncPatternEnable() const;
66
72 [[nodiscard]] ResultBool setPacketTemplate(Packet packet);
73
79 [[nodiscard]] ResultBool loadTemplateConfigFile(const std::string &configPath);
80#ifndef CCSDS_MCU
86 [[nodiscard]] ResultBool loadTemplateConfig(const Config &cfg);
87#endif
88
94 void setDataFieldSize( std::uint16_t size );
95
101 std::uint16_t getDataFieldSize() const;
102
109 ResultBool setApplicationData( const std::vector<std::uint8_t> &data );
110
116 void setAutoUpdateEnable( bool enable );
117
123 void setAutoValidateEnable( bool enable );
124
131
138 ResultBuffer getPacketBufferAtIndex( std::uint16_t index );
139
140
146 std::vector<std::uint8_t> getPacketsBuffer() const;
147
154
161 ResultBuffer getApplicationDataBufferAtIndex( std::uint16_t index );
162
168 [[nodiscard]] std::uint16_t getTotalPackets() const;
169
175 [[nodiscard]] bool getAutoUpdateEnable() const { return m_updateEnable; }
176
183
189 std::vector<Packet> getPackets();
190
196 [[nodiscard]] ResultBool addPacket(Packet packet);
197
203 [[nodiscard]] ResultBool addPacketFromBuffer(const std::vector<std::uint8_t>& packetBuffer);
204
210 [[nodiscard]] ResultBool load(const std::vector<Packet>& packets);
211
217 [[nodiscard]] ResultBool load(const std::vector<std::uint8_t>& packetsBuffer);
218
224 [[nodiscard]] ResultBool read(const std::string& binaryFile);
225
231 [[nodiscard]] ResultBool write(const std::string& binaryFile) const;
232
238 [[nodiscard]] ResultBool readTemplate(const std::string& filename);
239
243 void clear();
244
248 void clearPackets();
249
256
262 std::vector<Packet>& getPacketsReference() { return m_packets; }
263
264 private:
266 bool m_templateIsSet { false };
267 bool m_updateEnable { true };
268 bool m_validateEnable { true };
269 bool m_syncPattEnable { false };
270 std::vector<Packet> m_packets;
271 std::uint16_t m_sequenceCount{ 0 };
272
274 std::uint32_t m_syncPattern{0x1ACFFC1D};
275 };
276} // namespace CCSDS
277
278#endif // CCSDS_MANAGER_H
Defines the Validator class for CCSDS packet validation.
Manages CCSDS packets and their templates.
bool m_templateIsSet
Boolean to indicate if Template has been set or not.
ResultBool loadTemplateConfigFile(const std::string &configPath)
Loads a template packet from a configuration file.
ResultBool setPacketTemplate(Packet packet)
Sets a new packet template.
std::vector< Packet > getPackets()
Retrieves all stored packets.
ResultBuffer getPacketTemplate()
Retrieves the packet template in serialized form.
void setSyncPatternEnable(bool enable)
enable sync pattern utilization both in serialization, deserialization, read and write.
std::vector< Packet > m_packets
Collection of stored packets.
std::uint16_t getDataFieldSize() const
retrieves the set data field size (this includes the secondary header if present)
bool m_validateEnable
bool indicating whether automatic validation is enabled (default: true).
ResultBool readTemplate(const std::string &filename)
Load a template packet from a binary or configuration file.
std::vector< Packet > & getPacketsReference()
Returns a reference to the packets vector.
void setSyncPattern(std::uint32_t syncPattern)
set sync pattern that should indicate the start of a CCSDS packet.
ResultBool load(const std::vector< Packet > &packets)
Load a vector of packets.
ResultBool addPacket(Packet packet)
Adds a new packet to the list.
std::uint32_t getSyncPattern() const
returns the currently set sync pattern.
bool m_syncPattEnable
bool indicating whether automatic sync pattern insertion is enabled (default: false).
std::uint16_t getTotalPackets() const
Retrieves the total number of packets managed.
Packet getTemplate()
Retrieves the packet template.
ResultBuffer getApplicationDataBuffer()
Retrieves the application data from the packets.
std::uint32_t m_syncPattern
ResultBool loadTemplateConfig(const Config &cfg)
Loads a template packet from a configuration object.
ResultBool read(const std::string &binaryFile)
Load a packet or a series of packets from a binary file.
void clearPackets()
Clears the packets and sets the counter to 0.
Packet m_templatePacket
The template packet used for generating new packets.
std::vector< std::uint8_t > getPacketsBuffer() const
Retrieves a buffer containing all the stored packets sequentially.
ResultBool addPacketFromBuffer(const std::vector< std::uint8_t > &packetBuffer)
Adds a new packet to the list.
void setAutoUpdateEnable(bool enable)
Enables or disables automatic updates for packets.
Manager(Packet packet)
Constructs a Manager with a given packet template.
void setDataFieldSize(std::uint16_t size)
Sets the size of the data field.
bool getSyncPatternEnable() const
returns the current settings of the sync pattern enable
bool getAutoUpdateEnable() const
Checks if automatic updates are enabled.
ResultBool setApplicationData(const std::vector< std::uint8_t > &data)
Sets the application data for the packet.
void clear()
Clears the manager, removes all packets and template.
bool m_updateEnable
bool indicating whether automatic updates are enabled (default: true).
void setAutoValidateEnable(bool enable)
Enables or disables automatic validation of packets.
ResultBuffer getApplicationDataBufferAtIndex(std::uint16_t index)
Retrieves the application data from a packet at the given index.
Validator & getValidatorReference()
Returns a reverence to the manager's Validator.
ResultBool write(const std::string &binaryFile) const
Write a packet or a series of packets to a binary file.
ResultBuffer getPacketBufferAtIndex(std::uint16_t index)
Retrieves a packet at the specified index.
std::uint16_t m_sequenceCount
Manager()=default
Default constructor.
Validator m_validator
Represents a CCSDS (Consultative Committee for Space Data Systems) packet.
Definition CCSDSPacket.h:59
void setUpdatePacketEnable(bool enable)
needs to be called as soon as possible, probably also from constructor.
Encapsulates a result that can hold either a value or an Error.
Definition CCSDSResult.h:82
Handles validation of CCSDS packets.
void configure(bool validatePacketCoherence, bool validateSequenceCount, bool validateAgainstTemplate)
Configures validation options.
void setTemplatePacket(const Packet &templatePacket)
Sets the template packet for validation.
Parses and stores config values from custom file format.
Definition CCSDSConfig.h:11
Contains definitions and classes for handling CCSDS headers.