Heater Health IF #236

Merged
meierj merged 44 commits from mueller/heater-health-if into develop 2022-05-13 18:38:13 +02:00
3 changed files with 15 additions and 21 deletions
Showing only changes of commit 1f8a68dabe - Show all commits

View File

@ -3,8 +3,8 @@
#include <cstdint> #include <cstdint>
namespace heaterSwitches { namespace heater {
enum switcherList: uint8_t { enum Switchers: uint8_t {
HEATER_0, HEATER_0,
HEATER_1, HEATER_1,
HEATER_2, HEATER_2,

View File

@ -71,7 +71,7 @@ ReturnValue_t HeaterHandler::initialize() {
} }
ReturnValue_t HeaterHandler::initializeHeaterMap() { ReturnValue_t HeaterHandler::initializeHeaterMap() {
for (power::Switch_t switchNr = 0; switchNr < heaterSwitches::NUMBER_OF_SWITCHES; switchNr++) { for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) {
heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr])); heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr]));
} }
return RETURN_OK; return RETURN_OK;
@ -159,14 +159,14 @@ ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t o
} }
void HeaterHandler::handleActiveCommands() { void HeaterHandler::handleActiveCommands() {
for (uint8_t idx = 0; idx < heater::NUMBER_OF_HEATERS; idx++) { for (uint8_t idx = 0; idx < heater::NUMBER_OF_SWITCHES; idx++) {
if (heaterVec[idx].active) { if (heaterVec[idx].active) {
switch (heaterVec[idx].action) { switch (heaterVec[idx].action) {
case SET_SWITCH_ON: case SET_SWITCH_ON:
handleSwitchOnCommand(idx); handleSwitchOnCommand(static_cast<heater::Switchers>(idx));
break; break;
case SET_SWITCH_OFF: case SET_SWITCH_OFF:
handleSwitchOffCommand(idx); handleSwitchOffCommand(static_cast<heater::Switchers>(idx));
break; break;
default: default:
sif::error << "HeaterHandler::handleActiveCommands: Invalid action commanded" sif::error << "HeaterHandler::handleActiveCommands: Invalid action commanded"
@ -177,7 +177,7 @@ void HeaterHandler::handleActiveCommands() {
} }
} }
void HeaterHandler::handleSwitchOnCommand(uint8_t heaterIdx) { void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
auto& heater = heaterVec.at(heaterIdx); auto& heater = heaterVec.at(heaterIdx);
/* Check if command waits for main switch being set on and whether the timeout has expired */ /* Check if command waits for main switch being set on and whether the timeout has expired */
@ -238,7 +238,7 @@ void HeaterHandler::handleSwitchOnCommand(uint8_t heaterIdx) {
} }
} }
void HeaterHandler::handleSwitchOffCommand(uint8_t heaterIdx) { void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
auto& heater = heaterVec.at(heaterIdx); auto& heater = heaterVec.at(heaterIdx);
// Check whether switch is already off // Check whether switch is already off
@ -271,14 +271,14 @@ void HeaterHandler::handleSwitchOffCommand(uint8_t heaterIdx) {
heater.active = false; heater.active = false;
} }
HeaterHandler::SwitchState HeaterHandler::checkSwitchState(uint8_t switchNr) { HeaterHandler::SwitchState HeaterHandler::checkSwitchState(heater::Switchers switchNr) {
return heaterVec.at(switchNr).switchState; return heaterVec.at(switchNr).switchState;
} }
bool HeaterHandler::allSwitchesOff() { bool HeaterHandler::allSwitchesOff() {
bool allSwitchesOrd = false; bool allSwitchesOrd = false;
/* Or all switches. As soon one switch is on, allSwitchesOrd will be true */ /* Or all switches. As soon one switch is on, allSwitchesOrd will be true */
for (power::Switch_t switchNr = 0; switchNr < heaterSwitches::NUMBER_OF_SWITCHES; switchNr++) { for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) {
allSwitchesOrd = allSwitchesOrd || heaterVec.at(switchNr).switchState; allSwitchesOrd = allSwitchesOrd || heaterVec.at(switchNr).switchState;
} }
return !allSwitchesOrd; return !allSwitchesOrd;

View File

@ -21,18 +21,12 @@
class PowerSwitchIF; class PowerSwitchIF;
class HealthTableIF; class HealthTableIF;
namespace heater {
static constexpr uint8_t NUMBER_OF_HEATERS = 8;
}
using HeaterPair = std::pair<HealthDevice*, gpioId_t>; using HeaterPair = std::pair<HealthDevice*, gpioId_t>;
struct HeaterHelper { struct HeaterHelper {
public: public:
HeaterHelper(std::array<HeaterPair, heater::NUMBER_OF_HEATERS> heaters) : heaters(heaters) {} HeaterHelper(std::array<HeaterPair, heater::NUMBER_OF_SWITCHES> heaters) : heaters(heaters) {}
std::array<HeaterPair, heater::NUMBER_OF_HEATERS> heaters = {}; std::array<HeaterPair, heater::NUMBER_OF_SWITCHES> heaters = {};
}; };
/** /**
* @brief This class intends the control of heaters. * @brief This class intends the control of heaters.
@ -144,7 +138,7 @@ class HeaterHandler : public ExecutableObjectIF,
* @brief Returns the state of a switch (ON - true, or OFF - false). * @brief Returns the state of a switch (ON - true, or OFF - false).
* @param switchNr The number of the switch to check. * @param switchNr The number of the switch to check.
*/ */
SwitchState checkSwitchState(power::Switch_t switchNr); SwitchState checkSwitchState(heater::Switchers switchNr);
/** /**
* @brief This function runs commands waiting for execution. * @brief This function runs commands waiting for execution.
@ -158,9 +152,9 @@ class HeaterHandler : public ExecutableObjectIF,
*/ */
void setInitialSwitchStates(); void setInitialSwitchStates();
void handleSwitchOnCommand(uint8_t heaterIdx); void handleSwitchOnCommand(heater::Switchers heaterIdx);
void handleSwitchOffCommand(uint8_t heaterIdx); void handleSwitchOffCommand(heater::Switchers heaterIdx);
/** /**
* @brief Checks if all switches are off. * @brief Checks if all switches are off.