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,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();

View File

@ -1,8 +1,8 @@
#include <etl/crc32.h>
#include <catch2/catch_test_macros.hpp>
#include <utility>
#include <random>
#include <utility>
#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<store_address_t>& 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<std::mt19937::result_type> distU8(0, 255);
std::array<uint8_t, 1024> 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<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);
}
}