From 10378ef1bb166365b552cd8f9caa5b670ccaf239 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Feb 2023 13:13:09 +0100 Subject: [PATCH 01/10] bugfix for GPS handler --- bsp_q7s/core/ObjectFactory.cpp | 4 +- linux/ObjectFactory.cpp | 4 +- linux/devices/CMakeLists.txt | 2 +- ...ler.cpp => GpsHyperionLinuxController.cpp} | 70 ++++++++++--------- ...troller.h => GpsHyperionLinuxController.h} | 8 +-- .../devicedefinitions/GPSDefinitions.h | 2 +- tmtc | 2 +- 7 files changed, 49 insertions(+), 43 deletions(-) rename linux/devices/{GPSHyperionLinuxController.cpp => GpsHyperionLinuxController.cpp} (85%) rename linux/devices/{GPSHyperionLinuxController.h => GpsHyperionLinuxController.h} (92%) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 847cce5f..31dedeba 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -23,7 +23,7 @@ #include "linux/boardtest/UartTestClass.h" #include "linux/callbacks/gpioCallbacks.h" #include "linux/csp/CspComIF.h" -#include "linux/devices/GPSHyperionLinuxController.h" +#include "linux/devices/GpsHyperionLinuxController.h" #include "linux/devices/ScexUartReader.h" #include "linux/devices/devicedefinitions/PlocMPSoCDefinitions.h" #include "linux/devices/devicedefinitions/StarTrackerDefinitions.h" @@ -474,7 +474,7 @@ void ObjectFactory::createAcsBoardComponents(LinuxLibgpioIF* gpioComIF, SerialCo RESET_ARGS_GNSS.gpioComIF = gpioComIF; RESET_ARGS_GNSS.waitPeriodMs = 100; auto gpsCtrl = - new GPSHyperionLinuxController(objects::GPS_CONTROLLER, objects::NO_OBJECT, debugGps); + new GpsHyperionLinuxController(objects::GPS_CONTROLLER, objects::NO_OBJECT, debugGps); gpsCtrl->setResetPinTriggerFunction(gps::triggerGpioResetPin, &RESET_ARGS_GNSS); AcsBoardHelper acsBoardHelper = AcsBoardHelper( diff --git a/linux/ObjectFactory.cpp b/linux/ObjectFactory.cpp index cf27972f..469187a6 100644 --- a/linux/ObjectFactory.cpp +++ b/linux/ObjectFactory.cpp @@ -121,8 +121,8 @@ void ObjectFactory::createSunSensorComponents(GpioIF* gpioComIF, SpiComIF* spiCo fdir = new SusFdir(objects::SUS_5_N_LOC_XFYMZB_PT_ZB); susHandlers[5]->setCustomFdir(fdir); - spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, SUS::MAX_CMD_SIZE, spi::SUS_MAX_1227_MODE, - spi::SUS_MAX1227_SPI_FREQ); + spiCookie = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, SUS::MAX_CMD_SIZE, + spi::SUS_MAX_1227_MODE, spi::SUS_MAX1227_SPI_FREQ); susHandlers[6] = new SusHandler(objects::SUS_6_R_LOC_XFYBZM_PT_XF, 6, objects::SPI_MAIN_COM_IF, spiCookie); fdir = new SusFdir(objects::SUS_6_R_LOC_XFYBZM_PT_XF); diff --git a/linux/devices/CMakeLists.txt b/linux/devices/CMakeLists.txt index a6a909d0..4864e01f 100644 --- a/linux/devices/CMakeLists.txt +++ b/linux/devices/CMakeLists.txt @@ -1,5 +1,5 @@ if(EIVE_BUILD_GPSD_GPS_HANDLER) - target_sources(${OBSW_NAME} PRIVATE GPSHyperionLinuxController.cpp) + target_sources(${OBSW_NAME} PRIVATE GpsHyperionLinuxController.cpp) endif() target_sources( diff --git a/linux/devices/GPSHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp similarity index 85% rename from linux/devices/GPSHyperionLinuxController.cpp rename to linux/devices/GpsHyperionLinuxController.cpp index d112d507..e9832854 100644 --- a/linux/devices/GPSHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -1,4 +1,4 @@ -#include "GPSHyperionLinuxController.h" +#include "GpsHyperionLinuxController.h" #include @@ -16,26 +16,26 @@ #include #include -GPSHyperionLinuxController::GPSHyperionLinuxController(object_id_t objectId, object_id_t parentId, +GpsHyperionLinuxController::GpsHyperionLinuxController(object_id_t objectId, object_id_t parentId, bool debugHyperionGps) : ExtendedControllerBase(objectId), gpsSet(this), debugHyperionGps(debugHyperionGps) { timeUpdateCd.resetTimer(); } -GPSHyperionLinuxController::~GPSHyperionLinuxController() { +GpsHyperionLinuxController::~GpsHyperionLinuxController() { gps_stream(&gps, WATCH_DISABLE, nullptr); gps_close(&gps); } -void GPSHyperionLinuxController::performControlOperation() { +void GpsHyperionLinuxController::performControlOperation() { #ifdef FSFW_OSAL_LINUX readGpsDataFromGpsd(); #endif } -LocalPoolDataSetBase *GPSHyperionLinuxController::getDataSetHandle(sid_t sid) { return &gpsSet; } +LocalPoolDataSetBase *GpsHyperionLinuxController::getDataSetHandle(sid_t sid) { return &gpsSet; } -ReturnValue_t GPSHyperionLinuxController::checkModeCommand(Mode_t mode, Submode_t submode, +ReturnValue_t GpsHyperionLinuxController::checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode) { if (not modeCommanded) { if (mode == MODE_ON or mode == MODE_OFF) { @@ -54,7 +54,7 @@ ReturnValue_t GPSHyperionLinuxController::checkModeCommand(Mode_t mode, Submode_ return returnvalue::OK; } -ReturnValue_t GPSHyperionLinuxController::executeAction(ActionId_t actionId, +ReturnValue_t GpsHyperionLinuxController::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t *data, size_t size) { switch (actionId) { @@ -72,7 +72,7 @@ ReturnValue_t GPSHyperionLinuxController::executeAction(ActionId_t actionId, return returnvalue::OK; } -ReturnValue_t GPSHyperionLinuxController::initializeLocalDataPool( +ReturnValue_t GpsHyperionLinuxController::initializeLocalDataPool( localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(GpsHyperion::ALTITUDE, new PoolEntry({0.0})); localDataPoolMap.emplace(GpsHyperion::LONGITUDE, new PoolEntry({0.0})); @@ -92,13 +92,13 @@ ReturnValue_t GPSHyperionLinuxController::initializeLocalDataPool( return returnvalue::OK; } -void GPSHyperionLinuxController::setResetPinTriggerFunction(gpioResetFunction_t resetCallback, +void GpsHyperionLinuxController::setResetPinTriggerFunction(gpioResetFunction_t resetCallback, void *args) { this->resetCallback = resetCallback; resetCallbackArgs = args; } -ReturnValue_t GPSHyperionLinuxController::initialize() { +ReturnValue_t GpsHyperionLinuxController::initialize() { ReturnValue_t result = ExtendedControllerBase::initialize(); if (result != returnvalue::OK) { return result; @@ -127,13 +127,13 @@ ReturnValue_t GPSHyperionLinuxController::initialize() { return result; } -ReturnValue_t GPSHyperionLinuxController::handleCommandMessage(CommandMessage *message) { +ReturnValue_t GpsHyperionLinuxController::handleCommandMessage(CommandMessage *message) { return ExtendedControllerBase::handleCommandMessage(message); } #ifdef FSFW_OSAL_LINUX -void GPSHyperionLinuxController::readGpsDataFromGpsd() { +void GpsHyperionLinuxController::readGpsDataFromGpsd() { auto readError = [&](int error) { if (gpsReadFailedSwitch) { gpsReadFailedSwitch = false; @@ -146,27 +146,33 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() { if (readMode == ReadModes::SOCKET) { gps_stream(&gps, WATCH_ENABLE | WATCH_JSON, nullptr); // Exit if no data is seen in 2 seconds (should not happen) - if (not gps_waiting(&gps, 2000000)) { - return; - } - int result = gps_read(&gps); - if (result == -1) { - readError(result); - return; - } - if (MODE_SET != (MODE_SET & gps.set)) { - if (noModeSetCntr >= 0) { - noModeSetCntr++; + if (gps_waiting(&gps, 2000000)) { + int result = gps_read(&gps); + while (result > 0) { + result = gps_read(&gps); } - 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 (result == -1) { + readError(result); + return; } + 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; + } + // did not event get mode, nothing to see. + return; + } + } + noModeSetCntr = 0; } - noModeSetCntr = 0; } else if (readMode == ReadModes::SHM) { int result = gps_read(&gps); if (result == -1) { @@ -174,10 +180,10 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() { return; } } - handleGpsRead(); + handleGpsReadData(); } -ReturnValue_t GPSHyperionLinuxController::handleGpsRead() { +ReturnValue_t GpsHyperionLinuxController::handleGpsReadData() { PoolReadGuard pg(&gpsSet); if (pg.getReadResult() != returnvalue::OK) { #if FSFW_VERBOSE_LEVEL >= 1 diff --git a/linux/devices/GPSHyperionLinuxController.h b/linux/devices/GpsHyperionLinuxController.h similarity index 92% rename from linux/devices/GPSHyperionLinuxController.h rename to linux/devices/GpsHyperionLinuxController.h index a4c12e57..e0c3dd36 100644 --- a/linux/devices/GPSHyperionLinuxController.h +++ b/linux/devices/GpsHyperionLinuxController.h @@ -20,15 +20,15 @@ * This device handler can only be used on Linux system where the gpsd daemon with shared memory * export is running. */ -class GPSHyperionLinuxController : public ExtendedControllerBase { +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, + GpsHyperionLinuxController(object_id_t objectId, object_id_t parentId, bool debugHyperionGps = false); - virtual ~GPSHyperionLinuxController(); + virtual ~GpsHyperionLinuxController(); using gpioResetFunction_t = ReturnValue_t (*)(const uint8_t* actionData, size_t len, void* args); @@ -49,7 +49,7 @@ class GPSHyperionLinuxController : public ExtendedControllerBase { ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; - ReturnValue_t handleGpsRead(); + ReturnValue_t handleGpsReadData(); private: GpsPrimaryDataset gpsSet; diff --git a/mission/devices/devicedefinitions/GPSDefinitions.h b/mission/devices/devicedefinitions/GPSDefinitions.h index 387d08be..0b88cfa5 100644 --- a/mission/devices/devicedefinitions/GPSDefinitions.h +++ b/mission/devices/devicedefinitions/GPSDefinitions.h @@ -63,7 +63,7 @@ class GpsPrimaryDataset : public StaticLocalDataSet<18> { lp_var_t(sid.objectId, GpsHyperion::UNIX_SECONDS, this); private: - friend class GPSHyperionLinuxController; + friend class GpsHyperionLinuxController; GpsPrimaryDataset(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, GpsHyperion::DATASET_ID) {} }; diff --git a/tmtc b/tmtc index 04f5a769..5e27a22a 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 04f5a769629ae79048f68a37d0555e458c9f9a94 +Subproject commit 5e27a22a85acca321cc4ef5067c01924579d2c1e -- 2.43.0 From fd7709ea81e09a176470bc47a11dc2b9467a7d04 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 09:20:20 +0100 Subject: [PATCH 02/10] bump changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02a48aed..2c843068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ change warranting a new major release: # [unreleased] +## Fixed + +- `GpsHyperionLinuxController`: Fix `gpsd` polling by continuously calling `gps_read` in one cycle + until it does not have any data left anymore. + PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/368 + # [v1.24.0] 2023-02-03 - eive-tmtc v2.10.0 -- 2.43.0 From 4d6215f54624ed37b8b4c12aad04241893f00c39 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 10:20:22 +0100 Subject: [PATCH 03/10] fixes for scheduling --- bsp_q7s/core/scheduling.cpp | 78 ++++++++++---------- linux/devices/GpsHyperionLinuxController.cpp | 39 ++++++---- linux/devices/GpsHyperionLinuxController.h | 6 +- 3 files changed, 68 insertions(+), 55 deletions(-) diff --git a/bsp_q7s/core/scheduling.cpp b/bsp_q7s/core/scheduling.cpp index d8136d3a..d08bb848 100644 --- a/bsp_q7s/core/scheduling.cpp +++ b/bsp_q7s/core/scheduling.cpp @@ -173,54 +173,25 @@ void scheduling::initTasks() { } #endif - PeriodicTaskIF* acsCtrlTask = factory->createPeriodicTask( - "ACS_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.4, missedDeadlineFunc); #if OBSW_ADD_GPS_CTRL == 1 - result = acsCtrlTask->addComponent(objects::GPS_CONTROLLER); + PeriodicTaskIF* gpsTask = factory->createPeriodicTask( + "GPS_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.4, missedDeadlineFunc); + result = gpsTask->addComponent(objects::GPS_CONTROLLER); if (result != returnvalue::OK) { scheduling::printAddObjectError("GPS_CTRL", objects::GPS_CONTROLLER); } #endif /* OBSW_ADD_GPS_CTRL */ + PeriodicTaskIF* acsSysTask = factory->createPeriodicTask( + "SYS_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.4, missedDeadlineFunc); + static_cast(acsSysTask); + // To be removed soon because it will be part of the ACS PST. #if OBSW_ADD_ACS_CTRL == 1 - acsCtrlTask->addComponent(objects::ACS_CONTROLLER); + gpsTask->addComponent(objects::ACS_CONTROLLER); if (result != returnvalue::OK) { scheduling::printAddObjectError("ACS_CTRL", objects::ACS_CONTROLLER); } #endif -#if OBSW_Q7S_EM == 1 - acsCtrlTask->addComponent(objects::MGM_0_LIS3_HANDLER); - acsCtrlTask->addComponent(objects::MGM_1_RM3100_HANDLER); - acsCtrlTask->addComponent(objects::MGM_2_LIS3_HANDLER); - acsCtrlTask->addComponent(objects::MGM_3_RM3100_HANDLER); - acsCtrlTask->addComponent(objects::IMTQ_HANDLER); - acsCtrlTask->addComponent(objects::SUS_0_N_LOC_XFYFZM_PT_XF); - acsCtrlTask->addComponent(objects::SUS_6_R_LOC_XFYBZM_PT_XF); - acsCtrlTask->addComponent(objects::SUS_1_N_LOC_XBYFZM_PT_XB); - acsCtrlTask->addComponent(objects::SUS_7_R_LOC_XBYBZM_PT_XB); - acsCtrlTask->addComponent(objects::SUS_2_N_LOC_XFYBZB_PT_YB); - acsCtrlTask->addComponent(objects::SUS_8_R_LOC_XBYBZB_PT_YB); - acsCtrlTask->addComponent(objects::SUS_3_N_LOC_XFYBZF_PT_YF); - acsCtrlTask->addComponent(objects::SUS_9_R_LOC_XBYBZB_PT_YF); - acsCtrlTask->addComponent(objects::SUS_4_N_LOC_XMYFZF_PT_ZF); - acsCtrlTask->addComponent(objects::SUS_10_N_LOC_XMYBZF_PT_ZF); - acsCtrlTask->addComponent(objects::SUS_5_N_LOC_XFYMZB_PT_ZB); - acsCtrlTask->addComponent(objects::SUS_11_R_LOC_XBYMZB_PT_ZB); - acsCtrlTask->addComponent(objects::GYRO_0_ADIS_HANDLER); - acsCtrlTask->addComponent(objects::GYRO_1_L3G_HANDLER); - acsCtrlTask->addComponent(objects::GYRO_2_ADIS_HANDLER); - acsCtrlTask->addComponent(objects::GYRO_3_L3G_HANDLER); - acsCtrlTask->addComponent(objects::GPS_CONTROLLER); - acsCtrlTask->addComponent(objects::STAR_TRACKER); - acsCtrlTask->addComponent(objects::RW1); - acsCtrlTask->addComponent(objects::RW2); - acsCtrlTask->addComponent(objects::RW3); - acsCtrlTask->addComponent(objects::RW4); -#endif - - PeriodicTaskIF* acsSysTask = factory->createPeriodicTask( - "SYS_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.4, missedDeadlineFunc); - static_cast(acsSysTask); #if OBSW_ADD_ACS_BOARD == 1 result = acsSysTask->addComponent(objects::ACS_BOARD_ASS); if (result != returnvalue::OK) { @@ -244,6 +215,35 @@ void scheduling::initTasks() { scheduling::printAddObjectError("ACS_SUBSYSTEM", objects::ACS_SUBSYSTEM); } +#if OBSW_Q7S_EM == 1 + acsSysTask->addComponent(objects::MGM_0_LIS3_HANDLER); + acsSysTask->addComponent(objects::MGM_1_RM3100_HANDLER); + acsSysTask->addComponent(objects::MGM_2_LIS3_HANDLER); + acsSysTask->addComponent(objects::MGM_3_RM3100_HANDLER); + acsSysTask->addComponent(objects::IMTQ_HANDLER); + acsSysTask->addComponent(objects::SUS_0_N_LOC_XFYFZM_PT_XF); + acsSysTask->addComponent(objects::SUS_6_R_LOC_XFYBZM_PT_XF); + acsSysTask->addComponent(objects::SUS_1_N_LOC_XBYFZM_PT_XB); + acsSysTask->addComponent(objects::SUS_7_R_LOC_XBYBZM_PT_XB); + acsSysTask->addComponent(objects::SUS_2_N_LOC_XFYBZB_PT_YB); + acsSysTask->addComponent(objects::SUS_8_R_LOC_XBYBZB_PT_YB); + acsSysTask->addComponent(objects::SUS_3_N_LOC_XFYBZF_PT_YF); + acsSysTask->addComponent(objects::SUS_9_R_LOC_XBYBZB_PT_YF); + acsSysTask->addComponent(objects::SUS_4_N_LOC_XMYFZF_PT_ZF); + acsSysTask->addComponent(objects::SUS_10_N_LOC_XMYBZF_PT_ZF); + acsSysTask->addComponent(objects::SUS_5_N_LOC_XFYMZB_PT_ZB); + acsSysTask->addComponent(objects::SUS_11_R_LOC_XBYMZB_PT_ZB); + acsSysTask->addComponent(objects::GYRO_0_ADIS_HANDLER); + acsSysTask->addComponent(objects::GYRO_1_L3G_HANDLER); + acsSysTask->addComponent(objects::GYRO_2_ADIS_HANDLER); + acsSysTask->addComponent(objects::GYRO_3_L3G_HANDLER); + acsSysTask->addComponent(objects::GPS_CONTROLLER); + acsSysTask->addComponent(objects::STAR_TRACKER); + acsSysTask->addComponent(objects::RW1); + acsSysTask->addComponent(objects::RW2); + acsSysTask->addComponent(objects::RW3); + acsSysTask->addComponent(objects::RW4); +#endif #if OBSW_ADD_RTD_DEVICES == 1 PeriodicTaskIF* tcsPollingTask = factory->createPeriodicTask( "TCS_POLLING_TASK", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.5, missedDeadlineFunc); @@ -414,7 +414,9 @@ void scheduling::initTasks() { strHelperTask->startTask(); #endif /* OBSW_ADD_STAR_TRACKER == 1 */ - acsCtrlTask->startTask(); +#if OBSW_ADD_GPS_CTRL == 1 + gpsTask->startTask(); +#endif acsSysTask->startTask(); #if OBSW_ADD_RTD_DEVICES == 1 tcsPollingTask->startTask(); diff --git a/linux/devices/GpsHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp index e9832854..9f3ebbbd 100644 --- a/linux/devices/GpsHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -27,12 +27,6 @@ GpsHyperionLinuxController::~GpsHyperionLinuxController() { gps_close(&gps); } -void GpsHyperionLinuxController::performControlOperation() { -#ifdef FSFW_OSAL_LINUX - readGpsDataFromGpsd(); -#endif -} - LocalPoolDataSetBase *GpsHyperionLinuxController::getDataSetHandle(sid_t sid) { return &gpsSet; } ReturnValue_t GpsHyperionLinuxController::checkModeCommand(Mode_t mode, Submode_t submode, @@ -98,6 +92,18 @@ void GpsHyperionLinuxController::setResetPinTriggerFunction(gpioResetFunction_t resetCallbackArgs = args; } +ReturnValue_t GpsHyperionLinuxController::performOperation(uint8_t opCode) { + while (true) { + bool noDataRead = readGpsDataFromGpsd(); + if (noDataRead) { + handleQueue(); + poolManager.performHkOperation(); + } + } + // Should never be reached. + return returnvalue::OK; +} + ReturnValue_t GpsHyperionLinuxController::initialize() { ReturnValue_t result = ExtendedControllerBase::initialize(); if (result != returnvalue::OK) { @@ -133,7 +139,7 @@ ReturnValue_t GpsHyperionLinuxController::handleCommandMessage(CommandMessage *m #ifdef FSFW_OSAL_LINUX -void GpsHyperionLinuxController::readGpsDataFromGpsd() { +bool GpsHyperionLinuxController::readGpsDataFromGpsd() { auto readError = [&](int error) { if (gpsReadFailedSwitch) { gpsReadFailedSwitch = false; @@ -145,15 +151,15 @@ void GpsHyperionLinuxController::readGpsDataFromGpsd() { currentClientBuf = gps_data(&gps); if (readMode == ReadModes::SOCKET) { gps_stream(&gps, WATCH_ENABLE | WATCH_JSON, nullptr); - // Exit if no data is seen in 2 seconds (should not happen) - if (gps_waiting(&gps, 2000000)) { + // Perform other necessary handling if not data seen for 0.2 seconds. + if (gps_waiting(&gps, 200000)) { int result = gps_read(&gps); while (result > 0) { result = gps_read(&gps); } if (result == -1) { readError(result); - return; + return false; } if (MODE_SET != (MODE_SET & gps.set)) { if (mode == MODE_ON) { @@ -168,19 +174,20 @@ void GpsHyperionLinuxController::readGpsDataFromGpsd() { noModeSetCntr = -1; } // did not event get mode, nothing to see. - return; + return false; } } noModeSetCntr = 0; + } else { + return false; } } else if (readMode == ReadModes::SHM) { - int result = gps_read(&gps); - if (result == -1) { - readError(result); - return; - } + sif::error << "GpsHyperionLinuxController::readGpsDataFromGpsdPermanentLoop: " + "SHM read not implemented" + << std::endl; } handleGpsReadData(); + return true; } ReturnValue_t GpsHyperionLinuxController::handleGpsReadData() { diff --git a/linux/devices/GpsHyperionLinuxController.h b/linux/devices/GpsHyperionLinuxController.h index e0c3dd36..829857b2 100644 --- a/linux/devices/GpsHyperionLinuxController.h +++ b/linux/devices/GpsHyperionLinuxController.h @@ -32,6 +32,7 @@ class GpsHyperionLinuxController : public ExtendedControllerBase { using gpioResetFunction_t = ReturnValue_t (*)(const uint8_t* actionData, size_t len, void* args); + ReturnValue_t performOperation(uint8_t opCode) override; void setResetPinTriggerFunction(gpioResetFunction_t resetCallback, void* args); ReturnValue_t handleCommandMessage(CommandMessage* message) override; void performControlOperation() override; @@ -66,7 +67,10 @@ class GpsHyperionLinuxController : public ExtendedControllerBase { uint32_t timeIsConstantCounter = 0; Countdown timeUpdateCd = Countdown(60); - void readGpsDataFromGpsd(); + // Returns true if data was read and function should be called again + // immediately, and false if the gps_waiting blocked for 0.2 seconds + // without new data arriving. + bool readGpsDataFromGpsd(); }; #endif /* MISSION_DEVICES_GPSHYPERIONHANDLER_H_ */ -- 2.43.0 From c49580ea5166183e0cf76b662666e430884edbf3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 10:22:28 +0100 Subject: [PATCH 04/10] bump changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c843068..c22dd4ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,8 @@ change warranting a new major release: ## Fixed - `GpsHyperionLinuxController`: Fix `gpsd` polling by continuously calling `gps_read` in one cycle - until it does not have any data left anymore. + until it does not have any data left anymore. Also, the data is now polled in a permanenty loop, + where controller handling is done on 0.2 second timeouts. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/368 # [v1.24.0] 2023-02-03 -- 2.43.0 From 4d6d4dd44d59f4c364a55dfe001ad2f4ada23416 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 10:24:13 +0100 Subject: [PATCH 05/10] small tweak --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c22dd4ce..fdd57f46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ change warranting a new major release: ## Fixed - `GpsHyperionLinuxController`: Fix `gpsd` polling by continuously calling `gps_read` in one cycle - until it does not have any data left anymore. Also, the data is now polled in a permanenty loop, + until it does not have any data left anymore. Also, the data is now polled in a permanent loop, where controller handling is done on 0.2 second timeouts. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/368 -- 2.43.0 From 1a4dbce3503f68354d1fc8e24d56a3ecb776305b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 10:30:17 +0100 Subject: [PATCH 06/10] tweaks and logic fixes --- linux/devices/GpsHyperionLinuxController.cpp | 10 ++++------ linux/devices/GpsHyperionLinuxController.h | 5 ++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/linux/devices/GpsHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp index 9f3ebbbd..e557f5c2 100644 --- a/linux/devices/GpsHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -94,8 +94,8 @@ void GpsHyperionLinuxController::setResetPinTriggerFunction(gpioResetFunction_t ReturnValue_t GpsHyperionLinuxController::performOperation(uint8_t opCode) { while (true) { - bool noDataRead = readGpsDataFromGpsd(); - if (noDataRead) { + bool callAgain = readGpsDataFromGpsd(); + if (not callAgain) { handleQueue(); poolManager.performHkOperation(); } @@ -137,7 +137,7 @@ ReturnValue_t GpsHyperionLinuxController::handleCommandMessage(CommandMessage *m return ExtendedControllerBase::handleCommandMessage(message); } -#ifdef FSFW_OSAL_LINUX +void GpsHyperionLinuxController::performControlOperation() {} bool GpsHyperionLinuxController::readGpsDataFromGpsd() { auto readError = [&](int error) { @@ -159,7 +159,7 @@ bool GpsHyperionLinuxController::readGpsDataFromGpsd() { } if (result == -1) { readError(result); - return false; + return true; } if (MODE_SET != (MODE_SET & gps.set)) { if (mode == MODE_ON) { @@ -327,5 +327,3 @@ ReturnValue_t GpsHyperionLinuxController::handleGpsReadData() { } return returnvalue::OK; } - -#endif diff --git a/linux/devices/GpsHyperionLinuxController.h b/linux/devices/GpsHyperionLinuxController.h index 829857b2..d2dc91b6 100644 --- a/linux/devices/GpsHyperionLinuxController.h +++ b/linux/devices/GpsHyperionLinuxController.h @@ -67,9 +67,8 @@ class GpsHyperionLinuxController : public ExtendedControllerBase { uint32_t timeIsConstantCounter = 0; Countdown timeUpdateCd = Countdown(60); - // Returns true if data was read and function should be called again - // immediately, and false if the gps_waiting blocked for 0.2 seconds - // without new data arriving. + // Returns true if the function should be called again or false if other + // controller handling can be done. bool readGpsDataFromGpsd(); }; -- 2.43.0 From ee01b6253e1aef58d45c4ca882b0029cba30b5cf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 10:39:19 +0100 Subject: [PATCH 07/10] small logic tweak --- linux/devices/GpsHyperionLinuxController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/devices/GpsHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp index e557f5c2..c1760e98 100644 --- a/linux/devices/GpsHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -159,7 +159,7 @@ bool GpsHyperionLinuxController::readGpsDataFromGpsd() { } if (result == -1) { readError(result); - return true; + return false; } if (MODE_SET != (MODE_SET & gps.set)) { if (mode == MODE_ON) { -- 2.43.0 From 67835dd7f7dc1051902e85e758f41d0110d2de90 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 10:40:09 +0100 Subject: [PATCH 08/10] one regular cycle before permanent loop --- linux/devices/GpsHyperionLinuxController.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux/devices/GpsHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp index c1760e98..44038a09 100644 --- a/linux/devices/GpsHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -93,6 +93,8 @@ void GpsHyperionLinuxController::setResetPinTriggerFunction(gpioResetFunction_t } ReturnValue_t GpsHyperionLinuxController::performOperation(uint8_t opCode) { + handleQueue(); + poolManager.performHkOperation(); while (true) { bool callAgain = readGpsDataFromGpsd(); if (not callAgain) { -- 2.43.0 From 9d7291eea2ceb8f93c33a9b2bd783c6c5c403437 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 18:12:41 +0100 Subject: [PATCH 09/10] this works now --- linux/devices/GpsHyperionLinuxController.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/linux/devices/GpsHyperionLinuxController.cpp b/linux/devices/GpsHyperionLinuxController.cpp index 44038a09..6bbbcfb7 100644 --- a/linux/devices/GpsHyperionLinuxController.cpp +++ b/linux/devices/GpsHyperionLinuxController.cpp @@ -1,5 +1,6 @@ #include "GpsHyperionLinuxController.h" +#include #include #include "OBSWConfig.h" @@ -96,8 +97,8 @@ ReturnValue_t GpsHyperionLinuxController::performOperation(uint8_t opCode) { handleQueue(); poolManager.performHkOperation(); while (true) { - bool callAgain = readGpsDataFromGpsd(); - if (not callAgain) { + bool callAgainImmediately = readGpsDataFromGpsd(); + if (not callAgainImmediately) { handleQueue(); poolManager.performHkOperation(); } @@ -126,6 +127,7 @@ ReturnValue_t GpsHyperionLinuxController::initialize() { if (retval != 0) { openError("Socket", retval); } + gps_stream(&gps, WATCH_ENABLE | WATCH_JSON, nullptr); } else if (readMode == ReadModes::SHM) { int retval = gps_open(GPSD_SHARED_MEMORY, "", &gps); if (retval != 0) { @@ -142,25 +144,19 @@ ReturnValue_t GpsHyperionLinuxController::handleCommandMessage(CommandMessage *m void GpsHyperionLinuxController::performControlOperation() {} bool GpsHyperionLinuxController::readGpsDataFromGpsd() { - auto readError = [&](int error) { + auto readError = [&]() { if (gpsReadFailedSwitch) { gpsReadFailedSwitch = false; sif::warning << "GPSHyperionHandler::readGpsDataFromGpsd: Reading GPS data failed | " "Error " - << error << " | " << gps_errstr(error) << std::endl; + << errno << " | " << gps_errstr(errno) << std::endl; } }; - currentClientBuf = gps_data(&gps); if (readMode == ReadModes::SOCKET) { - gps_stream(&gps, WATCH_ENABLE | WATCH_JSON, nullptr); // Perform other necessary handling if not data seen for 0.2 seconds. if (gps_waiting(&gps, 200000)) { - int result = gps_read(&gps); - while (result > 0) { - result = gps_read(&gps); - } - if (result == -1) { - readError(result); + if (-1 == gps_read(&gps)) { + readError(); return false; } if (MODE_SET != (MODE_SET & gps.set)) { -- 2.43.0 From 86babcf07b9521b84fd9d139cb63feacb1b8a680 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Feb 2023 18:23:04 +0100 Subject: [PATCH 10/10] important fix --- bsp_q7s/core/scheduling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp_q7s/core/scheduling.cpp b/bsp_q7s/core/scheduling.cpp index d08bb848..43c50c02 100644 --- a/bsp_q7s/core/scheduling.cpp +++ b/bsp_q7s/core/scheduling.cpp @@ -187,7 +187,7 @@ void scheduling::initTasks() { static_cast(acsSysTask); // To be removed soon because it will be part of the ACS PST. #if OBSW_ADD_ACS_CTRL == 1 - gpsTask->addComponent(objects::ACS_CONTROLLER); + acsSysTask->addComponent(objects::ACS_CONTROLLER); if (result != returnvalue::OK) { scheduling::printAddObjectError("ACS_CTRL", objects::ACS_CONTROLLER); } -- 2.43.0