announce mode worsk for heaters
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
This commit is contained in:
@ -30,8 +30,8 @@ HeaterHandler::HeaterHandler(object_id_t setObjectId_, GpioIF* gpioInterface_, H
|
||||
if (mainLineSwitcher == nullptr) {
|
||||
throw std::invalid_argument("HeaterHandler::HeaterHandler: Invalid PowerSwitchIF");
|
||||
}
|
||||
heaterMutex = MutexFactory::instance()->createMutex();
|
||||
if (heaterMutex == nullptr) {
|
||||
heaterHealthAndStateMutex = MutexFactory::instance()->createMutex();
|
||||
if (heaterHealthAndStateMutex == nullptr) {
|
||||
throw std::runtime_error("HeaterHandler::HeaterHandler: Creating Mutex failed");
|
||||
}
|
||||
auto mqArgs = MqArgs(setObjectId_, static_cast<void*>(this));
|
||||
@ -114,7 +114,7 @@ void HeaterHandler::readCommandQueue() {
|
||||
continue;
|
||||
}
|
||||
result = modeHelper.handleModeCommand(&command);
|
||||
if(result == returnvalue::OK) {
|
||||
if (result == returnvalue::OK) {
|
||||
continue;
|
||||
}
|
||||
} while (result == returnvalue::OK);
|
||||
@ -141,7 +141,11 @@ ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t
|
||||
auto action = static_cast<SwitchAction>(data[1]);
|
||||
// Always accepts OFF commands
|
||||
if (action == SwitchAction::SET_SWITCH_ON) {
|
||||
HasHealthIF::HealthState health = heater.healthDevice->getHealth();
|
||||
HasHealthIF::HealthState health;
|
||||
{
|
||||
MutexGuard mg(heaterHealthAndStateMutex);
|
||||
health = heater.healthDevice->getHealth();
|
||||
}
|
||||
if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY or
|
||||
health == HasHealthIF::NEEDS_RECOVERY) {
|
||||
return HasHealthIF::OBJECT_NOT_HEALTHY;
|
||||
@ -264,7 +268,10 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
|
||||
triggerEvent(GPIO_PULL_HIGH_FAILED, result);
|
||||
} else {
|
||||
triggerEvent(HEATER_WENT_ON, heaterIdx, 0);
|
||||
heater.switchState = ON;
|
||||
{
|
||||
MutexGuard mg(heaterHealthAndStateMutex);
|
||||
heater.switchState = ON;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
triggerEvent(SWITCH_ALREADY_ON, heaterIdx);
|
||||
@ -311,10 +318,9 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) {
|
||||
<< " low" << std::endl;
|
||||
triggerEvent(GPIO_PULL_LOW_FAILED, result);
|
||||
} else {
|
||||
result = heaterMutex->lockMutex();
|
||||
heater.switchState = OFF;
|
||||
if (result == returnvalue::OK) {
|
||||
heaterMutex->unlockMutex();
|
||||
{
|
||||
MutexGuard mg(heaterHealthAndStateMutex);
|
||||
heater.switchState = OFF;
|
||||
}
|
||||
triggerEvent(HEATER_WENT_OFF, heaterIdx, 0);
|
||||
// When all switches are off, also main line switch will be turned off
|
||||
@ -339,7 +345,7 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) {
|
||||
}
|
||||
|
||||
HeaterHandler::SwitchState HeaterHandler::checkSwitchState(heater::Switchers switchNr) const {
|
||||
MutexGuard mg(heaterMutex);
|
||||
MutexGuard mg(heaterHealthAndStateMutex);
|
||||
return heaterVec.at(switchNr).switchState;
|
||||
}
|
||||
|
||||
@ -354,8 +360,16 @@ ReturnValue_t HeaterHandler::switchHeater(heater::Switchers heater, SwitchState
|
||||
|
||||
void HeaterHandler::announceMode(bool recursive) {
|
||||
triggerEvent(MODE_INFO, mode, submode);
|
||||
|
||||
SwitchState states[helper.heaters.size()];
|
||||
{
|
||||
MutexGuard mg(heaterHealthAndStateMutex);
|
||||
for (unsigned idx = 0; idx < helper.heaters.size(); idx++) {
|
||||
states[idx] = heaterVec[idx].switchState;
|
||||
}
|
||||
}
|
||||
for (unsigned idx = 0; idx < helper.heaters.size(); idx++) {
|
||||
if (heaterVec[idx].switchState == SWITCH_ON) {
|
||||
if (states[idx] == ON) {
|
||||
EventManagerIF::triggerEvent(helper.heaters[idx].first->getObjectId(), MODE_INFO, MODE_ON, 0);
|
||||
} else {
|
||||
EventManagerIF::triggerEvent(helper.heaters[idx].first->getObjectId(), MODE_INFO, MODE_OFF,
|
||||
@ -386,7 +400,7 @@ object_id_t HeaterHandler::getObjectId() const { return SystemObject::getObjectI
|
||||
|
||||
bool HeaterHandler::allSwitchesOff() {
|
||||
bool allSwitchesOrd = false;
|
||||
MutexGuard mg(heaterMutex);
|
||||
MutexGuard mg(heaterHealthAndStateMutex);
|
||||
/* Or all switches. As soon one switch is on, allSwitchesOrd will be true */
|
||||
for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) {
|
||||
allSwitchesOrd = allSwitchesOrd || heaterVec.at(switchNr).switchState;
|
||||
@ -419,7 +433,7 @@ uint32_t HeaterHandler::getSwitchDelayMs(void) const { return 2000; }
|
||||
HasHealthIF::HealthState HeaterHandler::getHealth(heater::Switchers heater) {
|
||||
auto* healthDev = heaterVec.at(heater).healthDevice;
|
||||
if (healthDev != nullptr) {
|
||||
MutexGuard mg(heaterMutex);
|
||||
MutexGuard mg(heaterHealthAndStateMutex);
|
||||
return healthDev->getHealth();
|
||||
}
|
||||
return HasHealthIF::HealthState::FAULTY;
|
||||
|
Reference in New Issue
Block a user