diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 08f1fc64..987cb7a3 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -623,7 +623,7 @@ void ObjectFactory::createHeaterComponents(PowerSwitchIF* pwrSwitcher, HealthTab heaterGpiosCookie->addGpio(gpioIds::HEATER_7, gpio); new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, heaterGpiosCookie, pwrSwitcher, - pcdu::Switches::PDU2_CH3_TCS_BOARD_HEATER_IN_8V, healthTable); + pcdu::Switches::PDU2_CH3_TCS_BOARD_HEATER_IN_8V); } void ObjectFactory::createSolarArrayDeploymentComponents() { diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 5f62122d..dec71a2a 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -12,20 +12,17 @@ HeaterHandler::HeaterHandler(object_id_t setObjectId_, object_id_t gpioDriverId_, CookieIF* gpioCookie_, PowerSwitchIF* mainLineSwitcher_, - power::Switch_t mainLineSwitch_, HealthTableIF* healthTable_) + power::Switch_t mainLineSwitch_) : SystemObject(setObjectId_), gpioDriverId(gpioDriverId_), gpioCookie(gpioCookie_), mainLineSwitcher(mainLineSwitcher_), mainLineSwitch(mainLineSwitch_), - healthTable(healthTable_), + healthHelper(this, getObjectId()), actionHelper(this, nullptr) { if (mainLineSwitcher == nullptr) { throw std::invalid_argument("HeaterHandler::HeaterHandler: Invalid PowerSwitchIF"); } - if (healthTable == nullptr) { - throw std::invalid_argument("HeaterHandler::HeaterHandler: Invalid HealthTableIF"); - } auto mqArgs = MqArgs(setObjectId_, static_cast(this)); commandQueue = QueueFactory::instance()->createMessageQueue( cmdQueueSize, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); @@ -65,9 +62,7 @@ ReturnValue_t HeaterHandler::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } - if (healthTable != nullptr) { - healthTable->registerObject(getObjectId()); - } + healthHelper.initialize(commandQueue->getId()); IPCStore = ObjectManager::instance()->get(objects::IPC_STORE); if (IPCStore == nullptr) { @@ -103,16 +98,24 @@ void HeaterHandler::setInitialSwitchStates() { } void HeaterHandler::readCommandQueue() { + ReturnValue_t result = RETURN_OK; CommandMessage command; - ReturnValue_t result = commandQueue->receiveMessage(&command); - if (result != RETURN_OK) { - return; - } - - result = actionHelper.handleActionMessage(&command); - if (result == RETURN_OK) { - return; - } + do { + result = commandQueue->receiveMessage(&command); + if (result == MessageQueueIF::EMPTY) { + break; + } else if (result != RETURN_OK) { + sif::warning << "HeaterHandler::readCommandQueue: Message reception error" << std::endl; + } + result = actionHelper.handleActionMessage(&command); + if (result == RETURN_OK) { + continue; + } + result = healthHelper.handleHealthCommand(&command); + if (result == RETURN_OK) { + continue; + } + } while (result == RETURN_OK); } ReturnValue_t HeaterHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, @@ -353,16 +356,8 @@ ReturnValue_t HeaterHandler::getFuseState(uint8_t fuseNr) const { return 0; } uint32_t HeaterHandler::getSwitchDelayMs(void) const { return 2000; } ReturnValue_t HeaterHandler::setHealth(HealthState health) { - if (healthTable != nullptr) { - healthTable->setHealth(getObjectId(), health); - return RETURN_OK; - } - return RETURN_FAILED; + healthHelper.setHealth(health); + return RETURN_OK; } -HasHealthIF::HealthState HeaterHandler::getHealth() { - if (healthTable != nullptr) { - return healthTable->getHealth(getObjectId()); - } - return HasHealthIF::HealthState::HEALTHY; -} +HasHealthIF::HealthState HeaterHandler::getHealth() { return healthHelper.getHealth(); } diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index ba0ac99e..aa8eea90 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -42,8 +43,7 @@ class HeaterHandler : public ExecutableObjectIF, static const DeviceCommandId_t SWITCH_HEATER = 0x0; HeaterHandler(object_id_t setObjectId, object_id_t gpioDriverId, CookieIF* gpioCookie, - PowerSwitchIF* mainLineSwitcherObjectId, power::Switch_t mainLineSwitch, - HealthTableIF* healthTable); + PowerSwitchIF* mainLineSwitcherObjectId, power::Switch_t mainLineSwitch); virtual ~HeaterHandler(); @@ -141,7 +141,7 @@ class HeaterHandler : public ExecutableObjectIF, /** Switch number of the heater power supply switch */ power::Switch_t mainLineSwitch; - HealthTableIF* healthTable = nullptr; + HealthHelper healthHelper; ActionHelper actionHelper;