From 7f74cca11ff165964fa490fa9467689d666143de Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 17 Feb 2023 11:50:14 +0100 Subject: [PATCH] add more mode support for heaters --- CHANGELOG.md | 8 +++- mission/controller/ThermalController.cpp | 2 +- mission/controller/ThermalController.h | 7 ++-- mission/devices/HeaterHandler.cpp | 49 ++++++++++++++++++++++++ mission/devices/HeaterHandler.h | 21 ++++++++++ 5 files changed, 81 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06289802..73088716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,13 +17,17 @@ change warranting a new major release: # [unreleased] -<<<<<<< HEAD ## Added - Added new heater info set for the TCS controller. This set contains the heater switch states and the current draw. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/351 -======= +- The HeaterHandler now exposes a mode which reflects whether the heater power + is on or off. It also triggers mode events for its heater children objects + which show whether the specific heaters are on or off. The heater handler + will be part of the TCS tree. + PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/351 + # [v1.28.0] 2023-02-17 eive-tmtc: v2.12.7 diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index cdb14fab..71137668 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -22,7 +22,7 @@ ThermalController::ThermalController(object_id_t objectId, HeaterHandler& heater susTemperatures(this), deviceTemperatures(this), heaterInfo(this), - imtqThermalSet(objects::IMTQ_HANDLER), + imtqThermalSet(objects::IMTQ_HANDLER, ThermalStateCfg()), max31865Set0(objects::RTD_0_IC3_PLOC_HEATSPREADER, EiveMax31855::RtdCommands::EXCHANGE_SET_ID), max31865Set1(objects::RTD_1_IC4_PLOC_MISSIONBOARD, diff --git a/mission/controller/ThermalController.h b/mission/controller/ThermalController.h index 542b8913..122ae8f6 100644 --- a/mission/controller/ThermalController.h +++ b/mission/controller/ThermalController.h @@ -9,11 +9,12 @@ #include #include -#include "mission/devices/devicedefinitions/GomspaceDefinitions.h" -#include "mission/devices/HeaterHandler.h" -#include "mission/trace.h" #include +#include "mission/devices/HeaterHandler.h" +#include "mission/devices/devicedefinitions/GomspaceDefinitions.h" +#include "mission/trace.h" + /** * NOP Limit: Hard limit for device, usually from datasheet. Device damage is possible lif NOP limit * is exceeded. diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 43f53bf7..06beb0bc 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -8,11 +8,13 @@ #include #include "devices/powerSwitcherList.h" +#include "fsfw/subsystem/helper.h" HeaterHandler::HeaterHandler(object_id_t setObjectId_, GpioIF* gpioInterface_, HeaterHelper helper, PowerSwitchIF* mainLineSwitcher_, power::Switch_t mainLineSwitch_) : SystemObject(setObjectId_), helper(helper), + modeHelper(this), gpioInterface(gpioInterface_), mainLineSwitcher(mainLineSwitcher_), mainLineSwitch(mainLineSwitch_), @@ -46,6 +48,12 @@ ReturnValue_t HeaterHandler::performOperation(uint8_t operationCode) { heater.first->performOperation(0); } handleSwitchHandling(); + if (waitForSwitchOff) { + if (mainLineSwitcher->getSwitchState(mainLineSwitch) == SWITCH_OFF) { + waitForSwitchOff = false; + mode = MODE_OFF; + } + } } catch (const std::out_of_range& e) { sif::warning << "HeaterHandler::performOperation: " "Out of range error | " @@ -76,6 +84,10 @@ ReturnValue_t HeaterHandler::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } + result = modeHelper.initialize(); + if (result != returnvalue::OK) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } return returnvalue::OK; } @@ -218,6 +230,9 @@ void HeaterHandler::handleSwitchHandling() { void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) { ReturnValue_t result = returnvalue::OK; auto& heater = heaterVec.at(heaterIdx); + if (waitForSwitchOff) { + waitForSwitchOff = false; + } /* Check if command waits for main switch being set on and whether the timeout has expired */ if (heater.waitMainSwitchOn && heater.mainSwitchCountdown.hasTimedOut()) { // TODO - This requires the initiation of an FDIR procedure @@ -235,6 +250,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) { // Check state of main line switch ReturnValue_t mainSwitchState = mainLineSwitcher->getSwitchState(mainLineSwitch); if (mainSwitchState == PowerSwitchIF::SWITCH_ON) { + mode = HasModesIF::MODE_ON; if (checkSwitchState(heaterIdx) == SwitchState::OFF) { gpioId_t gpioId = heater.gpioId; result = gpioInterface->pullHigh(gpioId); @@ -298,6 +314,7 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) { // When all switches are off, also main line switch will be turned off if (allSwitchesOff()) { mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF); + waitForSwitchOff = true; } } } else { @@ -329,6 +346,38 @@ ReturnValue_t HeaterHandler::switchHeater(heater::Switchers heater, SwitchState return returnvalue::FAILED; } +void HeaterHandler::announceMode(bool recursive) { + triggerEvent(MODE_INFO, mode, submode); + for (unsigned idx = 0; idx < helper.heaters.size(); idx++) { + if (heaterVec[idx].switchState == SWITCH_ON) { + EventManagerIF::triggerEvent(helper.heaters[idx].first->getObjectId(), MODE_INFO, MODE_ON, 0); + } else { + EventManagerIF::triggerEvent(helper.heaters[idx].first->getObjectId(), MODE_INFO, MODE_OFF, + 0); + } + } +} + +void HeaterHandler::getMode(Mode_t* mode, Submode_t* submode) { + if (!mode || !submode) { + return; + } + *mode = this->mode; + *submode = this->submode; +} + +const HasHealthIF* HeaterHandler::getOptHealthIF() const { return nullptr; } + +const HasModesIF& HeaterHandler::getModeIF() const { return *this; } + +ReturnValue_t HeaterHandler::connectModeTreeParent(HasModeTreeChildrenIF& parent) { + return modetree::connectModeTreeParent(parent, *this, nullptr, modeHelper); +} + +ModeTreeChildIF& HeaterHandler::getModeTreeChildIF() { return *this; } + +object_id_t HeaterHandler::getObjectId() const { return SystemObject::getObjectId(); } + bool HeaterHandler::allSwitchesOff() { bool allSwitchesOrd = false; MutexGuard mg(heaterMutex); diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index ac4f94f4..ac856d9c 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -40,6 +42,9 @@ struct HeaterHelper { */ class HeaterHandler : public ExecutableObjectIF, public PowerSwitchIF, + public HasModesIF, + public ModeTreeChildIF, + public ModeTreeConnectionIF, public SystemObject, public HasActionsIF { friend class ThermalController; @@ -131,9 +136,11 @@ class HeaterHandler : public ExecutableObjectIF, MutexIF* heaterMutex = nullptr; HeaterHelper helper; + ModeHelper modeHelper; /** Size of command queue */ size_t cmdQueueSize = 20; + bool waitForSwitchOff = true; GpioIF* gpioInterface = nullptr; @@ -152,6 +159,9 @@ class HeaterHandler : public ExecutableObjectIF, StorageManagerIF* ipcStore = nullptr; + Mode_t mode = HasModesIF::MODE_OFF; + Submode_t submode = 0; + void readCommandQueue(); /** @@ -172,6 +182,17 @@ class HeaterHandler : public ExecutableObjectIF, */ void setInitialSwitchStates(); + // HasModesIF implementation + void announceMode(bool recursive) override; + void getMode(Mode_t* mode, Submode_t* submode) override; + + // Mode Tree helper overrides + object_id_t getObjectId() const override; + const HasHealthIF* getOptHealthIF() const override; + const HasModesIF& getModeIF() const override; + ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF& parent) override; + ModeTreeChildIF& getModeTreeChildIF() override; + void handleSwitchOnCommand(heater::Switchers heaterIdx); void handleSwitchOffCommand(heater::Switchers heaterIdx);