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

This commit is contained in:
Robin Müller 2022-05-03 00:55:01 +02:00
parent c1d754d8ff
commit cce0d5448d
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 161 additions and 43 deletions

View File

@ -23,8 +23,9 @@
Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) { Q7STestTask::Q7STestTask(object_id_t objectId) : TestTask(objectId) {
doTestSdCard = false; doTestSdCard = false;
doTestScratchApi = false; doTestScratchApi = false;
doTestGps = false; doTestGpsShm = true;
doTestXadc = true; doTestGpsSocket = false;
doTestXadc = false;
} }
ReturnValue_t Q7STestTask::performOneShotAction() { ReturnValue_t Q7STestTask::performOneShotAction() {
@ -36,15 +37,20 @@ ReturnValue_t Q7STestTask::performOneShotAction() {
} }
// testJsonLibDirect(); // testJsonLibDirect();
// testDummyParams(); // testDummyParams();
// testProtHandler(); if (doTestProtHandler) {
testProtHandler();
}
FsOpCodes opCode = FsOpCodes::APPEND_TO_FILE; FsOpCodes opCode = FsOpCodes::APPEND_TO_FILE;
testFileSystemHandlerDirect(opCode); testFileSystemHandlerDirect(opCode);
return TestTask::performOneShotAction(); return TestTask::performOneShotAction();
} }
ReturnValue_t Q7STestTask::performPeriodicAction() { ReturnValue_t Q7STestTask::performPeriodicAction() {
if (doTestGps) { if (doTestGpsShm) {
testGpsDaemon(); testGpsDaemonShm();
}
if (doTestGpsSocket) {
testGpsDaemonSocket();
} }
if (doTestXadc) { if (doTestXadc) {
xadcTest(); xadcTest();
@ -238,8 +244,8 @@ void Q7STestTask::testProtHandler() {
} }
} }
void Q7STestTask::testGpsDaemon() { void Q7STestTask::testGpsDaemonShm() {
gpsmm gpsmm(GPSD_SHARED_MEMORY, 0); gpsmm gpsmm(GPSD_SHARED_MEMORY, "");
gps_data_t* gps; gps_data_t* gps;
gps = gpsmm.read(); gps = gpsmm.read();
if (gps == nullptr) { if (gps == nullptr) {
@ -266,6 +272,90 @@ void Q7STestTask::testGpsDaemon() {
sif::info << "Speed(m/s): " << gps->fix.speed << std::endl; 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) { void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
auto fsHandler = ObjectManager::instance()->get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER); auto fsHandler = ObjectManager::instance()->get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER);
if (fsHandler == nullptr) { if (fsHandler == nullptr) {

View File

@ -14,14 +14,21 @@ class Q7STestTask : public TestTask {
private: private:
bool doTestSdCard = false; bool doTestSdCard = false;
bool doTestScratchApi = false; bool doTestScratchApi = false;
bool doTestGps = false; bool doTestGpsShm = false;
bool doTestGpsSocket = false;
bool doTestProtHandler = false;
bool doTestXadc = false; bool doTestXadc = false;
bool gpsNotOpenSwitch = false;
bool gpsReadFailedSwitch = false;
int32_t noModeSetCntr = 0;
CoreController* coreController = nullptr; CoreController* coreController = nullptr;
ReturnValue_t performOneShotAction() override; ReturnValue_t performOneShotAction() override;
ReturnValue_t performPeriodicAction() override; ReturnValue_t performPeriodicAction() override;
void testGpsDaemon(); void testGpsDaemonShm();
void testGpsDaemonSocket();
void testSdCard(); void testSdCard();
void fileTests(); void fileTests();

View File

@ -109,56 +109,73 @@ ReturnValue_t GPSHyperionLinuxController::handleCommandMessage(CommandMessage *m
#ifdef FSFW_OSAL_LINUX #ifdef FSFW_OSAL_LINUX
void GPSHyperionLinuxController::readGpsDataFromGpsd() { void GPSHyperionLinuxController::readGpsDataFromGpsd() {
gpsmm gpsmm("localhost", DEFAULT_GPSD_PORT); gps_data_t *gps = nullptr;
// The data from the device will generally be read all at once. Therefore, we auto openError = [&](const char *type) {
// can set all field here
if (not gpsmm.is_open()) {
if (gpsNotOpenSwitch) { if (gpsNotOpenSwitch) {
// Opening failed // Opening failed
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM failed | " sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM " << type
<< "Error " << errno << " | " << gps_errstr(errno) << std::endl; << " failed | Error " << errno << " | " << gps_errstr(errno) << std::endl;
#endif #endif
gpsNotOpenSwitch = false; gpsNotOpenSwitch = false;
} }
return; };
} auto readError = [&]() {
// 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) { if (gpsReadFailedSwitch) {
gpsReadFailedSwitch = false; gpsReadFailedSwitch = false;
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed" sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed"
<< std::endl; << std::endl;
} }
return; };
} if (readMode == ReadModes::SOCKET) {
if (MODE_SET != (MODE_SET & gps->set)) { gpsmm gpsmm("localhost", DEFAULT_GPSD_PORT);
if (noModeSetCntr >= 0) { // The data from the device will generally be read all at once. Therefore, we
noModeSetCntr++; // can set all field here
if (not gpsmm.is_open()) {
return openError("Socket");
} }
if (noModeSetCntr == 10) { // Stopwatch watch;
// TODO: Trigger event here gpsmm.stream(WATCH_ENABLE | WATCH_JSON);
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: No mode could be " if (not gpsmm.waiting(50000000)) {
"read for 10 consecutive reads" return;
<< std::endl; }
noModeSetCntr = -1; gps = gpsmm.read();
if (gps == nullptr) {
readError();
return;
}
if (MODE_SET != (MODE_SET & gps->set)) {
if (noModeSetCntr >= 0) {
noModeSetCntr++;
}
if (noModeSetCntr == 10) {
// TODO: Trigger event here
sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: No mode could be "
"read for 10 consecutive reads"
<< std::endl;
noModeSetCntr = -1;
}
return;
} else {
noModeSetCntr = 0;
} }
return;
} else { } else {
noModeSetCntr = 0; gpsmm gpsmm(GPSD_SHARED_MEMORY, "");
if (not gpsmm.is_open()) {
return openError("SHM");
}
gps = gpsmm.read();
if (gps == nullptr) {
readError();
return;
}
}
if (gps != nullptr) {
handleGpsRead(gps);
} }
handleGpsRead(gps);
} }
ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t *gps) {
ReturnValue_t GPSHyperionLinuxController::handleGpsRead(gps_data_t* gps) {
PoolReadGuard pg(&gpsSet); PoolReadGuard pg(&gpsSet);
if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) { if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1

View File

@ -24,6 +24,8 @@ class GPSHyperionLinuxController : public ExtendedControllerBase {
public: public:
static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 60 * 5; static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 60 * 5;
enum ReadModes { SHM = 0, SOCKET = 1 };
GPSHyperionLinuxController(object_id_t objectId, object_id_t parentId, GPSHyperionLinuxController(object_id_t objectId, object_id_t parentId,
bool debugHyperionGps = false); bool debugHyperionGps = false);
virtual ~GPSHyperionLinuxController(); virtual ~GPSHyperionLinuxController();
@ -48,8 +50,10 @@ class GPSHyperionLinuxController : public ExtendedControllerBase {
LocalDataPoolManager& poolManager) override; LocalDataPoolManager& poolManager) override;
ReturnValue_t handleGpsRead(gps_data_t* gps); ReturnValue_t handleGpsRead(gps_data_t* gps);
private: private:
GpsPrimaryDataset gpsSet; GpsPrimaryDataset gpsSet;
ReadModes readMode = ReadModes::SHM;
Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000); Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000);
bool modeCommanded = true; bool modeCommanded = true;
bool timeInit = true; bool timeInit = true;