SD Card, Scratch Buffer and README updates #52

Merged
meierj merged 41 commits from mueller/first-sd-tests into develop 2021-07-09 22:02:31 +02:00
4 changed files with 39 additions and 5 deletions
Showing only changes of commit d1aa68ea80 - Show all commits

View File

@ -3,6 +3,8 @@
#include "fsfw/timemanager/Stopwatch.h"
#include "fsfw/tasks/TaskFactory.h"
#include "bsp_q7s/memory/scratchApi.h"
#include <iostream>
#include <fstream>
#include <cstdio>
@ -12,6 +14,7 @@ Q7STestTask::Q7STestTask(object_id_t objectId): TestTask(objectId) {
ReturnValue_t Q7STestTask::performOneShotAction() {
//sdCardTests();
testScratchApi();
return TestTask::performOneShotAction();
}
@ -50,3 +53,15 @@ void Q7STestTask::fileTests() {
system("echo \"Hallo Welt\" > /tmp/test2.txt");
system("echo \"Hallo Welt\"");
}
void Q7STestTask::testScratchApi() {
ReturnValue_t result = scratch::writeNumber("TEST", 1);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "Q7STestTask::scratchApiTest: Writing number failed" << std::endl;
}
int number = 0;
result = scratch::readNumber("TEST", number);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "Q7STestTask::scratchApiTest: Reading number failed" << std::endl;
}
}

View File

@ -11,6 +11,9 @@ private:
void sdCardTests();
void fileTests();
void testScratchApi();
};

View File

@ -66,7 +66,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
statestring = "off";
}
std::ostringstream command;
command << "h7hw sd set " << sdstring << " " << statestring;
command << "q7hw sd set " << sdstring << " " << statestring;
int result = std::system(command.str().c_str());
if(result == 0) {
return HasReturnvaluesIF::RETURN_OK;

View File

@ -2,9 +2,11 @@
#define BSP_Q7S_MEMORY_SCRATCHAPI_H_
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "linux/utility/utility.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <type_traits>
#include <cstdlib>
@ -18,10 +20,11 @@ namespace {
static size_t counter = 0;
}
template<typename T, class = typename std::enable_if<std::is_unsigned<T>::value>::type>
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");
@ -30,15 +33,28 @@ inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
return HasReturnvaluesIF::RETURN_OK;
}
template<typename T, class = typename std::enable_if<std::is_unsigned<T>::value>::type>
template<typename T, class = typename std::enable_if<std::is_integral<T>::value>::type>
inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
std::ostringstream oss;
oss << "xsc_scratch read " << name << " > /tmp/scratchro" << counter++;
using namespace std;
string filename = "/tmp/sro" + counter++;
ostringstream oss;
oss << "xsc_scratch read " << name << " < " << filename;
sif::debug << oss.str() << std::endl;
int result = std::system(oss.str().c_str());
if(result != 0) {
utility::handleSystemError(result, "scratch::writeNumber");
return HasReturnvaluesIF::RETURN_FAILED;
}
ifstream file(filename);
string line;
if (not std::getline(file, line)) {
return HasReturnvaluesIF::RETURN_FAILED;
}
size_t pos = line.find("=");
std::string valueAsString = line.substr(pos);
sif::debug << valueAsString << std::endl;
num = std::stoi(valueAsString);
return HasReturnvaluesIF::RETURN_OK;
}