From 5d3f00da7f7c88a872f23e5015535e9615e6f4aa Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Jul 2023 10:06:45 +0200 Subject: [PATCH] that should do the job --- src/fsfw/cfdp/handler/CMakeLists.txt | 5 ++--- src/fsfw/cfdp/handler/DestHandler.cpp | 16 +++++++++++----- src/fsfw/cfdp/handler/DestHandler.h | 8 ++++++-- src/fsfw/cfdp/handler/MetadataParser.cpp | 3 --- src/fsfw/cfdp/handler/MetadataParser.h | 15 --------------- src/fsfw/cfdp/tlv/MessageToUserTlv.cpp | 3 +++ src/fsfw/cfdp/tlv/MessageToUserTlv.h | 1 + 7 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 src/fsfw/cfdp/handler/MetadataParser.cpp delete mode 100644 src/fsfw/cfdp/handler/MetadataParser.h diff --git a/src/fsfw/cfdp/handler/CMakeLists.txt b/src/fsfw/cfdp/handler/CMakeLists.txt index ea3d7633..ddbcc470 100644 --- a/src/fsfw/cfdp/handler/CMakeLists.txt +++ b/src/fsfw/cfdp/handler/CMakeLists.txt @@ -1,4 +1,3 @@ target_sources( - ${LIB_FSFW_NAME} - PRIVATE SourceHandler.cpp DestHandler.cpp MetadataParser.cpp -PutRequest.cpp FaultHandlerBase.cpp UserBase.cpp) + ${LIB_FSFW_NAME} PRIVATE SourceHandler.cpp DestHandler.cpp PutRequest.cpp + FaultHandlerBase.cpp UserBase.cpp) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 03a360b7..6f1e9f40 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -16,7 +16,7 @@ using namespace returnvalue; cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) : tlvVec(params.maxTlvsInOnePdu), - userTlvVec(params.maxTlvsInOnePdu), + msgToUserVec(params.maxTlvsInOnePdu), destParams(std::move(params)), fsfwParams(fsfwParams), transactionParams(params.maxFilenameLen) { @@ -137,7 +137,7 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { cfdp::StringLv destFileName; MetadataInfo metadataInfo(transactionParams.fileSize, sourceFileName, destFileName); MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), - metadataInfo, nullptr, 0); + metadataInfo, tlvVec.data(), tlvVec.size()); ReturnValue_t result = reader.parseData(); // TODO: The standard does not really specify what happens if this kind of error happens // I think it might be a good idea to cache some sort of error code, which @@ -355,9 +355,15 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met params.fileSize = transactionParams.fileSize.getSize(); params.destFileName = transactionParams.destName.data(); params.sourceFileName = transactionParams.sourceName.data(); - // TODO: Is this really correct? Implement this correctly.. - // params.msgsToUserArray = dynamic_cast(userTlvVec.data()); - // params.msgsToUserLen = reader.getNumberOfParsedOptions(); + unsigned tlvIdx = 0; + for (const auto& opt : tlvVec) { + if (opt.getType() == TlvType::MSG_TO_USER) { + msgToUserVec[tlvIdx] = MessageToUserTlv(opt.getValue(), opt.getLengthField()); + tlvIdx++; + } + } + params.msgsToUserArray = msgToUserVec.data(); + params.msgsToUserLen = tlvIdx; destParams.user.metadataRecvdIndication(params); return result; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 40fe5e10..dc98d0e0 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -13,6 +13,7 @@ #include "fsfw/cfdp/handler/mib.h" #include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/cfdp/pdu/PduConfig.h" +#include "fsfw/cfdp/tlv/MessageToUserTlv.h" #include "fsfw/container/DynamicFIFO.h" #include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/storagemanager/storeAddress.h" @@ -30,6 +31,9 @@ struct DestHandlerParams { // TODO: This container can potentially take tons of space. For a better // memory efficient implementation, an additional abstraction could be // be used so users can use uint32_t as the pair type + // TODO: Actually, we can provide a better abstraction via interface, which + // allows using something like a bounded map. This simplifies + // the implementation significantly. LostSegmentsListBase& lostSegmentsContainer) : cfg(std::move(cfg)), user(user), @@ -43,7 +47,7 @@ struct DestHandlerParams { PacketInfoListBase& packetListRef; LostSegmentsListBase& lostSegmentsContainer; - uint8_t maxTlvsInOnePdu = 10; + uint8_t maxTlvsInOnePdu = 20; size_t maxFilenameLen = 255; }; @@ -143,7 +147,7 @@ class DestHandler { }; std::vector tlvVec; - std::vector userTlvVec; + std::vector msgToUserVec; DestHandlerParams destParams; cfdp::FsfwParams fsfwParams; TransactionParams transactionParams; diff --git a/src/fsfw/cfdp/handler/MetadataParser.cpp b/src/fsfw/cfdp/handler/MetadataParser.cpp deleted file mode 100644 index 2c90815f..00000000 --- a/src/fsfw/cfdp/handler/MetadataParser.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "MetadataParser.h" - -cfdp::MetadataParser::MetadataParser(MetadataPduReader& reader) {} diff --git a/src/fsfw/cfdp/handler/MetadataParser.h b/src/fsfw/cfdp/handler/MetadataParser.h deleted file mode 100644 index 3ab7478a..00000000 --- a/src/fsfw/cfdp/handler/MetadataParser.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "fsfw/cfdp/pdu/MetadataPduReader.h" - -namespace cfdp { - -class MetadataParser { - public: - explicit MetadataParser(MetadataPduReader& reader); - - private: - -}; - -} // namespace cfdp \ No newline at end of file diff --git a/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp b/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp index 9a3e55ff..884dff38 100644 --- a/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp +++ b/src/fsfw/cfdp/tlv/MessageToUserTlv.cpp @@ -7,3 +7,6 @@ MessageToUserTlv::MessageToUserTlv() : Tlv() {} MessageToUserTlv::MessageToUserTlv(const std::vector& data) : Tlv(cfdp::TlvType::MSG_TO_USER, data.data(), data.size()) {} + +MessageToUserTlv::MessageToUserTlv(const uint8_t* value, size_t size) + : Tlv(cfdp::TlvType::MSG_TO_USER, value, size) {} diff --git a/src/fsfw/cfdp/tlv/MessageToUserTlv.h b/src/fsfw/cfdp/tlv/MessageToUserTlv.h index e7f63ed2..0f393a72 100644 --- a/src/fsfw/cfdp/tlv/MessageToUserTlv.h +++ b/src/fsfw/cfdp/tlv/MessageToUserTlv.h @@ -9,6 +9,7 @@ class MessageToUserTlv : public cfdp::Tlv { public: MessageToUserTlv(); MessageToUserTlv(uint8_t* value, size_t size); + MessageToUserTlv(const uint8_t* value, size_t size); explicit MessageToUserTlv(const std::vector& data); private: