continued dest handler
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good

This commit is contained in:
Robin Müller 2022-09-02 17:54:25 +02:00
parent c90d1c8071
commit 108e7737e2
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
3 changed files with 50 additions and 16 deletions

View File

@ -1,6 +1,8 @@
#ifndef FSFW_CFDP_FILESIZE_H_
#define FSFW_CFDP_FILESIZE_H_
#include <optional>
#include "fsfw/serialize/SerializeAdapter.h"
#include "fsfw/serialize/SerializeIF.h"
@ -52,13 +54,15 @@ struct FileSize : public SerializeIF {
}
}
ReturnValue_t setFileSize(uint64_t fileSize_, bool largeFile_) {
ReturnValue_t setFileSize(uint64_t fileSize_, std::optional<bool> largeFile_) {
if (largeFile_) {
largeFile = largeFile_.value();
}
if (not largeFile and fileSize > UINT32_MAX) {
// TODO: emit warning here
return returnvalue::FAILED;
}
this->fileSize = fileSize_;
this->largeFile = largeFile_;
return returnvalue::OK;
}

View File

@ -49,20 +49,32 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() {
return status;
}
if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) {
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) {
if (infoIter->pduType == PduType::FILE_DATA) {
result = handleFileDataPdu(*infoIter);
if (result != OK) {
status = result;
if (step == TransactionStep::RECEIVING_FILE_DATA_PDUS) {
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) {
if (infoIter->pduType == PduType::FILE_DATA) {
result = handleFileDataPdu(*infoIter);
if (result != OK) {
status = result;
}
// 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) {
result = handleEofPdu(*infoIter);
if (result != OK) {
status = result;
}
// Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++);
}
// Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++);
}
if (infoIter->pduType == PduType::FILE_DIRECTIVE and
infoIter->directiveType == FileDirectives::EOF_DIRECTIVE) {
result = handleEofPdu(*infoIter);
}
}
if (step == TransactionStep::TRANSFER_COMPLETION) {
}
if (step == TransactionStep::SENDING_FINISHED_PDU) {
}
return OK;
}
if (cfdpState == CfdpStates::BUSY_CLASS_2_ACKED) {
@ -141,7 +153,6 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info)
size_t fileSegmentLen = 0;
const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen);
FileOpParams fileOpParams(tp.sourceName.data(), fileSegmentLen);
result = dp.user.vfs.writeToFile(fileOpParams, fileData);
if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) {
FileSegmentRecvdParams segParams;
segParams.offset = offset.value();
@ -153,6 +164,10 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info)
segParams.segmentMetadata = {segMetadata, segmentMetadatLen};
dp.user.fileSegmentRecvdIndication(segParams);
}
result = dp.user.vfs.writeToFile(fileOpParams, fileData);
if (offset.value() + fileSegmentLen > tp.progress) {
tp.progress = offset.value() + fileSegmentLen;
}
if (result != returnvalue::OK) {
// TODO: Proper Error handling
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -175,8 +190,15 @@ ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) {
if (result != OK) {
return result;
}
// TODO: Error handling
if (eofInfo.getConditionCode() == ConditionCode::NO_ERROR) {
tp.crc = eofInfo.getChecksum();
uint64_t fileSizeFromEof = eofInfo.getFileSize().value();
// CFDP 4.6.1.2.9: Declare file size error if progress exceeds file size
if (fileSizeFromEof > tp.progress) {
// TODO: File size error
}
tp.fileSize.setFileSize(fileSizeFromEof, std::nullopt);
}
return returnvalue::OK;
}

View File

@ -2,6 +2,7 @@
#define FSFW_CFDP_CFDPDESTHANDLER_H
#include <etl/list.h>
#include <etl/set.h>
#include <utility>
@ -30,17 +31,23 @@ struct PacketInfo {
struct DestHandlerParams {
DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable,
etl::ilist<PacketInfo>& packetList)
etl::ilist<PacketInfo>& packetList,
// TODO: This container can potentially take tons of space. For a better
// memory efficient implementation, an additional abstraction could be
// be used so users can use uint32_t as the pair type
etl::iset<etl::pair<uint64_t, uint64_t>>& lostSegmentsContainer)
: cfg(std::move(cfg)),
user(user),
remoteCfgTable(remoteCfgTable),
packetListRef(packetList) {}
packetListRef(packetList),
lostSegmentsContainer(lostSegmentsContainer) {}
LocalEntityCfg cfg;
UserBase& user;
RemoteConfigTableIF& remoteCfgTable;
etl::ilist<PacketInfo>& packetListRef;
etl::iset<etl::pair<uint64_t, uint64_t>>& lostSegmentsContainer;
uint8_t maxTlvsInOnePdu = 10;
size_t maxFilenameLen = 255;
};
@ -99,6 +106,7 @@ class DestHandler {
TransactionId transactionId;
PduConfig pduConf;
uint32_t crc = 0;
uint64_t progress = 0;
RemoteEntityCfg* remoteCfg = nullptr;
};