From cd1200d23d92f335300e32ede87c2ecf332bf209 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 26 Jul 2022 14:04:05 +0200 Subject: [PATCH] introspection fsfw, HeaterHandler adapted --- fsfw | 2 +- mission/devices/HeaterHandler.cpp | 67 +++++++------------ mission/devices/HeaterHandler.h | 16 ++--- .../devicedefinitions/HeaterDefinitions.h | 26 +++++++ 4 files changed, 59 insertions(+), 52 deletions(-) create mode 100644 mission/devices/devicedefinitions/HeaterDefinitions.h diff --git a/fsfw b/fsfw index 5abbf42e..a1af2ceb 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 5abbf42e9f9b48cc244faabe88dc845e66cd0d24 +Subproject commit a1af2cebf3a53dd17e7dd948f1e698d9c4621696 diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 6953dc54..dc6b5668 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -104,39 +104,22 @@ void HeaterHandler::readCommandQueue() { } while (result == RETURN_OK); } -ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size) { - if (data == nullptr or size < 3) { - return HasActionsIF::INVALID_PARAMETERS; - } - if (actionId != SWITCH_HEATER) { - return COMMAND_NOT_SUPPORTED; - } - auto switchNr = data[0]; - if (switchNr > 7) { - return HasActionsIF::INVALID_PARAMETERS; - } - auto& heater = heaterVec.at(switchNr); +ReturnValue_t HeaterHandler::executeAction(Action* action) { + return action->handle(); +} - auto actionRaw = data[1]; - if (actionRaw != 0 and actionRaw != 1) { - return HasActionsIF::INVALID_PARAMETERS; - } - auto action = static_cast(data[1]); + ReturnValue_t HeaterHandler::handleAction(SetHeaterAction *heaterAction){ + auto& heater = heaterVec.at(heaterAction->switchNr); + auto action = heaterAction->switchAction; // Always accepts OFF commands - if (action == SwitchAction::SET_SWITCH_ON) { + if (action == SetHeaterAction::SwitchAction::SET_SWITCH_ON) { HasHealthIF::HealthState health = heater.healthDevice->getHealth(); if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY or health == HasHealthIF::NEEDS_RECOVERY) { return HasHealthIF::OBJECT_NOT_HEALTHY; } - CmdSourceParam cmdSource = CmdSourceParam::EXTERNAL; - uint8_t cmdSourceRaw = data[2]; - if (cmdSourceRaw > 1) { - return HasActionsIF::INVALID_PARAMETERS; - } - cmdSource = static_cast(data[2]); - if (health == HasHealthIF::EXTERNAL_CONTROL and cmdSource == CmdSourceParam::INTERNAL) { + auto cmdSource = heaterAction->cmdSource; + if (health == HasHealthIF::EXTERNAL_CONTROL and cmdSource == SetHeaterAction::CmdSourceParam::INTERNAL) { return HasHealthIF::IS_EXTERNALLY_CONTROLLED; } } @@ -146,9 +129,9 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t } heater.action = action; heater.cmdActive = true; - heater.replyQueue = commandedBy; + heater.replyQueue = heaterAction->commandedBy; return RETURN_OK; -} + } ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) { ReturnValue_t result; @@ -158,13 +141,13 @@ ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t o switch (onOff) { case PowerSwitchIF::SWITCH_ON: commandData[0] = switchNr; - commandData[1] = SET_SWITCH_ON; - commandData[2] = CmdSourceParam::INTERNAL; + commandData[1] = static_cast(SetHeaterAction::SwitchAction::SET_SWITCH_ON); + commandData[2] = static_cast(SetHeaterAction::CmdSourceParam::INTERNAL); break; case PowerSwitchIF::SWITCH_OFF: commandData[0] = switchNr; - commandData[1] = SET_SWITCH_OFF; - commandData[2] = CmdSourceParam::INTERNAL; + commandData[1] = static_cast(SetHeaterAction::SwitchAction::SET_SWITCH_OFF); + commandData[2] = static_cast(SetHeaterAction::CmdSourceParam::INTERNAL); break; default: sif::error << "HeaterHandler::sendSwitchCommand: Invalid switch request" << std::endl; @@ -174,7 +157,7 @@ ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t o result = ipcStore->addData(&storeAddress, commandData, sizeof(commandData)); if (result == RETURN_OK) { CommandMessage message; - ActionMessage::setCommand(&message, SWITCH_HEATER, storeAddress); + ActionMessage::setCommand(&message, static_cast(HeaterCommands::SWITCH_HEATER), storeAddress); /* Send heater command to own command queue */ result = commandQueue->sendMessage(commandQueue->getId(), &message, 0); if (result != RETURN_OK) { @@ -193,7 +176,7 @@ void HeaterHandler::handleSwitchHandling() { // will shut down the heater if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY) { heaterVec[idx].cmdActive = true; - heaterVec[idx].action = SET_SWITCH_OFF; + heaterVec[idx].action = SetHeaterAction::SwitchAction::SET_SWITCH_OFF; triggerEvent(FAULTY_HEATER_WAS_ON, idx, 0); handleSwitchOffCommand(static_cast(idx)); continue; @@ -201,10 +184,10 @@ void HeaterHandler::handleSwitchHandling() { } if (heaterVec[idx].cmdActive) { switch (heaterVec[idx].action) { - case SET_SWITCH_ON: + case SetHeaterAction::SwitchAction::SET_SWITCH_ON: handleSwitchOnCommand(static_cast(idx)); break; - case SET_SWITCH_OFF: + case SetHeaterAction::SwitchAction::SET_SWITCH_OFF: handleSwitchOffCommand(static_cast(idx)); break; default: @@ -228,7 +211,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) { heater.cmdActive = false; heater.waitMainSwitchOn = false; if (heater.replyQueue != commandQueue->getId()) { - actionHelper.finish(false, heater.replyQueue, heater.action, MAIN_SWITCH_SET_TIMEOUT); + actionHelper.finish(false, heater.replyQueue, static_cast(heater.action), MAIN_SWITCH_SET_TIMEOUT); } return; } @@ -254,9 +237,9 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) { // HeaterHandler itself if (heater.replyQueue != commandQueue->getId()) { if (result == RETURN_OK) { - actionHelper.finish(true, heater.replyQueue, heater.action, result); + actionHelper.finish(true, heater.replyQueue, static_cast(heater.action), result); } else { - actionHelper.finish(false, heater.replyQueue, heater.action, result); + actionHelper.finish(false, heater.replyQueue, static_cast(heater.action), result); } } heater.cmdActive = false; @@ -272,7 +255,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) { sif::debug << "HeaterHandler::handleSwitchHandling: Failed to get state of" << " main line switch" << std::endl; if (heater.replyQueue != commandQueue->getId()) { - actionHelper.finish(false, heater.replyQueue, heater.action, mainSwitchState); + actionHelper.finish(false, heater.replyQueue, static_cast(heater.action), mainSwitchState); } heater.cmdActive = false; } @@ -308,9 +291,9 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) { if (heater.replyQueue != NO_COMMANDER) { // Report back switch command reply if necessary if (result == HasReturnvaluesIF::RETURN_OK) { - actionHelper.finish(true, heater.replyQueue, heater.action, result); + actionHelper.finish(true, heater.replyQueue, static_cast(heater.action), result); } else { - actionHelper.finish(false, heater.replyQueue, heater.action, result); + actionHelper.finish(false, heater.replyQueue, static_cast(heater.action), result); } } heater.cmdActive = false; diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index 0f4420b4..69e8f391 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -18,6 +18,7 @@ #include #include "devices/heaterSwitcherList.h" +#include "devicedefinitions/HeaterDefinitions.h" class PowerSwitchIF; class HealthTableIF; @@ -47,11 +48,6 @@ class HeaterHandler : public ExecutableObjectIF, static const ReturnValue_t MAIN_SWITCH_SET_TIMEOUT = MAKE_RETURN_CODE(0xA4); static const ReturnValue_t COMMAND_ALREADY_WAITING = MAKE_RETURN_CODE(0xA5); - enum CmdSourceParam : uint8_t { INTERNAL = 0, EXTERNAL = 1 }; - - /** Device command IDs */ - static const DeviceCommandId_t SWITCH_HEATER = 0x0; - HeaterHandler(object_id_t setObjectId, GpioIF* gpioInterface_, HeaterHelper helper, PowerSwitchIF* mainLineSwitcherObjectId, power::Switch_t mainLineSwitch); @@ -70,8 +66,8 @@ class HeaterHandler : public ExecutableObjectIF, uint32_t getSwitchDelayMs(void) const override; MessageQueueId_t getCommandQueue() const override; - ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size) override; + ReturnValue_t executeAction(Action* action) override; + ReturnValue_t handleAction(SetHeaterAction *heaterAction); ReturnValue_t initialize() override; private: @@ -89,7 +85,7 @@ class HeaterHandler : public ExecutableObjectIF, static const MessageQueueId_t NO_COMMANDER = 0; enum SwitchState : bool { ON = true, OFF = false }; - enum SwitchAction : uint8_t { SET_SWITCH_OFF, SET_SWITCH_ON, NONE }; + /** * @brief Struct holding information about a heater command to execute. @@ -106,7 +102,7 @@ class HeaterHandler : public ExecutableObjectIF, : healthDevice(pair.first), gpioId(pair.second), switchState(initState) {} HealthDevice* healthDevice = nullptr; gpioId_t gpioId = gpio::NO_GPIO; - SwitchAction action = SwitchAction::NONE; + SetHeaterAction::SwitchAction action = SetHeaterAction::SwitchAction::NONE; MessageQueueId_t replyQueue = MessageQueueIF::NO_QUEUE; bool cmdActive = false; SwitchState switchState = SwitchState::OFF; @@ -138,6 +134,8 @@ class HeaterHandler : public ExecutableObjectIF, /** Switch number of the heater power supply switch */ power::Switch_t mainLineSwitch; + SetHeaterAction setHeaterAction = SetHeaterAction(this); + ActionHelper actionHelper; StorageManagerIF* ipcStore = nullptr; diff --git a/mission/devices/devicedefinitions/HeaterDefinitions.h b/mission/devices/devicedefinitions/HeaterDefinitions.h new file mode 100644 index 00000000..655df90d --- /dev/null +++ b/mission/devices/devicedefinitions/HeaterDefinitions.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include +#include + +class HeaterHandler; + +FSFW_ENUM(HeaterCommands, DeviceCommandId_t, ((SWITCH_HEATER, 0x0, "Switch Heater"))) + +class SetHeaterAction : public TemplateAction { + public: + FSFW_ENUM(SwitchAction, uint8_t, + ((SET_SWITCH_OFF, "Set switch to Off"))((SET_SWITCH_ON, "Set switch to On")) ((NONE, "No Action"))) + FSFW_ENUM(CmdSourceParam, uint8_t, ((INTERNAL, 0, "Internal"))((EXTERNAL, 1, "External"))) + + SetHeaterAction(HeaterHandler *owner) : TemplateAction(owner, HeaterCommands::SWITCH_HEATER) {} + + MinMaxParameter switchNr = + MinMaxParameter::createMinMaxParameter(this, "Heater number", 0, 7); + Parameter switchAction = + Parameter::createParameter(this, "Switch Action"); + Parameter cmdSource = + Parameter::createParameter(this, "Command Source"); +}; \ No newline at end of file