diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index e1b48fd2..ac5e5292 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -2072,8 +2072,7 @@ ReturnValue_t CoreController::initClockFromTimeFile() { std::string fileName = currMntPrefix + BACKUP_TIME_FILE; std::error_code e; if (sdcMan->isSdCardUsable(std::nullopt) and std::filesystem::exists(fileName, e) and - ((gpsFix == FixMode::UNKNOWN or gpsFix == FixMode::NOT_SEEN) or - not utility::timeSanityCheck())) { + ((gpsFix == FixMode::NOT_SEEN) or not utility::timeSanityCheck())) { ifstream timeFile(fileName); string nextWord; getline(timeFile, nextWord); diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index 79224ed2..78925b9c 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -209,7 +209,7 @@ class CoreController : public ExtendedControllerBase, public ReceivesParameterMe static constexpr MutexIF::TimeoutType TIMEOUT_TYPE = MutexIF::TimeoutType::WAITING; static constexpr uint32_t MUTEX_TIMEOUT = 20; bool enableHkSet = false; - GpsHyperion::FixMode gpsFix = GpsHyperion::FixMode::UNKNOWN; + GpsHyperion::FixMode gpsFix = GpsHyperion::FixMode::NOT_SEEN; // States for SD state machine, which is used in non-blocking mode enum class SdStates { diff --git a/linux/acs/GpsHyperionLinuxController.cpp b/linux/acs/GpsHyperionLinuxController.cpp index a2dbd81b..71967140 100644 --- a/linux/acs/GpsHyperionLinuxController.cpp +++ b/linux/acs/GpsHyperionLinuxController.cpp @@ -58,8 +58,8 @@ ReturnValue_t GpsHyperionLinuxController::checkModeCommand(Mode_t mode, Submode_ PoolReadGuard pg(&gpsSet); gpsSet.setValidity(false, true); // There can't be a fix with a device that is off. - triggerEvent(GpsHyperion::GPS_FIX_CHANGE, gpsSet.fixMode.value, 0); - gpsSet.fixMode.value = 0; + handleFixChangedEvent(GpsHyperion::FixMode::NOT_SEEN); + gpsSet.fixMode.value = GpsHyperion::FixMode::NOT_SEEN; oneShotSwitches.reset(); modeCommanded = false; } @@ -249,11 +249,12 @@ ReturnValue_t GpsHyperionLinuxController::handleCoreTelemetry(bool modeIsSet) { uint8_t newFix = 0; if (modeIsSet) { // 0: Not seen, 1: No fix, 2: 2D-Fix, 3: 3D-Fix - if (gps.fix.mode == 2 or gps.fix.mode == 3) { + if (gps.fix.mode == GpsHyperion::FixMode::FIX_2D or + gps.fix.mode == GpsHyperion::FixMode::FIX_3D) { validFix = true; } newFix = gps.fix.mode; - if (newFix == 0 or newFix == 1) { + if (newFix == GpsHyperion::FixMode::NOT_SEEN or newFix == GpsHyperion::FixMode::NO_FIX) { if (modeCommanded and maxTimeToReachFix.hasTimedOut()) { // We are supposed to be on and functioning, but no fix was found if (mode == MODE_ON or mode == MODE_NORMAL) { @@ -264,9 +265,7 @@ ReturnValue_t GpsHyperionLinuxController::handleCoreTelemetry(bool modeIsSet) { } } if (gpsSet.fixMode.value != newFix) { -#if OBSW_Q7S_EM != 1 - triggerEvent(GpsHyperion::GPS_FIX_CHANGE, gpsSet.fixMode.value, newFix); -#endif + handleFixChangedEvent(newFix); } gpsSet.fixMode = newFix; gpsSet.fixMode.setValid(modeIsSet); @@ -297,7 +296,7 @@ ReturnValue_t GpsHyperionLinuxController::handleCoreTelemetry(bool modeIsSet) { // Negative latitude -> South direction gpsSet.latitude.value = gps.fix.latitude; // As specified in gps.h: Only valid if mode >= 2 - if (gps.fix.mode >= 2) { + if (gps.fix.mode >= GpsHyperion::FixMode::FIX_2D) { latValid = true; } } @@ -306,7 +305,7 @@ ReturnValue_t GpsHyperionLinuxController::handleCoreTelemetry(bool modeIsSet) { // Negative longitude -> West direction gpsSet.longitude.value = gps.fix.longitude; // As specified in gps.h: Only valid if mode >= 2 - if (gps.fix.mode >= 2) { + if (gps.fix.mode >= GpsHyperion::FixMode::FIX_2D) { longValid = true; } } @@ -319,7 +318,7 @@ ReturnValue_t GpsHyperionLinuxController::handleCoreTelemetry(bool modeIsSet) { if (ALTITUDE_SET == (ALTITUDE_SET & gps.set) && std::isfinite(gps.fix.altitude)) { gpsSet.altitude.value = gps.fix.altitude; // As specified in gps.h: Only valid if mode == 3 - if (gps.fix.mode == 3) { + if (gps.fix.mode == GpsHyperion::FixMode::FIX_3D) { altitudeValid = true; } } @@ -430,3 +429,12 @@ void GpsHyperionLinuxController::overwriteTimeIfNotSane(timeval time, bool valid timeInit = true; } } + +void GpsHyperionLinuxController::handleFixChangedEvent(uint8_t newFix) { + if (gainedNewFix.hasTimedOut()) { + triggerEvent(GpsHyperion::GPS_FIX_CHANGE, newFix, fixChangeCounter); + fixChangeCounter = 0; + } + fixChangeCounter++; + gainedNewFix.resetTimer(); +} diff --git a/linux/acs/GpsHyperionLinuxController.h b/linux/acs/GpsHyperionLinuxController.h index 3378ac55..9f63bac5 100644 --- a/linux/acs/GpsHyperionLinuxController.h +++ b/linux/acs/GpsHyperionLinuxController.h @@ -1,14 +1,13 @@ #ifndef MISSION_DEVICES_GPSHYPERIONHANDLER_H_ #define MISSION_DEVICES_GPSHYPERIONHANDLER_H_ +#include +#include +#include +#include #include #include -#include "eive/eventSubsystemIds.h" -#include "fsfw/FSFW.h" -#include "fsfw/controller/ExtendedControllerBase.h" -#include "fsfw/devicehandlers/DeviceHandlerBase.h" - #ifdef FSFW_OSAL_LINUX #include #include @@ -65,6 +64,8 @@ class GpsHyperionLinuxController : public ExtendedControllerBase { const char* currentClientBuf = nullptr; ReadModes readMode = ReadModes::SOCKET; Countdown maxTimeToReachFix = Countdown(MAX_SECONDS_TO_REACH_FIX * 1000); + Countdown gainedNewFix = Countdown(60 * 2 * 1000); + uint32_t fixChangeCounter = 0; bool modeCommanded = false; bool timeInit = false; uint8_t satNotSetCounter = 0; @@ -92,6 +93,8 @@ class GpsHyperionLinuxController : public ExtendedControllerBase { // we set it with the roughly valid time from the GPS. For some reason, NTP might only work // if the time difference between sys time and current time is not too large void overwriteTimeIfNotSane(timeval time, bool validFix); + + void handleFixChangedEvent(uint8_t newFix); }; #endif /* MISSION_DEVICES_GPSHYPERIONHANDLER_H_ */ diff --git a/mission/acs/archive/GPSDefinitions.h b/mission/acs/archive/GPSDefinitions.h index 67169cbc..8feb46a7 100644 --- a/mission/acs/archive/GPSDefinitions.h +++ b/mission/acs/archive/GPSDefinitions.h @@ -7,10 +7,10 @@ namespace GpsHyperion { -enum class FixMode : uint8_t { NOT_SEEN = 0, NO_FIX = 1, FIX_2D = 2, FIX_3D = 3, UNKNOWN = 4 }; +enum FixMode : uint8_t { NOT_SEEN = 0, NO_FIX = 1, FIX_2D = 2, FIX_3D = 3 }; static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::GPS_HANDLER; -//! [EXPORT] : [COMMENT] Fix has changed. P1: Old fix. P2: New fix +//! [EXPORT] : [COMMENT] Fix has changed. P1: New fix. P2: Missed fix changes //! 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 @@ -53,8 +53,6 @@ static constexpr uint8_t SKYVIEW_ENTRIES = 6; static constexpr uint8_t MAX_SATELLITES = 30; -enum GpsFixModes : uint8_t { INVALID = 0, NO_FIX = 1, FIX_2D = 2, FIX_3D = 3 }; - } // namespace GpsHyperion class GpsPrimaryDataset : public StaticLocalDataSet {