eive-obsw/bsp_q7s/memory/scratchApi.cpp
Robin Mueller aa0da618ca
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit
Merge remote-tracking branch 'origin/develop' into irini
2022-08-29 15:49:23 +02:00

51 lines
1.4 KiB
C++

#include "scratchApi.h"
ReturnValue_t scratch::writeString(std::string name, std::string string) {
std::ostringstream oss("xsc_scratch write ", std::ostringstream::ate);
oss << name << " \"" << string << "\"";
int result = std::system(oss.str().c_str());
if (result != 0) {
utility::handleSystemError(result, "scratch::writeString");
return returnvalue::FAILED;
}
return returnvalue::OK;
}
ReturnValue_t scratch::readString(std::string key, std::string &string) {
std::ifstream file;
std::string filename;
ReturnValue_t result = readToFile(key, file, filename);
if (result != returnvalue::OK) {
return result;
}
std::string line;
if (not std::getline(file, line)) {
std::remove(filename.c_str());
return returnvalue::FAILED;
}
size_t pos = line.find("=");
if (pos == std::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;
}
string = line.substr(pos + 1);
return returnvalue::OK;
}
ReturnValue_t scratch::clearValue(std::string key) {
std::ostringstream oss("xsc_scratch clear ", std::ostringstream::ate);
oss << key;
int result = std::system(oss.str().c_str());
if (result != 0) {
utility::handleSystemError(result, "scratch::clearValue");
return returnvalue::FAILED;
}
return returnvalue::OK;
}