fsfw/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h

106 lines
4.0 KiB
C
Raw Normal View History

2022-07-19 18:13:25 +02:00
#ifndef FSFW_TMTCPACKET_TMPACKETCREATOR_H
#define FSFW_TMTCPACKET_TMPACKETCREATOR_H
2022-07-20 22:21:15 +02:00
#include "PusTmIF.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
2022-07-22 17:09:44 +02:00
#include "fsfw/tmtcpacket/pus/CustomUserDataIF.h"
2022-08-30 12:04:15 +02:00
#include "fsfw/util/dataWrapper.h"
2022-07-19 18:13:25 +02:00
2022-07-20 22:21:15 +02:00
struct PusTmSecHeader {
2022-07-22 16:06:31 +02:00
PusTmSecHeader() = default;
2022-09-05 14:44:35 +02:00
PusTmSecHeader(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper)
2022-07-22 16:06:31 +02:00
: service(service), subservice(subservice), timeStamper(timeStamper) {}
uint8_t service = 0;
uint8_t subservice = 0;
2022-09-05 14:44:35 +02:00
TimeWriterIF* timeStamper = nullptr;
2022-07-22 16:06:31 +02:00
uint8_t pusVersion = ecss::PusVersion::PUS_C;
uint8_t scTimeRefStatus = 0;
uint16_t messageTypeCounter = 0;
uint16_t destId = 0;
2022-07-19 18:13:25 +02:00
};
2022-07-20 22:21:15 +02:00
struct PusTmParams {
2022-07-22 16:06:31 +02:00
PusTmParams() = default;
explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){};
2022-08-30 12:04:15 +02:00
PusTmParams(PusTmSecHeader secHeader, util::DataWrapper dataWrapper)
2022-07-22 16:06:31 +02:00
: secHeader(secHeader), dataWrapper(dataWrapper) {}
2022-09-05 14:44:35 +02:00
PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper)
2022-07-22 16:06:31 +02:00
: secHeader(service, subservice, timeStamper) {}
2022-09-05 14:44:35 +02:00
PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper,
2022-08-30 12:04:15 +02:00
util::DataWrapper dataWrapper_)
2022-07-22 16:06:31 +02:00
: PusTmParams(service, subservice, timeStamper) {
dataWrapper = dataWrapper_;
}
2022-07-20 22:21:15 +02:00
PusTmSecHeader secHeader;
2022-08-30 12:04:15 +02:00
util::DataWrapper dataWrapper{};
2022-07-20 22:21:15 +02:00
};
2022-09-05 14:44:35 +02:00
class TimeWriterIF;
2022-07-20 22:21:15 +02:00
2022-07-28 13:24:50 +02:00
/**
* This class provides a high-level interface to create PUS TM packets and then @serialize
* them into a raw byte format. It implements @SerializeIF for that purpose.
* A custom time stamper can be set, with the implementation of @TimeStamperIF as the only
* requirement.
*/
2022-07-22 17:09:44 +02:00
class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF {
2022-07-19 18:13:25 +02:00
public:
2022-07-28 13:24:50 +02:00
/**
* Empty creator with all-default parameters. Please note that serializing this will
* generate an invalid PUS packet with no timestamp.
*/
2022-07-20 22:21:15 +02:00
PusTmCreator();
2022-07-22 16:06:31 +02:00
PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusParams);
2022-07-19 18:13:25 +02:00
~PusTmCreator() override = default;
2022-09-05 14:44:35 +02:00
void setTimeStamper(TimeWriterIF& timeStamper);
/**
* This function disables the CRC16 calculation on serialization. This is useful to avoid
* duplicate calculation if some lower level component needs to update fields like the sequence
* count, which would require a checksum update.
*/
void disableCrcCalculation();
void enableCrcCalculation();
[[nodiscard]] bool crcCalculationEnabled() const;
2022-07-20 22:21:15 +02:00
SpacePacketParams& getSpParams();
void setApid(uint16_t apid);
2022-07-22 16:41:32 +02:00
void setDestId(uint16_t destId);
void setService(uint8_t service);
void setSubservice(uint8_t subservice);
2022-07-22 16:41:32 +02:00
void setMessageTypeCounter(uint16_t messageTypeCounter);
2022-07-20 22:21:15 +02:00
PusTmParams& getParams();
void updateSpLengthField();
2022-07-20 11:43:16 +02:00
[[nodiscard]] uint16_t getPacketIdRaw() const override;
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
2022-07-19 18:13:25 +02:00
[[nodiscard]] uint16_t getPacketDataLen() const override;
[[nodiscard]] uint8_t getPusVersion() const override;
[[nodiscard]] uint8_t getService() const override;
[[nodiscard]] uint8_t getSubService() const override;
2022-07-20 22:21:15 +02:00
uint8_t getScTimeRefStatus() override;
uint16_t getMessageTypeCounter() override;
uint16_t getDestId() override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
[[nodiscard]] size_t getSerializedSize() const override;
2022-09-05 14:44:35 +02:00
[[nodiscard]] TimeWriterIF* getTimestamper() const;
2022-07-22 17:09:44 +02:00
ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override;
2022-07-25 11:26:45 +02:00
ReturnValue_t setSerializableUserData(SerializeIF& serializable) override;
2022-07-19 18:13:25 +02:00
2022-08-15 19:16:31 +02:00
// Load all big endian (network endian) helpers into scope
using SerializeIF::serializeBe;
2022-07-19 18:13:25 +02:00
private:
2022-07-27 21:11:12 +02:00
// Forbidden to use
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
2022-07-22 16:06:31 +02:00
void setup();
2022-07-20 22:21:15 +02:00
PusTmParams pusParams{};
2022-07-27 11:26:47 +02:00
bool calculateCrcOnSerialization = true;
2022-07-20 22:21:15 +02:00
SpacePacketCreator spCreator;
2022-07-19 18:13:25 +02:00
};
#endif // FSFW_TMTCPACKET_TMPACKETCREATOR_H