From 9c8434d856e47b5fd63fe76aef08c8d8bd10e1ef Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 19 Jul 2023 23:43:40 +0200 Subject: [PATCH] LOOKING GOOOD --- src/fsfw/cfdp/handler/SourceHandler.cpp | 45 ++++++++++++++++++++----- src/fsfw/cfdp/handler/SourceHandler.h | 14 ++++++-- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/fsfw/cfdp/handler/SourceHandler.cpp b/src/fsfw/cfdp/handler/SourceHandler.cpp index 0c4c6ed8..501eb9fd 100644 --- a/src/fsfw/cfdp/handler/SourceHandler.cpp +++ b/src/fsfw/cfdp/handler/SourceHandler.cpp @@ -29,6 +29,8 @@ cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwPa sif::error << "cfdp::SourceHandler: Seq count provider bit width " << sourceParams.seqCountProvider.bitWidth() << " not allowed" << std::endl; #else + sif::printError("cfdp::SourceHandler: Seq count provider bit width %d not allowed\n", + sourceParams.seqCountProvider.bitWidth()); #endif // Yeah, what am I supposed to do here? Can't throw an exception in the FSFW.. transactionParams.seqCountWidth = cfdp::WidthInBytes::ONE_BYTE; @@ -70,7 +72,14 @@ cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::fsmNacked() { if (result != OK) { // TODO: Error handling } - return fsmResult; + if (sourceParams.cfg.indicCfg.eofSentIndicRequired) { + sourceParams.user.eofSentIndication(transactionParams.id); + } + if (transactionParams.closureRequested) { + step = TransactionStep::WAIT_FOR_FINISH; + return fsmResult; + } + step = TransactionStep::NOTICE_OF_COMPLETION; } if (step == TransactionStep::WAIT_FOR_FINISH) { // TODO: In case this is a request with closure, wait for finish. @@ -78,11 +87,8 @@ cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::fsmNacked() { step = TransactionStep::NOTICE_OF_COMPLETION; } if (step == TransactionStep::NOTICE_OF_COMPLETION) { - // TODO: Notice of completion - // We are done, go back to idle state. - // TODO: Possible reset state? - step = TransactionStep::IDLE; - state = CfdpState::IDLE; + noticeOfCompletion(); + reset(); } return fsmResult; } @@ -98,6 +104,11 @@ cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::stateMachine() { } ReturnValue_t cfdp::SourceHandler::checksumGeneration() { + if (transactionParams.fileSize.value() == 0) { + // NULL checksum for empty file. + transactionParams.crc = 0; + return OK; + } std::array buf{}; etl::crc32 crcCalc; uint64_t currentOffset = 0; @@ -227,14 +238,13 @@ ReturnValue_t cfdp::SourceHandler::prepareAndSendNextFileDataPdu() { } ReturnValue_t cfdp::SourceHandler::prepareAndSendEofPdu() { - // TODO: Checksum - auto eofInfo = EofInfo(ConditionCode::NO_ERROR, 0, transactionParams.fileSize); + auto eofInfo = + EofInfo(ConditionCode::NO_ERROR, transactionParams.crc, transactionParams.fileSize); auto eofPdu = EofPduCreator(transactionParams.pduConf, eofInfo); ReturnValue_t result = sendGenericPdu(eofPdu); if (result != OK) { return result; } - step = TransactionStep::WAIT_FOR_FINISH; return OK; } @@ -276,3 +286,20 @@ ReturnValue_t cfdp::SourceHandler::sendGenericPdu(const SerializeIF& pdu) const TmTcMessage tcMsg(storeId); return fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tcMsg); } + +ReturnValue_t cfdp::SourceHandler::noticeOfCompletion() { + if (sourceParams.cfg.indicCfg.transactionFinishedIndicRequired) { + cfdp::TransactionFinishedParams params(transactionParams.id, ConditionCode::NO_ERROR, + FileDeliveryCode::DATA_COMPLETE, + FileDeliveryStatus::RETAINED_IN_FILESTORE); + sourceParams.user.transactionFinishedIndication(params); + } + return OK; +} + +ReturnValue_t cfdp::SourceHandler::reset() { + step = TransactionStep::IDLE; + state = cfdp::CfdpState::IDLE; + transactionParams.reset(); + return OK; +} diff --git a/src/fsfw/cfdp/handler/SourceHandler.h b/src/fsfw/cfdp/handler/SourceHandler.h index b517d709..31fafcb2 100644 --- a/src/fsfw/cfdp/handler/SourceHandler.h +++ b/src/fsfw/cfdp/handler/SourceHandler.h @@ -73,8 +73,16 @@ class SourceHandler { PduConfig pduConf; cfdp::TransactionId id{}; cfdp::WidthInBytes seqCountWidth; - uint32_t seqNum = 0; + + void reset() { + sourceNameSize = 0; + destNameSize = 0; + fileSize.setFileSize(0, false); + progress = 0; + closureRequested = false; + } } transactionParams; + cfdp::CfdpState state = cfdp::CfdpState::IDLE; TransactionStep step = TransactionStep::IDLE; std::array fileBuf{}; @@ -87,8 +95,10 @@ class SourceHandler { ReturnValue_t prepareAndSendMetadataPdu(); ReturnValue_t prepareAndSendNextFileDataPdu(); ReturnValue_t prepareAndSendEofPdu(); + ReturnValue_t noticeOfCompletion(); + ReturnValue_t reset(); - ReturnValue_t sendGenericPdu(const SerializeIF& pdu) const; + [[nodiscard]] ReturnValue_t sendGenericPdu(const SerializeIF& pdu) const; }; } // namespace cfdp