eive-obsw/mission/memory/NVMParameterBase.cpp

45 lines
1.3 KiB
C++
Raw Normal View History

2021-07-16 21:51:30 +02:00
#include "NVMParameterBase.h"
#include <fstream>
2022-01-17 15:58:27 +01:00
#include "fsfw/memory/HasFileSystemIF.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
NVMParameterBase::NVMParameterBase(std::string fullName) : fullName(fullName) {}
2021-07-16 21:51:30 +02:00
ReturnValue_t NVMParameterBase::readJsonFile() {
2022-01-17 15:58:27 +01:00
if (std::filesystem::exists(fullName)) {
// Read JSON file content into object
std::ifstream i(fullName);
i >> json;
return HasReturnvaluesIF::RETURN_OK;
}
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
2021-07-16 21:51:30 +02:00
}
ReturnValue_t NVMParameterBase::writeJsonFile() {
2022-01-17 15:58:27 +01:00
std::ofstream o(fullName);
o << std::setw(4) << json;
return HasReturnvaluesIF::RETURN_OK;
2021-07-16 21:51:30 +02:00
}
2022-01-17 15:58:27 +01:00
void NVMParameterBase::setFullName(std::string fullName) { this->fullName = fullName; }
2021-07-16 21:51:30 +02:00
2022-01-17 15:58:27 +01:00
std::string NVMParameterBase::getFullName() const { return fullName; }
2021-07-16 21:51:30 +02:00
2022-01-17 15:58:27 +01:00
bool NVMParameterBase::getJsonFileExists() { return std::filesystem::exists(fullName); }
2021-07-16 21:51:30 +02:00
void NVMParameterBase::printKeys() const {
2022-01-17 15:58:27 +01:00
sif::info << "Printing keys for JSON file " << fullName << std::endl;
for (const auto& key : keys) {
sif::info << key << std::endl;
}
2021-07-16 21:51:30 +02:00
}
void NVMParameterBase::print() const {
2022-01-17 15:58:27 +01:00
sif::info << "Printing JSON file " << fullName << std::endl;
for (const auto& key : keys) {
sif::info << key << ": " << json[key] << std::endl;
}
2021-07-16 21:51:30 +02:00
}