From 108e7737e25a18ddef19adc06e5067c840e7bf8f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 2 Sep 2022 17:54:25 +0200 Subject: [PATCH] continued dest handler --- src/fsfw/cfdp/FileSize.h | 8 +++-- src/fsfw/cfdp/handler/DestHandler.cpp | 46 ++++++++++++++++++++------- src/fsfw/cfdp/handler/DestHandler.h | 12 +++++-- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/fsfw/cfdp/FileSize.h b/src/fsfw/cfdp/FileSize.h index 227555e6..b0b48452 100644 --- a/src/fsfw/cfdp/FileSize.h +++ b/src/fsfw/cfdp/FileSize.h @@ -1,6 +1,8 @@ #ifndef FSFW_CFDP_FILESIZE_H_ #define FSFW_CFDP_FILESIZE_H_ +#include + #include "fsfw/serialize/SerializeAdapter.h" #include "fsfw/serialize/SerializeIF.h" @@ -52,13 +54,15 @@ struct FileSize : public SerializeIF { } } - ReturnValue_t setFileSize(uint64_t fileSize_, bool largeFile_) { + ReturnValue_t setFileSize(uint64_t fileSize_, std::optional largeFile_) { + if (largeFile_) { + largeFile = largeFile_.value(); + } if (not largeFile and fileSize > UINT32_MAX) { // TODO: emit warning here return returnvalue::FAILED; } this->fileSize = fileSize_; - this->largeFile = largeFile_; return returnvalue::OK; } diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 6aeac040..e152cbd5 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -49,20 +49,32 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() { return status; } if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { - for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { - if (infoIter->pduType == PduType::FILE_DATA) { - result = handleFileDataPdu(*infoIter); - if (result != OK) { - status = result; + if (step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { + for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { + if (infoIter->pduType == PduType::FILE_DATA) { + result = handleFileDataPdu(*infoIter); + if (result != OK) { + status = result; + } + // 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) { + result = handleEofPdu(*infoIter); + if (result != OK) { + status = result; + } + // Store data was deleted in PDU handler because a store guard is used + dp.packetListRef.erase(infoIter++); } - // Store data was deleted in PDU handler because a store guard is used - dp.packetListRef.erase(infoIter++); - } - if (infoIter->pduType == PduType::FILE_DIRECTIVE and - infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { - result = handleEofPdu(*infoIter); } } + if (step == TransactionStep::TRANSFER_COMPLETION) { + } + if (step == TransactionStep::SENDING_FINISHED_PDU) { + } return OK; } if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) { @@ -141,7 +153,6 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) size_t fileSegmentLen = 0; const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); FileOpParams fileOpParams(tp.sourceName.data(), fileSegmentLen); - result = dp.user.vfs.writeToFile(fileOpParams, fileData); if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { FileSegmentRecvdParams segParams; segParams.offset = offset.value(); @@ -153,6 +164,10 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) segParams.segmentMetadata = {segMetadata, segmentMetadatLen}; dp.user.fileSegmentRecvdIndication(segParams); } + result = dp.user.vfs.writeToFile(fileOpParams, fileData); + if (offset.value() + fileSegmentLen > tp.progress) { + tp.progress = offset.value() + fileSegmentLen; + } if (result != returnvalue::OK) { // TODO: Proper Error handling #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -175,8 +190,15 @@ ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { if (result != OK) { return result; } + // TODO: Error handling if (eofInfo.getConditionCode() == ConditionCode::NO_ERROR) { tp.crc = eofInfo.getChecksum(); + uint64_t fileSizeFromEof = eofInfo.getFileSize().value(); + // CFDP 4.6.1.2.9: Declare file size error if progress exceeds file size + if (fileSizeFromEof > tp.progress) { + // TODO: File size error + } + tp.fileSize.setFileSize(fileSizeFromEof, std::nullopt); } return returnvalue::OK; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index 8215d22d..b24a35bc 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -2,6 +2,7 @@ #define FSFW_CFDP_CFDPDESTHANDLER_H #include +#include #include @@ -30,17 +31,23 @@ struct PacketInfo { struct DestHandlerParams { DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable, - etl::ilist& packetList) + etl::ilist& packetList, + // 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 + etl::iset>& lostSegmentsContainer) : cfg(std::move(cfg)), user(user), remoteCfgTable(remoteCfgTable), - packetListRef(packetList) {} + packetListRef(packetList), + lostSegmentsContainer(lostSegmentsContainer) {} LocalEntityCfg cfg; UserBase& user; RemoteConfigTableIF& remoteCfgTable; etl::ilist& packetListRef; + etl::iset>& lostSegmentsContainer; uint8_t maxTlvsInOnePdu = 10; size_t maxFilenameLen = 255; }; @@ -99,6 +106,7 @@ class DestHandler { TransactionId transactionId; PduConfig pduConf; uint32_t crc = 0; + uint64_t progress = 0; RemoteEntityCfg* remoteCfg = nullptr; };