diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index b0b7213c..c39caa12 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -8,6 +8,7 @@ #include "fsfw/timemanager/Stopwatch.h" #include "fsfw/version.h" #include "watchdogConf.h" +#include #if OBSW_USE_TMTC_TCP_BRIDGE == 0 #include "fsfw/osal/common/UdpTmTcBridge.h" #else @@ -57,6 +58,16 @@ ReturnValue_t CoreController::handleCommandMessage(CommandMessage *message) { } void CoreController::performControlOperation() { + EventMessage event; + for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == RETURN_OK; + result = eventQueue->receiveMessage(&event)) { + switch (event.getEvent()) { + case(GpsHyperion::GPS_FIX_CHANGE): { + gpsFix = static_cast(event.getParameter2()); + break; + } + } + } performWatchdogControlOperation(); sdStateMachine(); performMountedSdCardOperations(); @@ -91,6 +102,17 @@ ReturnValue_t CoreController::initialize() { sdStateMachine(); triggerEvent(REBOOT_SW, CURRENT_CHIP, CURRENT_COPY); + EventManagerIF* eventManager = ObjectManager::instance()->get( + objects::EVENT_MANAGER); + result = eventManager->registerListener(eventQueue->getId()); + if(result != HasReturnvaluesIF::RETURN_OK) { + sif::warning << "CoreController::initialize: Registering as event listener failed" << std::endl; + } + result = eventManager->subscribeToEvent(this->getCommandQueue(), + event::getEventId(GpsHyperion::GPS_FIX_CHANGE)); + if(result != HasReturnvaluesIF::RETURN_OK) { + sif::warning << "Subscribing for GPS GPS_FIX_CHANGE event failed" << std::endl; + } return ExtendedControllerBase::initialize(); } @@ -1211,6 +1233,7 @@ void CoreController::performMountedSdCardOperations() { doPerformMountedSdCardOps = false; } } + timeFileHandler(); } void CoreController::performRebootFileHandling(bool recreateFile) { @@ -1657,6 +1680,51 @@ void CoreController::setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::C rewriteRebootFile(rebootFile); } +ReturnValue_t CoreController::timeFileHandler() { + if(gpsFix == GpsHyperion::FixMode::FIX_2D or gpsFix == GpsHyperion::FixMode::FIX_3D) { + // It is assumed that the system time is set from the GPS time + timeval currentTime = {}; + ReturnValue_t result = Clock::getClock_timeval(¤tTime); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + std::ofstream timeFile(TIME_FILE); + timeFile << "UNIX SECONDS: " << currentTime.tv_sec; + } + return RETURN_OK; +} + +ReturnValue_t CoreController::initClockFromTimeFile() { + using namespace GpsHyperion; + using namespace std; + if ((gpsFix == FixMode::UNKNOWN or gpsFix == FixMode::NOT_SEEN) and + std::filesystem::exists(TIME_FILE)) { + + ifstream timeFile(TIME_FILE); + string nextWord; + getline(timeFile, nextWord); + istringstream iss(nextWord); + iss >> nextWord; + if(iss.bad() or nextWord != "UNIX") { + return RETURN_FAILED; + } + iss >> nextWord; + if(iss.bad() or nextWord != "SECONDS:") { + return RETURN_FAILED; + } + iss >> nextWord; + timeval currentTime = {}; + char* checkPtr; + currentTime.tv_sec = strtol(nextWord.c_str(), &checkPtr, 10); + if(iss.bad() or *checkPtr) { + return RETURN_FAILED; + } + Clock::setClock(¤tTime); + return RETURN_OK; + } + return RETURN_OK; +} + void CoreController::readHkData() { ReturnValue_t result = RETURN_OK; result = hkSet.read(TIMEOUT_TYPE, MUTEX_TIMEOUT); @@ -1690,3 +1758,9 @@ void CoreController::readHkData() { return; } } + +bool CoreController::isNumber(const std::string& s) +{ + return !s.empty() && std::find_if(s.begin(), + s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end(); +} diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index e31378ef..05ec6315 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -7,6 +7,7 @@ #include #include "CoreDefinitions.h" +#include "mission/devices/devicedefinitions/GPSDefinitions.h" #include "bsp_q7s/memory/SdCardManager.h" #include "events/subsystemIdRanges.h" #include "fsfw/controller/ExtendedControllerBase.h" @@ -53,10 +54,13 @@ class CoreController : public ExtendedControllerBase { static constexpr char CONF_FOLDER[] = "conf"; static constexpr char VERSION_FILE_NAME[] = "version.txt"; static constexpr char REBOOT_FILE_NAME[] = "reboot.txt"; + static constexpr char TIME_FILE_NAME[] = "time.txt"; const std::string VERSION_FILE = "/" + std::string(CONF_FOLDER) + "/" + std::string(VERSION_FILE_NAME); const std::string REBOOT_FILE = "/" + std::string(CONF_FOLDER) + "/" + std::string(REBOOT_FILE_NAME); + const std::string TIME_FILE = + "/" + std::string(CONF_FOLDER) + "/" + std::string(TIME_FILE_NAME); static constexpr ActionId_t LIST_DIRECTORY_INTO_FILE = 0; static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5; @@ -126,6 +130,7 @@ class CoreController : public ExtendedControllerBase { // Designated value for rechecking FIFO open static constexpr int RETRY_FIFO_OPEN = -2; int watchdogFifoFd = 0; + GpsHyperion::FixMode gpsFix = GpsHyperion::FixMode::UNKNOWN; // States for SD state machine, which is used in non-blocking mode enum class SdStates { @@ -151,6 +156,7 @@ class CoreController : public ExtendedControllerBase { static constexpr bool BLOCKING_SD_INIT = false; SdCardManager* sdcMan = nullptr; + MessageQueueIF* eventQueue = nullptr; struct SdInfo { sd::SdCard pref = sd::SdCard::NONE; @@ -192,6 +198,9 @@ class CoreController : public ExtendedControllerBase { ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t* msToReachTheMode); void performMountedSdCardOperations(); ReturnValue_t initVersionFile(); + + ReturnValue_t initClockFromTimeFile(); + ReturnValue_t timeFileHandler(); ReturnValue_t initBootCopy(); ReturnValue_t initWatchdogFifo(); ReturnValue_t initSdCardBlocking(); @@ -226,6 +235,7 @@ class CoreController : public ExtendedControllerBase { bool parseRebootFile(std::string path, RebootFile& file); void rewriteRebootFile(RebootFile file); void readHkData(); + bool isNumber(const std::string& s); }; #endif /* BSP_Q7S_CORE_CORECONTROLLER_H_ */ diff --git a/common/config/commonSubsystemIds.h b/common/config/commonSubsystemIds.h index a93986a1..aa86aae2 100644 --- a/common/config/commonSubsystemIds.h +++ b/common/config/commonSubsystemIds.h @@ -6,24 +6,26 @@ namespace SUBSYSTEM_ID { enum: uint8_t { COMMON_SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE, - PCDU_HANDLER = 108, - HEATER_HANDLER = 109, - SA_DEPL_HANDLER = 110, - PLOC_MPSOC_HANDLER = 111, - IMTQ_HANDLER = 112, - RW_HANDLER = 113, - STR_HANDLER = 114, - PLOC_SUPERVISOR_HANDLER = 115, - FILE_SYSTEM = 116, - PLOC_UPDATER = 117, - PLOC_MEMORY_DUMPER = 118, - PDEC_HANDLER = 119, - STR_HELPER = 120, - PLOC_MPSOC_HELPER = 121, - PL_PCDU_HANDLER = 122, - ACS_BOARD_ASS = 123, - SUS_BOARD_ASS = 124, - TCS_BOARD_ASS = 125, + ACS_SUBSYSTEM = 112, + PCDU_HANDLER = 113, + HEATER_HANDLER = 114, + SA_DEPL_HANDLER = 115, + PLOC_MPSOC_HANDLER = 116, + IMTQ_HANDLER = 117, + RW_HANDLER = 118, + STR_HANDLER = 119, + PLOC_SUPERVISOR_HANDLER = 120, + FILE_SYSTEM = 121, + PLOC_UPDATER = 122, + PLOC_MEMORY_DUMPER = 123, + PDEC_HANDLER = 124, + STR_HELPER = 125, + PLOC_MPSOC_HELPER = 126, + PL_PCDU_HANDLER = 127, + ACS_BOARD_ASS = 128, + SUS_BOARD_ASS = 129, + TCS_BOARD_ASS = 130, + GPS_HANDLER = 131, COMMON_SUBSYSTEM_ID_END }; } diff --git a/fsfw b/fsfw index a11d7455..5bda877d 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit a11d7455dfaf2e736f73f6c4dda1f8c06b9f1234 +Subproject commit 5bda877d97b41e82bf36d939c9f367cef611446a diff --git a/linux/devices/GPSHyperionLinuxController.cpp b/linux/devices/GPSHyperionLinuxController.cpp index 34e02001..6d19d274 100644 --- a/linux/devices/GPSHyperionLinuxController.cpp +++ b/linux/devices/GPSHyperionLinuxController.cpp @@ -132,7 +132,11 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() { } // 0: Not seen, 1: No fix, 2: 2D-Fix, 3: 3D-Fix - gpsSet.fixMode.value = gps->fix.mode; + int newFixMode = gps->fix.mode; + if(gpsSet.fixMode.value != newFixMode) { + triggerEvent(GpsHyperion::GPS_FIX_CHANGE, gpsSet.fixMode.value, newFixMode); + } + gpsSet.fixMode.value = newFixMode; if (gps->fix.mode == 0 or gps->fix.mode == 1) { if (modeCommanded and maxTimeToReachFix.hasTimedOut()) { // We are supposed to be on and functioning, but not fix was found diff --git a/linux/devices/GPSHyperionLinuxController.h b/linux/devices/GPSHyperionLinuxController.h index 46acb5fc..ac8a4735 100644 --- a/linux/devices/GPSHyperionLinuxController.h +++ b/linux/devices/GPSHyperionLinuxController.h @@ -2,6 +2,7 @@ #define MISSION_DEVICES_GPSHYPERIONHANDLER_H_ #include "fsfw/FSFW.h" +#include "commonSubsystemIds.h" #include "fsfw/controller/ExtendedControllerBase.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "mission/devices/devicedefinitions/GPSDefinitions.h" @@ -22,6 +23,8 @@ class GPSHyperionLinuxController : public ExtendedControllerBase { public: static constexpr uint32_t MAX_SECONDS_TO_REACH_FIX = 60 * 60 * 5; + + GPSHyperionLinuxController(object_id_t objectId, object_id_t parentId, bool debugHyperionGps = false); virtual ~GPSHyperionLinuxController(); diff --git a/mission/devices/devicedefinitions/GPSDefinitions.h b/mission/devices/devicedefinitions/GPSDefinitions.h index 5a565fea..bf3fbe52 100644 --- a/mission/devices/devicedefinitions/GPSDefinitions.h +++ b/mission/devices/devicedefinitions/GPSDefinitions.h @@ -6,6 +6,19 @@ namespace GpsHyperion { +enum class FixMode: uint8_t { + NOT_SEEN = 0, + NO_FIX = 1, + FIX_2D = 2, + FIX_3D = 3, + UNKNOWN = 4 +}; + +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); + static constexpr DeviceCommandId_t GPS_REPLY = 0; static constexpr DeviceCommandId_t TRIGGER_RESET_PIN = 5; diff --git a/tmtc b/tmtc index 8f2ff303..25bab108 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 8f2ff3034fff627b807f32c02fd9e676126bae5f +Subproject commit 25bab108df76045e10af2efc26a0397f78574f9c