#include #include "Q7STestTask.h" #include "fsfw/timemanager/Stopwatch.h" #include "fsfw/tasks/TaskFactory.h" #include "bsp_q7s/memory/scratchApi.h" #include #include #include #include Q7STestTask::Q7STestTask(object_id_t objectId): TestTask(objectId) { } ReturnValue_t Q7STestTask::performOneShotAction() { //sdCardTests(); testScratchApi(); Stopwatch stopwatch; // for convenience using json = nlohmann::json; json helloTest; // add a number that is stored as double (note the implicit conversion of j to an object) helloTest["pi"] = 3.141; std::string mntPrefix = SdCardManager::instance()->getCurrentMountPrefix(); std::ofstream o("/mnt/sd0/pretty.json"); o << std::setw(4) << helloTest << std::endl; return TestTask::performOneShotAction(); } void Q7STestTask::sdCardTests() { using namespace std; Stopwatch stopwatch; int result = std::system("q7hw sd info all > /tmp/sd_status.txt"); if(result != 0) { sif::debug << "system call failed with " << result << endl; } ifstream sdStatus("/tmp/sd_status.txt"); string line; uint8_t idx = 0; while (std::getline(sdStatus, line)) { std::istringstream iss(line); string word; while(iss >> word) { if(word == "on") { sif::info << "SD card " << static_cast(idx) << " is on" << endl; } else if(word == "off") { sif::info << "SD card " << static_cast(idx) << " is off" << endl; } } idx++; } std::remove("/tmp/sd_status.txt"); } void Q7STestTask::fileTests() { using namespace std; ofstream testFile("/tmp/test.txt"); testFile << "Hallo Welt" << endl; testFile.close(); 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; } }