fsfw/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h

98 lines
3.4 KiB
C
Raw Normal View History

2020-10-28 02:20:12 +01:00
#ifndef FSFW_TMTCPACKET_SPACEPACKETBASE_H_
#define FSFW_TMTCPACKET_SPACEPACKETBASE_H_
2020-05-15 19:51:39 +02:00
#include <cstddef>
2022-08-22 16:23:36 +02:00
#include "fsfw/returnvalues/returnvalue.h"
2022-07-20 11:43:16 +02:00
#include "fsfw/tmtcpacket/ReadablePacketIF.h"
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include "fsfw/tmtcpacket/ccsds/defs.h"
2022-02-02 10:29:30 +01:00
/**
2020-05-15 19:51:39 +02:00
* @defgroup tmtcpackets Space Packets
* This is the group, where all classes associated with Telecommand and
* Telemetry packets belong to.
* The class hierarchy resembles the dependency between the different standards
* applied, namely the CCSDS Space Packet standard and the ECCSS Packet
* Utilization Standard. Most field and structure names are taken from these
* standards.
*/
/**
* This class is the basic data handler for any CCSDS Space Packet
* compatible Telecommand and Telemetry packet.
* It does not contain the packet data itself but a pointer to the
2022-07-21 11:34:11 +02:00
* data must be set on instantiation or with the @setData or @setReadOnlyData call.
* The @isNull and @checkSize methods can be used to check the validity of the data pointed to.
*
* This is a zero-copy reader class. It does not contain the packet data itself but a pointer to
* the data. Calling any accessor methods without pointing the object to valid data first will
* cause undefined behaviour.
* @ingroup tmtcpackets
*/
2022-07-19 18:13:25 +02:00
class SpacePacketReader : public SpacePacketIF,
public ReadablePacketIF,
public RedirectableDataPointerIF {
2022-02-02 10:29:30 +01:00
public:
2022-07-21 11:34:11 +02:00
/**
* Initialize an empty space packet reader which points to no data
*/
2022-07-19 18:13:25 +02:00
SpacePacketReader() = default;
2022-02-02 10:29:30 +01:00
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed.
* @param set_address The position where the packet data lies.
*/
2022-07-19 18:13:25 +02:00
explicit SpacePacketReader(const uint8_t* setAddress, size_t maxSize);
2022-02-02 10:29:30 +01:00
/**
* No data is allocated, so the destructor is empty.
*/
2022-07-18 10:42:56 +02:00
~SpacePacketReader() override;
2022-02-02 10:29:30 +01:00
2022-07-21 11:34:11 +02:00
/**
* Check whether any data is set for the reader object
* @return
*/
[[nodiscard]] bool isNull() const;
/**
* Get size of the buffer. This is the size which is passed to the constructor or to the
* @setData call. It is not the content of the CCSDS data length field and it is not necessarily
* equal to the full packet length of the space packet.
* @return
*/
[[nodiscard]] size_t getBufSize() const;
2022-07-20 11:43:16 +02:00
[[nodiscard]] uint16_t getPacketIdRaw() const override;
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
2022-07-18 10:20:26 +02:00
[[nodiscard]] uint16_t getPacketDataLen() const override;
2022-07-27 17:00:43 +02:00
[[nodiscard]] const uint8_t* getFullData() const override;
2022-07-19 18:13:25 +02:00
2022-02-02 10:29:30 +01:00
// Helper methods:
2022-07-21 11:34:11 +02:00
[[nodiscard]] ReturnValue_t checkSize() const;
2022-02-02 10:29:30 +01:00
2022-11-15 10:46:46 +01:00
const uint8_t* getPacketData() const;
2022-02-02 10:29:30 +01:00
2022-07-21 11:34:11 +02:00
ReturnValue_t setReadOnlyData(const uint8_t* data, size_t maxSize);
2022-07-19 18:13:25 +02:00
protected:
2022-02-02 10:29:30 +01:00
/**
2022-07-19 18:13:25 +02:00
* A pointer to a structure which defines the data structure of
* the packet header.
* To be hardware-safe, all elements are of byte size.
2022-02-02 10:29:30 +01:00
*/
2022-07-20 11:43:16 +02:00
const ccsds::PrimaryHeader* spHeader{};
2022-07-19 18:13:25 +02:00
const uint8_t* packetDataField{};
2022-07-21 11:34:11 +02:00
size_t bufSize = 0;
/**
* With this method, the packet data pointer can be redirected to another
* location.
* @param data A pointer to another raw Space Packet.
*/
ReturnValue_t setData(uint8_t* data, size_t maxSize, void* args) override;
2022-07-19 18:13:25 +02:00
2022-07-21 11:34:11 +02:00
ReturnValue_t setInternalFields(const uint8_t* data, size_t maxSize);
};
2020-10-28 02:20:12 +01:00
#endif /* FSFW_TMTCPACKET_SPACEPACKETBASE_H_ */