segmented file transfer working

This commit is contained in:
Robin Müller 2022-09-06 16:33:38 +02:00
parent aebd401d5b
commit c54caf134a
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 48 additions and 11 deletions

View File

@ -35,9 +35,10 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() {
checkAndHandleError(result, errorIdx); checkAndHandleError(result, errorIdx);
// Store data was deleted in PDU handler because a store guard is used // Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++); dp.packetListRef.erase(infoIter++);
} } else {
infoIter++; infoIter++;
} }
}
if (fsmRes.step == TransactionStep::IDLE) { if (fsmRes.step == TransactionStep::IDLE) {
// To decrease the already high complexity of the software, all packets arriving before // To decrease the already high complexity of the software, all packets arriving before
// a metadata PDU are deleted. // a metadata PDU are deleted.
@ -61,18 +62,18 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() {
checkAndHandleError(result, errorIdx); checkAndHandleError(result, errorIdx);
// Store data was deleted in PDU handler because a store guard is used // Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++); dp.packetListRef.erase(infoIter++);
} } else if (infoIter->pduType == PduType::FILE_DIRECTIVE and
// TODO: Support for check timer missing
if (infoIter->pduType == PduType::FILE_DIRECTIVE and
infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) { infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) {
// TODO: Support for check timer missing
result = handleEofPdu(*infoIter); result = handleEofPdu(*infoIter);
checkAndHandleError(result, errorIdx); checkAndHandleError(result, errorIdx);
// Store data was deleted in PDU handler because a store guard is used // Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++); dp.packetListRef.erase(infoIter++);
} } else {
infoIter++; infoIter++;
} }
} }
}
if (fsmRes.step == TransactionStep::TRANSFER_COMPLETION) { if (fsmRes.step == TransactionStep::TRANSFER_COMPLETION) {
result = handleTransferCompletion(); result = handleTransferCompletion();
checkAndHandleError(result, errorIdx); checkAndHandleError(result, errorIdx);
@ -160,6 +161,7 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info)
size_t fileSegmentLen = 0; size_t fileSegmentLen = 0;
const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen);
FileOpParams fileOpParams(tp.destName.data(), fileSegmentLen); FileOpParams fileOpParams(tp.destName.data(), fileSegmentLen);
fileOpParams.offset = offset.value();
if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) {
FileSegmentRecvdParams segParams; FileSegmentRecvdParams segParams;
segParams.offset = offset.value(); segParams.offset = offset.value();

View File

@ -1,8 +1,8 @@
#include <etl/crc32.h> #include <etl/crc32.h>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <utility>
#include <random> #include <random>
#include <utility>
#include "fsfw/cfdp.h" #include "fsfw/cfdp.h"
#include "fsfw/cfdp/pdu/EofPduCreator.h" #include "fsfw/cfdp/pdu/EofPduCreator.h"
@ -118,11 +118,14 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR); CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR);
}; };
auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res) { auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res,
const std::vector<store_address_t>& idsToCheck) {
REQUIRE(res.result == OK); REQUIRE(res.result == OK);
REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED);
REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); 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()); REQUIRE(packetInfoList.empty());
}; };
@ -179,7 +182,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt);
packetInfoList.push_back(packetInfo); packetInfoList.push_back(packetInfo);
destHandler.performStateMachine(); destHandler.performStateMachine();
fileDataPduCheck(res); fileDataPduCheck(res, {storeId});
eofPreparation(cfdpFileSize, crc32); eofPreparation(cfdpFileSize, crc32);
// After EOF, operation is done because no closure was requested // After EOF, operation is done because no closure was requested
destHandler.performStateMachine(); destHandler.performStateMachine();
@ -193,7 +196,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
std::mt19937 rng(dev()); std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> distU8(0, 255); std::uniform_int_distribution<std::mt19937::result_type> distU8(0, 255);
std::array<uint8_t, 1024> largerFileData{}; std::array<uint8_t, 1024> largerFileData{};
for(auto& val: largerFileData) { for (auto& val : largerFileData) {
val = distU8(rng); val = distU8(rng);
} }
etl::crc32 crcCalc; etl::crc32 crcCalc;
@ -206,5 +209,37 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
destHandler.performStateMachine(); destHandler.performStateMachine();
REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY);
auto transactionId = destHandler.getTransactionId(); auto transactionId = destHandler.getTransactionId();
std::vector<store_address_t> idsToCheck;
{
FileSize offset(0);
FileDataInfo fdPduInfo(offset, reinterpret_cast<const uint8_t*>(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<const uint8_t*>(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);
} }
} }