From d80941514fe14bdffd5c113633c5b89ab85c4083 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 20 Jul 2022 11:43:16 +0200 Subject: [PATCH] start refactoring PUS TM handling --- .../datalinklayer/MapPacketExtraction.cpp | 2 +- src/fsfw/pus/Service17Test.cpp | 39 ++--- src/fsfw/pus/Service17Test.h | 13 +- src/fsfw/tcdistribution/CCSDSDistributor.cpp | 2 +- .../tcdistribution/CcsdsPacketCheckerBase.cpp | 2 +- .../tcdistribution/CcsdsPacketCheckerBase.h | 2 +- src/fsfw/tmtcpacket/CMakeLists.txt | 7 +- src/fsfw/tmtcpacket/ReadablePacketIF.h | 2 +- src/fsfw/tmtcpacket/SpacePacketCreator.h | 87 ----------- src/fsfw/tmtcpacket/ccsds/CMakeLists.txt | 2 + src/fsfw/tmtcpacket/ccsds/PacketId.h | 68 ++++++++ src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h | 56 +++++++ .../{ => ccsds}/SpacePacketCreator.cpp | 16 +- .../tmtcpacket/ccsds/SpacePacketCreator.h | 53 +++++++ .../tmtcpacket/{ => ccsds}/SpacePacketIF.h | 59 +++---- .../{ => ccsds}/SpacePacketReader.cpp | 19 +-- .../{ => ccsds}/SpacePacketReader.h | 13 +- src/fsfw/tmtcpacket/ccsds/defs.h | 36 +++++ src/fsfw/tmtcpacket/ccsds/header.cpp | 29 ++++ src/fsfw/tmtcpacket/ccsds/header.h | 30 ++++ src/fsfw/tmtcpacket/ccsds_header.h | 15 -- src/fsfw/tmtcpacket/cfdp/CfdpPacket.h | 2 +- .../packetmatcher/PacketMatchTree.cpp | 12 +- src/fsfw/tmtcpacket/pus/PusIF.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 4 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 8 +- src/fsfw/tmtcpacket/pus/tc/PusTcIF.h | 2 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp | 9 +- src/fsfw/tmtcpacket/pus/tc/PusTcReader.h | 6 +- src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h | 2 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 8 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 10 +- src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp | 11 +- src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h | 59 ++++--- src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h | 2 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h | 6 +- .../tmtcpacket/pus/tm/TmPacketStoredPusC.h | 145 +++++++++--------- src/fsfw/tmtcservices/CMakeLists.txt | 3 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 14 +- src/fsfw/tmtcservices/PusServiceBase.h | 4 +- src/fsfw/tmtcservices/SourceSequenceCounter.h | 2 +- src/fsfw/tmtcservices/TmStoreHelper.cpp | 43 ++++++ src/fsfw/tmtcservices/TmStoreHelper.h | 33 ++++ .../tmtcservices/VerificationReporter.cpp | 10 +- unittests/tmtcpacket/testCcsdsCreator.cpp | 19 ++- unittests/tmtcpacket/testCcsdsReader.cpp | 2 +- 46 files changed, 615 insertions(+), 355 deletions(-) delete mode 100644 src/fsfw/tmtcpacket/SpacePacketCreator.h create mode 100644 src/fsfw/tmtcpacket/ccsds/CMakeLists.txt create mode 100644 src/fsfw/tmtcpacket/ccsds/PacketId.h create mode 100644 src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h rename src/fsfw/tmtcpacket/{ => ccsds}/SpacePacketCreator.cpp (75%) create mode 100644 src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h rename src/fsfw/tmtcpacket/{ => ccsds}/SpacePacketIF.h (56%) rename src/fsfw/tmtcpacket/{ => ccsds}/SpacePacketReader.cpp (62%) rename src/fsfw/tmtcpacket/{ => ccsds}/SpacePacketReader.h (88%) create mode 100644 src/fsfw/tmtcpacket/ccsds/defs.h create mode 100644 src/fsfw/tmtcpacket/ccsds/header.cpp create mode 100644 src/fsfw/tmtcpacket/ccsds/header.h delete mode 100644 src/fsfw/tmtcpacket/ccsds_header.h create mode 100644 src/fsfw/tmtcservices/TmStoreHelper.cpp create mode 100644 src/fsfw/tmtcservices/TmStoreHelper.h diff --git a/src/fsfw/datalinklayer/MapPacketExtraction.cpp b/src/fsfw/datalinklayer/MapPacketExtraction.cpp index 1467f2aa..feb1cc91 100644 --- a/src/fsfw/datalinklayer/MapPacketExtraction.cpp +++ b/src/fsfw/datalinklayer/MapPacketExtraction.cpp @@ -6,7 +6,7 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/storagemanager/StorageManagerIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" #include "fsfw/tmtcservices/TmTcMessage.h" diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index f784acf4..87549808 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -5,33 +5,25 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h" -Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId), packetSubCounter(0) {} +Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId, + StorageManagerIF* tmStore, StorageManagerIF* ipcStore, + InternalErrorReporterIF* errReporter) + : PusServiceBase(objectId, apid, serviceId, ipcStore), + helper(tmStore, MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, errReporter), + packetSubCounter(0) {} -Service17Test::~Service17Test() {} +Service17Test::~Service17Test() = default; ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { switch (subservice) { case Subservice::CONNECTION_TEST: { -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, - packetSubCounter++); -#else - TmPacketStoredPusC connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, - packetSubCounter++); -#endif - connectionPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); + helper.preparePacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter); + helper.sendPacket(); return HasReturnvaluesIF::RETURN_OK; } case Subservice::EVENT_TRIGGER_TEST: { -#if FSFW_USE_PUS_C_TELEMETRY == 0 - TmPacketStoredPusA connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, - packetSubCounter++); -#else - TmPacketStoredPusC connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, - packetSubCounter++); -#endif - connectionPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); + helper.preparePacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); + helper.sendPacket(); triggerEvent(TEST, 1234, 5678); return RETURN_OK; } @@ -41,3 +33,12 @@ ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { } ReturnValue_t Service17Test::performService() { return HasReturnvaluesIF::RETURN_OK; } + +ReturnValue_t Service17Test::initialize() { + ReturnValue_t result = PusServiceBase::initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + helper.setMsgDestination(requestQueue->getDefaultDestination()); + helper.setMsgSource(requestQueue->getId()); + if (tm) } diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index c2248020..0f690ea4 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -3,6 +3,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/PusServiceBase.h" +#include "fsfw/tmtcservices/TmStoreHelper.h" /** * @brief Test Service @@ -32,12 +33,16 @@ class Service17Test : public PusServiceBase { EVENT_TRIGGER_TEST = 128, }; - Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId); - virtual ~Service17Test(); - virtual ReturnValue_t handleRequest(uint8_t subservice) override; - virtual ReturnValue_t performService() override; + Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId, + InternalErrorReporterIF* errReporter, StorageManagerIF* tmStore = nullptr, + StorageManagerIF* ipcStore = nullptr); + ~Service17Test() override; + ReturnValue_t handleRequest(uint8_t subservice) override; + ReturnValue_t performService() override; + ReturnValue_t initialize() override; protected: + TmStoreHelper helper; uint16_t packetSubCounter = 0; }; diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp index f18e55de..9601825c 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -2,7 +2,7 @@ #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" #define CCSDS_DISTRIBUTOR_DEBUGGING 0 diff --git a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp index 8c97f646..e1b6337f 100644 --- a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp +++ b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.cpp @@ -1,7 +1,7 @@ #include "CcsdsPacketCheckerBase.h" #include "fsfw/tcdistribution/definitions.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" CcsdsPacketCheckerBase::CcsdsPacketCheckerBase(uint16_t apid, ccsds::PacketType packetType_, uint8_t ccsdsVersion_) diff --git a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h index f5a9b317..0f7f7e14 100644 --- a/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h +++ b/src/fsfw/tcdistribution/CcsdsPacketCheckerBase.h @@ -2,7 +2,7 @@ #define FSFW_TESTS_CCSDSPACKETCHECKERBASE_H #include "CcsdsPacketCheckIF.h" -#include "fsfw/tmtcpacket/SpacePacketIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" class CcsdsPacketCheckerBase : public CcsdsPacketCheckIF, public HasReturnvaluesIF { public: diff --git a/src/fsfw/tmtcpacket/CMakeLists.txt b/src/fsfw/tmtcpacket/CMakeLists.txt index 69b3cc48..8c70d351 100644 --- a/src/fsfw/tmtcpacket/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/CMakeLists.txt @@ -1,7 +1,6 @@ -target_sources( - ${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp SpacePacketCreator.cpp - PacketStorageHelper.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE PacketStorageHelper.cpp) +add_subdirectory(ccsds) +add_subdirectory(pus) add_subdirectory(cfdp) add_subdirectory(packetmatcher) -add_subdirectory(pus) diff --git a/src/fsfw/tmtcpacket/ReadablePacketIF.h b/src/fsfw/tmtcpacket/ReadablePacketIF.h index c1287e81..01478273 100644 --- a/src/fsfw/tmtcpacket/ReadablePacketIF.h +++ b/src/fsfw/tmtcpacket/ReadablePacketIF.h @@ -1,7 +1,7 @@ #ifndef FSFW_TMTCPACKET_SPACEPACKETREADERIF_H #define FSFW_TMTCPACKET_SPACEPACKETREADERIF_H -#include "SpacePacketIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" class ReadablePacketIF { public: diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.h b/src/fsfw/tmtcpacket/SpacePacketCreator.h deleted file mode 100644 index 9c74046b..00000000 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef FSFW_TMTCPACKET_SPACEPACKETCREATOR_H -#define FSFW_TMTCPACKET_SPACEPACKETCREATOR_H - -#include "SpacePacketIF.h" -#include "fsfw/serialize/SerializeIF.h" - -struct PacketId { - public: - /** - * Simple wrapper for Space Packet IDs. Does not check the APID for validity - * @param packetType_ - * @param secHeaderFlag_ - * @param apid_ - */ - PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_) - : packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {} - - /** - * NOTE: If the APID has an invalid value, the invalid bits will be cut off - * @return - */ - [[nodiscard]] uint16_t raw() const { - return (static_cast(packetType) << 12) | - (static_cast(secHeaderFlag) << 11) | (apid & 0x7ff); - } - - ccsds::PacketType packetType; - bool secHeaderFlag; - uint16_t apid; -}; - -struct PacketSeqCtrl { - public: - PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount) - : seqFlags(seqFlags), seqCount(seqCount) {} - - /** - * NOTE: If the sequence control has an invalid value, the invalid bits will be cut off - * @return - */ - [[nodiscard]] uint16_t raw() const { - return (static_cast(seqFlags) << 14) | (seqCount & 0x3FFF); - } - ccsds::SequenceFlags seqFlags; - uint16_t seqCount; -}; - -struct SpacePacketParams { - PacketId packetId; - PacketSeqCtrl packetSeqCtrl; - uint16_t dataLen; - uint8_t version = 0b000; -}; - -class SpacePacketCreator : public SpacePacketIF, public SerializeIF { - public: - /* - SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, - ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, - uint8_t version = 0); - */ - explicit SpacePacketCreator(SpacePacketParams ¶ms); - [[nodiscard]] bool isValid() const; - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; - [[nodiscard]] uint16_t getPacketDataLen() const override; - - void setApid(uint16_t apid); - void setSeqCount(uint16_t seqCount); - void setSeqFlags(ccsds::SequenceFlags flags); - void setDataLen(uint16_t dataLen); - - ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const; - 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; - - private: - void checkFieldValidity(); - - bool valid{}; - SpacePacketParams params; -}; -#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/ccsds/CMakeLists.txt b/src/fsfw/tmtcpacket/ccsds/CMakeLists.txt new file mode 100644 index 00000000..68efe09c --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp + SpacePacketCreator.cpp header.cpp) diff --git a/src/fsfw/tmtcpacket/ccsds/PacketId.h b/src/fsfw/tmtcpacket/ccsds/PacketId.h new file mode 100644 index 00000000..49587483 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/PacketId.h @@ -0,0 +1,68 @@ +#ifndef FSFW_TMTCPACKET_PACKETID_H +#define FSFW_TMTCPACKET_PACKETID_H + +#include + +#include "defs.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/serialize/SerializeIF.h" + +struct PacketId : public SerializeIF { + public: + PacketId() = default; + /** + * Simple wrapper for Space Packet IDs. Does not check the APID for validity + * @param packetType_ + * @param secHeaderFlag_ + * @param apid_ + */ + PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_) + : packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {} + + /** + * NOTE: If the APID has an invalid value, the invalid bits will be cut off + * @return + */ + [[nodiscard]] uint16_t raw() const { + return (static_cast(packetType) << 12) | + (static_cast(secHeaderFlag) << 11) | (apid & 0x7ff); + } + + static PacketId fromRaw(uint16_t raw) { + uint8_t highByte = (raw >> 8) & 0xff; + uint8_t lowByte = raw & 0xff; + return {static_cast((highByte >> 4) & 0b1), + static_cast((highByte >> 3) & 0b1), + static_cast((highByte & 0b111) << 8 | lowByte)}; + } + + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override { + uint16_t pscRaw = raw(); + return SerializeAdapter::serialize(&pscRaw, buffer, size, maxSize, streamEndianness); + } + + [[nodiscard]] size_t getSerializedSize() const override { return 2; } + + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override { + if (*size < 2) { + return SerializeIF::STREAM_TOO_SHORT; + } + uint8_t highByte = **buffer; + *buffer += 1; + uint8_t lowByte = **buffer; + *buffer += 1; + *size -= 2; + packetType = static_cast((highByte >> 4) & 0b1); + secHeaderFlag = (highByte >> 3) & 0b1; + apid = static_cast((highByte & 0b111) << 8 | lowByte); + return HasReturnvaluesIF::RETURN_OK; + } + + ccsds::PacketType packetType = ccsds::PacketType::TM; + bool secHeaderFlag = false; + uint16_t apid = 0; +}; + +#endif // FSFW_TMTCPACKET_PACKETID_H diff --git a/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h b/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h new file mode 100644 index 00000000..830a6fa2 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h @@ -0,0 +1,56 @@ +#ifndef FSFW_TMTCPACKET_PACKETSEQCTRL_H +#define FSFW_TMTCPACKET_PACKETSEQCTRL_H + +#include "defs.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/serialize/SerializeIF.h" + +struct PacketSeqCtrl : public SerializeIF { + public: + PacketSeqCtrl() = default; + + PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount) + : seqFlags(seqFlags), seqCount(seqCount) {} + + /** + * NOTE: If the sequence control has an invalid value, the invalid bits will be cut off + * @return + */ + [[nodiscard]] uint16_t raw() const { + return (static_cast(seqFlags) << 14) | (seqCount & 0x3FFF); + } + + static PacketSeqCtrl fromRaw(uint16_t raw) { + uint8_t highByte = (raw >> 8) & 0xff; + uint8_t lowByte = raw & 0xff; + return {static_cast((highByte >> 6) & 0b11), + static_cast(((highByte << 8) | lowByte) & 0x3FFF)}; + } + + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override { + uint16_t packetIdRaw = raw(); + return SerializeAdapter::serialize(&packetIdRaw, buffer, size, maxSize, streamEndianness); + } + [[nodiscard]] size_t getSerializedSize() const override { return 2; } + + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override { + if (*size < 2) { + return SerializeIF::STREAM_TOO_SHORT; + } + uint8_t highByte = **buffer; + *buffer += 1; + uint8_t lowByte = **buffer; + *buffer += 1; + *size -= 2; + seqFlags = static_cast((highByte >> 6) & 0b11); + seqCount = ((highByte << 8) | lowByte) & 0x3FFF; + return HasReturnvaluesIF::RETURN_OK; + } + + ccsds::SequenceFlags seqFlags = ccsds::SequenceFlags::CONTINUATION; + uint16_t seqCount = 0; +}; + +#endif // FSFW_TMTCPACKET_PACKETSEQCTRL_H diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp similarity index 75% rename from src/fsfw/tmtcpacket/SpacePacketCreator.cpp rename to src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp index ff131059..ce1852ab 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.cpp @@ -1,13 +1,23 @@ #include "SpacePacketCreator.h" +#include + #include "fsfw/serialize/SerializeAdapter.h" -SpacePacketCreator::SpacePacketCreator(SpacePacketParams ¶ms_) : params(params_) { +SpacePacketCreator::SpacePacketCreator(SpacePacketParams params_) : params(std::move(params_)) { checkFieldValidity(); } -uint16_t SpacePacketCreator::getPacketId() const { return params.packetId.raw(); } -uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return params.packetSeqCtrl.raw(); } +SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, + uint16_t apid, ccsds::SequenceFlags seqFlags, + uint16_t seqCount, uint16_t dataLen, uint8_t version) + : params(SpacePacketParams(PacketId(packetType, secHeaderFlag, apid), + PacketSeqCtrl(seqFlags, seqCount), dataLen)) { + params.version = version; +} + +uint16_t SpacePacketCreator::getPacketIdRaw() const { return params.packetId.raw(); } +uint16_t SpacePacketCreator::getPacketSeqCtrlRaw() const { return params.packetSeqCtrl.raw(); } uint16_t SpacePacketCreator::getPacketDataLen() const { return params.dataLen; } ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, diff --git a/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h new file mode 100644 index 00000000..5e2888c0 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketCreator.h @@ -0,0 +1,53 @@ +#ifndef FSFW_TMTCPACKET_SPACEPACKETCREATOR_H +#define FSFW_TMTCPACKET_SPACEPACKETCREATOR_H + +#include + +#include "PacketId.h" +#include "PacketSeqCtrl.h" +#include "SpacePacketIF.h" +#include "fsfw/serialize/SerializeIF.h" + +struct SpacePacketParams { + SpacePacketParams(PacketId packetId, PacketSeqCtrl psc, uint16_t dataLen) + : packetId(std::move(packetId)), packetSeqCtrl(std::move(psc)), dataLen(dataLen) {} + + PacketId packetId{}; + PacketSeqCtrl packetSeqCtrl{}; + uint16_t dataLen = 0; + uint8_t version = 0b000; +}; + +class SpacePacketCreator : public SpacePacketIF, public SerializeIF { + public: + explicit SpacePacketCreator(SpacePacketParams params); + SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid, + ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen, + uint8_t version = 0); + + [[nodiscard]] bool isValid() const; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; + [[nodiscard]] uint16_t getPacketDataLen() const override; + + void setApid(uint16_t apid); + void setSeqCount(uint16_t seqCount); + void setSeqFlags(ccsds::SequenceFlags flags); + void setDataLen(uint16_t dataLen); + + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const; + 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; + + private: + void checkFieldValidity(); + + SpacePacketCreator() = default; + bool valid{}; + SpacePacketParams params; +}; +#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/SpacePacketIF.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h similarity index 56% rename from src/fsfw/tmtcpacket/SpacePacketIF.h rename to src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h index 21ee4c32..5db7b254 100644 --- a/src/fsfw/tmtcpacket/SpacePacketIF.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketIF.h @@ -4,37 +4,10 @@ #include #include -#include "ccsds_header.h" - -namespace ccsds { - -enum PacketType : uint8_t { TM = 0, TC = 1 }; - -enum SequenceFlags : uint8_t { - CONTINUATION = 0b00, - FIRST_SEGMENT = 0b01, - LAST_SEGMENT = 0b10, - UNSEGMENTED = 0b11 -}; - -static const uint16_t LIMIT_APID = 2048; // 2^11 -static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14 -static const uint16_t APID_IDLE_PACKET = 0x7FF; - -constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, - bool secondaryHeaderFlag = true) { - return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); -} - -constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { - return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag); -} - -constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { - return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag); -} - -} // namespace ccsds +#include "PacketId.h" +#include "PacketSeqCtrl.h" +#include "fsfw/tmtcpacket/ccsds/defs.h" +#include "header.h" class SpacePacketIF { public: @@ -45,7 +18,7 @@ class SpacePacketIF { /** * This is the minimum size of a SpacePacket. */ - static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE; + static const uint16_t MINIMUM_SIZE = sizeof(ccsds::PrimaryHeader) + CRC_SIZE; virtual ~SpacePacketIF() = default; @@ -54,21 +27,25 @@ class SpacePacketIF { * the CCSDS packet ID * @return The CCSDS packet ID */ - [[nodiscard]] virtual uint16_t getPacketId() const = 0; + [[nodiscard]] virtual uint16_t getPacketIdRaw() const = 0; /** * Returns the third and the fourth byte of the CCSDS header which are the packet sequence * control field * @return */ - [[nodiscard]] virtual uint16_t getPacketSeqCtrl() const = 0; + [[nodiscard]] virtual uint16_t getPacketSeqCtrlRaw() const = 0; /** * Returns the fifth and the sixth byte of the CCSDS header which is the packet length field * @return */ [[nodiscard]] virtual uint16_t getPacketDataLen() const = 0; + virtual PacketId getPacketId() { return PacketId::fromRaw(getPacketIdRaw()); } + + virtual PacketSeqCtrl getPacketSeqCtrl() { return PacketSeqCtrl::fromRaw(getPacketSeqCtrlRaw()); } + [[nodiscard]] virtual uint16_t getApid() const { - uint16_t packetId = getPacketId(); + uint16_t packetId = getPacketIdRaw(); // Uppermost 11 bits of packet ID return ((packetId >> 8) & 0b111) | (packetId & 0xFF); } @@ -78,12 +55,12 @@ class SpacePacketIF { * @return */ [[nodiscard]] virtual uint8_t getVersion() const { - uint16_t packetId = getPacketId(); + uint16_t packetId = getPacketIdRaw(); return (packetId >> 13) & 0b111; } [[nodiscard]] virtual ccsds::PacketType getPacketType() const { - return static_cast((getPacketId() >> 12) & 0b1); + return static_cast((getPacketIdRaw() >> 12) & 0b1); } [[nodiscard]] virtual bool isTc() const { return getPacketType() == ccsds::PacketType::TC; } @@ -95,20 +72,20 @@ class SpacePacketIF { * which is checked with this method. * @return Returns true if the bit is set and false if not. */ - [[nodiscard]] virtual bool hasSecHeader() const { return (getPacketId() >> 11) & 0b1; } + [[nodiscard]] virtual bool hasSecHeader() const { return (getPacketIdRaw() >> 11) & 0b1; } [[nodiscard]] virtual ccsds::SequenceFlags getSequenceFlags() const { - return static_cast(getPacketSeqCtrl() >> 14 & 0b11); + return static_cast(getPacketSeqCtrlRaw() >> 14 & 0b11); } - [[nodiscard]] virtual uint16_t getSequenceCount() const { return getPacketSeqCtrl() & 0x3FFF; } + [[nodiscard]] virtual uint16_t getSequenceCount() const { return getPacketSeqCtrlRaw() & 0x3FFF; } /** * Returns the full packet length based of the packet data length field * @return */ [[nodiscard]] virtual size_t getFullPacketLen() const { - return sizeof(CCSDSPrimaryHeader) + getPacketDataLen() + 1; + return ccsds::HEADER_LEN + getPacketDataLen() + 1; } }; diff --git a/src/fsfw/tmtcpacket/SpacePacketReader.cpp b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp similarity index 62% rename from src/fsfw/tmtcpacket/SpacePacketReader.cpp rename to src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp index 2d7d2eda..a0ad5328 100644 --- a/src/fsfw/tmtcpacket/SpacePacketReader.cpp +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.cpp @@ -1,4 +1,4 @@ -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "SpacePacketReader.h" #include @@ -18,27 +18,24 @@ ReturnValue_t SpacePacketReader::checkLength() const { SpacePacketReader::~SpacePacketReader() = default; -inline uint16_t SpacePacketReader::getPacketId() const { - return ((spHeader->packetIdHAndVersion) << 8) + spHeader->packetIdL; -} +inline uint16_t SpacePacketReader::getPacketIdRaw() const { return ccsds::getPacketId(*spHeader); } const uint8_t* SpacePacketReader::getPacketData() { return packetDataField; } ReturnValue_t SpacePacketReader::setData(uint8_t* pData, size_t maxSize_, void* args) { setInternalFields(pData, maxSize_); + return HasReturnvaluesIF::RETURN_OK; } -uint16_t SpacePacketReader::getPacketSeqCtrl() const { - return (spHeader->packetSeqCtrlH << 8) + spHeader->packetSeqCtrlL; +uint16_t SpacePacketReader::getPacketSeqCtrlRaw() const { + return ccsds::getPacketSeqCtrl(*spHeader); } -uint16_t SpacePacketReader::getPacketDataLen() const { - return (spHeader->packetLenH << 8) | spHeader->packetIdL; -} +uint16_t SpacePacketReader::getPacketDataLen() const { return ccsds::getPacketLen(*spHeader); } void SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) { maxSize = maxSize_; - spHeader = reinterpret_cast(data); - packetDataField = data + sizeof(CCSDSPrimaryHeader); + spHeader = reinterpret_cast(data); + packetDataField = data + ccsds::HEADER_LEN; } const uint8_t* SpacePacketReader::getFullData() { return reinterpret_cast(spHeader); diff --git a/src/fsfw/tmtcpacket/SpacePacketReader.h b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h similarity index 88% rename from src/fsfw/tmtcpacket/SpacePacketReader.h rename to src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h index eb1d5c93..43119146 100644 --- a/src/fsfw/tmtcpacket/SpacePacketReader.h +++ b/src/fsfw/tmtcpacket/ccsds/SpacePacketReader.h @@ -1,13 +1,12 @@ #ifndef FSFW_TMTCPACKET_SPACEPACKETBASE_H_ #define FSFW_TMTCPACKET_SPACEPACKETBASE_H_ -#include - #include -#include "ReadablePacketIF.h" -#include "ccsds_header.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" +#include "fsfw/tmtcpacket/ReadablePacketIF.h" +#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" +#include "fsfw/tmtcpacket/ccsds/defs.h" /** * @defgroup tmtcpackets Space Packets @@ -46,8 +45,8 @@ class SpacePacketReader : public SpacePacketIF, */ ~SpacePacketReader() override; - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; const uint8_t* getFullData() override; @@ -70,7 +69,7 @@ class SpacePacketReader : public SpacePacketIF, * the packet header. * To be hardware-safe, all elements are of byte size. */ - const CCSDSPrimaryHeader* spHeader{}; + const ccsds::PrimaryHeader* spHeader{}; const uint8_t* packetDataField{}; size_t maxSize = 0; diff --git a/src/fsfw/tmtcpacket/ccsds/defs.h b/src/fsfw/tmtcpacket/ccsds/defs.h new file mode 100644 index 00000000..1c7de540 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/defs.h @@ -0,0 +1,36 @@ +#ifndef CCSDS_HEADER_H_ +#define CCSDS_HEADER_H_ + +#include + +namespace ccsds { + +enum PacketType : uint8_t { TM = 0, TC = 1 }; + +enum SequenceFlags : uint8_t { + CONTINUATION = 0b00, + FIRST_SEGMENT = 0b01, + LAST_SEGMENT = 0b10, + UNSEGMENTED = 0b11 +}; + +static const uint16_t LIMIT_APID = 2048; // 2^11 +static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14 +static const uint16_t APID_IDLE_PACKET = 0x7FF; + +constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, + bool secondaryHeaderFlag = true) { + return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); +} + +constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { + return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag); +} + +constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) { + return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag); +} + +} // namespace ccsds + +#endif /* CCSDS_HEADER_H_ */ diff --git a/src/fsfw/tmtcpacket/ccsds/header.cpp b/src/fsfw/tmtcpacket/ccsds/header.cpp new file mode 100644 index 00000000..b7aa270e --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/header.cpp @@ -0,0 +1,29 @@ +#include "header.h" + +uint16_t ccsds::getPacketId(const PrimaryHeader &header) { + return ((header.packetIdHAndVersion & 0x1F00) << 8) + header.packetIdL; +} + +uint16_t ccsds::getPacketSeqCtrl(const PrimaryHeader &header) { + return (header.packetSeqCtrlH << 8) | header.packetSeqCtrlL; +} + +uint8_t ccsds::getVersion(const PrimaryHeader &header) { + return (header.packetIdHAndVersion >> 5) & 0b111; +} + +uint16_t ccsds::getPacketLen(const PrimaryHeader &header) { + return (header.packetLenH << 8) | header.packetLenL; +} + +void ccsds::setPacketId(PrimaryHeader &header, uint16_t packetId) { + header.packetIdHAndVersion = (packetId >> 8) & 0x1F; + header.packetIdL = packetId & 0xff; +} + +void ccsds::setApid(PrimaryHeader &header, uint16_t apid) { + uint16_t packetIdRaw = getPacketId(header); + packetIdRaw &= ~0x7FF; + packetIdRaw |= apid & 0x7FF; + setPacketId(header, packetIdRaw); +} diff --git a/src/fsfw/tmtcpacket/ccsds/header.h b/src/fsfw/tmtcpacket/ccsds/header.h new file mode 100644 index 00000000..d416f697 --- /dev/null +++ b/src/fsfw/tmtcpacket/ccsds/header.h @@ -0,0 +1,30 @@ +#ifndef FSFW_TMTCPACKET_HEADER_H +#define FSFW_TMTCPACKET_HEADER_H + +#include +#include + +namespace ccsds { + +static constexpr size_t HEADER_LEN = 6; + +struct PrimaryHeader { + uint8_t packetIdHAndVersion; + uint8_t packetIdL; + uint8_t packetSeqCtrlH; + uint8_t packetSeqCtrlL; + uint8_t packetLenH; + uint8_t packetLenL; +}; + +uint16_t getPacketId(const PrimaryHeader& header); +uint16_t getPacketSeqCtrl(const PrimaryHeader& header); +uint8_t getVersion(const PrimaryHeader& header); +uint16_t getPacketLen(const PrimaryHeader& header); + +void setPacketId(PrimaryHeader& header, uint16_t packetId); +void setApid(PrimaryHeader& header, uint16_t apid); + +} // namespace ccsds + +#endif // FSFW_TMTCPACKET_HEADER_H diff --git a/src/fsfw/tmtcpacket/ccsds_header.h b/src/fsfw/tmtcpacket/ccsds_header.h deleted file mode 100644 index c0db194e..00000000 --- a/src/fsfw/tmtcpacket/ccsds_header.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CCSDS_HEADER_H_ -#define CCSDS_HEADER_H_ - -#include - -struct CCSDSPrimaryHeader { - uint8_t packetIdHAndVersion; - uint8_t packetIdL; - uint8_t packetSeqCtrlH; - uint8_t packetSeqCtrlL; - uint8_t packetLenH; - uint8_t packetLenL; -}; - -#endif /* CCSDS_HEADER_H_ */ diff --git a/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h b/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h index e47d3b6f..e391202f 100644 --- a/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h +++ b/src/fsfw/tmtcpacket/cfdp/CfdpPacket.h @@ -1,7 +1,7 @@ #ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ #define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" class CfdpReader : public SpacePacketReader { public: diff --git a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp index 1ab8729b..c1f6665a 100644 --- a/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp +++ b/src/fsfw/tmtcpacket/packetmatcher/PacketMatchTree.cpp @@ -32,8 +32,8 @@ PacketMatchTree::~PacketMatchTree() = default; ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type, uint8_t subtype) { // We assume adding APID is always requested. PusTmMinimal::TmPacketMinimalPointer data{}; - data.secHeader.service_type = type; - data.secHeader.service_subtype = subtype; + data.secHeader.service = type; + data.secHeader.subservice = subtype; PusTmMinimal testPacket((uint8_t*)&data); testPacket.setApid(apid); @@ -122,13 +122,13 @@ ReturnValue_t PacketMatchTree::findOrInsertMatch(iterator startAt, VALUE_T test, } ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type, uint8_t subtype) { - PusTmMinimal::TmPacketMinimalPointer data; - data.secHeader.service_type = type; - data.secHeader.service_subtype = subtype; + PusTmMinimal::TmPacketMinimalPointer data{}; + data.secHeader.service = type; + data.secHeader.subservice = subtype; PusTmMinimal testPacket((uint8_t*)&data); testPacket.setApid(apid); iterator foundElement = findMatch(begin(), &testPacket); - if (foundElement == this->end()) { + if (foundElement == PacketMatchTree::end()) { return NO_MATCH; } if (type == 0) { diff --git a/src/fsfw/tmtcpacket/pus/PusIF.h b/src/fsfw/tmtcpacket/pus/PusIF.h index 61d4fcff..5eeae04d 100644 --- a/src/fsfw/tmtcpacket/pus/PusIF.h +++ b/src/fsfw/tmtcpacket/pus/PusIF.h @@ -3,7 +3,7 @@ #include -#include "fsfw/tmtcpacket/SpacePacketIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" class PusIF : public SpacePacketIF { public: diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index cbd6da53..7de759c8 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -51,9 +51,9 @@ ReturnValue_t PusTcCreator::deSerialize(const uint8_t **buffer, size_t *size, return HasReturnvaluesIF::RETURN_FAILED; } -uint16_t PusTcCreator::getPacketId() const { return spCreator.getPacketId(); } +uint16_t PusTcCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); } -uint16_t PusTcCreator::getPacketSeqCtrl() const { return spCreator.getPacketSeqCtrl(); } +uint16_t PusTcCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); } uint16_t PusTcCreator::getPacketDataLen() const { return spCreator.getPacketDataLen(); } diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index ffa2ed7c..cc220fa9 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -2,8 +2,8 @@ #define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" -#include "fsfw/tmtcpacket/SpacePacketCreator.h" -#include "fsfw/tmtcpacket/SpacePacketIF.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h" #include "fsfw/tmtcpacket/pus/definitions.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" @@ -29,8 +29,8 @@ class PusTcCreator : public PusTcIF, public SerializeIF { [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; [[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getAcknowledgeFlags() const override; diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h index a8204a1f..889260c1 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcIF.h @@ -45,7 +45,7 @@ class PusTcIF : public PusIF { public: ~PusTcIF() override = default; static const size_t MIN_LEN = - (sizeof(CCSDSPrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2); + (sizeof(ccsds::PrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2); /** * This is a getter for the packet's Ack field, which are the lowest four diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp index 0ead9bde..43c30a46 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.cpp @@ -21,10 +21,10 @@ ReturnValue_t PusTcReader::parseData() { } // Might become variable sized field in the future size_t secHeaderLen = ecss::PusTcDataFieldHeader::MIN_LEN; - pointers.secHeaderStart = pointers.spHeaderStart + sizeof(CCSDSPrimaryHeader); + pointers.secHeaderStart = pointers.spHeaderStart + ccsds::HEADER_LEN; // TODO: No support for spare bytes yet pointers.userDataStart = pointers.secHeaderStart + secHeaderLen; - appDataSize = size - (sizeof(CCSDSPrimaryHeader) + secHeaderLen); + appDataSize = size - (ccsds::HEADER_LEN + secHeaderLen); pointers.crcStart = pointers.userDataStart + appDataSize; return HasReturnvaluesIF::RETURN_OK; } @@ -50,8 +50,8 @@ uint16_t PusTcReader::getErrorControl() const { return pointers.crcStart[0] << 8 | pointers.crcStart[1]; } -uint16_t PusTcReader::getPacketId() const { return spReader.getPacketId(); } -uint16_t PusTcReader::getPacketSeqCtrl() const { return spReader.getPacketSeqCtrl(); } +uint16_t PusTcReader::getPacketIdRaw() const { return spReader.getPacketIdRaw(); } +uint16_t PusTcReader::getPacketSeqCtrlRaw() const { return spReader.getPacketSeqCtrlRaw(); } uint16_t PusTcReader::getPacketDataLen() const { return spReader.getPacketDataLen(); } uint8_t PusTcReader::getPusVersion() const { return spReader.getVersion(); } const uint8_t* PusTcReader::getFullData() { return pointers.spHeaderStart; } @@ -64,6 +64,7 @@ ReturnValue_t PusTcReader::setData(uint8_t* pData, size_t size_, void* args) { } ReturnValue_t PusTcReader::setData(const uint8_t* data, size_t size_) { setData(const_cast(data), size_, nullptr); + return HasReturnvaluesIF::RETURN_OK; } /* diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h index 85623980..b2045761 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcReader.h @@ -5,7 +5,7 @@ #include "PusTcIF.h" #include "fsfw/tmtcpacket/RedirectableDataPointerIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" /** * This class is the basic data handler for any ECSS PUS Telecommand packet. @@ -40,8 +40,8 @@ class PusTcReader : public PusTcIF, public ReadablePacketIF, public Redirectable * to the screen. */ // void print(); - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; [[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getAcknowledgeFlags() const override; diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h index bb2b3642..fe976673 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h @@ -6,7 +6,7 @@ #include "../definitions.h" #include "PusTcReader.h" #include "fsfw/FSFW.h" -#include "fsfw/tmtcpacket/ccsds_header.h" +#include "fsfw/tmtcpacket/ccsds/defs.h" /** * This struct defines the data structure of a PUS Telecommand A packet when diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 5a1f4144..acf0435d 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -1,10 +1,12 @@ #include "PusTmCreator.h" -PusTmCreator::PusTmCreator(PusTmParams params_) : params(params_){}; +PusTmCreator::PusTmCreator(PusTmParams& params_) : params(params_){}; -uint16_t PusTmCreator::getPacketId() const { return 0; } -uint16_t PusTmCreator::getPacketSeqCtrl() const { return 0; } +uint16_t PusTmCreator::getPacketIdRaw() const { return 0; } +uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return 0; } uint16_t PusTmCreator::getPacketDataLen() const { return 0; } uint8_t PusTmCreator::getPusVersion() const { return 0; } uint8_t PusTmCreator::getService() const { return 0; } uint8_t PusTmCreator::getSubService() const { return 0; } +const uint8_t* PusTmCreator::getUserData(size_t& appDataLen) const { return nullptr; } +uint16_t PusTmCreator::getUserDataSize() const { return 0; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index fbdeb7d9..4a45e904 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -16,16 +16,18 @@ struct PusTmParams { class PusTmCreator : public PusIF { public: ~PusTmCreator() override = default; - explicit PusTmCreator(PusTmParams params); + explicit PusTmCreator(PusTmParams& params); - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; [[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getService() const override; [[nodiscard]] uint8_t getSubService() const override; + const uint8_t* getUserData(size_t& appDataLen) const override; + [[nodiscard]] uint16_t getUserDataSize() const override; private: - PusTmParams params; + PusTmParams& params; }; #endif // FSFW_TMTCPACKET_TMPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp index 4042528a..f2cc7fcc 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.cpp @@ -5,8 +5,9 @@ #include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h" +PusTmMinimal::PusTmMinimal(mintm::MinimalPusTm* data) { tmData = data; } PusTmMinimal::PusTmMinimal(uint8_t* data) { - this->tmData = reinterpret_cast(data); + this->tmData = reinterpret_cast(data); } PusTmMinimal::~PusTmMinimal() = default; @@ -27,8 +28,8 @@ void PusTmMinimal::setInterpretTimestampObject(PacketTimestampInterpreterIF* int PacketTimestampInterpreterIF* PusTmMinimal::timestampInterpreter = nullptr; // TODO: Implement all of this ReturnValue_t PusTmMinimal::setData(uint8_t* dataPtr, size_t size, void* args) { return 0; } -uint16_t PusTmMinimal::getPacketId() const { return 0; } -uint16_t PusTmMinimal::getPacketSeqCtrl() const { return 0; } +uint16_t PusTmMinimal::getPacketIdRaw() const { return 0; } +uint16_t PusTmMinimal::getPacketSeqCtrlRaw() const { return 0; } uint16_t PusTmMinimal::getPacketDataLen() const { return 0; } uint8_t PusTmMinimal::getPusVersion() const { return 0; } uint8_t PusTmMinimal::getService() const { return tmData->secHeader.service; } @@ -36,7 +37,9 @@ uint8_t PusTmMinimal::getSubService() const { return tmData->secHeader.subservic const uint8_t* PusTmMinimal::getUserData(size_t& appDataLen) const { return nullptr; } uint16_t PusTmMinimal::getUserDataSize() const { return 0; } uint8_t PusTmMinimal::getScTimeRefStatus() { return 0; } -uint16_t PusTmMinimal::getMessageTypeCounter() { return tmData->secHeader.messageTypeCounter; } +uint16_t PusTmMinimal::getMessageTypeCounter() { + return (tmData->secHeader.messageTypeH << 8) | tmData->secHeader.messageTypeL; +} uint16_t PusTmMinimal::getDestId() { return 0; } const uint8_t* PusTmMinimal::getTimestamp(size_t& timeStampLen) { return nullptr; } size_t PusTmMinimal::getTimestampLen() { return 0; } diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h index a09523fb..b9146def 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmMinimal.h @@ -3,10 +3,39 @@ #include "PusTmIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" struct timeval; + class PacketTimestampInterpreterIF; + +namespace mintm { + +// NOTE: Only PUS C compatible! +struct PusTmMinimalSecHeader { + uint8_t versionAndScTimeRefStatus; + uint8_t service; + uint8_t subservice; + uint8_t messageTypeH; + uint8_t messageTypeL; +}; + +/** + * This struct defines the data structure of a PUS Telecommand Packet when + * accessed via a pointer. + * @ingroup tmtcpackets + */ +struct MinimalPusTm { + ccsds::PrimaryHeader primary; + PusTmMinimalSecHeader secHeader; + uint8_t rest; +}; + +// Must include a checksum and is therefore at least one larger than the above struct. +static const uint16_t MINIMUM_SIZE = sizeof(MinimalPusTm) + 1; + +} // namespace mintm + /** * This is a minimal version of a PUS TmPacket without any variable field, or, * in other words with Service Type, Subtype and subcounter only. @@ -15,6 +44,7 @@ class PacketTimestampInterpreterIF; */ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { public: + explicit PusTmMinimal(mintm::MinimalPusTm* data); /** * This is the default constructor. * It sets its internal data pointer to the address passed and also @@ -33,8 +63,8 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { static void setInterpretTimestampObject(PacketTimestampInterpreterIF* interpreter); ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override; - [[nodiscard]] uint16_t getPacketId() const override; - [[nodiscard]] uint16_t getPacketSeqCtrl() const override; + [[nodiscard]] uint16_t getPacketIdRaw() const override; + [[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; [[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getService() const override; @@ -47,27 +77,6 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { const uint8_t* getTimestamp(size_t& timeStampLen) override; size_t getTimestampLen() override; - // NOTE: Only PUS C compatible! - struct PusTmMinimalSecHeader { - uint8_t versionAndScTimeRefStatus; - uint8_t service; - uint8_t subservice; - uint16_t messageTypeCounter; - }; - - /** - * This struct defines the data structure of a PUS Telecommand Packet when - * accessed via a pointer. - * @ingroup tmtcpackets - */ - struct TmPacketMinimalPointer { - CCSDSPrimaryHeader primary; - PusTmMinimalSecHeader secHeader; - uint8_t rest; - }; - // Must include a checksum and is therefore at least one larger than the above struct. - static const uint16_t MINIMUM_SIZE = sizeof(TmPacketMinimalPointer) + 1; - protected: /** * A pointer to a structure which defines the data structure of @@ -75,7 +84,7 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF { * * To be hardware-safe, all elements are of byte size. */ - TmPacketMinimalPointer* tmData; + mintm::MinimalPusTm* tmData; static PacketTimestampInterpreterIF* timestampInterpreter; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h index e1622466..fe7619cf 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h @@ -4,7 +4,7 @@ #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" namespace Factory { diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h index bf9de122..7d1eb255 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h @@ -5,7 +5,7 @@ #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/TimeStamperIF.h" -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" namespace Factory { void setStaticFrameworkObjectIds(); @@ -35,7 +35,7 @@ struct PUSTmDataFieldHeaderPusC { * @ingroup tmtcpackets */ struct TmPacketPointerPusC { - CCSDSPrimaryHeader primary; + ccsds::PrimaryHeader primary; PUSTmDataFieldHeaderPusC dataField; uint8_t data; }; @@ -52,7 +52,7 @@ class TmPacketPusC : public TmPacketBase { * This constant defines the minimum size of a valid PUS Telemetry Packet. */ static const uint32_t TM_PACKET_MIN_SIZE = - (sizeof(CCSDSPrimaryHeader) + sizeof(PUSTmDataFieldHeaderPusC) + 2); + ccsds::HEADER_LEN + sizeof(PUSTmDataFieldHeaderPusC) + 2; //! Maximum size of a TM Packet in this mission. static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h index fe65e2ca..2a1f645f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h @@ -1,72 +1,73 @@ -#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ -#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ - -#include "TmPacketPusC.h" -#include "TmPacketStoredBase.h" - -/** - * This class generates a ECSS PUS C Telemetry packet within a given - * intermediate storage. - * As most packets are passed between tasks with the help of a storage - * anyway, it seems logical to create a Packet-In-Storage access class - * which saves the user almost all storage handling operation. - * Packets can both be newly created with the class and be "linked" to - * packets in a store with the help of a storeAddress. - * @ingroup tmtcpackets - */ -class TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC { - public: - /** - * This is a default constructor which does not set the data pointer. - * However, it does try to set the packet store. - */ - TmPacketStoredPusC(store_address_t setAddress); - /** - * With this constructor, new space is allocated in the packet store and - * a new PUS Telemetry Packet is created there. - * Packet Application Data passed in data is copied into the packet. - * The Application data is passed in two parts, first a header, then a - * data field. This allows building a Telemetry Packet from two separate - * data sources. - * @param apid Sets the packet's APID field. - * @param service Sets the packet's Service ID field. - * This specifies the source service. - * @param subservice Sets the packet's Service Subtype field. - * This specifies the source sub-service. - * @param packet_counter Sets the Packet counter field of this packet - * @param data The payload data to be copied to the - * Application Data Field - * @param size The amount of data to be copied. - * @param headerData The header Data of the Application field, - * will be copied in front of data - * @param headerSize The size of the headerDataF - * @param destinationId Destination ID containing the application process ID as specified - * by PUS C - * @param timeRefField 4 bit time reference field as specified by PUS C - */ - TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter = 0, - const uint8_t* data = nullptr, uint32_t size = 0, - const uint8_t* headerData = nullptr, uint32_t headerSize = 0, - uint16_t destinationId = 0, uint8_t timeRefField = 0); - /** - * Another ctor to directly pass structured content and header data to the - * packet to avoid additional buffers. - */ - TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter, - SerializeIF* content, SerializeIF* header = nullptr, - uint16_t destinationId = 0, uint8_t timeRefField = 0); - - uint8_t* getAllTmData() override; - - private: - /** - * Implementation required by base class - * @param newPointer - * @param maxSize - * @param args - * @return - */ - ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args) override; -}; - -#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */ +//#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ +//#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ +// +//#include "TmPacketPusC.h" +//#include "TmPacketStoredBase.h" +// +///** +// * This class generates a ECSS PUS C Telemetry packet within a given +// * intermediate storage. +// * As most packets are passed between tasks with the help of a storage +// * anyway, it seems logical to create a Packet-In-Storage access class +// * which saves the user almost all storage handling operation. +// * Packets can both be newly created with the class and be "linked" to +// * packets in a store with the help of a storeAddress. +// * @ingroup tmtcpackets +// */ +// class TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC { +// public: +// /** +// * This is a default constructor which does not set the data pointer. +// * However, it does try to set the packet store. +// */ +// TmPacketStoredPusC(store_address_t setAddress); +// /** +// * With this constructor, new space is allocated in the packet store and +// * a new PUS Telemetry Packet is created there. +// * Packet Application Data passed in data is copied into the packet. +// * The Application data is passed in two parts, first a header, then a +// * data field. This allows building a Telemetry Packet from two separate +// * data sources. +// * @param apid Sets the packet's APID field. +// * @param service Sets the packet's Service ID field. +// * This specifies the source service. +// * @param subservice Sets the packet's Service Subtype field. +// * This specifies the source sub-service. +// * @param packet_counter Sets the Packet counter field of this packet +// * @param data The payload data to be copied to the +// * Application Data Field +// * @param size The amount of data to be copied. +// * @param headerData The header Data of the Application field, +// * will be copied in front of data +// * @param headerSize The size of the headerDataF +// * @param destinationId Destination ID containing the application process ID as specified +// * by PUS C +// * @param timeRefField 4 bit time reference field as specified by PUS C +// */ +// TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter = +// 0, +// const uint8_t* data = nullptr, uint32_t size = 0, +// const uint8_t* headerData = nullptr, uint32_t headerSize = 0, +// uint16_t destinationId = 0, uint8_t timeRefField = 0); +// /** +// * Another ctor to directly pass structured content and header data to the +// * packet to avoid additional buffers. +// */ +// TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter, +// SerializeIF* content, SerializeIF* header = nullptr, +// uint16_t destinationId = 0, uint8_t timeRefField = 0); +// +// uint8_t* getAllTmData() override; +// +// private: +// /** +// * Implementation required by base class +// * @param newPointer +// * @param maxSize +// * @param args +// * @return +// */ +// ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args) override; +//}; +// +//#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */ diff --git a/src/fsfw/tmtcservices/CMakeLists.txt b/src/fsfw/tmtcservices/CMakeLists.txt index d2a3f4ed..fcbcb49d 100644 --- a/src/fsfw/tmtcservices/CMakeLists.txt +++ b/src/fsfw/tmtcservices/CMakeLists.txt @@ -6,4 +6,5 @@ target_sources( TmTcBridge.cpp TmTcMessage.cpp VerificationReporter.cpp - SpacePacketParser.cpp) + SpacePacketParser.cpp + TmStoreHelper.cpp) diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index f0cdb61b..b18a736b 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -12,8 +12,8 @@ object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetDestination = 0; PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - StorageManagerIF* store_) - : SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), store(store_) { + StorageManagerIF* ipcStore_) + : SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), ipcStore(ipcStore_) { requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION); } @@ -52,7 +52,7 @@ void PusServiceBase::handleRequestQueue() { if (status == RETURN_OK) { const uint8_t* dataPtr; size_t dataLen = 0; - result = store->getData(message.getStorageId(), &dataPtr, &dataLen); + result = ipcStore->getData(message.getStorageId(), &dataPtr, &dataLen); if (result != HasReturnvaluesIF::RETURN_OK) { // TODO: Warning? } @@ -73,7 +73,7 @@ void PusServiceBase::handleRequestQueue() { &this->currentPacket, result, 0, errorParameter1, errorParameter2); } - store->deleteData(message.getStorageId()); + ipcStore->deleteData(message.getStorageId()); errorParameter1 = 0; errorParameter2 = 0; } else if (status == MessageQueueIF::EMPTY) { @@ -112,6 +112,12 @@ ReturnValue_t PusServiceBase::initialize() { } this->requestQueue->setDefaultDestination(destService->getReportReceptionQueue()); distributor->registerService(this); + if (ipcStore == nullptr) { + ipcStore = ObjectManager::instance()->get(objects::IPC_STORE); + if (ipcStore == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + } return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 57547ace..d487c6c6 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -52,7 +52,7 @@ class PusServiceBase : public ExecutableObjectIF, * The Service Identifier as specified in ECSS PUS. */ PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - StorageManagerIF* store); + StorageManagerIF* ipcStore); /** * The destructor is empty. */ @@ -144,7 +144,7 @@ class PusServiceBase : public ExecutableObjectIF, * It is deleted after handleRequest was executed. */ // TcPacketStoredPus currentPacket; - StorageManagerIF* store; + StorageManagerIF* ipcStore; PusTcReader currentPacket; static object_id_t packetSource; diff --git a/src/fsfw/tmtcservices/SourceSequenceCounter.h b/src/fsfw/tmtcservices/SourceSequenceCounter.h index 836ac5e9..da96dc4e 100644 --- a/src/fsfw/tmtcservices/SourceSequenceCounter.h +++ b/src/fsfw/tmtcservices/SourceSequenceCounter.h @@ -1,7 +1,7 @@ #ifndef FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ #define FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_ -#include "../tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" class SourceSequenceCounter { private: diff --git a/src/fsfw/tmtcservices/TmStoreHelper.cpp b/src/fsfw/tmtcservices/TmStoreHelper.cpp new file mode 100644 index 00000000..54e6ffc8 --- /dev/null +++ b/src/fsfw/tmtcservices/TmStoreHelper.cpp @@ -0,0 +1,43 @@ +#include "TmStoreHelper.h" + +#include "TmTcMessage.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" + +TmStoreHelper::TmStoreHelper(StorageManagerIF *tmStore, MessageQueueId_t tmtcMsgDest, + MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF *reporter) + : creator(params), + tmtcMsgDest(tmtcMsgDest), + tmtcMsgSrc(tmtcMsgSrc), + errReporter(reporter), + tmStore(tmStore) {} + +void TmStoreHelper::preparePacket(uint16_t apid, uint8_t service, uint8_t subservice, + uint16_t counter) { + // TODO: Implement + // creator.setApid(apid); + params.service = service; + params.subservice = subservice; + params.messageTypeCounter = counter; + // TODO: Implement serialize and then serialize into the store +} + +ReturnValue_t TmStoreHelper::sendPacket() { + TmTcMessage tmMessage(currentAddr); + ReturnValue_t result = MessageQueueSenderIF::sendMessage(tmtcMsgDest, &tmMessage, tmtcMsgSrc); + if (result != HasReturnvaluesIF::RETURN_OK) { + tmStore->deleteData(currentAddr); + if (errReporter != nullptr) { + errReporter->lostTm(); + } + return result; + } + return HasReturnvaluesIF::RETURN_OK; +} + +void TmStoreHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; } + +void TmStoreHelper::setMsgSource(MessageQueueId_t msgSrc) { tmtcMsgSrc = msgSrc; } + +void TmStoreHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { + errReporter = reporter; +} diff --git a/src/fsfw/tmtcservices/TmStoreHelper.h b/src/fsfw/tmtcservices/TmStoreHelper.h new file mode 100644 index 00000000..bada3b7d --- /dev/null +++ b/src/fsfw/tmtcservices/TmStoreHelper.h @@ -0,0 +1,33 @@ +#ifndef FSFW_TMTCSERVICES_STOREHELPER_H +#define FSFW_TMTCSERVICES_STOREHELPER_H + +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueMessageIF.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h" + +// TODO: Serializing a packet into a store and sending the message are two different tasks +// Move them into separate classes +class TmStoreHelper { + public: + TmStoreHelper(StorageManagerIF* tmStore, MessageQueueId_t tmtcMsgDest, + MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF* reporter); + + void setInternalErrorReporter(InternalErrorReporterIF* reporter); + void setMsgDestination(MessageQueueId_t msgDest); + void setMsgSource(MessageQueueId_t msgSrc); + void preparePacket(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t counter); + ReturnValue_t sendPacket(); + + private: + PusTmParams params{}; + PusTmCreator creator; + + bool doErrorReporting = true; + MessageQueueId_t tmtcMsgDest; + MessageQueueId_t tmtcMsgSrc; + InternalErrorReporterIF* errReporter; + store_address_t currentAddr{}; + StorageManagerIF* tmStore; +}; +#endif // FSFW_TMTCSERVICES_STOREHELPER_H diff --git a/src/fsfw/tmtcservices/VerificationReporter.cpp b/src/fsfw/tmtcservices/VerificationReporter.cpp index bf33d1c4..04b42934 100644 --- a/src/fsfw/tmtcservices/VerificationReporter.cpp +++ b/src/fsfw/tmtcservices/VerificationReporter.cpp @@ -22,8 +22,8 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, PusTcReader* return; } PusVerificationMessage message(set_report_id, currentPacket->getAcknowledgeFlags(), - currentPacket->getPacketId(), currentPacket->getPacketSeqCtrl(), 0, - set_step); + currentPacket->getPacketIdRaw(), + currentPacket->getPacketSeqCtrlRaw(), 0, set_step); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -59,9 +59,9 @@ void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* cur if (currentPacket == nullptr) { return; } - PusVerificationMessage message(report_id, currentPacket->getAcknowledgeFlags(), - currentPacket->getPacketId(), currentPacket->getPacketSeqCtrl(), - error_code, step, parameter1, parameter2); + PusVerificationMessage message( + report_id, currentPacket->getAcknowledgeFlags(), currentPacket->getPacketIdRaw(), + currentPacket->getPacketSeqCtrlRaw(), error_code, step, parameter1, parameter2); ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message); if (status != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/unittests/tmtcpacket/testCcsdsCreator.cpp b/unittests/tmtcpacket/testCcsdsCreator.cpp index d56669a7..2043d6a6 100644 --- a/unittests/tmtcpacket/testCcsdsCreator.cpp +++ b/unittests/tmtcpacket/testCcsdsCreator.cpp @@ -2,11 +2,12 @@ #include #include -#include "fsfw/tmtcpacket/SpacePacketCreator.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" TEST_CASE("CCSDS Creator", "[ccsds-creator]") { - SpacePacketCreator base = SpacePacketCreator(ccsds::PacketType::TC, true, 0x02, - ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02), + PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + SpacePacketCreator base = SpacePacketCreator(params); std::array buf{}; uint8_t* bufPtr = buf.data(); size_t serLen = 0; @@ -27,7 +28,7 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { REQUIRE(base.getSequenceCount() == 0x34); REQUIRE(base.getPacketDataLen() == 0x16); REQUIRE(base.getPacketType() == ccsds::PacketType::TC); - REQUIRE(base.getPacketId() == 0x1802); + REQUIRE(base.getPacketIdRaw() == 0x1802); REQUIRE(base.getSerializedSize() == 6); } @@ -71,17 +72,15 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") { } SECTION("Invalid APID") { - SpacePacketCreator invalid = - SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0xFFFF), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16); + SpacePacketCreator invalid = SpacePacketCreator( + ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); REQUIRE(not invalid.isValid()); REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } SECTION("Invalid Seq Count") { - SpacePacketCreator invalid = - SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0x02), - PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16); + SpacePacketCreator invalid = SpacePacketCreator( + ccsds::PacketType::TC, true, 0x02, ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF, 0x16); REQUIRE(not invalid.isValid()); REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED); } diff --git a/unittests/tmtcpacket/testCcsdsReader.cpp b/unittests/tmtcpacket/testCcsdsReader.cpp index b8a6f3dd..89ee5a46 100644 --- a/unittests/tmtcpacket/testCcsdsReader.cpp +++ b/unittests/tmtcpacket/testCcsdsReader.cpp @@ -1,5 +1,5 @@ #include -#include "fsfw/tmtcpacket/SpacePacketReader.h" +#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h" TEST_CASE("CCSDS Reader", "[ccsds-reader]") {} \ No newline at end of file