eive-obsw/bsp_q7s/memory/scratchApi.h

50 lines
1.4 KiB
C
Raw Normal View History

2021-07-09 16:57:34 +02:00
#ifndef BSP_Q7S_MEMORY_SCRATCHAPI_H_
#define BSP_Q7S_MEMORY_SCRATCHAPI_H_
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "linux/utility/utility.h"
#include <iostream>
#include <sstream>
#include <type_traits>
#include <cstdlib>
/**
* @brief API for the scratch buffer
*/
namespace scratch {
namespace {
static size_t counter = 0;
}
template<typename T, class = typename std::enable_if<std::is_unsigned<T>::value>::type>
inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
std::ostringstream oss;
oss << "xsc_scratch write " << name << " " << 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_unsigned<T>::value>::type>
inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
std::ostringstream oss;
oss << "xsc_scratch read " << name << " > /tmp/scratchro" << counter++;
int result = std::system(oss.str().c_str());
if(result != 0) {
utility::handleSystemError(result, "scratch::writeNumber");
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t writeString(std::string name, std::string string);
}
#endif /* BSP_Q7S_MEMORY_SCRATCHAPI_H_ */