From f5421e9abd389dde5e6524f76b9e579dbf494c47 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 16:10:06 +0200 Subject: [PATCH] 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