From c54caf134a860c376187e7730341d399f4ae89df Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 16:33:38 +0200 Subject: [PATCH] segmented file transfer working --- src/fsfw/cfdp/handler/DestHandler.cpp | 14 ++++--- unittests/cfdp/handler/testDestHandler.cpp | 45 +++++++++++++++++++--- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 4bc7134c..cd3cc3b4 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -35,8 +35,9 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); + } else { + infoIter++; } - infoIter++; } if (fsmRes.step == TransactionStep::IDLE) { // To decrease the already high complexity of the software, all packets arriving before @@ -61,16 +62,16 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); - } - // TODO: Support for check timer missing - if (infoIter->pduType == PduType::FILE_DIRECTIVE and - infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { + } else if (infoIter->pduType == PduType::FILE_DIRECTIVE and + infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { + // TODO: Support for check timer missing result = handleEofPdu(*infoIter); checkAndHandleError(result, errorIdx); // Store data was deleted in PDU handler because a store guard is used dp.packetListRef.erase(infoIter++); + } else { + infoIter++; } - infoIter++; } } if (fsmRes.step == TransactionStep::TRANSFER_COMPLETION) { @@ -160,6 +161,7 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) size_t fileSegmentLen = 0; const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); FileOpParams fileOpParams(tp.destName.data(), fileSegmentLen); + fileOpParams.offset = offset.value(); if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { FileSegmentRecvdParams segParams; segParams.offset = offset.value(); diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index cdf8e104..404d8eed 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include "fsfw/cfdp.h" #include "fsfw/cfdp/pdu/EofPduCreator.h" @@ -118,11 +118,14 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); }; - auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res) { + auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res, + const std::vector& idsToCheck) { REQUIRE(res.result == OK); REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); - REQUIRE(not tcStore.hasDataAtId(storeId)); + for (const auto id : idsToCheck) { + REQUIRE(not tcStore.hasDataAtId(id)); + } REQUIRE(packetInfoList.empty()); }; @@ -179,7 +182,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); - fileDataPduCheck(res); + fileDataPduCheck(res, {storeId}); eofPreparation(cfdpFileSize, crc32); // After EOF, operation is done because no closure was requested destHandler.performStateMachine(); @@ -193,7 +196,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { std::mt19937 rng(dev()); std::uniform_int_distribution distU8(0, 255); std::array largerFileData{}; - for(auto& val: largerFileData) { + for (auto& val : largerFileData) { val = distU8(rng); } etl::crc32 crcCalc; @@ -206,5 +209,37 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { destHandler.performStateMachine(); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); auto transactionId = destHandler.getTransactionId(); + + std::vector idsToCheck; + { + FileSize offset(0); + FileDataInfo fdPduInfo(offset, reinterpret_cast(largerFileData.data()), + largerFileData.size() / 2); + FileDataCreator fdPduCreator(conf, fdPduInfo); + REQUIRE(tcStore.getFreeElement(&storeId, fdPduCreator.getSerializedSize(), &buf) == OK); + REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); + idsToCheck.push_back(storeId); + packetInfoList.push_back(packetInfo); + } + + { + FileSize offset(512); + FileDataInfo fdPduInfo(offset, reinterpret_cast(largerFileData.data() + 512), + largerFileData.size() / 2); + FileDataCreator fdPduCreator(conf, fdPduInfo); + REQUIRE(tcStore.getFreeElement(&storeId, fdPduCreator.getSerializedSize(), &buf) == OK); + REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); + idsToCheck.push_back(storeId); + packetInfoList.push_back(packetInfo); + } + + destHandler.performStateMachine(); + fileDataPduCheck(res, idsToCheck); + eofPreparation(cfdpFileSize, crc32); + // After EOF, operation is done because no closure was requested + destHandler.performStateMachine(); + eofCheck(res, transactionId); } } \ No newline at end of file