CFDP SOURCE handler #157
@ -6,13 +6,13 @@
|
|||||||
|
|
||||||
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
|
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
|
||||||
#include "fsfw/filesystem/HasFileSystemIF.h"
|
#include "fsfw/filesystem/HasFileSystemIF.h"
|
||||||
|
#include "fsfw/objectmanager.h"
|
||||||
|
#include "fsfw/tmtcservices/TmTcMessage.h"
|
||||||
|
|
||||||
using namespace returnvalue;
|
using namespace returnvalue;
|
||||||
|
|
||||||
cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwParams)
|
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() {
|
cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::fsmNacked() {
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
@ -109,42 +109,70 @@ ReturnValue_t cfdp::SourceHandler::putRequest(PutRequestFull& putRequest, Remote
|
|||||||
if (state != CfdpState::IDLE) {
|
if (state != CfdpState::IDLE) {
|
||||||
return SOURCE_TRANSACTION_PENDING;
|
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()) {
|
if (putRequest.sourceNameSize > transactionParams.sourceName.size()) {
|
||||||
return FAILED;
|
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()) {
|
if (putRequest.destNameSize > transactionParams.destName.size()) {
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
std::memcpy(transactionParams.destName.data(), putRequest.destName, putRequest.destNameSize);
|
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;
|
||||||
|
|||||||
|
if (fileSize > UINT32_MAX) {
|
||||||
|
transactionParams.pduConf.largeFile = true;
|
||||||
|
}
|
||||||
|
transactionParams.fileSize.setFileSize(fileSize, transactionParams.pduConf.largeFile);
|
||||||
currentRemoteCfg = cfg;
|
currentRemoteCfg = cfg;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
|
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
|
||||||
// FileSize fileSize();
|
cfdp::StringLv sourceName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
|
||||||
// auto metadataInfo = MetadataInfo(transactionParams.pduConf, transactionParams.fileSize);
|
cfdp::StringLv destName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
|
||||||
// TODO: Implement
|
auto metadataInfo = MetadataInfo(transactionParams.fileSize, sourceName, destName);
|
||||||
// Advance FSM if everythings works
|
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;
|
step = TransactionStep::SENDING_FILE_DATA;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -161,3 +189,24 @@ ReturnValue_t cfdp::SourceHandler::prepareAndSendEofPdu() {
|
|||||||
step = TransactionStep::WAIT_FOR_FINISH;
|
step = TransactionStep::WAIT_FOR_FINISH;
|
||||||
return OK;
|
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;
|
||||||
|
}
|
||||||
|
@ -44,6 +44,8 @@ class SourceHandler {
|
|||||||
ReturnValue_t putRequest(PutRequestFull& putRequest, RemoteEntityCfg& cfg);
|
ReturnValue_t putRequest(PutRequestFull& putRequest, RemoteEntityCfg& cfg);
|
||||||
FsmResult& stateMachine();
|
FsmResult& stateMachine();
|
||||||
|
|
||||||
|
ReturnValue_t initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class TransactionStep : uint8_t {
|
enum class TransactionStep : uint8_t {
|
||||||
IDLE = 0,
|
IDLE = 0,
|
||||||
@ -57,17 +59,13 @@ class SourceHandler {
|
|||||||
NOTICE_OF_COMPLETION = 8
|
NOTICE_OF_COMPLETION = 8
|
||||||
};
|
};
|
||||||
struct TransactionParams {
|
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{};
|
uint32_t crc{};
|
||||||
std::vector<char> sourceName;
|
std::array<char, 524> sourceName{};
|
||||||
std::vector<char> destName;
|
size_t sourceNameSize = 0;
|
||||||
|
std::array<char, 524> destName{};
|
||||||
|
size_t destNameSize = 0;
|
||||||
cfdp::FileSize fileSize;
|
cfdp::FileSize fileSize;
|
||||||
EntityId destId;
|
bool closureRequested = false;
|
||||||
TransmissionMode transmissionMode;
|
|
||||||
bool closureRequested;
|
|
||||||
PduConfig pduConf;
|
PduConfig pduConf;
|
||||||
} transactionParams;
|
} transactionParams;
|
||||||
cfdp::CfdpState state = cfdp::CfdpState::IDLE;
|
cfdp::CfdpState state = cfdp::CfdpState::IDLE;
|
||||||
|
Loading…
Reference in New Issue
Block a user
boop
Will be added when fault declaration works properly