writing api for scratch buffer
This commit is contained in:
49
bsp_q7s/memory/scratchApi.h
Normal file
49
bsp_q7s/memory/scratchApi.h
Normal file
@ -0,0 +1,49 @@
|
||||
#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_ */
|
Reference in New Issue
Block a user