2022-02-25 11:58:02 +01:00
|
|
|
#include "EiveSystem.h"
|
2022-04-14 09:54:07 +02:00
|
|
|
|
2023-03-10 15:21:36 +01:00
|
|
|
#include <eive/objects.h>
|
2023-03-08 18:56:27 +01:00
|
|
|
#include <fsfw/events/EventManager.h>
|
|
|
|
#include <fsfw/ipc/QueueFactory.h>
|
2023-03-24 20:50:33 +01:00
|
|
|
#include <mission/acs/defs.h>
|
2023-03-24 21:20:27 +01:00
|
|
|
#include <mission/com/defs.h>
|
|
|
|
#include <mission/controller/tcsDefs.h>
|
2023-02-13 01:26:30 +01:00
|
|
|
|
2023-03-21 14:38:10 +01:00
|
|
|
#include "mission/sysDefs.h"
|
|
|
|
|
2022-09-29 19:40:00 +02:00
|
|
|
EiveSystem::EiveSystem(object_id_t setObjectId, uint32_t maxNumberOfSequences,
|
2022-04-14 09:54:07 +02:00
|
|
|
uint32_t maxNumberOfTables)
|
2023-03-08 18:56:27 +01:00
|
|
|
: Subsystem(setObjectId, maxNumberOfSequences, maxNumberOfTables) {
|
2023-03-13 17:36:41 +01:00
|
|
|
auto mqArgs = MqArgs(SubsystemBase::getObjectId(), static_cast<void*>(this));
|
2023-03-08 18:56:27 +01:00
|
|
|
eventQueue =
|
|
|
|
QueueFactory::instance()->createMessageQueue(10, EventMessage::EVENT_MESSAGE_SIZE, &mqArgs);
|
|
|
|
}
|
2023-02-13 01:26:30 +01:00
|
|
|
|
|
|
|
void EiveSystem::announceMode(bool recursive) {
|
|
|
|
const char* modeStr = "UNKNOWN";
|
|
|
|
switch (mode) {
|
2023-03-21 14:38:10 +01:00
|
|
|
case (satsystem::Mode::BOOT): {
|
|
|
|
modeStr = "OFF/BOOT";
|
2023-02-13 01:26:30 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-03-21 14:38:10 +01:00
|
|
|
case (satsystem::Mode::SAFE): {
|
2023-02-13 01:26:30 +01:00
|
|
|
modeStr = "SAFE";
|
|
|
|
break;
|
|
|
|
}
|
2023-03-21 14:38:10 +01:00
|
|
|
case (satsystem::Mode::PTG_IDLE): {
|
2023-02-13 01:26:30 +01:00
|
|
|
modeStr = "POINTING IDLE";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (acs::AcsMode::PTG_INERTIAL): {
|
|
|
|
modeStr = "POINTING INERTIAL";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (acs::AcsMode::PTG_TARGET): {
|
|
|
|
modeStr = "POINTING TARGET";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (acs::AcsMode::PTG_TARGET_GS): {
|
|
|
|
modeStr = "POINTING TARGET GS";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sif::info << "EIVE system is now in " << modeStr << " mode" << std::endl;
|
|
|
|
return Subsystem::announceMode(recursive);
|
|
|
|
}
|
2023-03-08 18:56:27 +01:00
|
|
|
|
|
|
|
void EiveSystem::performChildOperation() {
|
2023-03-21 14:38:10 +01:00
|
|
|
Subsystem::performChildOperation();
|
2023-03-08 18:56:27 +01:00
|
|
|
handleEventMessages();
|
2023-03-21 14:38:10 +01:00
|
|
|
if (not isInTransition and performSafeRecovery) {
|
|
|
|
commandSelfToSafe();
|
|
|
|
performSafeRecovery = false;
|
|
|
|
}
|
2023-03-08 18:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t EiveSystem::initialize() {
|
2023-03-13 15:59:19 +01:00
|
|
|
auto* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
|
2023-03-08 18:56:27 +01:00
|
|
|
if (manager == nullptr) {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::error << "AcsSubsystem::initialize: Invalid event manager" << std::endl;
|
|
|
|
#endif
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
ReturnValue_t result = manager->registerListener(eventQueue->getId());
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::warning << "AcsSubsystem::registerListener: Failed to register as "
|
|
|
|
"listener"
|
|
|
|
<< std::endl;
|
|
|
|
#endif
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
2023-03-13 17:36:41 +01:00
|
|
|
manager->subscribeToEvent(eventQueue->getId(),
|
|
|
|
event::getEventId(tcsCtrl::PCDU_SYSTEM_OVERHEATING));
|
|
|
|
manager->subscribeToEvent(eventQueue->getId(), event::getEventId(tcsCtrl::OBC_OVERHEATING));
|
|
|
|
|
2023-03-10 15:21:36 +01:00
|
|
|
return Subsystem::initialize();
|
2023-03-08 18:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EiveSystem::handleEventMessages() {
|
|
|
|
EventMessage event;
|
2023-03-13 17:36:41 +01:00
|
|
|
for (ReturnValue_t status = eventQueue->receiveMessage(&event); status == returnvalue::OK;
|
|
|
|
status = eventQueue->receiveMessage(&event)) {
|
2023-03-08 18:56:27 +01:00
|
|
|
switch (event.getMessageId()) {
|
|
|
|
case EventMessage::EVENT_MESSAGE:
|
2023-03-13 17:36:41 +01:00
|
|
|
switch (event.getEvent()) {
|
|
|
|
case tcsCtrl::OBC_OVERHEATING:
|
|
|
|
case tcsCtrl::PCDU_SYSTEM_OVERHEATING: {
|
2023-03-21 14:38:10 +01:00
|
|
|
if (isInTransition) {
|
|
|
|
performSafeRecovery = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-13 17:36:41 +01:00
|
|
|
commandSelfToSafe();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-03-08 18:56:27 +01:00
|
|
|
break;
|
|
|
|
default:
|
2023-03-21 15:17:31 +01:00
|
|
|
sif::debug << "EiveSystem: Did not subscribe to event " << event.getEvent() << std::endl;
|
2023-03-08 18:56:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-21 14:38:10 +01:00
|
|
|
|
|
|
|
void EiveSystem::commandSelfToSafe() { startTransition(satsystem::Mode::SAFE, 0); }
|