diff --git a/src/fsfw/serialize/SerialBufferAdapter.cpp b/src/fsfw/serialize/SerialBufferAdapter.cpp index 81919f37..0893dbde 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.cpp +++ b/src/fsfw/serialize/SerialBufferAdapter.cpp @@ -125,6 +125,13 @@ void SerialBufferAdapter::setBuffer(uint8_t* buffer, count_t bufferLeng this->bufferLength = bufferLength; } +template +void SerialBufferAdapter::setConstBuffer(const uint8_t* buf, count_t bufLen) { + this->buffer = nullptr; + this->bufferLength = bufLen; + this->constBuffer = buf; +} + // forward Template declaration for linker template class SerialBufferAdapter; template class SerialBufferAdapter; diff --git a/src/fsfw/serialize/SerialBufferAdapter.h b/src/fsfw/serialize/SerialBufferAdapter.h index 3b95fa20..e53a12bc 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.h +++ b/src/fsfw/serialize/SerialBufferAdapter.h @@ -21,6 +21,7 @@ template class SerialBufferAdapter : public SerializeIF { public: + SerialBufferAdapter() = default; /** * Constructor for constant uint8_t buffer. Length field can be serialized optionally. * Type of length can be supplied as template type. @@ -40,12 +41,12 @@ class SerialBufferAdapter : public SerializeIF { */ SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, bool serializeLength = false); - virtual ~SerialBufferAdapter(); + ~SerialBufferAdapter() override; - virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; - virtual size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; /** * @brief This function deserializes a buffer into the member buffer. @@ -59,12 +60,13 @@ class SerialBufferAdapter : public SerializeIF { * @param bigEndian * @return */ - virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override; uint8_t* getBuffer(); - const uint8_t* getConstBuffer() const; + [[nodiscard]] const uint8_t* getConstBuffer() const; void setBuffer(uint8_t* buffer, count_t bufferLength); + void setConstBuffer(const uint8_t* buf, count_t bufLen); private: bool serializeLength = false; diff --git a/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h b/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h index 779a0414..33592ed1 100644 --- a/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h +++ b/src/fsfw/tmtcpacket/pus/CustomUserDataIF.h @@ -7,6 +7,6 @@ class CustomUserDataIF { public: virtual ~CustomUserDataIF() = default; virtual ReturnValue_t setRawUserData(const uint8_t* data, size_t len) = 0; - virtual ReturnValue_t setSerializableUserData(SerializeIF& serializable) = 0; + virtual ReturnValue_t setSerializableUserData(const SerializeIF& serializable) = 0; }; #endif // FSFW_TMTCPACKET_CREATORDATAIF_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 09914e09..1288b6d8 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -51,7 +51,7 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max if (result != returnvalue::OK) { return result; } - size_t userDataLen = pusParams.dataWrapper.getLength(); + size_t userDataLen = pusParams.data->getSerializedSize(); **buffer = ((pusParams.secHeader.pusVersion << 4) & 0xF0) | (pusParams.secHeader.scTimeRefStatus & 0x0F); *buffer += 1; @@ -77,15 +77,8 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max } } - if (pusParams.dataWrapper.type == util::DataTypes::RAW and - pusParams.dataWrapper.dataUnion.raw.data != nullptr) { - std::memcpy(*buffer, pusParams.dataWrapper.dataUnion.raw.data, userDataLen); - *buffer += userDataLen; - *size += userDataLen; - } else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and - pusParams.dataWrapper.dataUnion.serializable != nullptr) { - result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, - streamEndianness); + if (pusParams.data != nullptr) { + result = pusParams.data->serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; } @@ -111,7 +104,7 @@ TimeWriterIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader. SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } void PusTmCreator::updateSpLengthField() { - size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + pusParams.dataWrapper.getLength() + + size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + pusParams.data->getSerializedSize() + sizeof(ecss::PusChecksumT) - 1; if (pusParams.secHeader.timeStamper != nullptr) { headerLen += pusParams.secHeader.timeStamper->getSerializedSize(); @@ -134,12 +127,12 @@ void PusTmCreator::setMessageTypeCounter(uint16_t messageTypeCounter) { void PusTmCreator::setDestId(uint16_t destId) { pusParams.secHeader.destId = destId; } ReturnValue_t PusTmCreator::setRawUserData(const uint8_t* data, size_t len) { - pusParams.dataWrapper.setRawData({data, len}); + pusParams.adapter.setConstBuffer(data, len); updateSpLengthField(); return returnvalue::OK; } -ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF& serializable) { - pusParams.dataWrapper.setSerializable(serializable); +ReturnValue_t PusTmCreator::setSerializableUserData(const SerializeIF& serializable) { + pusParams.data = &serializable; updateSpLengthField(); return returnvalue::OK; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 09d02945..c108aa73 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -22,20 +22,29 @@ struct PusTmSecHeader { struct PusTmParams { PusTmParams() = default; - explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){}; - PusTmParams(PusTmSecHeader secHeader, util::DataWrapper dataWrapper) - : secHeader(secHeader), dataWrapper(dataWrapper) {} - + explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader) {}; + PusTmParams(PusTmSecHeader secHeader, const SerializeIF& data) + : secHeader(secHeader), data(&data) {} + PusTmParams(PusTmSecHeader secHeader, const uint8_t* data, size_t dataLen) + : secHeader(secHeader), adapter(data, dataLen), data(&adapter) { + } PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper) : secHeader(service, subservice, timeStamper) {} PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper, - util::DataWrapper dataWrapper_) + const SerializeIF& data_) : PusTmParams(service, subservice, timeStamper) { - dataWrapper = dataWrapper_; + data = &data_; } + + PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper, + const uint8_t* data, size_t dataLen) + : secHeader(service, subservice, timeStamper), + adapter(data, dataLen), + data(&adapter) {} PusTmSecHeader secHeader; - util::DataWrapper dataWrapper{}; + SerialBufferAdapter adapter; + const SerializeIF* data = nullptr; }; class TimeWriterIF; @@ -88,7 +97,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF [[nodiscard]] size_t getSerializedSize() const override; [[nodiscard]] TimeWriterIF* getTimestamper() const; ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override; - ReturnValue_t setSerializableUserData(SerializeIF& serializable) override; + ReturnValue_t setSerializableUserData(const SerializeIF& serializable) override; // Load all big endian (network endian) helpers into scope using SerializeIF::serializeBe;