From f28b9ea61b52cf8b7c4675b2e5bb5dc87143a61e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 22 Jul 2022 16:41:32 +0200 Subject: [PATCH] APID getter bugfix --- src/fsfw/tcdistribution/CCSDSDistributor.h | 2 +- src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h | 3 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 31 ++++++++++++++++ src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 4 ++ unittests/tmtcpacket/testPusTmCreator.cpp | 41 +++++++++++++++++++++ 5 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.h b/src/fsfw/tcdistribution/CCSDSDistributor.h index 2d9b1fbd..b5cfc5a4 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.h +++ b/src/fsfw/tcdistribution/CCSDSDistributor.h @@ -31,7 +31,7 @@ class CCSDSDistributor : public TcDistributor, /** * The destructor is empty. */ - virtual ~CCSDSDistributor(); + ~CCSDSDistributor() override; MessageQueueId_t getRequestQueue() override; ReturnValue_t registerApplication(uint16_t apid, MessageQueueId_t id) override; diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h index de01e819..41d087ad 100644 --- a/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h @@ -51,9 +51,8 @@ class SpacePacketIF { virtual PacketSeqCtrl getPacketSeqCtrl() { return PacketSeqCtrl::fromRaw(getPacketSeqCtrlRaw()); } [[nodiscard]] virtual uint16_t getApid() const { - uint16_t packetId = getPacketIdRaw(); // Uppermost 11 bits of packet ID - return ((packetId >> 8) & 0b111) | (packetId & 0xFF); + return getPacketIdRaw() & 0x7ff; } /** diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 479358b7..9cbdeb5c 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -13,17 +13,27 @@ PusTmCreator::PusTmCreator(SpacePacketParams initSpParams, PusTmParams initPusPa PusTmCreator::PusTmCreator() { setup(); } uint16_t PusTmCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } + uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); } + uint16_t PusTmCreator::getPacketDataLen() const { return spCreator.getPacketDataLen(); } + uint8_t PusTmCreator::getPusVersion() const { return pusParams.secHeader.pusVersion; } + uint8_t PusTmCreator::getService() const { return pusParams.secHeader.service; } + uint8_t PusTmCreator::getSubService() const { return pusParams.secHeader.subservice; } + PusTmParams& PusTmCreator::getParams() { return pusParams; } + void PusTmCreator::setTimeStamper(TimeStamperIF* timeStamper_) { pusParams.secHeader.timeStamper = timeStamper_; } + uint8_t PusTmCreator::getScTimeRefStatus() { return pusParams.secHeader.scTimeRefStatus; } + uint16_t PusTmCreator::getMessageTypeCounter() { return pusParams.secHeader.messageTypeCounter; } + uint16_t PusTmCreator::getDestId() { return pusParams.secHeader.destId; } ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize, @@ -83,7 +93,9 @@ ReturnValue_t PusTmCreator::deSerialize(const uint8_t** buffer, size_t* size, } ecss::DataWrapper& PusTmCreator::getDataWrapper() { return pusParams.dataWrapper; } + TimeStamperIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader.timeStamper; } + SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); } void PusTmCreator::updateSpLengthField() { @@ -105,3 +117,22 @@ void PusTmCreator::setup() { updateSpLengthField(); spCreator.setPacketType(ccsds::PacketType::TM); } + +void PusTmCreator::setMessageTypeCounter(uint16_t messageTypeCounter) { + pusParams.secHeader.messageTypeCounter = messageTypeCounter; +}; + +void PusTmCreator::setDestId(uint16_t destId) { pusParams.secHeader.destId = destId; } + +void PusTmCreator::setRawSourceData(ecss::DataWrapper::BufPairT bufPair) { + pusParams.dataWrapper.type = ecss::DataTypes::RAW; + pusParams.dataWrapper.dataUnion.raw.data = bufPair.first; + pusParams.dataWrapper.dataUnion.raw.len = bufPair.second; + updateSpLengthField(); +} + +void PusTmCreator::setSerializableSourceData(SerializeIF* serializable) { + pusParams.dataWrapper.type = ecss::DataTypes::SERIALIZABLE; + pusParams.dataWrapper.dataUnion.serializable = serializable; + updateSpLengthField(); +} diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 97c96391..c0406dc0 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -47,7 +47,11 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CreatorDataIF { void setTimeStamper(TimeStamperIF* timeStamper); SpacePacketParams& getSpParams(); + void setRawSourceData(ecss::DataWrapper::BufPairT bufPair); + void setSerializableSourceData(SerializeIF* serializable); void setApid(uint16_t apid); + void setDestId(uint16_t destId); + void setMessageTypeCounter(uint16_t messageTypeCounter); PusTmParams& getParams(); void updateSpLengthField(); [[nodiscard]] uint16_t getPacketIdRaw() const override; diff --git a/unittests/tmtcpacket/testPusTmCreator.cpp b/unittests/tmtcpacket/testPusTmCreator.cpp index 6b92b134..0cb1c093 100644 --- a/unittests/tmtcpacket/testPusTmCreator.cpp +++ b/unittests/tmtcpacket/testPusTmCreator.cpp @@ -62,4 +62,45 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") { REQUIRE(buf[20] == 0x03); REQUIRE(buf[21] == 0x79); } + + SECTION("Custom Fields") { + creator.setApid(0x3ff); + SECTION("Using Params") { + auto& pusParams = creator.getParams(); + pusParams.secHeader.destId = 0xfff; + pusParams.secHeader.messageTypeCounter = 0x313; + } + SECTION("Using Setters") { + auto& pusParams = creator.getParams(); + creator.setDestId(0xfff); + creator.setMessageTypeCounter(0x313); + } + REQUIRE(creator.getApid() == 0x3ff); + REQUIRE(creator.getDestId() == 0xfff); + REQUIRE(creator.getMessageTypeCounter() == 0x313); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + // Message Sequence Count + REQUIRE(((buf[9] << 8) | buf[10]) == 0x313); + // Destination ID + REQUIRE(((buf[11] << 8) | buf[12]) == 0xfff); + } + + SECTION("Deserialization fails") { + const uint8_t* roDataPtr = nullptr; + REQUIRE(creator.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_FAILED); + } + + SECTION("Serialize with Raw Data") { + std::array data{1, 2, 3}; + creator.setRawSourceData({data.data(), data.size()}); + REQUIRE(creator.getFullPacketLen() == 25); + REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(buf[20] == 1); + REQUIRE(buf[21] == 2); + REQUIRE(buf[22] == 3); + } + + SECTION("Serialize with Serializable") { + + } } \ No newline at end of file