introspection fsfw, HeaterHandler adapted

This commit is contained in:
Ulrich Mohr 2022-07-26 14:04:05 +02:00
parent d2a12ea71e
commit cd1200d23d
4 changed files with 59 additions and 52 deletions

2
fsfw

@ -1 +1 @@
Subproject commit 5abbf42e9f9b48cc244faabe88dc845e66cd0d24 Subproject commit a1af2cebf3a53dd17e7dd948f1e698d9c4621696

View File

@ -104,39 +104,22 @@ void HeaterHandler::readCommandQueue() {
} while (result == RETURN_OK); } while (result == RETURN_OK);
} }
ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, ReturnValue_t HeaterHandler::executeAction(Action* action) {
const uint8_t* data, size_t size) { return action->handle();
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);
auto actionRaw = data[1]; ReturnValue_t HeaterHandler::handleAction(SetHeaterAction *heaterAction){
if (actionRaw != 0 and actionRaw != 1) { auto& heater = heaterVec.at(heaterAction->switchNr);
return HasActionsIF::INVALID_PARAMETERS; auto action = heaterAction->switchAction;
}
auto action = static_cast<SwitchAction>(data[1]);
// Always accepts OFF commands // Always accepts OFF commands
if (action == SwitchAction::SET_SWITCH_ON) { if (action == SetHeaterAction::SwitchAction::SET_SWITCH_ON) {
HasHealthIF::HealthState health = heater.healthDevice->getHealth(); HasHealthIF::HealthState health = heater.healthDevice->getHealth();
if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY or if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY or
health == HasHealthIF::NEEDS_RECOVERY) { health == HasHealthIF::NEEDS_RECOVERY) {
return HasHealthIF::OBJECT_NOT_HEALTHY; return HasHealthIF::OBJECT_NOT_HEALTHY;
} }
CmdSourceParam cmdSource = CmdSourceParam::EXTERNAL; auto cmdSource = heaterAction->cmdSource;
uint8_t cmdSourceRaw = data[2]; if (health == HasHealthIF::EXTERNAL_CONTROL and cmdSource == SetHeaterAction::CmdSourceParam::INTERNAL) {
if (cmdSourceRaw > 1) {
return HasActionsIF::INVALID_PARAMETERS;
}
cmdSource = static_cast<CmdSourceParam>(data[2]);
if (health == HasHealthIF::EXTERNAL_CONTROL and cmdSource == CmdSourceParam::INTERNAL) {
return HasHealthIF::IS_EXTERNALLY_CONTROLLED; return HasHealthIF::IS_EXTERNALLY_CONTROLLED;
} }
} }
@ -146,9 +129,9 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t
} }
heater.action = action; heater.action = action;
heater.cmdActive = true; heater.cmdActive = true;
heater.replyQueue = commandedBy; heater.replyQueue = heaterAction->commandedBy;
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) { ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) {
ReturnValue_t result; ReturnValue_t result;
@ -158,13 +141,13 @@ ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t o
switch (onOff) { switch (onOff) {
case PowerSwitchIF::SWITCH_ON: case PowerSwitchIF::SWITCH_ON:
commandData[0] = switchNr; commandData[0] = switchNr;
commandData[1] = SET_SWITCH_ON; commandData[1] = static_cast<uint8_t>(SetHeaterAction::SwitchAction::SET_SWITCH_ON);
commandData[2] = CmdSourceParam::INTERNAL; commandData[2] = static_cast<uint8_t>(SetHeaterAction::CmdSourceParam::INTERNAL);
break; break;
case PowerSwitchIF::SWITCH_OFF: case PowerSwitchIF::SWITCH_OFF:
commandData[0] = switchNr; commandData[0] = switchNr;
commandData[1] = SET_SWITCH_OFF; commandData[1] = static_cast<uint8_t>(SetHeaterAction::SwitchAction::SET_SWITCH_OFF);
commandData[2] = CmdSourceParam::INTERNAL; commandData[2] = static_cast<uint8_t>(SetHeaterAction::CmdSourceParam::INTERNAL);
break; break;
default: default:
sif::error << "HeaterHandler::sendSwitchCommand: Invalid switch request" << std::endl; 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)); result = ipcStore->addData(&storeAddress, commandData, sizeof(commandData));
if (result == RETURN_OK) { if (result == RETURN_OK) {
CommandMessage message; CommandMessage message;
ActionMessage::setCommand(&message, SWITCH_HEATER, storeAddress); ActionMessage::setCommand(&message, static_cast<ActionId_t>(HeaterCommands::SWITCH_HEATER), storeAddress);
/* Send heater command to own command queue */ /* Send heater command to own command queue */
result = commandQueue->sendMessage(commandQueue->getId(), &message, 0); result = commandQueue->sendMessage(commandQueue->getId(), &message, 0);
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -193,7 +176,7 @@ void HeaterHandler::handleSwitchHandling() {
// will shut down the heater // will shut down the heater
if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY) { if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY) {
heaterVec[idx].cmdActive = true; 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); triggerEvent(FAULTY_HEATER_WAS_ON, idx, 0);
handleSwitchOffCommand(static_cast<heater::Switchers>(idx)); handleSwitchOffCommand(static_cast<heater::Switchers>(idx));
continue; continue;
@ -201,10 +184,10 @@ void HeaterHandler::handleSwitchHandling() {
} }
if (heaterVec[idx].cmdActive) { if (heaterVec[idx].cmdActive) {
switch (heaterVec[idx].action) { switch (heaterVec[idx].action) {
case SET_SWITCH_ON: case SetHeaterAction::SwitchAction::SET_SWITCH_ON:
handleSwitchOnCommand(static_cast<heater::Switchers>(idx)); handleSwitchOnCommand(static_cast<heater::Switchers>(idx));
break; break;
case SET_SWITCH_OFF: case SetHeaterAction::SwitchAction::SET_SWITCH_OFF:
handleSwitchOffCommand(static_cast<heater::Switchers>(idx)); handleSwitchOffCommand(static_cast<heater::Switchers>(idx));
break; break;
default: default:
@ -228,7 +211,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
heater.cmdActive = false; heater.cmdActive = false;
heater.waitMainSwitchOn = false; heater.waitMainSwitchOn = false;
if (heater.replyQueue != commandQueue->getId()) { if (heater.replyQueue != commandQueue->getId()) {
actionHelper.finish(false, heater.replyQueue, heater.action, MAIN_SWITCH_SET_TIMEOUT); actionHelper.finish(false, heater.replyQueue, static_cast<ActionId_t>(heater.action), MAIN_SWITCH_SET_TIMEOUT);
} }
return; return;
} }
@ -254,9 +237,9 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
// HeaterHandler itself // HeaterHandler itself
if (heater.replyQueue != commandQueue->getId()) { if (heater.replyQueue != commandQueue->getId()) {
if (result == RETURN_OK) { if (result == RETURN_OK) {
actionHelper.finish(true, heater.replyQueue, heater.action, result); actionHelper.finish(true, heater.replyQueue, static_cast<ActionId_t>(heater.action), result);
} else { } else {
actionHelper.finish(false, heater.replyQueue, heater.action, result); actionHelper.finish(false, heater.replyQueue, static_cast<ActionId_t>(heater.action), result);
} }
} }
heater.cmdActive = false; heater.cmdActive = false;
@ -272,7 +255,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
sif::debug << "HeaterHandler::handleSwitchHandling: Failed to get state of" sif::debug << "HeaterHandler::handleSwitchHandling: Failed to get state of"
<< " main line switch" << std::endl; << " main line switch" << std::endl;
if (heater.replyQueue != commandQueue->getId()) { if (heater.replyQueue != commandQueue->getId()) {
actionHelper.finish(false, heater.replyQueue, heater.action, mainSwitchState); actionHelper.finish(false, heater.replyQueue, static_cast<ActionId_t>(heater.action), mainSwitchState);
} }
heater.cmdActive = false; heater.cmdActive = false;
} }
@ -308,9 +291,9 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) {
if (heater.replyQueue != NO_COMMANDER) { if (heater.replyQueue != NO_COMMANDER) {
// Report back switch command reply if necessary // Report back switch command reply if necessary
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
actionHelper.finish(true, heater.replyQueue, heater.action, result); actionHelper.finish(true, heater.replyQueue, static_cast<ActionId_t>(heater.action), result);
} else { } else {
actionHelper.finish(false, heater.replyQueue, heater.action, result); actionHelper.finish(false, heater.replyQueue, static_cast<ActionId_t>(heater.action), result);
} }
} }
heater.cmdActive = false; heater.cmdActive = false;

View File

@ -18,6 +18,7 @@
#include <vector> #include <vector>
#include "devices/heaterSwitcherList.h" #include "devices/heaterSwitcherList.h"
#include "devicedefinitions/HeaterDefinitions.h"
class PowerSwitchIF; class PowerSwitchIF;
class HealthTableIF; 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 MAIN_SWITCH_SET_TIMEOUT = MAKE_RETURN_CODE(0xA4);
static const ReturnValue_t COMMAND_ALREADY_WAITING = MAKE_RETURN_CODE(0xA5); 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, HeaterHandler(object_id_t setObjectId, GpioIF* gpioInterface_, HeaterHelper helper,
PowerSwitchIF* mainLineSwitcherObjectId, power::Switch_t mainLineSwitch); PowerSwitchIF* mainLineSwitcherObjectId, power::Switch_t mainLineSwitch);
@ -70,8 +66,8 @@ class HeaterHandler : public ExecutableObjectIF,
uint32_t getSwitchDelayMs(void) const override; uint32_t getSwitchDelayMs(void) const override;
MessageQueueId_t getCommandQueue() const override; MessageQueueId_t getCommandQueue() const override;
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, ReturnValue_t executeAction(Action* action) override;
const uint8_t* data, size_t size) override; ReturnValue_t handleAction(SetHeaterAction *heaterAction);
ReturnValue_t initialize() override; ReturnValue_t initialize() override;
private: private:
@ -89,7 +85,7 @@ class HeaterHandler : public ExecutableObjectIF,
static const MessageQueueId_t NO_COMMANDER = 0; static const MessageQueueId_t NO_COMMANDER = 0;
enum SwitchState : bool { ON = true, OFF = false }; 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. * @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(pair.first), gpioId(pair.second), switchState(initState) {}
HealthDevice* healthDevice = nullptr; HealthDevice* healthDevice = nullptr;
gpioId_t gpioId = gpio::NO_GPIO; gpioId_t gpioId = gpio::NO_GPIO;
SwitchAction action = SwitchAction::NONE; SetHeaterAction::SwitchAction action = SetHeaterAction::SwitchAction::NONE;
MessageQueueId_t replyQueue = MessageQueueIF::NO_QUEUE; MessageQueueId_t replyQueue = MessageQueueIF::NO_QUEUE;
bool cmdActive = false; bool cmdActive = false;
SwitchState switchState = SwitchState::OFF; SwitchState switchState = SwitchState::OFF;
@ -138,6 +134,8 @@ class HeaterHandler : public ExecutableObjectIF,
/** Switch number of the heater power supply switch */ /** Switch number of the heater power supply switch */
power::Switch_t mainLineSwitch; power::Switch_t mainLineSwitch;
SetHeaterAction setHeaterAction = SetHeaterAction(this);
ActionHelper actionHelper; ActionHelper actionHelper;
StorageManagerIF* ipcStore = nullptr; StorageManagerIF* ipcStore = nullptr;

View File

@ -0,0 +1,26 @@
#pragma once
#include <fsfw/action/MinMaxParameter.h>
#include <fsfw/action/TemplateAction.h>
#include <fsfw/introspection/Enum.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
class HeaterHandler;
FSFW_ENUM(HeaterCommands, DeviceCommandId_t, ((SWITCH_HEATER, 0x0, "Switch Heater")))
class SetHeaterAction : public TemplateAction<HeaterHandler, SetHeaterAction, HeaterCommands> {
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<uint8_t> switchNr =
MinMaxParameter<uint8_t>::createMinMaxParameter(this, "Heater number", 0, 7);
Parameter<SwitchAction> switchAction =
Parameter<SwitchAction>::createParameter(this, "Switch Action");
Parameter<CmdSourceParam> cmdSource =
Parameter<CmdSourceParam>::createParameter(this, "Command Source");
};