fsfw/devicehandlers/HealthDevice.cpp

60 lines
1.6 KiB
C++
Raw Permalink Normal View History

2020-08-13 20:53:35 +02:00
#include "HealthDevice.h"
#include "../ipc/QueueFactory.h"
HealthDevice::HealthDevice(object_id_t setObjectId,
MessageQueueId_t parentQueue) :
SystemObject(setObjectId), lastHealth(HEALTHY), parentQueue(
parentQueue), commandQueue(), healthHelper(this, setObjectId) {
2020-08-25 18:24:46 +02:00
commandQueue = QueueFactory::instance()->createMessageQueue(3);
}
HealthDevice::~HealthDevice() {
QueueFactory::instance()->deleteMessageQueue(commandQueue);
}
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
2020-10-12 18:18:41 +02:00
CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
2021-04-20 16:16:35 +02:00
result = healthHelper.handleHealthCommand(&command);
}
2021-04-20 16:16:35 +02:00
return result;
}
ReturnValue_t HealthDevice::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (parentQueue != 0) {
return healthHelper.initialize(parentQueue);
} else {
return healthHelper.initialize();
}
}
MessageQueueId_t HealthDevice::getCommandQueue() const {
return commandQueue->getId();
}
void HealthDevice::setParentQueue(MessageQueueId_t parentQueue) {
2020-06-25 18:09:32 +02:00
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 HasReturnvaluesIF::RETURN_OK;
}
HasHealthIF::HealthState HealthDevice::getHealth() {
return healthHelper.getHealth();
}