introspection fsfw, HeaterHandler adapted
This commit is contained in:
parent
d2a12ea71e
commit
cd1200d23d
2
fsfw
2
fsfw
@ -1 +1 @@
|
||||
Subproject commit 5abbf42e9f9b48cc244faabe88dc845e66cd0d24
|
||||
Subproject commit a1af2cebf3a53dd17e7dd948f1e698d9c4621696
|
@ -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<SwitchAction>(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<CmdSourceParam>(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<uint8_t>(SetHeaterAction::SwitchAction::SET_SWITCH_ON);
|
||||
commandData[2] = static_cast<uint8_t>(SetHeaterAction::CmdSourceParam::INTERNAL);
|
||||
break;
|
||||
case PowerSwitchIF::SWITCH_OFF:
|
||||
commandData[0] = switchNr;
|
||||
commandData[1] = SET_SWITCH_OFF;
|
||||
commandData[2] = CmdSourceParam::INTERNAL;
|
||||
commandData[1] = static_cast<uint8_t>(SetHeaterAction::SwitchAction::SET_SWITCH_OFF);
|
||||
commandData[2] = static_cast<uint8_t>(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<ActionId_t>(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<heater::Switchers>(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<heater::Switchers>(idx));
|
||||
break;
|
||||
case SET_SWITCH_OFF:
|
||||
case SetHeaterAction::SwitchAction::SET_SWITCH_OFF:
|
||||
handleSwitchOffCommand(static_cast<heater::Switchers>(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<ActionId_t>(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<ActionId_t>(heater.action), result);
|
||||
} else {
|
||||
actionHelper.finish(false, heater.replyQueue, heater.action, result);
|
||||
actionHelper.finish(false, heater.replyQueue, static_cast<ActionId_t>(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<ActionId_t>(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<ActionId_t>(heater.action), result);
|
||||
} else {
|
||||
actionHelper.finish(false, heater.replyQueue, heater.action, result);
|
||||
actionHelper.finish(false, heater.replyQueue, static_cast<ActionId_t>(heater.action), result);
|
||||
}
|
||||
}
|
||||
heater.cmdActive = false;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <vector>
|
||||
|
||||
#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;
|
||||
|
26
mission/devices/devicedefinitions/HeaterDefinitions.h
Normal file
26
mission/devices/devicedefinitions/HeaterDefinitions.h
Normal 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");
|
||||
};
|
Loading…
Reference in New Issue
Block a user