#include "SourceHandler.h" #include #include #include "fsfw/filesystem/HasFileSystemIF.h" using namespace returnvalue; cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwParams) : transactionParams(params.maxFilePathSize), sourceParams(std::move(params)), fsfwParams(fsfwParams) {} void cfdp::SourceHandler::fsmNacked() { if (step == TransactionStep::IDLE) { step = TransactionStep::TRANSACTION_START; } if (step == TransactionStep::TRANSACTION_START) { // TODO: Use put request information to start the transaction step = TransactionStep::CRC_PROCEDURE; } if (step == TransactionStep::CRC_PROCEDURE) { ReturnValue_t result = checksumGeneration(); if (result != OK) { // TODO: Some error handling } } if (step == TransactionStep::SENDING_METADATA) { // TODO: Prepare and send metadata PDU } if (step == TransactionStep::SENDING_FILE_DATA) { // TODO: Prepare and send file data PDUs } if (step == TransactionStep::SENDING_EOF) { // TODO: Send EOF PDU } if (step == TransactionStep::WAIT_FOR_FINISH) { // TODO: In case this is a request with closure, wait for finish. } if (step == TransactionStep::NOTICE_OF_COMPLETION) { // TODO: Notice of completion } } void cfdp::SourceHandler::stateMachine() { if (state == cfdp::CfdpState::IDLE) { return; } if (state == cfdp::CfdpState::BUSY_CLASS_1_NACKED) { return fsmNacked(); } } ReturnValue_t cfdp::SourceHandler::checksumGeneration() { std::array buf{}; etl::crc32 crcCalc; uint64_t currentOffset = 0; FileOpParams params(transactionParams.destName.data(), transactionParams.fileSize.value()); while (currentOffset < transactionParams.fileSize.value()) { uint64_t readLen; if (currentOffset + buf.size() > transactionParams.fileSize.value()) { readLen = transactionParams.fileSize.value() - currentOffset; } else { readLen = buf.size(); } if (readLen > 0) { params.offset = currentOffset; params.size = readLen; auto result = sourceParams.user.vfs.readFromFile(params, buf.data(), buf.size()); if (result != OK) { // TODO: I think this is a case for a filestore rejection, but it might sense to print // a warning or trigger an event because this should generally not happen return FAILED; } crcCalc.add(buf.begin(), buf.begin() + readLen); } currentOffset += readLen; } transactionParams.crc = crcCalc.value(); return OK; } ReturnValue_t cfdp::SourceHandler::putRequest() { return 0; }