getFileSize API for fsfw
This commit is contained in:
parent
b53c48863f
commit
5e9d402598
@ -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
|
||||
}
|
||||
|
||||
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
|
||||
// FileSize fileSize();
|
||||
// auto metadataInfo = MetadataInfo();
|
||||
// TODO: Implement
|
||||
// Advance FSM if everythings works
|
||||
step = TransactionStep::SENDING_FILE_DATA;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user