CFDP SOURCE handler #157

Merged
muellerr merged 107 commits from cfdp-source-handler into develop 2023-10-19 10:59:55 +02:00
2 changed files with 83 additions and 36 deletions
Showing only changes of commit 8e62143ac8 - Show all commits

View File

@ -6,13 +6,13 @@
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
#include "fsfw/filesystem/HasFileSystemIF.h"
#include "fsfw/objectmanager.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
using namespace returnvalue;
cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwParams)
: transactionParams(params.maxFilePathSize),
sourceParams(std::move(params)),
fsfwParams(fsfwParams) {}
: sourceParams(std::move(params)), fsfwParams(fsfwParams) {}
cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::fsmNacked() {
ReturnValue_t result;
@ -109,42 +109,70 @@ ReturnValue_t cfdp::SourceHandler::putRequest(PutRequestFull& putRequest, Remote
if (state != CfdpState::IDLE) {
return SOURCE_TRANSACTION_PENDING;
}
transactionParams.closureRequested = putRequest.closureRequested;
transactionParams.destId = putRequest.destId;
transactionParams.transmissionMode = putRequest.transmissionMode;
if (transactionParams.transmissionMode == TransmissionMode::ACKNOWLEDGED) {
state = cfdp::CfdpState::BUSY_CLASS_2_ACKED;
} else if (transactionParams.transmissionMode == TransmissionMode::UNACKNOWLEDGED) {
state = cfdp::CfdpState::BUSY_CLASS_1_NACKED;
}
step = TransactionStep::IDLE;
if (transactionParams.transmissionMode == TransmissionMode::ACKNOWLEDGED) {
}
if (putRequest.sourceNameSize > transactionParams.sourceName.size()) {
return FAILED;
}
std::memcpy(transactionParams.sourceName.data(), putRequest.sourceName,
putRequest.sourceNameSize);
FilesystemParams params(transactionParams.sourceName.data());
if (!sourceParams.user.vfs.fileExists(params)) {
return FILE_DOES_NOT_EXIST;
}
size_t fileSize = 0;
sourceParams.user.vfs.getFileSize(params, fileSize);
transactionParams.fileSize.setFileSize(fileSize, false);
if (putRequest.destNameSize > transactionParams.destName.size()) {
return FAILED;
}
std::memcpy(transactionParams.destName.data(), putRequest.destName, putRequest.destNameSize);
std::memcpy(transactionParams.sourceName.data(), putRequest.sourceName,
putRequest.sourceNameSize);
transactionParams.sourceNameSize = putRequest.sourceNameSize;
transactionParams.destNameSize = putRequest.destNameSize;
FilesystemParams params(transactionParams.sourceName.data());
if (!sourceParams.user.vfs.fileExists(params)) {
return FILE_DOES_NOT_EXIST;
}
transactionParams.closureRequested = putRequest.closureRequested;
transactionParams.pduConf.mode = putRequest.transmissionMode;
transactionParams.pduConf.destId = putRequest.destId;
// Only used for PDU forwarding, file is sent to file receiver regularly here.
transactionParams.pduConf.direction = Direction::TOWARDS_RECEIVER;
transactionParams.pduConf.sourceId = sourceParams.cfg.localId;
if (transactionParams.pduConf.mode == TransmissionMode::ACKNOWLEDGED) {
state = cfdp::CfdpState::BUSY_CLASS_2_ACKED;
} else if (transactionParams.pduConf.mode == TransmissionMode::UNACKNOWLEDGED) {
state = cfdp::CfdpState::BUSY_CLASS_1_NACKED;
}
step = TransactionStep::IDLE;
size_t fileSize = 0;
sourceParams.user.vfs.getFileSize(params, fileSize);
transactionParams.pduConf.largeFile = false;
Review

boop

boop
Review

Will be added when fault declaration works properly

Will be added when fault declaration works properly
if (fileSize > UINT32_MAX) {
transactionParams.pduConf.largeFile = true;
}
transactionParams.fileSize.setFileSize(fileSize, transactionParams.pduConf.largeFile);
currentRemoteCfg = cfg;
return OK;
}
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
// FileSize fileSize();
// auto metadataInfo = MetadataInfo(transactionParams.pduConf, transactionParams.fileSize);
// TODO: Implement
// Advance FSM if everythings works
cfdp::StringLv sourceName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
cfdp::StringLv destName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
auto metadataInfo = MetadataInfo(transactionParams.fileSize, sourceName, destName);
auto metadataPdu = MetadataPduCreator(transactionParams.pduConf, metadataInfo);
uint8_t* dataPtr;
store_address_t storeId;
ReturnValue_t result =
fsfwParams.tcStore->getFreeElement(&storeId, metadataPdu.getSerializedSize(), &dataPtr);
if (result != OK) {
// TODO: Better error handling?
return result;
}
size_t serializedLen = 0;
result = metadataPdu.serializeBe(dataPtr, serializedLen, metadataPdu.getSerializedSize());
if (result != OK) {
return result;
}
TmTcMessage tcMsg(storeId);
result =
fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tcMsg);
if (result != OK) {
return result;
}
// Advance FSM if everything works
step = TransactionStep::SENDING_FILE_DATA;
return OK;
}
@ -161,3 +189,24 @@ ReturnValue_t cfdp::SourceHandler::prepareAndSendEofPdu() {
step = TransactionStep::WAIT_FOR_FINISH;
return OK;
}
ReturnValue_t cfdp::SourceHandler::initialize() {
if (fsfwParams.tmStore == nullptr) {
fsfwParams.tmStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if (fsfwParams.tmStore == nullptr) {
return FAILED;
}
}
if (fsfwParams.tcStore == nullptr) {
fsfwParams.tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (fsfwParams.tcStore == nullptr) {
return FAILED;
}
}
if (fsfwParams.msgQueue == nullptr) {
return FAILED;
}
return OK;
}

View File

@ -44,6 +44,8 @@ class SourceHandler {
ReturnValue_t putRequest(PutRequestFull& putRequest, RemoteEntityCfg& cfg);
FsmResult& stateMachine();
ReturnValue_t initialize();
private:
enum class TransactionStep : uint8_t {
IDLE = 0,
@ -57,17 +59,13 @@ class SourceHandler {
NOTICE_OF_COMPLETION = 8
};
struct TransactionParams {
// Initialize char vectors with length + 1 for 0 termination
explicit TransactionParams(size_t maxFileNameLen)
: sourceName(maxFileNameLen + 1), destName(maxFileNameLen + 1) {}
uint32_t crc{};
std::vector<char> sourceName;
std::vector<char> destName;
std::array<char, 524> sourceName{};
size_t sourceNameSize = 0;
std::array<char, 524> destName{};
size_t destNameSize = 0;
cfdp::FileSize fileSize;
EntityId destId;
TransmissionMode transmissionMode;
bool closureRequested;
bool closureRequested = false;
PduConfig pduConf;
} transactionParams;
cfdp::CfdpState state = cfdp::CfdpState::IDLE;