2022-01-17 15:58:27 +01:00
|
|
|
#include "Q7STestTask.h"
|
|
|
|
|
2021-08-19 14:16:26 +02:00
|
|
|
#include <bsp_q7s/core/CoreController.h>
|
2021-07-19 12:44:43 +02:00
|
|
|
#include <bsp_q7s/memory/FileSystemHandler.h>
|
2022-03-13 16:32:40 +01:00
|
|
|
#include <bsp_q7s/xadc/Xadc.h>
|
2022-08-26 03:20:44 +02:00
|
|
|
#include <fsfw/globalfunctions/arrayprinter.h>
|
2021-07-19 12:44:43 +02:00
|
|
|
#include <fsfw/objectmanager/ObjectManager.h>
|
2022-01-15 13:05:11 +01:00
|
|
|
#include <gps.h>
|
|
|
|
#include <libgpsmm.h>
|
2022-08-26 00:39:06 +02:00
|
|
|
#include <param/param_string.h>
|
2022-08-26 14:28:06 +02:00
|
|
|
#include <param/rparam_client.h>
|
2021-07-09 17:21:26 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
#include <cstdio>
|
2022-01-15 13:05:11 +01:00
|
|
|
#include <ctime>
|
2021-07-05 12:09:31 +02:00
|
|
|
#include <fstream>
|
2022-01-17 15:58:27 +01:00
|
|
|
#include <iomanip>
|
|
|
|
#include <iostream>
|
|
|
|
#include <nlohmann/json.hpp>
|
2021-07-05 12:09:31 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
#include "bsp_q7s/memory/SdCardManager.h"
|
|
|
|
#include "bsp_q7s/memory/scratchApi.h"
|
|
|
|
#include "fsfw/tasks/TaskFactory.h"
|
|
|
|
#include "fsfw/timemanager/Stopwatch.h"
|
2022-08-25 23:22:17 +02:00
|
|
|
#include "p60pdu.h"
|
2022-08-26 00:39:06 +02:00
|
|
|
#include "test/DummyParameter.h"
|
2022-08-25 23:22:17 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) {
|
|
|
|
doTestSdCard = false;
|
|
|
|
doTestScratchApi = false;
|
2022-05-03 11:39:12 +02:00
|
|
|
doTestGpsShm = false;
|
2022-05-03 00:55:01 +02:00
|
|
|
doTestGpsSocket = false;
|
|
|
|
doTestXadc = false;
|
2021-07-05 12:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t Q7STestTask::performOneShotAction() {
|
2022-01-17 15:58:27 +01:00
|
|
|
if (doTestSdCard) {
|
|
|
|
testSdCard();
|
|
|
|
}
|
|
|
|
if (doTestScratchApi) {
|
|
|
|
testScratchApi();
|
|
|
|
}
|
2022-08-26 00:39:06 +02:00
|
|
|
if (DO_TEST_GOMSPACE_API) {
|
|
|
|
uint8_t p60pdu_node = 3;
|
|
|
|
uint8_t hk_mem[P60PDU_HK_SIZE];
|
|
|
|
param_index_t p60pdu_hk{};
|
|
|
|
p60pdu_hk.physaddr = hk_mem;
|
|
|
|
if (!p60pdu_get_hk(&p60pdu_hk, p60pdu_node, 1000)) {
|
|
|
|
printf("Error getting p60pdu hk\n");
|
|
|
|
} else {
|
|
|
|
param_list(&p60pdu_hk, 1);
|
|
|
|
}
|
2022-08-25 23:22:17 +02:00
|
|
|
}
|
2022-08-26 00:39:06 +02:00
|
|
|
|
2022-08-26 14:28:06 +02:00
|
|
|
if (DO_TEST_GOMSPACE_GET_CONFIG) {
|
|
|
|
uint8_t p60pdu_node = 3;
|
|
|
|
param_index_t requestStruct{};
|
|
|
|
requestStruct.table = p60pdu_config;
|
|
|
|
requestStruct.mem_id = P60PDU_PARAM;
|
|
|
|
uint8_t hk_mem[P60PDU_PARAM_SIZE];
|
|
|
|
requestStruct.count = p60pdu_config_count;
|
|
|
|
requestStruct.size = P60PDU_PARAM_SIZE;
|
|
|
|
requestStruct.physaddr = hk_mem;
|
|
|
|
int result = rparam_get_full_table(&requestStruct, p60pdu_node, P60_PORT_RPARAM,
|
|
|
|
requestStruct.mem_id, 1000);
|
|
|
|
param_list(&requestStruct, 1);
|
|
|
|
return (result == 0);
|
|
|
|
}
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
// testJsonLibDirect();
|
|
|
|
// testDummyParams();
|
2022-05-03 00:55:01 +02:00
|
|
|
if (doTestProtHandler) {
|
|
|
|
testProtHandler();
|
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
FsOpCodes opCode = FsOpCodes::APPEND_TO_FILE;
|
|
|
|
testFileSystemHandlerDirect(opCode);
|
|
|
|
return TestTask::performOneShotAction();
|
2021-07-05 12:09:31 +02:00
|
|
|
}
|
|
|
|
|
2022-01-15 13:05:11 +01:00
|
|
|
ReturnValue_t Q7STestTask::performPeriodicAction() {
|
2022-05-03 00:55:01 +02:00
|
|
|
if (doTestGpsShm) {
|
|
|
|
testGpsDaemonShm();
|
|
|
|
}
|
|
|
|
if (doTestGpsSocket) {
|
|
|
|
testGpsDaemonSocket();
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-13 16:32:40 +01:00
|
|
|
if (doTestXadc) {
|
|
|
|
xadcTest();
|
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
return TestTask::performPeriodicAction();
|
2022-01-15 13:05:11 +01:00
|
|
|
}
|
|
|
|
|
2021-07-19 12:44:43 +02:00
|
|
|
void Q7STestTask::testSdCard() {
|
2022-01-17 15:58:27 +01:00
|
|
|
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<int>(idx) << " is on" << endl;
|
|
|
|
} else if (word == "off") {
|
|
|
|
sif::info << "SD card " << static_cast<int>(idx) << " is off" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
std::remove("/tmp/sd_status.txt");
|
2021-07-05 12:09:31 +02:00
|
|
|
}
|
2021-07-06 18:17:32 +02:00
|
|
|
|
|
|
|
void Q7STestTask::fileTests() {
|
2022-01-17 15:58:27 +01:00
|
|
|
using namespace std;
|
|
|
|
ofstream testFile("/tmp/test.txt");
|
|
|
|
testFile << "Hallo Welt" << endl;
|
|
|
|
testFile.close();
|
2021-07-06 18:17:32 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
system("echo \"Hallo Welt\" > /tmp/test2.txt");
|
|
|
|
system("echo \"Hallo Welt\"");
|
2021-07-06 18:17:32 +02:00
|
|
|
}
|
2021-07-09 17:21:26 +02:00
|
|
|
|
|
|
|
void Q7STestTask::testScratchApi() {
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t result = scratch::writeNumber("TEST", 1);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "Q7STestTask::scratchApiTest: Writing number failed" << std::endl;
|
|
|
|
}
|
|
|
|
int number = 0;
|
|
|
|
result = scratch::readNumber("TEST", number);
|
|
|
|
sif::info << "Q7STestTask::testScratchApi: Value for key \"TEST\": " << number << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "Q7STestTask::scratchApiTest: Reading number failed" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = scratch::writeString("TEST2", "halloWelt");
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "Q7STestTask::scratchApiTest: Writing string failed" << std::endl;
|
|
|
|
}
|
|
|
|
std::string string;
|
|
|
|
result = scratch::readString("TEST2", string);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "Q7STestTask::scratchApiTest: Reading number failed" << std::endl;
|
|
|
|
}
|
|
|
|
sif::info << "Q7STestTask::testScratchApi: Value for key \"TEST2\": " << string << std::endl;
|
|
|
|
|
|
|
|
result = scratch::clearValue("TEST");
|
|
|
|
result = scratch::clearValue("TEST2");
|
2021-07-09 17:21:26 +02:00
|
|
|
}
|
2021-07-16 21:51:30 +02:00
|
|
|
|
|
|
|
void Q7STestTask::testJsonLibDirect() {
|
2022-01-17 15:58:27 +01:00
|
|
|
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::string fileName = mntPrefix + "/pretty.json";
|
|
|
|
std::ofstream o(fileName);
|
|
|
|
o << std::setw(4) << helloTest << std::endl;
|
2021-07-16 21:51:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Q7STestTask::testDummyParams() {
|
2022-01-17 15:58:27 +01:00
|
|
|
std::string mntPrefix = SdCardManager::instance()->getCurrentMountPrefix();
|
|
|
|
DummyParameter param(mntPrefix, "dummy_json.txt");
|
|
|
|
param.printKeys();
|
|
|
|
param.print();
|
|
|
|
if (not param.getJsonFileExists()) {
|
2021-07-16 21:51:30 +02:00
|
|
|
param.writeJsonFile();
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t result = param.readJsonFile();
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
param.setValue(DummyParameter::DUMMY_KEY_PARAM_1, 3);
|
|
|
|
param.setValue(DummyParameter::DUMMY_KEY_PARAM_2, "blirb");
|
|
|
|
|
|
|
|
param.writeJsonFile();
|
|
|
|
param.print();
|
|
|
|
|
|
|
|
int test = 0;
|
2022-03-01 17:54:43 +01:00
|
|
|
result = param.getValue<int>(DummyParameter::DUMMY_KEY_PARAM_1, test);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1
|
2022-05-05 16:55:08 +02:00
|
|
|
<< " does not exist" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
std::string test2;
|
2022-03-01 17:54:43 +01:00
|
|
|
result = param.getValue<std::string>(DummyParameter::DUMMY_KEY_PARAM_2, test2);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1
|
2022-05-05 16:55:08 +02:00
|
|
|
<< " does not exist" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
sif::info << "Test value (3 expected): " << test << std::endl;
|
|
|
|
sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl;
|
2021-07-16 21:51:30 +02:00
|
|
|
}
|
2021-07-19 12:44:43 +02:00
|
|
|
|
2021-08-19 14:16:26 +02:00
|
|
|
ReturnValue_t Q7STestTask::initialize() {
|
2022-01-17 15:58:27 +01:00
|
|
|
coreController = ObjectManager::instance()->get<CoreController>(objects::CORE_CONTROLLER);
|
|
|
|
if (coreController == nullptr) {
|
|
|
|
sif::warning << "Q7STestTask::initialize: Could not retrieve CORE_CONTROLLER object"
|
2022-05-05 16:55:08 +02:00
|
|
|
<< std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
return TestTask::initialize();
|
2021-08-19 14:16:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Q7STestTask::testProtHandler() {
|
2022-01-17 15:58:27 +01:00
|
|
|
bool opPerformed = false;
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
// If any chips are unlocked, lock them here
|
2022-02-25 11:34:42 +01:00
|
|
|
result = coreController->setBootCopyProtection(xsc::Chip::ALL_CHIP, xsc::Copy::ALL_COPY, true,
|
2022-05-05 16:55:08 +02:00
|
|
|
opPerformed, true);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// unlock own copy
|
2022-02-25 11:34:42 +01:00
|
|
|
result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, false,
|
2022-05-05 16:55:08 +02:00
|
|
|
opPerformed, true);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
|
|
|
|
}
|
|
|
|
if (not opPerformed) {
|
|
|
|
sif::warning << "Q7STestTask::testProtHandler: No op performed" << std::endl;
|
|
|
|
}
|
|
|
|
int retval = std::system("print-chip-prot-status.sh");
|
|
|
|
if (retval != 0) {
|
|
|
|
utility::handleSystemError(retval, "Q7STestTask::testProtHandler");
|
|
|
|
}
|
|
|
|
|
|
|
|
// lock own copy
|
2022-02-25 11:34:42 +01:00
|
|
|
result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true,
|
2022-05-05 16:55:08 +02:00
|
|
|
opPerformed, true);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
|
|
|
|
}
|
|
|
|
if (not opPerformed) {
|
|
|
|
sif::warning << "Q7STestTask::testProtHandler: No op performed" << std::endl;
|
|
|
|
}
|
|
|
|
retval = std::system("print-chip-prot-status.sh");
|
|
|
|
if (retval != 0) {
|
|
|
|
utility::handleSystemError(retval, "Q7STestTask::testProtHandler");
|
|
|
|
}
|
|
|
|
|
|
|
|
// unlock specific copy
|
2022-02-25 11:34:42 +01:00
|
|
|
result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, false,
|
2022-05-05 16:55:08 +02:00
|
|
|
opPerformed, true);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
|
|
|
|
}
|
|
|
|
if (not opPerformed) {
|
|
|
|
sif::warning << "Q7STestTask::testProtHandler: No op performed" << std::endl;
|
|
|
|
}
|
|
|
|
retval = std::system("print-chip-prot-status.sh");
|
|
|
|
if (retval != 0) {
|
|
|
|
utility::handleSystemError(retval, "Q7STestTask::testProtHandler");
|
|
|
|
}
|
|
|
|
|
|
|
|
// lock specific copy
|
2022-02-25 11:34:42 +01:00
|
|
|
result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, true,
|
2022-05-05 16:55:08 +02:00
|
|
|
opPerformed, true);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
|
|
|
|
}
|
|
|
|
if (not opPerformed) {
|
|
|
|
sif::warning << "Q7STestTask::testProtHandler: No op performed" << std::endl;
|
|
|
|
}
|
|
|
|
retval = std::system("print-chip-prot-status.sh");
|
|
|
|
if (retval != 0) {
|
|
|
|
utility::handleSystemError(retval, "Q7STestTask::testProtHandler");
|
|
|
|
}
|
2021-08-19 14:16:26 +02:00
|
|
|
}
|
|
|
|
|
2022-05-03 00:55:01 +02:00
|
|
|
void Q7STestTask::testGpsDaemonShm() {
|
|
|
|
gpsmm gpsmm(GPSD_SHARED_MEMORY, "");
|
2022-01-17 15:58:27 +01:00
|
|
|
gps_data_t* gps;
|
|
|
|
gps = gpsmm.read();
|
|
|
|
if (gps == nullptr) {
|
|
|
|
sif::warning << "Q7STestTask: Reading GPS data failed" << std::endl;
|
|
|
|
}
|
|
|
|
sif::info << "-- Q7STestTask: GPS shared memory read test --" << std::endl;
|
2022-04-19 17:47:05 +02:00
|
|
|
#if LIBGPS_VERSION_MINOR <= 17
|
2022-04-18 00:25:33 +02:00
|
|
|
time_t timeRaw = gps->fix.time;
|
2022-04-19 17:47:05 +02:00
|
|
|
#else
|
|
|
|
time_t timeRaw = gps->fix.time.tv_sec;
|
|
|
|
#endif
|
2022-01-17 15:58:27 +01:00
|
|
|
std::tm* time = gmtime(&timeRaw);
|
|
|
|
sif::info << "Time: " << std::put_time(time, "%c %Z") << std::endl;
|
|
|
|
sif::info << "Visible satellites: " << gps->satellites_visible << std::endl;
|
|
|
|
sif::info << "Satellites used: " << gps->satellites_used << std::endl;
|
|
|
|
sif::info << "Fix (0:Not Seen|1:No Fix|2:2D|3:3D): " << gps->fix.mode << std::endl;
|
|
|
|
sif::info << "Latitude: " << gps->fix.latitude << std::endl;
|
|
|
|
sif::info << "Longitude: " << gps->fix.longitude << std::endl;
|
2022-04-19 17:47:05 +02:00
|
|
|
#if LIBGPS_VERSION_MINOR <= 17
|
2022-04-18 00:25:33 +02:00
|
|
|
sif::info << "Altitude(MSL): " << gps->fix.altitude << std::endl;
|
2022-04-19 17:47:05 +02:00
|
|
|
#else
|
|
|
|
sif::info << "Altitude(MSL): " << gps->fix.altMSL << std::endl;
|
|
|
|
#endif
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::info << "Speed(m/s): " << gps->fix.speed << std::endl;
|
2022-01-15 13:05:11 +01:00
|
|
|
}
|
|
|
|
|
2022-05-03 00:55:01 +02:00
|
|
|
void Q7STestTask::testGpsDaemonSocket() {
|
2022-05-05 16:55:08 +02:00
|
|
|
if (gpsmmShmPtr == nullptr) {
|
2022-05-03 11:39:49 +02:00
|
|
|
gpsmmShmPtr = new gpsmm("localhost", DEFAULT_GPSD_PORT);
|
2022-05-03 11:39:12 +02:00
|
|
|
}
|
2022-05-03 00:55:01 +02:00
|
|
|
// The data from the device will generally be read all at once. Therefore, we
|
|
|
|
// can set all field here
|
2022-05-03 11:39:49 +02:00
|
|
|
if (not gpsmmShmPtr->is_open()) {
|
2022-05-03 00:55:01 +02:00
|
|
|
if (gpsNotOpenSwitch) {
|
|
|
|
// Opening failed
|
|
|
|
#if FSFW_VERBOSE_LEVEL >= 1
|
|
|
|
sif::warning << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | "
|
2022-05-05 16:55:08 +02:00
|
|
|
<< "Error " << errno << " | " << gps_errstr(errno) << std::endl;
|
2022-05-03 00:55:01 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
gpsNotOpenSwitch = false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-05-03 11:39:12 +02:00
|
|
|
// Stopwatch watch;
|
2022-05-05 16:55:08 +02:00
|
|
|
gps_data_t* gps = nullptr;
|
2022-05-03 11:39:49 +02:00
|
|
|
gpsmmShmPtr->stream(WATCH_ENABLE | WATCH_JSON);
|
2022-05-05 16:55:08 +02:00
|
|
|
if (not gpsmmShmPtr->waiting(50000000)) {
|
2022-05-03 11:39:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-05-03 11:39:49 +02:00
|
|
|
gps = gpsmmShmPtr->read();
|
2022-05-03 11:39:12 +02:00
|
|
|
if (gps == nullptr) {
|
|
|
|
if (gpsReadFailedSwitch) {
|
|
|
|
gpsReadFailedSwitch = false;
|
2022-05-05 16:55:08 +02:00
|
|
|
sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed" << std::endl;
|
2022-05-03 11:39:12 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (MODE_SET != (MODE_SET & gps->set)) {
|
|
|
|
if (noModeSetCntr >= 0) {
|
|
|
|
noModeSetCntr++;
|
|
|
|
}
|
|
|
|
if (noModeSetCntr == 10) {
|
|
|
|
// TODO: Trigger event here
|
|
|
|
sif::warning << "Q7STestTask::testGpsDaemonSocket: No mode could be "
|
2022-05-05 16:55:08 +02:00
|
|
|
"read for 10 consecutive reads"
|
|
|
|
<< std::endl;
|
2022-05-03 11:39:12 +02:00
|
|
|
noModeSetCntr = -1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
noModeSetCntr = 0;
|
|
|
|
}
|
|
|
|
sif::info << "-- Q7STestTask: GPS socket read test --" << std::endl;
|
2022-05-03 00:55:01 +02:00
|
|
|
#if LIBGPS_VERSION_MINOR <= 17
|
2022-05-03 11:39:12 +02:00
|
|
|
time_t timeRaw = gps->fix.time;
|
2022-05-03 00:55:01 +02:00
|
|
|
#else
|
2022-05-03 11:39:12 +02:00
|
|
|
time_t timeRaw = gps->fix.time.tv_sec;
|
2022-05-03 00:55:01 +02:00
|
|
|
#endif
|
2022-05-03 11:39:12 +02:00
|
|
|
std::tm* time = gmtime(&timeRaw);
|
|
|
|
sif::info << "Time: " << std::put_time(time, "%c %Z") << std::endl;
|
|
|
|
sif::info << "Visible satellites: " << gps->satellites_visible << std::endl;
|
|
|
|
sif::info << "Satellites used: " << gps->satellites_used << std::endl;
|
|
|
|
sif::info << "Fix (0:Not Seen|1:No Fix|2:2D|3:3D): " << gps->fix.mode << std::endl;
|
|
|
|
sif::info << "Latitude: " << gps->fix.latitude << std::endl;
|
|
|
|
sif::info << "Longitude: " << gps->fix.longitude << std::endl;
|
2022-05-03 00:55:01 +02:00
|
|
|
}
|
|
|
|
|
2021-07-19 14:34:03 +02:00
|
|
|
void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
|
2022-01-17 15:58:27 +01:00
|
|
|
auto fsHandler = ObjectManager::instance()->get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER);
|
|
|
|
if (fsHandler == nullptr) {
|
|
|
|
sif::warning << "Q7STestTask::testFileSystemHandlerDirect: No FS handler running.."
|
2022-05-05 16:55:08 +02:00
|
|
|
<< std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
FileSystemHandler::FsCommandCfg cfg = {};
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
// Lambda for common code
|
|
|
|
auto createNonEmptyTmpDir = [&]() {
|
|
|
|
if (not std::filesystem::exists("/tmp/test")) {
|
|
|
|
result = fsHandler->createDirectory("/tmp", "test", false, &cfg);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2021-07-19 19:21:34 +02:00
|
|
|
return result;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2021-07-19 14:34:03 +02:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
// Creating sample files
|
|
|
|
sif::info << "Creating sample files in directory" << std::endl;
|
|
|
|
result = fsHandler->createFile("/tmp/test", "test1.txt", nullptr, 0, &cfg);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
return result;
|
2021-11-25 21:38:13 +01:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
result = fsHandler->createFile("/tmp/test", "test2.txt", nullptr, 0, &cfg);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (opCode) {
|
2022-05-05 16:55:08 +02:00
|
|
|
case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): {
|
|
|
|
// No mount prefix, cause file is created in tmp
|
|
|
|
cfg.useMountPrefix = false;
|
|
|
|
sif::info << "Creating empty file in /tmp folder" << std::endl;
|
|
|
|
// Do not delete file, user can check existence in shell
|
2022-01-17 15:58:27 +01:00
|
|
|
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
|
2022-05-05 16:55:08 +02:00
|
|
|
break;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-05-05 16:55:08 +02:00
|
|
|
case (FsOpCodes::REMOVE_TMP_FILE): {
|
|
|
|
sif::info << "Deleting /tmp/test.txt sample file" << std::endl;
|
|
|
|
// No mount prefix, cause file is created in tmp
|
|
|
|
cfg.useMountPrefix = false;
|
|
|
|
if (not std::filesystem::exists("/tmp/test.txt")) {
|
|
|
|
// Creating sample file
|
|
|
|
sif::info << "Creating sample file /tmp/test.txt to delete" << std::endl;
|
|
|
|
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
|
|
|
|
}
|
|
|
|
result = fsHandler->removeFile("/tmp", "test.txt", &cfg);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-05-05 16:55:08 +02:00
|
|
|
sif::info << "File removed successfully" << std::endl;
|
|
|
|
} else {
|
|
|
|
sif::warning << "File removal failed!" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-05-05 16:55:08 +02:00
|
|
|
case (FsOpCodes::CREATE_DIR_IN_TMP): {
|
|
|
|
// No mount prefix, cause file is created in tmp
|
|
|
|
cfg.useMountPrefix = false;
|
|
|
|
sif::info << "Creating empty file in /tmp folder" << std::endl;
|
|
|
|
// Do not delete file, user can check existence in shell
|
|
|
|
ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-05-05 16:55:08 +02:00
|
|
|
sif::info << "Directory created successfully" << std::endl;
|
|
|
|
} else {
|
|
|
|
sif::warning << "Directory creation failed!" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-05-05 16:55:08 +02:00
|
|
|
case (FsOpCodes::REMOVE_EMPTY_DIR_IN_TMP): {
|
|
|
|
// No mount prefix, cause file is created in tmp
|
|
|
|
cfg.useMountPrefix = false;
|
|
|
|
if (not std::filesystem::exists("/tmp/test")) {
|
|
|
|
result = fsHandler->createDirectory("/tmp", "test", false, &cfg);
|
|
|
|
} else {
|
|
|
|
// Delete any leftover files to regular dir removal works
|
|
|
|
std::remove("/tmp/test/*");
|
|
|
|
}
|
|
|
|
result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-05-05 16:55:08 +02:00
|
|
|
sif::info << "Directory removed successfully" << std::endl;
|
|
|
|
} else {
|
|
|
|
sif::warning << "Directory removal failed!" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-05-05 16:55:08 +02:00
|
|
|
case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): {
|
|
|
|
result = createNonEmptyTmpDir();
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-05-05 16:55:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
result = fsHandler->removeDirectory("/tmp/", "test", true, &cfg);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-05-05 16:55:08 +02:00
|
|
|
sif::info << "Directory removed recursively successfully" << std::endl;
|
|
|
|
} else {
|
|
|
|
sif::warning << "Recursive directory removal failed!" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2022-05-03 11:39:12 +02:00
|
|
|
}
|
2022-05-05 16:55:08 +02:00
|
|
|
case (FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY): {
|
|
|
|
result = createNonEmptyTmpDir();
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-05-05 16:55:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-05-05 16:55:08 +02:00
|
|
|
sif::info << "Directory removal attempt failed as expected" << std::endl;
|
|
|
|
} else {
|
|
|
|
sif::warning << "Directory removal worked when it should not have!" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2022-05-03 11:39:12 +02:00
|
|
|
}
|
2022-05-05 16:55:08 +02:00
|
|
|
case (FsOpCodes::RENAME_FILE): {
|
|
|
|
// No mount prefix, cause file is created in tmp
|
|
|
|
cfg.useMountPrefix = false;
|
|
|
|
if (std::filesystem::exists("/tmp/test.txt")) {
|
|
|
|
fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
|
|
|
|
}
|
|
|
|
sif::info << "Creating empty file /tmp/test.txt and rename to /tmp/test2.txt" << std::endl;
|
|
|
|
// Do not delete file, user can check existence in shell
|
|
|
|
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
|
|
|
|
fsHandler->renameFile("/tmp/", "test.txt", "test2.txt", &cfg);
|
|
|
|
break;
|
2022-05-03 11:39:12 +02:00
|
|
|
}
|
2022-05-05 16:55:08 +02:00
|
|
|
case (FsOpCodes::APPEND_TO_FILE): {
|
|
|
|
// No mount prefix, cause file is created in tmp
|
|
|
|
cfg.useMountPrefix = false;
|
|
|
|
if (std::filesystem::exists("/tmp/test.txt")) {
|
|
|
|
fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
|
|
|
|
}
|
|
|
|
if (std::filesystem::exists("/tmp/test.txt")) {
|
|
|
|
fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
|
|
|
|
}
|
|
|
|
sif::info << "Creating empty file /tmp/test.txt and adding content" << std::endl;
|
|
|
|
std::string content = "Hello World\n";
|
|
|
|
// Do not delete file, user can check existence in shell
|
|
|
|
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
|
|
|
|
fsHandler->appendToFile("/tmp/", "test.txt", reinterpret_cast<const uint8_t*>(content.data()),
|
|
|
|
content.size(), 0, &cfg);
|
2022-05-03 11:39:12 +02:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2021-07-19 12:44:43 +02:00
|
|
|
}
|
2022-03-13 16:32:40 +01:00
|
|
|
|
|
|
|
void Q7STestTask::xadcTest() {
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-03-13 16:32:40 +01:00
|
|
|
float temperature = 0;
|
|
|
|
float vccPint = 0;
|
|
|
|
float vccPaux = 0;
|
|
|
|
float vccInt = 0;
|
|
|
|
float vccAux = 0;
|
|
|
|
float vccBram = 0;
|
|
|
|
float vccOddr = 0;
|
|
|
|
float vrefp = 0;
|
|
|
|
float vrefn = 0;
|
|
|
|
Xadc xadc;
|
|
|
|
result = xadc.getTemperature(temperature);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: Chip Temperature: " << temperature << " °C" << std::endl;
|
|
|
|
}
|
|
|
|
result = xadc.getVccPint(vccPint);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: VCC PS internal: " << vccPint << " mV" << std::endl;
|
|
|
|
}
|
|
|
|
result = xadc.getVccPaux(vccPaux);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: VCC PS auxilliary: " << vccPaux << " mV" << std::endl;
|
|
|
|
}
|
|
|
|
result = xadc.getVccInt(vccInt);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: VCC PL internal: " << vccInt << " mV" << std::endl;
|
|
|
|
}
|
|
|
|
result = xadc.getVccAux(vccAux);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: VCC PL auxilliary: " << vccAux << " mV" << std::endl;
|
|
|
|
}
|
|
|
|
result = xadc.getVccBram(vccBram);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: VCC BRAM: " << vccBram << " mV" << std::endl;
|
|
|
|
}
|
|
|
|
result = xadc.getVccOddr(vccOddr);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: VCC PS I/O DDR : " << vccOddr << " mV" << std::endl;
|
|
|
|
}
|
|
|
|
result = xadc.getVrefp(vrefp);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: Vrefp : " << vrefp << " mV" << std::endl;
|
|
|
|
}
|
|
|
|
result = xadc.getVrefn(vrefn);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-03-13 16:32:40 +01:00
|
|
|
sif::info << "Q7STestTask::xadcTest: Vrefn : " << vrefn << " mV" << std::endl;
|
|
|
|
}
|
|
|
|
}
|