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

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

View File

@ -24,6 +24,8 @@ class GPSHyperionLinuxController : public ExtendedControllerBase {
public:
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,
bool debugHyperionGps = false);
virtual ~GPSHyperionLinuxController();
@ -48,8 +50,10 @@ class GPSHyperionLinuxController : public ExtendedControllerBase {
LocalDataPoolManager& poolManager) override;
ReturnValue_t handleGpsRead(gps_data_t* gps);
private:
GpsPrimaryDataset gpsSet;
ReadModes readMode = ReadModes::SHM;
Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000);
bool modeCommanded = true;
bool timeInit = true;