From c87667c03f82f2be88e2a684b98a25be4cdae26b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 11:26:17 +0200 Subject: [PATCH] some API improvements --- src/fsfw/cfdp/definitions.h | 2 +- src/fsfw/cfdp/handler/DestHandler.cpp | 9 ++++++--- src/fsfw/cfdp/handler/DestHandler.h | 14 ++++++++++++-- src/fsfw/cfdp/pdu/FileDataCreator.cpp | 2 +- src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp | 2 +- src/fsfw/cfdp/pdu/HeaderCreator.cpp | 6 +++--- src/fsfw/cfdp/pdu/HeaderCreator.h | 8 ++++---- src/fsfw/cfdp/pdu/HeaderReader.cpp | 4 ++-- src/fsfw/cfdp/pdu/PduHeaderIF.h | 2 +- src/fsfw/cfdp/pdu/PduHeaderReader.h | 2 +- unittests/cfdp/pdu/testCfdpHeader.cpp | 16 ++++++++-------- unittests/cfdp/pdu/testFileDirective.cpp | 2 +- unittests/cfdp/testCfdp.cpp | 2 +- 13 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/fsfw/cfdp/definitions.h b/src/fsfw/cfdp/definitions.h index 635ead17..e5c11a0b 100644 --- a/src/fsfw/cfdp/definitions.h +++ b/src/fsfw/cfdp/definitions.h @@ -49,7 +49,7 @@ enum ChecksumTypes { NULL_CHECKSUM = 15 }; -enum PduType : uint8_t { FILE_DIRECTIVE = 0, FILE_DATA = 1 }; +enum PduTypes : uint8_t { FILE_DIRECTIVE = 0, FILE_DATA = 1 }; enum TransmissionModes : uint8_t { ACKNOWLEDGED = 0, UNACKNOWLEDGED = 1 }; diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 3ddf96ff..a89a5eeb 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -29,7 +29,7 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { fsmRes.resetOfIteration(); if (fsmRes.step == TransactionStep::IDLE) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - if (infoIter->pduType == PduType::FILE_DIRECTIVE and + if (infoIter->pduType == PduTypes::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::METADATA) { result = handleMetadataPdu(*infoIter); checkAndHandleError(result, errorIdx); @@ -57,12 +57,12 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - if (infoIter->pduType == PduType::FILE_DATA) { + if (infoIter->pduType == PduTypes::FILE_DATA) { result = handleFileDataPdu(*infoIter); checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); - } else if (infoIter->pduType == PduType::FILE_DIRECTIVE and + } else if (infoIter->pduType == PduTypes::FILE_DIRECTIVE and infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { // TODO: Support for check timer missing result = handleEofPdu(*infoIter); @@ -463,3 +463,6 @@ void cfdp::DestHandler::setEventReporter(EventReportingProxyIF& reporter) { } const cfdp::DestHandlerParams& cfdp::DestHandler::getDestHandlerParams() const { return dp; } + +StorageManagerIF* cfdp::DestHandler::getTmStore() const { return fp.tcStore; } +StorageManagerIF* cfdp::DestHandler::getTcStore() const { return fp.tmStore; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 975ccaaf..8a8dd28e 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -21,11 +21,11 @@ namespace cfdp { struct PacketInfo { - PacketInfo(PduType type, store_address_t storeId, + PacketInfo(PduTypes type, store_address_t storeId, std::optional directive = std::nullopt) : pduType(type), directiveType(directive), storeId(storeId) {} - PduType pduType = PduType::FILE_DATA; + PduTypes pduType = PduTypes::FILE_DATA; std::optional directiveType = FileDirectives::INVALID_DIRECTIVE; store_address_t storeId = store_address_t::invalid(); PacketInfo() = default; @@ -62,6 +62,14 @@ struct DestHandlerParams { }; struct FsfwParams { + + FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, + EventReportingProxyIF* eventReporter, StorageManagerIF& tcStore, StorageManagerIF& tmStore) + : FsfwParams(packetDest, msgQueue, eventReporter) { + this->tcStore = &tcStore; + this->tmStore = &tmStore; + } + FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, EventReportingProxyIF* eventReporter) : packetDest(packetDest), msgQueue(msgQueue), eventReporter(eventReporter) {} @@ -127,6 +135,8 @@ class DestHandler { [[nodiscard]] TransactionStep getTransactionStep() const; [[nodiscard]] const TransactionId& getTransactionId() const; [[nodiscard]] const DestHandlerParams& getDestHandlerParams() const; + [[nodiscard]] StorageManagerIF* getTcStore() const; + [[nodiscard]] StorageManagerIF* getTmStore() const; private: struct TransactionParams { diff --git a/src/fsfw/cfdp/pdu/FileDataCreator.cpp b/src/fsfw/cfdp/pdu/FileDataCreator.cpp index 956752fb..b9a45b5a 100644 --- a/src/fsfw/cfdp/pdu/FileDataCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDataCreator.cpp @@ -3,7 +3,7 @@ #include FileDataCreator::FileDataCreator(PduConfig& conf, FileDataInfo& info) - : HeaderCreator(conf, cfdp::PduType::FILE_DATA, 0, info.getSegmentMetadataFlag()), info(info) { + : HeaderCreator(conf, cfdp::PduTypes::FILE_DATA, 0, info.getSegmentMetadataFlag()), info(info) { update(); } diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp index 474a1cc3..1e4da14d 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.cpp @@ -2,7 +2,7 @@ FileDirectiveCreator::FileDirectiveCreator(PduConfig &pduConf, cfdp::FileDirectives directiveCode, size_t directiveParamFieldLen) - : HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, directiveParamFieldLen + 1), + : HeaderCreator(pduConf, cfdp::PduTypes::FILE_DIRECTIVE, directiveParamFieldLen + 1), directiveCode(directiveCode) {} size_t FileDirectiveCreator::getSerializedSize() const { diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.cpp b/src/fsfw/cfdp/pdu/HeaderCreator.cpp index e64f8481..3c50c396 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.cpp +++ b/src/fsfw/cfdp/pdu/HeaderCreator.cpp @@ -1,6 +1,6 @@ #include "HeaderCreator.h" -HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, +HeaderCreator::HeaderCreator(PduConfig &pduConf, cfdp::PduTypes pduType, size_t initPduDataFieldLen, cfdp::SegmentMetadataFlag segmentMetadataFlag, cfdp::SegmentationControl segCtrl) : pduType(pduType), @@ -65,13 +65,13 @@ void HeaderCreator::setPduDataFieldLen(size_t pduDataFieldLen_) { pduDataFieldLen = pduDataFieldLen_; } -void HeaderCreator::setPduType(cfdp::PduType pduType_) { pduType = pduType_; } +void HeaderCreator::setPduType(cfdp::PduTypes pduType_) { pduType = pduType_; } void HeaderCreator::setSegmentMetadataFlag(cfdp::SegmentMetadataFlag segmentMetadataFlag_) { segmentMetadataFlag = segmentMetadataFlag_; } -cfdp::PduType HeaderCreator::getPduType() const { return pduType; } +cfdp::PduTypes HeaderCreator::getPduType() const { return pduType; } cfdp::Direction HeaderCreator::getDirection() const { return pduConf.direction; } diff --git a/src/fsfw/cfdp/pdu/HeaderCreator.h b/src/fsfw/cfdp/pdu/HeaderCreator.h index bbb4a518..a4b5c7ff 100644 --- a/src/fsfw/cfdp/pdu/HeaderCreator.h +++ b/src/fsfw/cfdp/pdu/HeaderCreator.h @@ -9,7 +9,7 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { public: HeaderCreator( - PduConfig& pduConf, cfdp::PduType pduType, size_t initPduDataFieldLen, + PduConfig& pduConf, cfdp::PduTypes pduType, size_t initPduDataFieldLen, cfdp::SegmentMetadataFlag segmentMetadataFlag = cfdp::SegmentMetadataFlag::NOT_PRESENT, cfdp::SegmentationControl segCtrl = cfdp::SegmentationControl::NO_RECORD_BOUNDARIES_PRESERVATION); @@ -29,13 +29,13 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { Endianness streamEndianness) override; void setPduDataFieldLen(size_t pduDataFieldLen); - void setPduType(cfdp::PduType pduType); + void setPduType(cfdp::PduTypes pduType); void setSegmentMetadataFlag(cfdp::SegmentMetadataFlag); [[nodiscard]] size_t getPduDataFieldLen() const override; [[nodiscard]] size_t getWholePduSize() const override; - [[nodiscard]] cfdp::PduType getPduType() const override; + [[nodiscard]] cfdp::PduTypes getPduType() const override; [[nodiscard]] cfdp::Direction getDirection() const override; [[nodiscard]] cfdp::TransmissionModes getTransmissionMode() const override; [[nodiscard]] bool getCrcFlag() const override; @@ -52,7 +52,7 @@ class HeaderCreator : public SerializeIF, public PduHeaderIF { void getTransactionSeqNum(cfdp::TransactionSeqNum& seqNum) const override; private: - cfdp::PduType pduType; + cfdp::PduTypes pduType; cfdp::SegmentMetadataFlag segmentMetadataFlag; cfdp::SegmentationControl segmentationCtrl; size_t pduDataFieldLen; diff --git a/src/fsfw/cfdp/pdu/HeaderReader.cpp b/src/fsfw/cfdp/pdu/HeaderReader.cpp index 3417a57c..f8b19ce2 100644 --- a/src/fsfw/cfdp/pdu/HeaderReader.cpp +++ b/src/fsfw/cfdp/pdu/HeaderReader.cpp @@ -57,8 +57,8 @@ size_t PduHeaderReader::getWholePduSize() const { return getPduDataFieldLen() + PduHeaderReader::getHeaderSize(); } -cfdp::PduType PduHeaderReader::getPduType() const { - return static_cast((pointers.fixedHeader->firstByte >> 4) & 0x01); +cfdp::PduTypes PduHeaderReader::getPduType() const { + return static_cast((pointers.fixedHeader->firstByte >> 4) & 0x01); } cfdp::Direction PduHeaderReader::getDirection() const { diff --git a/src/fsfw/cfdp/pdu/PduHeaderIF.h b/src/fsfw/cfdp/pdu/PduHeaderIF.h index a8d007b6..d9e4017d 100644 --- a/src/fsfw/cfdp/pdu/PduHeaderIF.h +++ b/src/fsfw/cfdp/pdu/PduHeaderIF.h @@ -17,7 +17,7 @@ class PduHeaderIF { [[nodiscard]] virtual size_t getWholePduSize() const = 0; [[nodiscard]] virtual size_t getPduDataFieldLen() const = 0; - [[nodiscard]] virtual cfdp::PduType getPduType() const = 0; + [[nodiscard]] virtual cfdp::PduTypes getPduType() const = 0; [[nodiscard]] virtual cfdp::Direction getDirection() const = 0; [[nodiscard]] virtual cfdp::TransmissionModes getTransmissionMode() const = 0; [[nodiscard]] virtual bool getCrcFlag() const = 0; diff --git a/src/fsfw/cfdp/pdu/PduHeaderReader.h b/src/fsfw/cfdp/pdu/PduHeaderReader.h index 7809f59c..a36b2145 100644 --- a/src/fsfw/cfdp/pdu/PduHeaderReader.h +++ b/src/fsfw/cfdp/pdu/PduHeaderReader.h @@ -56,7 +56,7 @@ class PduHeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { [[nodiscard]] size_t getPduDataFieldLen() const override; [[nodiscard]] size_t getWholePduSize() const override; - [[nodiscard]] cfdp::PduType getPduType() const override; + [[nodiscard]] cfdp::PduTypes getPduType() const override; [[nodiscard]] cfdp::Direction getDirection() const override; [[nodiscard]] cfdp::TransmissionModes getTransmissionMode() const override; [[nodiscard]] bool getCrcFlag() const override; diff --git a/unittests/cfdp/pdu/testCfdpHeader.cpp b/unittests/cfdp/pdu/testCfdpHeader.cpp index 6d22154b..b51450ec 100644 --- a/unittests/cfdp/pdu/testCfdpHeader.cpp +++ b/unittests/cfdp/pdu/testCfdpHeader.cpp @@ -21,7 +21,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { uint8_t* serTarget = serBuf.data(); const uint8_t* deserTarget = serTarget; size_t serSize = 0; - auto creator = HeaderCreator(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0); + auto creator = HeaderCreator(pduConf, cfdp::PduTypes::FILE_DIRECTIVE, 0); SECTION("Header State") { REQUIRE(seqNum.getSerializedSize() == 1); @@ -33,7 +33,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == false); REQUIRE(creator.getLenEntityIds() == 1); REQUIRE(creator.getLenSeqNum() == 1); - REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); REQUIRE(creator.getSegmentationControl() == false); REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); @@ -87,7 +87,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.direction = cfdp::Direction::TOWARDS_SENDER; pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - creator.setPduType(cfdp::PduType::FILE_DATA); + creator.setPduType(cfdp::PduTypes::FILE_DATA); creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); serTarget = serBuf.data(); serSize = 0; @@ -103,7 +103,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == true); REQUIRE(creator.getLenEntityIds() == 1); REQUIRE(creator.getLenSeqNum() == 1); - REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DATA); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); REQUIRE(creator.getSegmentationControl() == true); @@ -122,7 +122,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(creator.getLargeFileFlag() == true); REQUIRE(creator.getLenEntityIds() == 4); REQUIRE(creator.getLenSeqNum() == 2); - REQUIRE(creator.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(creator.getPduType() == cfdp::PduTypes::FILE_DATA); REQUIRE(creator.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); REQUIRE(creator.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); REQUIRE(creator.getSegmentationControl() == true); @@ -235,7 +235,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(reader.getLargeFileFlag() == false); REQUIRE(reader.getLenEntityIds() == 1); REQUIRE(reader.getLenSeqNum() == 1); - REQUIRE(reader.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(reader.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); REQUIRE(reader.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::NOT_PRESENT); REQUIRE(reader.getSegmentationControl() == false); REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionModes::ACKNOWLEDGED); @@ -255,7 +255,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { pduConf.direction = cfdp::Direction::TOWARDS_SENDER; pduConf.mode = cfdp::TransmissionModes::UNACKNOWLEDGED; creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); - creator.setPduType(cfdp::PduType::FILE_DATA); + creator.setPduType(cfdp::PduTypes::FILE_DATA); creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); REQUIRE(result == returnvalue::OK); @@ -278,7 +278,7 @@ TEST_CASE("CFDP Header", "[cfdp]") { REQUIRE(reader.getLargeFileFlag() == true); REQUIRE(reader.getLenEntityIds() == 4); REQUIRE(reader.getLenSeqNum() == 2); - REQUIRE(reader.getPduType() == cfdp::PduType::FILE_DATA); + REQUIRE(reader.getPduType() == cfdp::PduTypes::FILE_DATA); REQUIRE(reader.getSegmentMetadataFlag() == cfdp::SegmentMetadataFlag::PRESENT); REQUIRE(reader.getSegmentationControl() == true); REQUIRE(reader.getTransmissionMode() == cfdp::TransmissionModes::UNACKNOWLEDGED); diff --git a/unittests/cfdp/pdu/testFileDirective.cpp b/unittests/cfdp/pdu/testFileDirective.cpp index 3af8b966..cb1df08d 100644 --- a/unittests/cfdp/pdu/testFileDirective.cpp +++ b/unittests/cfdp/pdu/testFileDirective.cpp @@ -76,7 +76,7 @@ TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); REQUIRE(fdDeser.getPduDataFieldLen() == 5); REQUIRE(fdDeser.getHeaderSize() == 8); - REQUIRE(fdDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(fdDeser.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); serBuf[7] = 0xff; // Invalid file directive diff --git a/unittests/cfdp/testCfdp.cpp b/unittests/cfdp/testCfdp.cpp index 3bd474f7..2e493539 100644 --- a/unittests/cfdp/testCfdp.cpp +++ b/unittests/cfdp/testCfdp.cpp @@ -68,7 +68,7 @@ TEST_CASE("CFDP Base", "[cfdp]") { REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK); REQUIRE(fdDeser.getPduDataFieldLen() == 5); REQUIRE(fdDeser.getHeaderSize() == 8); - REQUIRE(fdDeser.getPduType() == cfdp::PduType::FILE_DIRECTIVE); + REQUIRE(fdDeser.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE); serBuf[7] = 0xff; // Invalid file directive