added JSON lib, bugfixes in FileSystemHandler

This commit is contained in:
2021-07-16 20:32:13 +02:00
committed by Robin Mueller
parent b3dfbcf7fe
commit 434a0f6a7a
15 changed files with 218 additions and 108 deletions

View File

@@ -4,6 +4,7 @@
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "linux/utility/utility.h"
#include "returnvalues/classIds.h"
#include <iostream>
#include <fstream>
@@ -18,6 +19,9 @@ namespace scratch {
static constexpr char PREFERED_SDC_KEY[] = "PREFSD";
static constexpr uint8_t INTERFACE_ID = CLASS_ID::SCRATCH_BUFFER;
static constexpr ReturnValue_t KEY_NOT_FOUND = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0);
namespace {
static uint8_t counter = 0;
}
@@ -25,7 +29,7 @@ static uint8_t counter = 0;
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
std::ostringstream oss;
oss << "xsc_scratch write " << name << " " << num;
oss << "xsc_scratch write " << name << " " << std::to_string(num);
int result = std::system(oss.str().c_str());
if(result != 0) {
utility::handleSystemError(result, "scratch::writeNumber");
@@ -43,8 +47,17 @@ inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
int result = std::system(oss.str().c_str());
if(result != 0) {
utility::handleSystemError(result, "scratch::writeNumber");
return HasReturnvaluesIF::RETURN_FAILED;
if(result == 256) {
sif::warning << "scratch::readNumber: Key " << name << " does not exist" << std::endl;
// Could not find value
std::remove(filename.c_str());
return KEY_NOT_FOUND;
}
else {
utility::handleSystemError(result, "scratch::readNumber");
std::remove(filename.c_str());
return HasReturnvaluesIF::RETURN_FAILED;
}
}
ifstream file(filename);
string line;
@@ -53,6 +66,13 @@ inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
}
size_t pos = line.find("=");
if(pos == string::npos) {
sif::warning << "scratch::readNumber: Output file format invalid, "
"no \"=\" found" << std::endl;
// Could not find value
std::remove(filename.c_str());
return KEY_NOT_FOUND;
}
std::string valueAsString = line.substr(pos + 1);
try {
num = std::stoi(valueAsString);