testing scratch API
This commit is contained in:
parent
bef73d7357
commit
e9cfa0c117
@ -3,6 +3,8 @@
|
|||||||
#include "fsfw/timemanager/Stopwatch.h"
|
#include "fsfw/timemanager/Stopwatch.h"
|
||||||
#include "fsfw/tasks/TaskFactory.h"
|
#include "fsfw/tasks/TaskFactory.h"
|
||||||
|
|
||||||
|
#include "bsp_q7s/memory/scratchApi.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -12,6 +14,7 @@ Q7STestTask::Q7STestTask(object_id_t objectId): TestTask(objectId) {
|
|||||||
|
|
||||||
ReturnValue_t Q7STestTask::performOneShotAction() {
|
ReturnValue_t Q7STestTask::performOneShotAction() {
|
||||||
//sdCardTests();
|
//sdCardTests();
|
||||||
|
testScratchApi();
|
||||||
return TestTask::performOneShotAction();
|
return TestTask::performOneShotAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,3 +53,15 @@ void Q7STestTask::fileTests() {
|
|||||||
system("echo \"Hallo Welt\" > /tmp/test2.txt");
|
system("echo \"Hallo Welt\" > /tmp/test2.txt");
|
||||||
system("echo \"Hallo Welt\"");
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,6 +11,9 @@ private:
|
|||||||
|
|
||||||
void sdCardTests();
|
void sdCardTests();
|
||||||
void fileTests();
|
void fileTests();
|
||||||
|
|
||||||
|
void testScratchApi();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
|
|||||||
statestring = "off";
|
statestring = "off";
|
||||||
}
|
}
|
||||||
std::ostringstream command;
|
std::ostringstream command;
|
||||||
command << "h7hw sd set " << sdstring << " " << statestring;
|
command << "q7hw sd set " << sdstring << " " << statestring;
|
||||||
int result = std::system(command.str().c_str());
|
int result = std::system(command.str().c_str());
|
||||||
if(result == 0) {
|
if(result == 0) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
#define BSP_Q7S_MEMORY_SCRATCHAPI_H_
|
#define BSP_Q7S_MEMORY_SCRATCHAPI_H_
|
||||||
|
|
||||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
#include "linux/utility/utility.h"
|
#include "linux/utility/utility.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -18,10 +20,11 @@ namespace {
|
|||||||
static size_t counter = 0;
|
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 {
|
inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "xsc_scratch write " << name << " " << num;
|
oss << "xsc_scratch write " << name << " " << num;
|
||||||
|
sif::debug << oss.str() << std::endl;
|
||||||
int result = std::system(oss.str().c_str());
|
int result = std::system(oss.str().c_str());
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
utility::handleSystemError(result, "scratch::writeNumber");
|
utility::handleSystemError(result, "scratch::writeNumber");
|
||||||
@ -30,15 +33,28 @@ inline ReturnValue_t writeNumber(std::string name, T num) noexcept {
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
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 {
|
inline ReturnValue_t readNumber(std::string name, T& num) noexcept {
|
||||||
std::ostringstream oss;
|
using namespace std;
|
||||||
oss << "xsc_scratch read " << name << " > /tmp/scratchro" << counter++;
|
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());
|
int result = std::system(oss.str().c_str());
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
utility::handleSystemError(result, "scratch::writeNumber");
|
utility::handleSystemError(result, "scratch::writeNumber");
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
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;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user