support both SHM and socket read
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
2022-05-03 00:55:01 +02:00
parent c1d754d8ff
commit cce0d5448d
4 changed files with 161 additions and 43 deletions

View File

@ -23,8 +23,9 @@
Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) {
doTestSdCard = false;
doTestScratchApi = false;
doTestGps = false;
doTestXadc = true;
doTestGpsShm = true;
doTestGpsSocket = false;
doTestXadc = false;
}
ReturnValue_t Q7STestTask::performOneShotAction() {
@ -36,15 +37,20 @@ ReturnValue_t Q7STestTask::performOneShotAction() {
}
// testJsonLibDirect();
// testDummyParams();
// testProtHandler();
if (doTestProtHandler) {
testProtHandler();
}
FsOpCodes opCode = FsOpCodes::APPEND_TO_FILE;
testFileSystemHandlerDirect(opCode);
return TestTask::performOneShotAction();
}
ReturnValue_t Q7STestTask::performPeriodicAction() {
if (doTestGps) {
testGpsDaemon();
if (doTestGpsShm) {
testGpsDaemonShm();
}
if (doTestGpsSocket) {
testGpsDaemonSocket();
}
if (doTestXadc) {
xadcTest();
@ -238,8 +244,8 @@ void Q7STestTask::testProtHandler() {
}
}
void Q7STestTask::testGpsDaemon() {
gpsmm gpsmm(GPSD_SHARED_MEMORY, 0);
void Q7STestTask::testGpsDaemonShm() {
gpsmm gpsmm(GPSD_SHARED_MEMORY, "");
gps_data_t* gps;
gps = gpsmm.read();
if (gps == nullptr) {
@ -266,6 +272,90 @@ void Q7STestTask::testGpsDaemon() {
sif::info << "Speed(m/s): " << gps->fix.speed << std::endl;
}
void Q7STestTask::testGpsDaemonSocket() {
gpsmm gpsmm("localhost", DEFAULT_GPSD_PORT);
// The data from the device will generally be read all at once. Therefore, we
// can set all field here
if (not gpsmm.is_open()) {
if (gpsNotOpenSwitch) {
// Opening failed
#if FSFW_VERBOSE_LEVEL >= 1
sif::warning << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | "
<< "Error " << errno << " | " << gps_errstr(errno) << std::endl;
#endif
gpsNotOpenSwitch = false;
}
return;
}
for (;;) {
struct gps_data_t* gps;
if (!gpsmm.waiting(50000000)) continue;
if ((gps = gpsmm.read()) == NULL) {
std::cerr << "Read error.\n";
} else {
sif::info << "-- Q7STestTask: GPS socket read test --" << std::endl;
#if LIBGPS_VERSION_MINOR <= 17
time_t timeRaw = gps->fix.time;
#else
time_t timeRaw = gps->fix.time.tv_sec;
#endif
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;
}
}
// // Stopwatch watch;
// gps_data_t *gps = nullptr;
// gpsmm.stream(WATCH_ENABLE | WATCH_JSON);
// if(not gpsmm.waiting(50000000)) {
// return;
// }
// gps = gpsmm.read();
// if (gps == nullptr) {
// if (gpsReadFailedSwitch) {
// gpsReadFailedSwitch = false;
// sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed"
// << std::endl;
// }
// 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 "
// "read for 10 consecutive reads"
// << std::endl;
// noModeSetCntr = -1;
// }
// return;
// } else {
// noModeSetCntr = 0;
// }
// sif::info << "-- Q7STestTask: GPS socket read test --" << std::endl;
//#if LIBGPS_VERSION_MINOR <= 17
// time_t timeRaw = gps->fix.time;
//#else
// time_t timeRaw = gps->fix.time.tv_sec;
//#endif
// 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;
}
void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
auto fsHandler = ObjectManager::instance()->get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER);
if (fsHandler == nullptr) {