2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/devicehandlers/HealthDevice.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
HealthDevice::HealthDevice(object_id_t setObjectId, MessageQueueId_t parentQueue)
|
|
|
|
: SystemObject(setObjectId),
|
|
|
|
lastHealth(HEALTHY),
|
|
|
|
parentQueue(parentQueue),
|
|
|
|
commandQueue(),
|
|
|
|
healthHelper(this, setObjectId) {
|
|
|
|
commandQueue = QueueFactory::instance()->createMessageQueue(3);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
HealthDevice::~HealthDevice() { QueueFactory::instance()->deleteMessageQueue(commandQueue); }
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
|
2022-02-02 10:29:30 +01:00
|
|
|
CommandMessage command;
|
|
|
|
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
|
|
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
result = healthHelper.handleHealthCommand(&command);
|
|
|
|
}
|
|
|
|
return result;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t HealthDevice::initialize() {
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t result = SystemObject::initialize();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (parentQueue != 0) {
|
|
|
|
return healthHelper.initialize(parentQueue);
|
|
|
|
} else {
|
|
|
|
return healthHelper.initialize();
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
MessageQueueId_t HealthDevice::getCommandQueue() const { return commandQueue->getId(); }
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
void HealthDevice::setParentQueue(MessageQueueId_t parentQueue) {
|
2022-02-02 10:29:30 +01:00
|
|
|
healthHelper.setParentQueue(parentQueue);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HealthDevice::hasHealthChanged() {
|
2022-02-02 10:29:30 +01:00
|
|
|
bool changed;
|
|
|
|
HealthState currentHealth = healthHelper.getHealth();
|
|
|
|
changed = currentHealth != lastHealth;
|
|
|
|
lastHealth = currentHealth;
|
|
|
|
return changed;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t HealthDevice::setHealth(HealthState health) {
|
2022-02-02 10:29:30 +01:00
|
|
|
healthHelper.setHealth(health);
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
HasHealthIF::HealthState HealthDevice::getHealth() { return healthHelper.getHealth(); }
|