fsfw/src/fsfw/devicehandlers/HealthDevice.cpp

58 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) {
2022-02-19 16:14:02 +01:00
auto mqArgs = MqArgs(setObjectId, static_cast<void*>(this));
2022-02-22 10:17:56 +01:00
commandQueue = QueueFactory::instance()->createMessageQueue(
3, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
}
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);
2022-08-16 01:08:26 +02:00
if (result == returnvalue::OK) {
2022-02-02 10:29:30 +01:00
result = healthHelper.handleHealthCommand(&command);
}
return result;
}
ReturnValue_t HealthDevice::initialize() {
2022-02-02 10:29:30 +01:00
ReturnValue_t result = SystemObject::initialize();
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
return result;
}
2023-04-03 18:54:35 +02:00
if (parentQueue != MessageQueueIF::NO_QUEUE) {
2022-02-02 10:29:30 +01:00
return healthHelper.initialize(parentQueue);
}
2023-04-03 18:54:35 +02:00
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);
2022-08-16 01:08:26 +02:00
return returnvalue::OK;
}
2022-02-02 10:29:30 +01:00
HasHealthIF::HealthState HealthDevice::getHealth() { return healthHelper.getHealth(); }