now a sd card will always be on
This commit is contained in:
@ -17,14 +17,13 @@
|
||||
namespace scratch {
|
||||
|
||||
namespace {
|
||||
static size_t counter = 0;
|
||||
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;
|
||||
sif::debug << oss.str() << std::endl;
|
||||
int result = std::system(oss.str().c_str());
|
||||
if(result != 0) {
|
||||
utility::handleSystemError(result, "scratch::writeNumber");
|
||||
@ -36,10 +35,10 @@ inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
|
||||
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
|
||||
inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
|
||||
using namespace std;
|
||||
string filename = "/tmp/sro" + counter++;
|
||||
string filename = "/tmp/sro" + std::to_string(counter++);
|
||||
ostringstream oss;
|
||||
oss << "xsc_scratch read " << name << " < " << filename;
|
||||
sif::debug << oss.str() << std::endl;
|
||||
oss << "xsc_scratch read " << name << " > " << filename;
|
||||
|
||||
int result = std::system(oss.str().c_str());
|
||||
if(result != 0) {
|
||||
utility::handleSystemError(result, "scratch::writeNumber");
|
||||
@ -52,9 +51,15 @@ inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
|
||||
}
|
||||
|
||||
size_t pos = line.find("=");
|
||||
std::string valueAsString = line.substr(pos);
|
||||
sif::debug << valueAsString << std::endl;
|
||||
num = std::stoi(valueAsString);
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user