#include "fsfw/devicehandlers/HealthDevice.h" #include "fsfw/ipc/QueueFactory.h" HealthDevice::HealthDevice(object_id_t setObjectId, MessageQueueId_t parentQueue) : SystemObject(setObjectId), lastHealth(HEALTHY), parentQueue(parentQueue), commandQueue(), healthHelper(this, setObjectId) { auto mqArgs = MqArgs(setObjectId, static_cast(this)); commandQueue = QueueFactory::instance()->createMessageQueue( 3, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); } HealthDevice::~HealthDevice() { QueueFactory::instance()->deleteMessageQueue(commandQueue); } ReturnValue_t HealthDevice::performOperation(uint8_t opCode) { CommandMessage command; ReturnValue_t result = commandQueue->receiveMessage(&command); if (result == returnvalue::OK) { result = healthHelper.handleHealthCommand(&command); } return result; } ReturnValue_t HealthDevice::initialize() { ReturnValue_t result = SystemObject::initialize(); if (result != returnvalue::OK) { return result; } if (parentQueue != MessageQueueIF::NO_QUEUE) { return healthHelper.initialize(parentQueue); } return healthHelper.initialize(); } MessageQueueId_t HealthDevice::getCommandQueue() const { return commandQueue->getId(); } void HealthDevice::setParentQueue(MessageQueueId_t parentQueue) { healthHelper.setParentQueue(parentQueue); } bool HealthDevice::hasHealthChanged() { bool changed; HealthState currentHealth = healthHelper.getHealth(); changed = currentHealth != lastHealth; lastHealth = currentHealth; return changed; } ReturnValue_t HealthDevice::setHealth(HealthState health) { healthHelper.setHealth(health); return returnvalue::OK; } HasHealthIF::HealthState HealthDevice::getHealth() { return healthHelper.getHealth(); }