From 5bb7023ff30823575187da06eba50a8acec78254 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 21:11:12 +0200 Subject: [PATCH] improvements for creator API --- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 12 ++++++++---- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 9 ++++++--- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 5 +++-- unittests/tmtcpacket/testPusTcCreator.cpp | 3 ++- unittests/tmtcpacket/testPusTmCreator.cpp | 3 ++- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index d6748619..f509717b 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -90,10 +90,6 @@ PusTcParams &PusTcCreator::getPusParams() { return pusParams; } SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); } -ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); -} - ReturnValue_t PusTcCreator::setRawUserData(const uint8_t *data, size_t len) { // TODO: Check length field? pusParams.dataWrapper.setRawData({data, len}); @@ -107,3 +103,11 @@ ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF &serializable) { updateSpLengthField(); return HasReturnvaluesIF::RETURN_OK; } + +ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); +} + +ReturnValue_t PusTcCreator::serialize(uint8_t *buffer, size_t maxSize) const { + return SerializeIF::serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); +} diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 0f903e7b..b41ad940 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -34,10 +34,10 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF PusTcParams &getPusParams(); SpacePacketParams &getSpParams(); - ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize); + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const override; + ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const override; [[nodiscard]] size_t getSerializedSize() const override; - ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, - Endianness streamEndianness) override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; @@ -52,6 +52,9 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF private: ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override; + // Forbidden to use + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override; SpacePacketCreator spCreator; PusTcParams pusParams; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 75760968..c8de3428 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -78,13 +78,14 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; [[nodiscard]] size_t getSerializedSize() const override; - ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness) override; [[nodiscard]] TimeStamperIF* getTimestamper() const; ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override; ReturnValue_t setSerializableUserData(SerializeIF& serializable) override; private: + // Forbidden to use + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override; void setup(); PusTmParams pusParams{}; bool calculateCrcOnSerialization = true; diff --git a/unittests/tmtcpacket/testPusTcCreator.cpp b/unittests/tmtcpacket/testPusTcCreator.cpp index c5b0743b..fdda717f 100644 --- a/unittests/tmtcpacket/testPusTcCreator.cpp +++ b/unittests/tmtcpacket/testPusTcCreator.cpp @@ -95,9 +95,10 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") { } SECTION("Deserialization Fails") { + SerializeIF& deser = creator; size_t deserLen = buf.size(); const uint8_t* roPtr = buf.data(); - REQUIRE(creator.deSerialize(&roPtr, &deserLen, SerializeIF::Endianness::NETWORK) == + REQUIRE(deser.deSerialize(&roPtr, &deserLen, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED); } diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 97f3d893..99c16550 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -97,8 +97,9 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { } SECTION("Deserialization fails") { + SerializeIF& deser = creator; const uint8_t* roDataPtr = nullptr; - REQUIRE(creator.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == + REQUIRE(deser.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED); }