eive-obsw/bsp_q7s/fs/FilesystemHelper.cpp

39 lines
1.2 KiB
C++
Raw Normal View History

2022-01-06 18:05:21 +01:00
#include "FilesystemHelper.h"
2022-03-27 13:07:18 +02:00
#include <filesystem>
#include <fstream>
2022-09-16 11:53:33 +02:00
#include "SdCardManager.h"
2022-09-26 11:39:17 +02:00
#include "eive/definitions.h"
2022-09-16 11:53:33 +02:00
#include "fsfw/serviceinterface.h"
2022-01-06 18:05:21 +01:00
2022-03-27 13:07:18 +02:00
FilesystemHelper::FilesystemHelper() {}
2022-01-06 18:05:21 +01:00
ReturnValue_t FilesystemHelper::checkPath(std::string path) {
2022-03-27 13:07:18 +02:00
SdCardManager* sdcMan = SdCardManager::instance();
if (sdcMan == nullptr) {
sif::warning << "FilesystemHelper::checkPath: Invalid SD card manager" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-03-27 13:07:18 +02:00
}
2022-09-26 11:39:17 +02:00
if (path.substr(0, sizeof(config::SD_0_MOUNT_POINT)) == std::string(config::SD_0_MOUNT_POINT)) {
2022-09-27 10:51:07 +02:00
if (!sdcMan->isSdCardUsable(sd::SLOT_0)) {
2022-03-27 13:07:18 +02:00
sif::warning << "FilesystemHelper::checkPath: SD card 0 not mounted" << std::endl;
return SD_NOT_MOUNTED;
2022-01-06 18:05:21 +01:00
}
2022-09-26 11:39:17 +02:00
} else if (path.substr(0, sizeof(config::SD_1_MOUNT_POINT)) ==
std::string(config::SD_1_MOUNT_POINT)) {
if (!sdcMan->isSdCardUsable(sd::SLOT_1)) {
2022-03-27 13:07:18 +02:00
sif::warning << "FilesystemHelper::checkPath: SD card 1 not mounted" << std::endl;
return SD_NOT_MOUNTED;
2022-01-06 18:05:21 +01:00
}
2022-03-27 13:07:18 +02:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-06 18:05:21 +01:00
}
ReturnValue_t FilesystemHelper::fileExists(std::string file) {
2022-03-27 13:07:18 +02:00
if (not std::filesystem::exists(file)) {
return FILE_NOT_EXISTS;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-06 18:05:21 +01:00
}