|
|
|
@ -43,10 +43,10 @@ HeaterHandler::~HeaterHandler() {}
|
|
|
|
|
ReturnValue_t HeaterHandler::performOperation(uint8_t operationCode) {
|
|
|
|
|
try {
|
|
|
|
|
readCommandQueue();
|
|
|
|
|
handleActiveCommands();
|
|
|
|
|
for (const auto& heater : helper.heaters) {
|
|
|
|
|
heater.first->performOperation(0);
|
|
|
|
|
}
|
|
|
|
|
handleSwitchHandling();
|
|
|
|
|
} catch (const std::out_of_range& e) {
|
|
|
|
|
sif::warning << "HeaterHandler::performOperation: "
|
|
|
|
|
"Out of range error | "
|
|
|
|
@ -117,29 +117,35 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t
|
|
|
|
|
return HasActionsIF::INVALID_PARAMETERS;
|
|
|
|
|
}
|
|
|
|
|
auto& heater = heaterVec.at(switchNr);
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
auto actionRaw = data[1];
|
|
|
|
|
if (actionRaw != 0 and actionRaw != 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;
|
|
|
|
|
auto action = static_cast<SwitchAction>(data[1]);
|
|
|
|
|
// Always accepts OFF commands
|
|
|
|
|
if (action == 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) {
|
|
|
|
|
return HasHealthIF::IS_EXTERNALLY_CONTROLLED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (heater.active) {
|
|
|
|
|
|
|
|
|
|
if (heater.cmdActive) {
|
|
|
|
|
return COMMAND_ALREADY_WAITING;
|
|
|
|
|
}
|
|
|
|
|
auto action = data[1];
|
|
|
|
|
if (action != 0 and action != 1) {
|
|
|
|
|
return HasActionsIF::INVALID_PARAMETERS;
|
|
|
|
|
}
|
|
|
|
|
heater.action = static_cast<SwitchAction>(data[1]);
|
|
|
|
|
heater.active = true;
|
|
|
|
|
heater.action = action;
|
|
|
|
|
heater.cmdActive = true;
|
|
|
|
|
heater.replyQueue = commandedBy;
|
|
|
|
|
return RETURN_OK;
|
|
|
|
|
}
|
|
|
|
@ -179,9 +185,21 @@ ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t o
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HeaterHandler::handleActiveCommands() {
|
|
|
|
|
void HeaterHandler::handleSwitchHandling() {
|
|
|
|
|
for (uint8_t idx = 0; idx < heater::NUMBER_OF_SWITCHES; idx++) {
|
|
|
|
|
if (heaterVec[idx].active) {
|
|
|
|
|
auto health = heaterVec[idx].healthDevice->getHealth();
|
|
|
|
|
if (heaterVec[idx].switchState == SwitchState::ON) {
|
|
|
|
|
// If a heater is still on but the device was marked faulty by the operator, the SW
|
|
|
|
|
// will shut down the heater
|
|
|
|
|
if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY) {
|
|
|
|
|
heaterVec[idx].cmdActive = true;
|
|
|
|
|
heaterVec[idx].action = SET_SWITCH_OFF;
|
|
|
|
|
triggerEvent(FAULTY_HEATER_WAS_ON, idx, 0);
|
|
|
|
|
handleSwitchOffCommand(static_cast<heater::Switchers>(idx));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (heaterVec[idx].cmdActive) {
|
|
|
|
|
switch (heaterVec[idx].action) {
|
|
|
|
|
case SET_SWITCH_ON:
|
|
|
|
|
handleSwitchOnCommand(static_cast<heater::Switchers>(idx));
|
|
|
|
@ -207,7 +225,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
|
|
|
|
|
triggerEvent(MAIN_SWITCH_TIMEOUT);
|
|
|
|
|
sif::error << "HeaterHandler::handleSwitchOnCommand: Main switch setting on timeout"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
heater.active = false;
|
|
|
|
|
heater.cmdActive = false;
|
|
|
|
|
heater.waitMainSwitchOn = false;
|
|
|
|
|
if (heater.replyQueue != commandQueue->getId()) {
|
|
|
|
|
actionHelper.finish(false, heater.replyQueue, heater.action, MAIN_SWITCH_SET_TIMEOUT);
|
|
|
|
@ -241,7 +259,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
|
|
|
|
|
actionHelper.finish(false, heater.replyQueue, heater.action, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
heater.active = false;
|
|
|
|
|
heater.cmdActive = false;
|
|
|
|
|
heater.waitMainSwitchOn = false;
|
|
|
|
|
} else if (mainSwitchState == PowerSwitchIF::SWITCH_OFF && heater.waitMainSwitchOn) {
|
|
|
|
|
// Just waiting for the main switch being set on
|
|
|
|
@ -251,12 +269,12 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
|
|
|
|
|
heater.mainSwitchCountdown.setTimeout(mainLineSwitcher->getSwitchDelayMs());
|
|
|
|
|
heater.waitMainSwitchOn = true;
|
|
|
|
|
} else {
|
|
|
|
|
sif::debug << "HeaterHandler::handleActiveCommands: Failed to get state of"
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
heater.active = false;
|
|
|
|
|
heater.cmdActive = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -295,7 +313,7 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) {
|
|
|
|
|
actionHelper.finish(false, heater.replyQueue, heater.action, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
heater.active = false;
|
|
|
|
|
heater.cmdActive = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HeaterHandler::SwitchState HeaterHandler::checkSwitchState(heater::Switchers switchNr) const {
|
|
|
|
|