only handle one message per cycle

This commit is contained in:
Robin Müller 2023-06-27 17:55:49 +02:00
parent 15a67b81f9
commit 1e767afa11
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814

View File

@ -105,25 +105,23 @@ ReturnValue_t HeaterHandler::initializeHeaterMap() {
void HeaterHandler::readCommandQueue() { void HeaterHandler::readCommandQueue() {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
CommandMessage command; CommandMessage command;
do {
if (not busyWithSwitchCommanding) { if (not busyWithSwitchCommanding) {
result = commandQueue->receiveMessage(&command); result = commandQueue->receiveMessage(&command);
if (result == MessageQueueIF::EMPTY) { if (result == MessageQueueIF::EMPTY) {
break; return;
} else if (result != returnvalue::OK) { } else if (result != returnvalue::OK) {
sif::warning << "HeaterHandler::readCommandQueue: Message reception error" << std::endl; sif::warning << "HeaterHandler::readCommandQueue: Message reception error" << std::endl;
break; return;
} }
result = modeHelper.handleModeCommand(&command); result = modeHelper.handleModeCommand(&command);
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
continue; return;
} }
result = actionHelper.handleActionMessage(&command); result = actionHelper.handleActionMessage(&command);
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
continue; return;
} }
} }
} while (result == returnvalue::OK);
} }
ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
@ -276,16 +274,11 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switch heaterIdx) {
triggerEvent(GPIO_PULL_HIGH_FAILED, result); triggerEvent(GPIO_PULL_HIGH_FAILED, result);
} }
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
if (getSwitchState(heaterIdx) == SwitchState::OFF) {
triggerEvent(HEATER_WENT_ON, heaterIdx, 0); triggerEvent(HEATER_WENT_ON, heaterIdx, 0);
{ {
MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX); MutexGuard mg(handlerLock, LOCK_TYPE, LOCK_TIMEOUT, LOCK_CTX);
heater.switchState = ON; heater.switchState = ON;
} }
} else {
triggerEvent(SWITCH_ALREADY_ON, heaterIdx);
}
EventManagerIF::triggerEvent(helper.heaters[heaterIdx].first->getObjectId(), MODE_INFO, EventManagerIF::triggerEvent(helper.heaters[heaterIdx].first->getObjectId(), MODE_INFO,
MODE_ON, 0); MODE_ON, 0);
busyWithSwitchCommanding = false; busyWithSwitchCommanding = false;