applied formatting
Some checks failed
EIVE/eive-obsw/pipeline/head Build queued...
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
2022-01-17 15:58:27 +01:00
parent 975b3cd294
commit 77c45c0de9
206 changed files with 28883 additions and 30263 deletions

View File

@ -1,17 +1,17 @@
#ifndef BSP_Q7S_MEMORY_SCRATCHAPI_H_
#define BSP_Q7S_MEMORY_SCRATCHAPI_H_
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
#include <type_traits>
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "linux/utility/utility.h"
#include "returnvalues/classIds.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <type_traits>
#include <cstdlib>
/**
* @brief API for the scratch buffer
*/
@ -48,7 +48,7 @@ ReturnValue_t readString(std::string key, std::string& string);
* @param num Number. Template allows to set signed, unsigned and floating point numbers
* @return
*/
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
template <typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
inline ReturnValue_t writeNumber(std::string key, T num) noexcept;
/**
@ -59,90 +59,88 @@ inline ReturnValue_t writeNumber(std::string key, T num) noexcept;
* @param num
* @return
*/
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
template <typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
inline ReturnValue_t readNumber(std::string key, T& num) noexcept;
// Anonymous namespace
namespace {
static uint8_t counter = 0;
ReturnValue_t readToFile(std::string name, std::ifstream& file, std::string& filename) {
using namespace std;
filename = "/tmp/sro" + std::to_string(counter++);
ostringstream oss;
oss << "xsc_scratch read " << name << " > " << filename;
using namespace std;
filename = "/tmp/sro" + std::to_string(counter++);
ostringstream oss;
oss << "xsc_scratch read " << name << " > " << filename;
int result = std::system(oss.str().c_str());
if(result != 0) {
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;
}
int result = std::system(oss.str().c_str());
if (result != 0) {
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;
}
file.open(filename);
return HasReturnvaluesIF::RETURN_OK;
}
file.open(filename);
return HasReturnvaluesIF::RETURN_OK;
}
} // End of anonymous namespace
} // End of anonymous namespace
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
template <typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
inline ReturnValue_t writeNumber(std::string key, T num) noexcept {
std::ostringstream oss;
oss << "xsc_scratch write " << key << " " << std::to_string(num);
int result = std::system(oss.str().c_str());
if(result != 0) {
utility::handleSystemError(result, "scratch::writeNumber");
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
std::ostringstream oss;
oss << "xsc_scratch write " << key << " " << std::to_string(num);
int result = std::system(oss.str().c_str());
if (result != 0) {
utility::handleSystemError(result, "scratch::writeNumber");
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
template <typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
inline ReturnValue_t readNumber(std::string key, T& num) noexcept {
using namespace std;
ifstream file;
std::string filename;
ReturnValue_t result = readToFile(key, file, filename);
if(result != HasReturnvaluesIF::RETURN_OK) {
std::remove(filename.c_str());
return result;
}
string line;
if (not std::getline(file, line)) {
std::remove(filename.c_str());
return HasReturnvaluesIF::RETURN_FAILED;
}
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);
}
catch(std::invalid_argument& e) {
sif::warning << "scratch::readNumber: stoi call failed with " << e.what() << std::endl;
}
using namespace std;
ifstream file;
std::string filename;
ReturnValue_t result = readToFile(key, file, filename);
if (result != HasReturnvaluesIF::RETURN_OK) {
std::remove(filename.c_str());
return HasReturnvaluesIF::RETURN_OK;
return result;
}
string line;
if (not std::getline(file, line)) {
std::remove(filename.c_str());
return HasReturnvaluesIF::RETURN_FAILED;
}
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);
} catch (std::invalid_argument& e) {
sif::warning << "scratch::readNumber: stoi call failed with " << e.what() << std::endl;
}
std::remove(filename.c_str());
return HasReturnvaluesIF::RETURN_OK;
}
}
} // namespace scratch
#endif /* BSP_Q7S_MEMORY_SCRATCHAPI_H_ */