CFDP SOURCE handler #157

Merged
muellerr merged 107 commits from cfdp-source-handler into develop 2023-10-19 10:59:55 +02:00
3 changed files with 49 additions and 13 deletions
Showing only changes of commit 0cccf26021 - Show all commits

View File

@ -8,6 +8,7 @@
#include "fsfw/cfdp/pdu/FileDataCreator.h" #include "fsfw/cfdp/pdu/FileDataCreator.h"
#include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h"
#include "fsfw/filesystem/HasFileSystemIF.h" #include "fsfw/filesystem/HasFileSystemIF.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/objectmanager.h" #include "fsfw/objectmanager.h"
#include "fsfw/serviceinterface.h" #include "fsfw/serviceinterface.h"
#include "fsfw/tmtcservices/TmTcMessage.h" #include "fsfw/tmtcservices/TmTcMessage.h"
@ -294,6 +295,7 @@ ReturnValue_t cfdp::SourceHandler::sendGenericPdu(const SerializeIF& pdu) const
if (result != OK) { if (result != OK) {
return result; return result;
} }
arrayprinter::print(dataPtr, serializedLen);
TmTcMessage tmMsg(storeId); TmTcMessage tmMsg(storeId);
return fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tmMsg); return fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tmMsg);
} }

View File

@ -9,7 +9,9 @@
#include "fsfw/cfdp/pdu/FileDataCreator.h" #include "fsfw/cfdp/pdu/FileDataCreator.h"
#include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h"
#include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/cfdp/pdu/MetadataPduReader.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
#include "fsfw/util/SeqCountProvider.h" #include "fsfw/util/SeqCountProvider.h"
#include "mocks/AcceptsTmMock.h" #include "mocks/AcceptsTmMock.h"
#include "mocks/EventReportingProxyMock.h" #include "mocks/EventReportingProxyMock.h"
@ -66,15 +68,15 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine(); SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
CHECK(fsmResult.packetsSent == 1); CHECK(fsmResult.packetsSent == 1);
CHECK(mqMock.numberOfSentMessages() == 1); CHECK(mqMock.numberOfSentMessages() == 1);
CommandMessage msg; TmTcMessage tmtcMessage;
REQUIRE(mqMock.getNextSentMessage(destQueueId, msg) == OK); REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
store_address_t storeId = CfdpMessage::getStoreId(&msg); auto accessor = tmStore.getData(tmtcMessage.getStorageId());
auto accessor = tmStore.getData(storeId);
REQUIRE(accessor.first == OK); REQUIRE(accessor.first == OK);
const uint8_t* pduPtr = accessor.second.data(); const uint8_t* pduPtr = accessor.second.data();
MetadataGenericInfo metadataInfo; MetadataGenericInfo metadataInfo;
MetadataPduReader metadataReader(pduPtr, accessor.second.size(), metadataInfo, nullptr, 0); MetadataPduReader metadataReader(pduPtr, accessor.second.size(), metadataInfo, nullptr, 0);
size_t srcFileSize = 0; size_t srcFileSize = 0;
arrayprinter::print(pduPtr, accessor.second.size());
REQUIRE(metadataReader.parseData() == OK); REQUIRE(metadataReader.parseData() == OK);
const char* srcNameRead = metadataReader.getSourceFileName().getString(srcFileSize); const char* srcNameRead = metadataReader.getSourceFileName().getString(srcFileSize);
REQUIRE(srcNameRead != nullptr); REQUIRE(srcNameRead != nullptr);

View File

@ -36,15 +36,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
REQUIRE(options[0]->getSerializedSize() == 2 + 1 + 10 + 1); REQUIRE(options[0]->getSerializedSize() == 2 + 1 + 10 + 1);
REQUIRE(options[1]->getSerializedSize() == 5); REQUIRE(options[1]->getSerializedSize() == 5);
SECTION("Serialize") { auto metadataCheckPartOne = [&]() {
MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, nullptr, 0);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
REQUIRE(serializer.getWholePduSize() == 27);
REQUIRE(serializer.getSourceFileName().getSerializedSize() == 10);
REQUIRE(serializer.getDestFileName().getSerializedSize() == 1);
REQUIRE(info.getSerializedSize() == 5);
REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 17);
REQUIRE(mdBuffer[10] == FileDirective::METADATA); REQUIRE(mdBuffer[10] == FileDirective::METADATA);
// no closure requested and checksum type is modular => 0x00 // no closure requested and checksum type is modular => 0x00
REQUIRE(mdBuffer[11] == 0x00); REQUIRE(mdBuffer[11] == 0x00);
@ -63,9 +55,49 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
REQUIRE(mdBuffer[23] == 't'); REQUIRE(mdBuffer[23] == 't');
REQUIRE(mdBuffer[24] == 'x'); REQUIRE(mdBuffer[24] == 'x');
REQUIRE(mdBuffer[25] == 't'); REQUIRE(mdBuffer[25] == 't');
};
SECTION("Serialize with empty dest name") {
MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, nullptr, 0);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
// 10 byte heater + 1 byte PDU directive field + 1 byte PDU content + FSS field (4) + source
// name field (10) + dest name field (1).
REQUIRE(serializer.getWholePduSize() == 27);
REQUIRE(serializer.getSourceFileName().getSerializedSize() == 10);
REQUIRE(serializer.getDestFileName().getSerializedSize() == 1);
REQUIRE(info.getSerializedSize() == 5);
REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 17);
REQUIRE(serializer.getSerializedSize() == serializer.getWholePduSize());
metadataCheckPartOne();
REQUIRE(mdBuffer[26] == 0); REQUIRE(mdBuffer[26] == 0);
} }
SECTION("Serialize with dest name") {
std::string secondFileName = "hello2.txt";
cfdp::StringLv destFileName2(secondFileName);
MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName2, nullptr, 0);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
// 10 byte heater + 1 byte PDU directive field + 1 byte PDU content + FSS field (4) + source
// name field (10) + dest name field (11).
REQUIRE(serializer.getWholePduSize() == 37);
REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 27);
REQUIRE(serializer.getSerializedSize() == serializer.getWholePduSize());
metadataCheckPartOne();
// Size of destination name field
REQUIRE(mdBuffer[26] == 10);
REQUIRE(mdBuffer[27] == 'h');
REQUIRE(mdBuffer[28] == 'e');
REQUIRE(mdBuffer[29] == 'l');
REQUIRE(mdBuffer[30] == 'l');
REQUIRE(mdBuffer[31] == 'o');
REQUIRE(mdBuffer[32] == '2');
REQUIRE(mdBuffer[33] == '.');
REQUIRE(mdBuffer[34] == 't');
REQUIRE(mdBuffer[35] == 'x');
REQUIRE(mdBuffer[36] == 't');
}
SECTION("Serialize with 2 options") { SECTION("Serialize with 2 options") {
std::string otherFileName = "hello2.txt"; std::string otherFileName = "hello2.txt";
cfdp::StringLv otherFileNameLv(otherFileName.data(), otherFileName.size()); cfdp::StringLv otherFileNameLv(otherFileName.data(), otherFileName.size());