diff --git a/linux/devices/GpsHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp index aa55b696..ee5f2321 100644 --- a/linux/devices/GpsHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -34,7 +34,6 @@ ReturnValue_t GpsHyperionLinuxController::checkModeCommand(Mode_t mode, Submode_ uint32_t *msToReachTheMode) { if (not modeCommanded) { if (mode == MODE_ON or mode == MODE_OFF) { - gpsNotOpenSwitch = true; // 5h time to reach fix *msToReachTheMode = MAX_SECONDS_TO_REACH_FIX; maxTimeToReachFix.resetTimer(); @@ -46,6 +45,7 @@ ReturnValue_t GpsHyperionLinuxController::checkModeCommand(Mode_t mode, Submode_ if (mode == MODE_OFF) { PoolReadGuard pg(&gpsSet); gpsSet.setValidity(false, true); + oneShotSwitches.reset(); } return returnvalue::OK; } @@ -102,7 +102,6 @@ ReturnValue_t GpsHyperionLinuxController::performOperation(uint8_t opCode) { if (not callAgainImmediately) { handleQueue(); poolManager.performHkOperation(); - TaskFactory::delayTask(200); } } // Should never be reached. @@ -115,25 +114,24 @@ ReturnValue_t GpsHyperionLinuxController::initialize() { return result; } auto openError = [&](const char *type, int error) { - if (gpsNotOpenSwitch) { - // Opening failed + // Opening failed #if FSFW_VERBOSE_LEVEL >= 1 - sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM " << type - << " failed | Error " << error << " | " << gps_errstr(error) << std::endl; + sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Opening GPSMM " << type + << " failed | Error " << error << " | " << gps_errstr(error) << std::endl; #endif - gpsNotOpenSwitch = false; - } }; if (readMode == ReadModes::SOCKET) { int retval = gps_open("localhost", DEFAULT_GPSD_PORT, &gps); if (retval != 0) { openError("Socket", retval); + return ObjectManager::CHILD_INIT_FAILED; } gps_stream(&gps, WATCH_ENABLE | WATCH_JSON, nullptr); } else if (readMode == ReadModes::SHM) { int retval = gps_open(GPSD_SHARED_MEMORY, "", &gps); if (retval != 0) { openError("SHM", retval); + return ObjectManager::CHILD_INIT_FAILED; } } return result; @@ -147,8 +145,8 @@ void GpsHyperionLinuxController::performControlOperation() {} bool GpsHyperionLinuxController::readGpsDataFromGpsd() { auto readError = [&]() { - if (gpsReadFailedSwitch) { - gpsReadFailedSwitch = false; + if (oneShotSwitches.gpsReadFailedSwitch) { + oneShotSwitches.gpsReadFailedSwitch = false; sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed | " "Error " << errno << " | " << gps_errstr(errno) << std::endl; @@ -156,23 +154,21 @@ bool GpsHyperionLinuxController::readGpsDataFromGpsd() { }; if (readMode == ReadModes::SOCKET) { // Perform other necessary handling if not data seen for 0.2 seconds. - if (gps_waiting(&gps, 0)) { + if (gps_waiting(&gps, 200000)) { if (-1 == gps_read(&gps)) { readError(); return false; } + oneShotSwitches.gpsReadFailedSwitch = true; if (MODE_SET != (MODE_SET & gps.set)) { - if (mode == MODE_ON) { - 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; - } + if (mode != MODE_OFF and maxTimeToReachFix.hasTimedOut() and + oneShotSwitches.cantGetFixSwitch) { + // TODO: Trigger event here + sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: No mode could be " + "read for 10 consecutive reads" + << std::endl; + triggerEvent(GpsHyperion::CANT_GET_FIX, maxTimeToReachFix.timeout); + oneShotSwitches.cantGetFixSwitch = false; // did not event get mode, nothing to see. return false; } diff --git a/linux/devices/GpsHyperionLinuxController.h b/linux/devices/GpsHyperionLinuxController.h index 5b0a84cd..5d4a35ff 100644 --- a/linux/devices/GpsHyperionLinuxController.h +++ b/linux/devices/GpsHyperionLinuxController.h @@ -58,10 +58,19 @@ class GpsHyperionLinuxController : public ExtendedControllerBase { const char* currentClientBuf = nullptr; ReadModes readMode = ReadModes::SOCKET; Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000); - bool modeCommanded = true; + bool modeCommanded = false; bool timeInit = false; - bool gpsNotOpenSwitch = true; - bool gpsReadFailedSwitch = true; + + struct OneShotSwitches { + void reset() { + gpsReadFailedSwitch = true; + cantGetFixSwitch = true; + } + bool gpsReadFailedSwitch = true; + bool cantGetFixSwitch = true; + + } oneShotSwitches; + bool debugHyperionGps = false; int32_t noModeSetCntr = 0; Countdown timeUpdateCd = Countdown(60); diff --git a/mission/devices/devicedefinitions/GPSDefinitions.h b/mission/devices/devicedefinitions/GPSDefinitions.h index 0b88cfa5..2ac7781d 100644 --- a/mission/devices/devicedefinitions/GPSDefinitions.h +++ b/mission/devices/devicedefinitions/GPSDefinitions.h @@ -13,6 +13,9 @@ static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::GPS_HANDLER; //! [EXPORT] : [COMMENT] Fix has changed. P1: Old fix. P2: New fix //! 0: Not seen, 1: No Fix, 2: 2D-Fix, 3: 3D-Fix static constexpr Event GPS_FIX_CHANGE = event::makeEvent(SUBSYSTEM_ID, 0, severity::INFO); +//! [EXPORT] : [COMMENT] Could not get fix in maximum allowed time. P1: Maximum allowed time +//! to get a fix after the GPS was switched on. +static constexpr Event CANT_GET_FIX = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW); static constexpr DeviceCommandId_t GPS_REPLY = 0; static constexpr DeviceCommandId_t TRIGGER_RESET_PIN_GNSS = 5;