diff --git a/src/fsfw/tmtcpacket/pus/defs.h b/src/fsfw/tmtcpacket/pus/defs.h index 69b3415c..c5172d8b 100644 --- a/src/fsfw/tmtcpacket/pus/defs.h +++ b/src/fsfw/tmtcpacket/pus/defs.h @@ -13,44 +13,6 @@ using PusChecksumT = uint16_t; //! Version numbers according to ECSS-E-ST-70-41C p.439 enum PusVersion : uint8_t { PUS_A = 1, PUS_C = 2 }; -struct RawData { - const uint8_t* data; - size_t len; -}; - -enum DataTypes { RAW, SERIALIZABLE }; - -union DataUnion { - RawData raw; - SerializeIF* serializable; -}; - -struct DataWrapper { - DataTypes type; - 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; - } - - 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; - } -}; - /** * This struct defines the data structure of a Space Packet when accessed * via a pointer. diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index d85d5b72..14a440a0 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -37,14 +37,14 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max if (result != returnvalue::OK) { return result; } - if (pusParams.dataWrapper.type == ecss::DataTypes::RAW) { + 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 == ecss::DataTypes::SERIALIZABLE and + } else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and pusParams.dataWrapper.dataUnion.serializable != nullptr) { result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness); diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 72691c40..4b0d81c8 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -7,6 +7,7 @@ #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_) {} @@ -15,7 +16,7 @@ struct PusTcParams { uint8_t subservice; uint8_t ackFlags = ecss::ACK_ALL; uint16_t sourceId = 0; - ecss::DataWrapper dataWrapper{}; + util::DataWrapper dataWrapper{}; uint8_t pusVersion = ecss::PusVersion::PUS_C; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 80853221..b754e990 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -77,12 +77,12 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max } } - if (pusParams.dataWrapper.type == ecss::DataTypes::RAW and + 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 == ecss::DataTypes::SERIALIZABLE and + } else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and pusParams.dataWrapper.dataUnion.serializable != nullptr) { result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 706a7b70..8fd4f690 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -4,6 +4,7 @@ #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,19 +23,19 @@ struct PusTmSecHeader { struct PusTmParams { PusTmParams() = default; explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){}; - PusTmParams(PusTmSecHeader secHeader, ecss::DataWrapper dataWrapper) + PusTmParams(PusTmSecHeader secHeader, util::DataWrapper dataWrapper) : secHeader(secHeader), dataWrapper(dataWrapper) {} PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper) : secHeader(service, subservice, timeStamper) {} PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper, - ecss::DataWrapper dataWrapper_) + util::DataWrapper dataWrapper_) : PusTmParams(service, subservice, timeStamper) { dataWrapper = dataWrapper_; } PusTmSecHeader secHeader; - ecss::DataWrapper dataWrapper{}; + util::DataWrapper dataWrapper{}; }; class TimeStamperIF; diff --git a/src/fsfw/tmtcservices/VerificationCodes.h b/src/fsfw/tmtcservices/VerificationCodes.h index 91b76bde..479074eb 100644 --- a/src/fsfw/tmtcservices/VerificationCodes.h +++ b/src/fsfw/tmtcservices/VerificationCodes.h @@ -5,7 +5,7 @@ namespace tcverif { -enum VerifFlags : uint8_t { +enum VerificationFlags : uint8_t { NONE = 0b0000, ACCEPTANCE = 0b0001, START = 0b0010, diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index ab69c9c8..845a73b8 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -11,13 +11,13 @@ class DataWithObjectIdPrefix : public SerializeIF { public: DataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen) : objectId(objectId) { - dataWrapper.type = ecss::DataTypes::RAW; + dataWrapper.type = util::DataTypes::RAW; dataWrapper.dataUnion.raw.data = srcData; dataWrapper.dataUnion.raw.len = srcDataLen; } DataWithObjectIdPrefix(object_id_t objectId, SerializeIF& serializable) : objectId(objectId) { - dataWrapper.type = ecss::DataTypes::SERIALIZABLE; + dataWrapper.type = util::DataTypes::SERIALIZABLE; dataWrapper.dataUnion.serializable = &serializable; } @@ -26,11 +26,11 @@ class DataWithObjectIdPrefix : public SerializeIF { if (*size + getSerializedSize() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } - if (dataWrapper.type != ecss::DataTypes::RAW) { + 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 == ecss::DataTypes::SERIALIZABLE) { + } else if (dataWrapper.type == util::DataTypes::SERIALIZABLE) { if (dataWrapper.dataUnion.serializable == nullptr) { return returnvalue::FAILED; } @@ -40,7 +40,7 @@ class DataWithObjectIdPrefix : public SerializeIF { if (result != returnvalue::OK) { return result; } - if (dataWrapper.type != ecss::DataTypes::RAW) { + 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; @@ -63,7 +63,7 @@ class DataWithObjectIdPrefix : public SerializeIF { private: object_id_t objectId; - ecss::DataWrapper dataWrapper{}; + util::DataWrapper dataWrapper{}; }; } // namespace telemetry diff --git a/src/fsfw/util/dataWrapper.h b/src/fsfw/util/dataWrapper.h new file mode 100644 index 00000000..74a9ff5f --- /dev/null +++ b/src/fsfw/util/dataWrapper.h @@ -0,0 +1,60 @@ +#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/pus/testService11.cpp b/unittests/pus/testService11.cpp index 72708f09..54279543 100644 --- a/unittests/pus/testService11.cpp +++ b/unittests/pus/testService11.cpp @@ -7,8 +7,8 @@ #include "tmtc/pusIds.h" TEST_CASE("PUS Service 11", "[pus-srvc11]") { - Service11TelecommandScheduling<13> pusService11(objects::PUS_SERVICE_11_TC_SCHEDULER, - apid::DEFAULT_APID, pus::PUS_SERVICE_11, nullptr); + Service11TelecommandScheduling<13> pusService11({objects::PUS_SERVICE_11_TC_SCHEDULER, + apid::DEFAULT_APID, pus::PUS_SERVICE_11}, nullptr); // TODO test something... } \ No newline at end of file diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp index 4e1bb4fb..2731b28f 100644 --- a/unittests/tmtcservices/testStoreAndSendHelper.cpp +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -44,7 +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 == ecss::DataTypes::RAW); + REQUIRE(params.dataWrapper.type == util::DataTypes::RAW); REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr); REQUIRE(params.dataWrapper.dataUnion.raw.len == 0); REQUIRE(tmHelper.sendCounter == 0); @@ -65,7 +65,7 @@ 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 == ecss::DataTypes::RAW); + REQUIRE(params.dataWrapper.type == util::DataTypes::RAW); REQUIRE(params.dataWrapper.dataUnion.raw.data == data.data()); REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size()); } @@ -75,7 +75,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 == ecss::DataTypes::SERIALIZABLE); + REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE); REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer); } @@ -86,7 +86,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 == ecss::DataTypes::SERIALIZABLE); + REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE); REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId); }