From 80355910ee6260496fdfc196230c603c0d654582 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 2 Sep 2022 09:05:10 +0200 Subject: [PATCH 1/5] better warning --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5351aeb4..7b00a708 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -360,7 +360,7 @@ if(NOT FSFW_CONFIG_PATH) if(NOT FSFW_BUILD_DOCS) message( WARNING - "${MSG_PREFIX} Flight Software Framework configuration path not set") + "${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set") message( WARNING "${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..") From f0b7a103d4412169a792c833258a7229376f3bae Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 15:30:53 +0200 Subject: [PATCH 2/5] refactor ctors --- src/fsfw/serialize/SerialBufferAdapter.cpp | 7 ++++++ src/fsfw/serialize/SerialBufferAdapter.h | 12 +++++----- src/fsfw/tmtcpacket/pus/CustomUserDataIF.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 21 ++++++----------- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 25 ++++++++++++++------- 5 files changed, 39 insertions(+), 28 deletions(-) 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; From 75dc7a405d566ba99cb742eb967f6261b2e0c440 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 16:02:32 +0200 Subject: [PATCH 3/5] del data wrapper --- src/fsfw/serialize/SerialBufferAdapter.cpp | 2 +- src/fsfw/serialize/SerialBufferAdapter.h | 4 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 28 ++++----- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 13 +++- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 20 ++++--- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 20 +++---- src/fsfw/util/dataWrapper.h | 60 ------------------- unittests/tmtcpacket/testPusTcCreator.cpp | 2 +- .../tmtcservices/testStoreAndSendHelper.cpp | 16 ++--- 9 files changed, 52 insertions(+), 113 deletions(-) delete mode 100644 src/fsfw/util/dataWrapper.h diff --git a/src/fsfw/serialize/SerialBufferAdapter.cpp b/src/fsfw/serialize/SerialBufferAdapter.cpp index 0893dbde..0293191e 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.cpp +++ b/src/fsfw/serialize/SerialBufferAdapter.cpp @@ -21,7 +21,7 @@ SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, count_t buffe bufferLength(bufferLength) {} template -SerialBufferAdapter::~SerialBufferAdapter() {} +SerialBufferAdapter::~SerialBufferAdapter() = default; template ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, diff --git a/src/fsfw/serialize/SerialBufferAdapter.h b/src/fsfw/serialize/SerialBufferAdapter.h index e53a12bc..395f93d2 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.h +++ b/src/fsfw/serialize/SerialBufferAdapter.h @@ -44,7 +44,7 @@ class SerialBufferAdapter : public SerializeIF { ~SerialBufferAdapter() override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override; + Endianness streamEndianness) const override; [[nodiscard]] size_t getSerializedSize() const override; @@ -61,7 +61,7 @@ class SerialBufferAdapter : public SerializeIF { * @return */ ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness) override; + Endianness streamEndianness) override; uint8_t* getBuffer(); [[nodiscard]] const uint8_t* getConstBuffer() const; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index 14a440a0..34d8396d 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -14,7 +14,6 @@ PusTcCreator::PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams) ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { const uint8_t *start = *buffer; - size_t userDataLen = pusParams.dataWrapper.getLength(); if (*size + getSerializedSize() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } @@ -37,17 +36,8 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max if (result != returnvalue::OK) { return result; } - if (pusParams.dataWrapper.type == util::DataTypes::RAW) { - const uint8_t *data = pusParams.dataWrapper.dataUnion.raw.data; - if (data != nullptr and userDataLen > 0) { - std::memcpy(*buffer, 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.appData != nullptr) { + result = pusParams.appData->serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; } @@ -58,8 +48,11 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max } void PusTcCreator::updateSpLengthField() { - spCreator.setDataLen(ecss::PusTcDataFieldHeader::MIN_SIZE + pusParams.dataWrapper.getLength() + - 1); + size_t len = ecss::PusTcDataFieldHeader::MIN_SIZE + 1; + if (pusParams.appData != nullptr) { + len += pusParams.appData->getSerializedSize(); + } + spCreator.setDataLen(len); } size_t PusTcCreator::getSerializedSize() const { return spCreator.getFullPacketLen(); } @@ -91,14 +84,15 @@ SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); } ReturnValue_t PusTcCreator::setRawUserData(const uint8_t *data, size_t len) { // TODO: Check length field? - pusParams.dataWrapper.setRawData({data, len}); + pusParams.bufAdapter.setConstBuffer(data, len); + pusParams.appData = &pusParams.bufAdapter; updateSpLengthField(); return returnvalue::OK; } -ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF &serializable) { +ReturnValue_t PusTcCreator::setSerializableUserData(const SerializeIF &serializable) { // TODO: Check length field? - pusParams.dataWrapper.setSerializable(serializable); + pusParams.appData = &serializable; updateSpLengthField(); return returnvalue::OK; } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 4b0d81c8..add8a379 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -7,16 +7,23 @@ #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" #include "fsfw/tmtcpacket/pus/defs.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" -#include "fsfw/util/dataWrapper.h" struct PusTcParams { PusTcParams(uint8_t service_, uint8_t subservice_) : service(service_), subservice(subservice_) {} + void setRawAppData(const uint8_t *data, size_t len) { + bufAdapter.setConstBuffer(data, len); + appData = &bufAdapter; + } + + void setSerializableAppData(const SerializeIF &serializable) { appData = &serializable; } + uint8_t service; uint8_t subservice; uint8_t ackFlags = ecss::ACK_ALL; uint16_t sourceId = 0; - util::DataWrapper dataWrapper{}; + SerialBufferAdapter bufAdapter; + const SerializeIF *appData = nullptr; uint8_t pusVersion = ecss::PusVersion::PUS_C; }; @@ -52,7 +59,7 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF [[nodiscard]] uint8_t getSubService() const override; [[nodiscard]] uint16_t getSourceId() const override; 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 helpers into the class namespace using SerializeIF::serializeBe; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 1288b6d8..41512c07 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -51,7 +51,6 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max if (result != returnvalue::OK) { return result; } - size_t userDataLen = pusParams.data->getSerializedSize(); **buffer = ((pusParams.secHeader.pusVersion << 4) & 0xF0) | (pusParams.secHeader.scTimeRefStatus & 0x0F); *buffer += 1; @@ -77,8 +76,8 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max } } - if (pusParams.data != nullptr) { - result = pusParams.data->serialize(buffer, size, maxSize, streamEndianness); + if (pusParams.sourceData != nullptr) { + result = pusParams.sourceData->serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; } @@ -104,8 +103,10 @@ 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.data->getSerializedSize() + - sizeof(ecss::PusChecksumT) - 1; + size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + sizeof(ecss::PusChecksumT) - 1; + if (pusParams.sourceData != nullptr) { + headerLen += pusParams.sourceData->getSerializedSize(); + } if (pusParams.secHeader.timeStamper != nullptr) { headerLen += pusParams.secHeader.timeStamper->getSerializedSize(); } @@ -127,12 +128,17 @@ 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.adapter.setConstBuffer(data, len); + if (data == nullptr or len == 0) { + pusParams.sourceData = nullptr; + } else { + pusParams.adapter.setConstBuffer(data, len); + pusParams.sourceData = &pusParams.adapter; + } updateSpLengthField(); return returnvalue::OK; } ReturnValue_t PusTmCreator::setSerializableUserData(const SerializeIF& serializable) { - pusParams.data = &serializable; + pusParams.sourceData = &serializable; updateSpLengthField(); return returnvalue::OK; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index c108aa73..caf6f219 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -4,7 +4,6 @@ #include "PusTmIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" -#include "fsfw/util/dataWrapper.h" struct PusTmSecHeader { PusTmSecHeader() = default; @@ -22,29 +21,26 @@ struct PusTmSecHeader { struct PusTmParams { PusTmParams() = default; - explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader) {}; + explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){}; PusTmParams(PusTmSecHeader secHeader, const SerializeIF& data) - : secHeader(secHeader), data(&data) {} + : secHeader(secHeader), sourceData(&data) {} PusTmParams(PusTmSecHeader secHeader, const uint8_t* data, size_t dataLen) - : secHeader(secHeader), adapter(data, dataLen), data(&adapter) { - } + : secHeader(secHeader), adapter(data, dataLen), sourceData(&adapter) {} PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper) : secHeader(service, subservice, timeStamper) {} PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper, const SerializeIF& data_) : PusTmParams(service, subservice, timeStamper) { - data = &data_; + sourceData = &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) {} + PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper, const uint8_t* data, + size_t dataLen) + : secHeader(service, subservice, timeStamper), adapter(data, dataLen), sourceData(&adapter) {} PusTmSecHeader secHeader; SerialBufferAdapter adapter; - const SerializeIF* data = nullptr; + const SerializeIF* sourceData = nullptr; }; class TimeWriterIF; diff --git a/src/fsfw/util/dataWrapper.h b/src/fsfw/util/dataWrapper.h deleted file mode 100644 index 74a9ff5f..00000000 --- a/src/fsfw/util/dataWrapper.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef FSFW_UTIL_DATAWRAPPER_H -#define FSFW_UTIL_DATAWRAPPER_H - -#include -#include -#include - -#include "fsfw/serialize.h" - -namespace util { - -struct RawData { - const uint8_t* data = nullptr; - size_t len = 0; -}; - -enum DataTypes { NONE, RAW, SERIALIZABLE }; - -union DataUnion { - RawData raw; - SerializeIF* serializable = nullptr; -}; - -struct DataWrapper { - DataTypes type = DataTypes::NONE; - DataUnion dataUnion; - using BufPairT = std::pair; - - [[nodiscard]] size_t getLength() const { - if (type == DataTypes::RAW) { - return dataUnion.raw.len; - } else if (type == DataTypes::SERIALIZABLE and dataUnion.serializable != nullptr) { - return dataUnion.serializable->getSerializedSize(); - } - return 0; - } - - [[nodiscard]] bool isNull() const { - if ((type == DataTypes::NONE) or (type == DataTypes::RAW and dataUnion.raw.data == nullptr) or - (type == DataTypes::SERIALIZABLE and dataUnion.serializable == nullptr)) { - return true; - } - return false; - } - - void setRawData(BufPairT bufPair) { - type = DataTypes::RAW; - dataUnion.raw.data = bufPair.first; - dataUnion.raw.len = bufPair.second; - } - - void setSerializable(SerializeIF& serializable) { - type = DataTypes::SERIALIZABLE; - dataUnion.serializable = &serializable; - } -}; - -} // namespace util - -#endif // FSFW_UTIL_DATAWRAPPER_H diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index b18c4717..58f8cbf9 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -71,7 +71,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { SECTION("Test with Application Data Raw") { auto& params = creator.getPusParams(); std::array data{1, 2, 3}; - params.dataWrapper.setRawData({data.data(), data.size()}); + params.setRawAppData(data.data(), data.size()); // To get correct size information, the SP length field needs to be updated automatically REQUIRE(creator.getSerializedSize() == 13); creator.updateSpLengthField(); diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp index 2731b28f..46418dfe 100644 --- a/unittests/tmtcservices/testStoreAndSendHelper.cpp +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -44,9 +44,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(creator.getSubService() == 2); REQUIRE(creator.getService() == 17); auto& params = creator.getParams(); - REQUIRE(params.dataWrapper.type == util::DataTypes::RAW); - REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr); - REQUIRE(params.dataWrapper.dataUnion.raw.len == 0); + REQUIRE(params.sourceData == nullptr); REQUIRE(tmHelper.sendCounter == 0); REQUIRE(tmHelper.storeAndSendTmPacket() == returnvalue::OK); REQUIRE(tmHelper.sendCounter == 1); @@ -65,9 +63,9 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == returnvalue::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); - REQUIRE(params.dataWrapper.type == util::DataTypes::RAW); - REQUIRE(params.dataWrapper.dataUnion.raw.data == data.data()); - REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size()); + REQUIRE(params.sourceData != nullptr); + REQUIRE(params.sourceData->getSerializedSize() == data.size()); + REQUIRE(params.adapter.getConstBuffer() == data.data()); } SECTION("Serializable Helper") { @@ -75,8 +73,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == returnvalue::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); - REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE); - REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer); + REQUIRE(params.sourceData == &simpleSer); } SECTION("Object ID prefix Helper") { @@ -86,8 +83,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == returnvalue::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); - REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE); - REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId); + REQUIRE(params.sourceData == &dataWithObjId); } // TODO: Error handling From 4c3f9feb938b83bf2472dccbb06162543f41f853 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 16:06:24 +0200 Subject: [PATCH 4/5] explicit include --- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index add8a379..a61b19d2 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -6,6 +6,7 @@ #include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" #include "fsfw/tmtcpacket/pus/defs.h" +#include "fsfw/serialize/SerialBufferAdapter.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" struct PusTcParams { From f5421e9abd389dde5e6524f76b9e579dbf494c47 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 16:10:06 +0200 Subject: [PATCH 5/5] refactor tm helper --- CMakeLists.txt | 3 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 1 + src/fsfw/tmtcservices/tmHelpers.h | 38 +++++++---------------- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b00a708..3011b244 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -360,7 +360,8 @@ if(NOT FSFW_CONFIG_PATH) if(NOT FSFW_BUILD_DOCS) message( WARNING - "${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set") + "${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set" + ) message( WARNING "${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..") diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index a61b19d2..abccef8d 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -1,12 +1,12 @@ #ifndef FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H #define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H +#include "fsfw/serialize/SerialBufferAdapter.h" #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" #include "fsfw/tmtcpacket/pus/defs.h" -#include "fsfw/serialize/SerialBufferAdapter.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" struct PusTcParams { diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index caf6f219..626d873e 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -2,6 +2,7 @@ #define FSFW_TMTCPACKET_TMPACKETCREATOR_H #include "PusTmIF.h" +#include "fsfw/serialize/SerialBufferAdapter.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index 845a73b8..be93f5ec 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -10,48 +10,33 @@ namespace telemetry { class DataWithObjectIdPrefix : public SerializeIF { public: DataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen) - : objectId(objectId) { - dataWrapper.type = util::DataTypes::RAW; - dataWrapper.dataUnion.raw.data = srcData; - dataWrapper.dataUnion.raw.len = srcDataLen; - } + : objectId(objectId), bufAdapter(srcData, srcDataLen), userData(&bufAdapter) {} - DataWithObjectIdPrefix(object_id_t objectId, SerializeIF& serializable) : objectId(objectId) { - dataWrapper.type = util::DataTypes::SERIALIZABLE; - dataWrapper.dataUnion.serializable = &serializable; - } + DataWithObjectIdPrefix(object_id_t objectId, const SerializeIF& serializable) + : objectId(objectId), userData(&serializable) {} ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override { if (*size + getSerializedSize() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } - if (dataWrapper.type != util::DataTypes::RAW) { - if ((dataWrapper.dataUnion.raw.data == nullptr) and (dataWrapper.dataUnion.raw.len > 0)) { - return returnvalue::FAILED; - } - } else if (dataWrapper.type == util::DataTypes::SERIALIZABLE) { - if (dataWrapper.dataUnion.serializable == nullptr) { - return returnvalue::FAILED; - } - } ReturnValue_t result = SerializeAdapter::serialize(&objectId, buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; } - if (dataWrapper.type != util::DataTypes::RAW) { - std::memcpy(*buffer, dataWrapper.dataUnion.raw.data, dataWrapper.dataUnion.raw.len); - *buffer += dataWrapper.dataUnion.raw.len; - *size += dataWrapper.dataUnion.raw.len; - } else { - return dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness); + if (userData != nullptr) { + return userData->serialize(buffer, size, maxSize, streamEndianness); } return returnvalue::OK; } [[nodiscard]] size_t getSerializedSize() const override { - return sizeof(objectId) + dataWrapper.getLength(); + size_t len = 0; + if (userData != nullptr) { + len += userData->getSerializedSize(); + } + return len; } ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, @@ -63,7 +48,8 @@ class DataWithObjectIdPrefix : public SerializeIF { private: object_id_t objectId; - util::DataWrapper dataWrapper{}; + SerialBufferAdapter bufAdapter; + const SerializeIF* userData = nullptr; }; } // namespace telemetry