CFDP SOURCE handler #157

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

View File

@ -4,6 +4,7 @@
#include <array>
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
#include "fsfw/filesystem/HasFileSystemIF.h"
using namespace returnvalue;
@ -124,6 +125,13 @@ ReturnValue_t cfdp::SourceHandler::putRequest(PutRequestFull& putRequest, Remote
}
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;
}
@ -133,6 +141,8 @@ ReturnValue_t cfdp::SourceHandler::putRequest(PutRequestFull& putRequest, Remote
}
Review

boop

boop
Review

Will be added when fault declaration works properly

Will be added when fault declaration works properly
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
// FileSize fileSize();
// auto metadataInfo = MetadataInfo();
// TODO: Implement
// Advance FSM if everythings works
step = TransactionStep::SENDING_FILE_DATA;

View File

@ -73,6 +73,7 @@ static constexpr Event FILENAME_TOO_LARGE_ERROR = event::makeEvent(SSID, 4, seve
} // namespace events
static constexpr ReturnValue_t SOURCE_TRANSACTION_PENDING = returnvalue::makeCode(CID, 0);
static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = returnvalue::makeCode(CID, 1);
} // namespace cfdp
#endif // FSFW_CFDP_HANDLER_DEFS_H

View File

@ -80,6 +80,8 @@ class HasFileSystemIF {
virtual bool isDirectory(const char* path) = 0;
virtual bool getFileSize(FilesystemParams params, size_t& fileSize) = 0;
virtual bool fileExists(FilesystemParams params) = 0;
/**

View File

@ -184,3 +184,11 @@ ReturnValue_t HostFilesystem::getBaseFilename(FilesystemParams params, char *nam
baseNameLen = baseName.size();
return returnvalue::OK;
}
bool HostFilesystem::getFileSize(FilesystemParams params, size_t &fileSize) {
if (!fileExists(params)) {
return false;
}
fileSize = std::filesystem::file_size(params.path);
return true;
}

View File

@ -11,6 +11,7 @@ class HostFilesystem : public HasFileSystemIF {
ReturnValue_t getBaseFilename(FilesystemParams params, char *nameBuf, size_t maxLen,
size_t &baseNameLen) override;
virtual bool getFileSize(FilesystemParams params, size_t &fileSize) override;
bool isDirectory(const char *path) override;
bool fileExists(FilesystemParams params) override;
ReturnValue_t truncateFile(FilesystemParams params) override;

View File

@ -145,3 +145,13 @@ ReturnValue_t FilesystemMock::getBaseFilename(FilesystemParams params, char *nam
}
bool FilesystemMock::isDirectory(const char *path) { return false; }
bool FilesystemMock::getFileSize(FilesystemParams params, size_t &fileSize) {
std::string filename(params.path);
auto iter = fileMap.find(filename);
if (iter == fileMap.end()) {
fileSize = iter->second.fileRaw.size();
return true;
}
return false;
}

View File

@ -62,6 +62,7 @@ class FilesystemMock : public HasFileSystemIF {
bool isDirectory(const char *path) override;
bool fileExists(FilesystemParams params) override;
ReturnValue_t truncateFile(FilesystemParams params) override;
bool getFileSize(FilesystemParams params, size_t &fileSize) override;
ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override;
ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize,