fsfw/fdir/FailureIsolationBase.cpp

173 lines
5.2 KiB
C++
Raw Permalink Normal View History

2020-08-13 20:53:35 +02:00
#include "../events/EventManagerIF.h"
#include "FailureIsolationBase.h"
#include "../health/HasHealthIF.h"
#include "../health/HealthMessage.h"
#include "../ipc/QueueFactory.h"
2021-06-05 19:52:38 +02:00
#include "../objectmanager/ObjectManager.h"
2020-08-08 13:28:59 +02:00
FailureIsolationBase::FailureIsolationBase(object_id_t owner,
object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) :
ownerId(owner), faultTreeParent(parent),
parameterDomainBase(parameterDomainBase) {
eventQueue = QueueFactory::instance()->createMessageQueue(messageDepth,
EventMessage::EVENT_MESSAGE_SIZE);
}
FailureIsolationBase::~FailureIsolationBase() {
QueueFactory::instance()->deleteMessageQueue(eventQueue);
}
ReturnValue_t FailureIsolationBase::initialize() {
2021-06-05 19:52:38 +02:00
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(
objects::EVENT_MANAGER);
2020-08-08 13:28:59 +02:00
if (manager == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-08-08 13:28:59 +02:00
sif::error << "FailureIsolationBase::initialize: Event Manager has not"
" been initialized!" << std::endl;
#endif
return RETURN_FAILED;
}
ReturnValue_t result = manager->registerListener(eventQueue->getId());
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
2020-08-08 13:28:59 +02:00
if (ownerId != objects::NO_OBJECT) {
result = manager->subscribeToAllEventsFrom(eventQueue->getId(), ownerId);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
2021-06-05 19:52:38 +02:00
owner = ObjectManager::instance()->get<HasHealthIF>(ownerId);
2020-08-08 13:28:59 +02:00
if (owner == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-08-08 13:28:59 +02:00
sif::error << "FailureIsolationBase::intialize: Owner object "
"invalid. Make sure it implements HasHealthIF" << std::endl;
#endif
2020-08-08 13:28:59 +02:00
return ObjectManagerIF::CHILD_INIT_FAILED;
}
}
2020-08-08 13:28:59 +02:00
if (faultTreeParent != objects::NO_OBJECT) {
2021-06-05 19:52:38 +02:00
ConfirmsFailuresIF* parentIF = ObjectManager::instance()->get<ConfirmsFailuresIF>(
faultTreeParent);
2020-08-08 13:28:59 +02:00
if (parentIF == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-08-08 13:28:59 +02:00
sif::error << "FailureIsolationBase::intialize: Parent object"
<< "invalid." << std::endl;
#endif
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-08-08 13:28:59 +02:00
sif::error << "Make sure it implements ConfirmsFailuresIF."
<< std::endl;
#endif
2020-08-08 13:28:59 +02:00
return ObjectManagerIF::CHILD_INIT_FAILED;
return RETURN_FAILED;
}
eventQueue->setDefaultDestination(parentIF->getEventReceptionQueue());
}
return RETURN_OK;
}
void FailureIsolationBase::checkForFailures() {
EventMessage event;
for (ReturnValue_t result = eventQueue->receiveMessage(&event);
result == RETURN_OK; result = eventQueue->receiveMessage(&event)) {
if (event.getSender() == eventQueue->getId()) {
//We already got this event, because we sent it.
continue;
}
switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE:
if (isFdirDisabledForSeverity(event.getSeverity())) {
//We do not handle events when disabled.
continue;
}
eventReceived(&event);
break;
case EventMessage::CONFIRMATION_REQUEST:
doConfirmFault(&event);
break;
case EventMessage::YOUR_FAULT:
eventConfirmed(&event);
break;
case EventMessage::MY_FAULT:
wasParentsFault(&event);
break;
default:
break;
}
}
decrementFaultCounters();
}
void FailureIsolationBase::setOwnerHealth(HasHealthIF::HealthState health) {
if (owner != NULL) {
owner->setHealth(health);
}
//else: owner has no health.
}
MessageQueueId_t FailureIsolationBase::getEventReceptionQueue() {
return eventQueue->getId();
}
ReturnValue_t FailureIsolationBase::sendConfirmationRequest(EventMessage* event,
MessageQueueId_t destination) {
event->setMessageId(EventMessage::CONFIRMATION_REQUEST);
2020-08-08 13:28:59 +02:00
if (destination != MessageQueueIF::NO_QUEUE) {
return eventQueue->sendMessage(destination, event);
2020-08-08 13:28:59 +02:00
} else if (faultTreeParent != objects::NO_OBJECT) {
return eventQueue->sendToDefault(event);
}
return RETURN_FAILED;
}
void FailureIsolationBase::eventConfirmed(EventMessage* event) {
}
void FailureIsolationBase::wasParentsFault(EventMessage* event) {
}
void FailureIsolationBase::doConfirmFault(EventMessage* event) {
ReturnValue_t result = confirmFault(event);
if (result == YOUR_FAULT) {
event->setMessageId(EventMessage::YOUR_FAULT);
eventQueue->reply(event);
} else if (result == MY_FAULT) {
event->setMessageId(EventMessage::MY_FAULT);
eventQueue->reply(event);
} else {
}
}
ReturnValue_t FailureIsolationBase::confirmFault(EventMessage* event) {
return YOUR_FAULT;
}
void FailureIsolationBase::triggerEvent(Event event, uint32_t parameter1,
uint32_t parameter2) {
//With this mechanism, all events are disabled for a certain device.
//That's not so good for visibility.
2020-12-08 14:43:44 +01:00
if (isFdirDisabledForSeverity(event::getSeverity(event))) {
return;
}
EventMessage message(event, ownerId, parameter1, parameter2);
EventManagerIF::triggerEvent(&message, eventQueue->getId());
eventReceived(&message);
}
bool FailureIsolationBase::isFdirDisabledForSeverity(EventSeverity_t severity) {
2020-12-08 14:43:44 +01:00
if ((owner != NULL) && (severity != severity::INFO)) {
if (owner->getHealth() == HasHealthIF::EXTERNAL_CONTROL) {
//External control disables handling of fault messages.
return true;
}
}
return false;
}
void FailureIsolationBase::throwFdirEvent(Event event, uint32_t parameter1,
uint32_t parameter2) {
EventMessage message(event, ownerId, parameter1, parameter2);
EventManagerIF::triggerEvent(&message, eventQueue->getId());
}