fsfw/src/fsfw/devicehandlers/HealthDevice.cpp

57 lines
1.7 KiB
C++
Raw Normal View History

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"
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);
}
2022-02-02 10:29:30 +01:00
HealthDevice::~HealthDevice() { QueueFactory::instance()->deleteMessageQueue(commandQueue); }
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;
}
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();
}
}
2022-02-02 10:29:30 +01:00
MessageQueueId_t HealthDevice::getCommandQueue() const { return commandQueue->getId(); }
void HealthDevice::setParentQueue(MessageQueueId_t parentQueue) {
2022-02-02 10:29:30 +01:00
healthHelper.setParentQueue(parentQueue);
}
bool HealthDevice::hasHealthChanged() {
2022-02-02 10:29:30 +01:00
bool changed;
HealthState currentHealth = healthHelper.getHealth();
changed = currentHealth != lastHealth;
lastHealth = currentHealth;
return changed;
}
ReturnValue_t HealthDevice::setHealth(HealthState health) {
2022-02-02 10:29:30 +01:00
healthHelper.setHealth(health);
return HasReturnvaluesIF::RETURN_OK;
}
2022-02-02 10:29:30 +01:00
HasHealthIF::HealthState HealthDevice::getHealth() { return healthHelper.getHealth(); }