143 lines
4.3 KiB
C++
143 lines
4.3 KiB
C++
#include "FreshDeviceHandlerBase.h"
|
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
|
#include "fsfw/subsystem/helper.h"
|
|
|
|
FreshDeviceHandlerBase::FreshDeviceHandlerBase(DhbConfig config)
|
|
: SystemObject(config.objectId),
|
|
actionHelper(this, nullptr),
|
|
modeHelper(this),
|
|
healthHelper(this, getObjectId()),
|
|
poolManager(this, nullptr) {
|
|
auto mqArgs = MqArgs(config.objectId, static_cast<void*>(this));
|
|
messageQueue = QueueFactory::instance()->createMessageQueue(
|
|
config.msgQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
|
}
|
|
FreshDeviceHandlerBase::~FreshDeviceHandlerBase() {
|
|
QueueFactory::instance()->deleteMessageQueue(messageQueue);
|
|
}
|
|
|
|
[[nodiscard]] object_id_t FreshDeviceHandlerBase::getObjectId() const {
|
|
return SystemObject::getObjectId();
|
|
}
|
|
|
|
ReturnValue_t FreshDeviceHandlerBase::performOperation(uint8_t opCode) {
|
|
handleQueue();
|
|
performDeviceOperation(opCode);
|
|
return returnvalue::OK;
|
|
}
|
|
|
|
void FreshDeviceHandlerBase::startTransition(Mode_t mode_, Submode_t submode_) {
|
|
triggerEvent(CHANGING_MODE, mode_, submode_);
|
|
mode = mode_;
|
|
submode = submode_;
|
|
modeHelper.modeChanged(mode, submode);
|
|
modeChanged(mode, submode);
|
|
announceMode(false);
|
|
}
|
|
|
|
void FreshDeviceHandlerBase::getMode(Mode_t* mode_, Submode_t* submode_) {
|
|
*mode_ = this->mode;
|
|
*submode_ = this->submode;
|
|
}
|
|
|
|
void FreshDeviceHandlerBase::announceMode(bool recursive) {
|
|
triggerEvent(MODE_INFO, mode, submode);
|
|
}
|
|
|
|
void FreshDeviceHandlerBase::modeChanged(Mode_t mode_, Submode_t submode_) {}
|
|
|
|
[[nodiscard]] MessageQueueId_t FreshDeviceHandlerBase::getCommandQueue() const {
|
|
return messageQueue->getId();
|
|
}
|
|
|
|
ReturnValue_t FreshDeviceHandlerBase::handleQueue() {
|
|
CommandMessage command;
|
|
ReturnValue_t result;
|
|
for (result = messageQueue->receiveMessage(&command); result == returnvalue::OK;
|
|
result = messageQueue->receiveMessage(&command)) {
|
|
result = actionHelper.handleActionMessage(&command);
|
|
if (result == returnvalue::OK) {
|
|
continue;
|
|
}
|
|
|
|
result = modeHelper.handleModeCommand(&command);
|
|
if (result == returnvalue::OK) {
|
|
continue;
|
|
}
|
|
|
|
result = healthHelper.handleHealthCommand(&command);
|
|
if (result == returnvalue::OK) {
|
|
continue;
|
|
}
|
|
|
|
result = poolManager.handleHousekeepingMessage(&command);
|
|
if (result == returnvalue::OK) {
|
|
continue;
|
|
}
|
|
|
|
result = handleCommandMessage(&command);
|
|
if (result == returnvalue::OK) {
|
|
continue;
|
|
}
|
|
command.setToUnknownCommand();
|
|
messageQueue->reply(&command);
|
|
}
|
|
}
|
|
|
|
HasHealthIF::HealthState FreshDeviceHandlerBase::getHealth() { return healthHelper.getHealth(); }
|
|
|
|
const HasHealthIF* FreshDeviceHandlerBase::getOptHealthIF() const { return this; }
|
|
|
|
const HasModesIF& FreshDeviceHandlerBase::getModeIF() const { return *this; }
|
|
|
|
ModeTreeChildIF& FreshDeviceHandlerBase::getModeTreeChildIF() { return *this; }
|
|
|
|
ReturnValue_t FreshDeviceHandlerBase::connectModeTreeParent(HasModeTreeChildrenIF& parent) {
|
|
return modetree::connectModeTreeParent(parent, *this, &healthHelper, modeHelper);
|
|
}
|
|
|
|
// Executable Overrides.
|
|
void FreshDeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_) { executingTask = task_; }
|
|
|
|
// Pool Manager overrides.
|
|
LocalDataPoolManager* FreshDeviceHandlerBase::getHkManagerHandle() { return &poolManager; }
|
|
|
|
[[nodiscard]] uint32_t FreshDeviceHandlerBase::getPeriodicOperationFrequency() const {
|
|
return this->executingTask->getPeriodMs();
|
|
}
|
|
|
|
ReturnValue_t FreshDeviceHandlerBase::initializeAfterTaskCreation() {
|
|
return poolManager.initializeAfterTaskCreation();
|
|
}
|
|
|
|
ReturnValue_t FreshDeviceHandlerBase::setHealth(HasHealthIF::HealthState health) {
|
|
if (health == HasHealthIF::FAULTY or health == HasHealthIF::PERMANENT_FAULTY) {
|
|
// TODO: Go to off where applicable. Health state machine? How does DHB do it?
|
|
}
|
|
healthHelper.setHealth(health);
|
|
return returnvalue::OK;
|
|
}
|
|
|
|
// System Object overrides.
|
|
ReturnValue_t FreshDeviceHandlerBase::initialize() {
|
|
ReturnValue_t result = modeHelper.initialize();
|
|
if (result != returnvalue::OK) {
|
|
return result;
|
|
}
|
|
result = healthHelper.initialize();
|
|
if (result != returnvalue::OK) {
|
|
return result;
|
|
}
|
|
result = actionHelper.initialize(messageQueue);
|
|
if (result != returnvalue::OK) {
|
|
return result;
|
|
}
|
|
|
|
result = poolManager.initialize(messageQueue);
|
|
if (result != returnvalue::OK) {
|
|
return result;
|
|
}
|
|
return SystemObject::initialize();
|
|
}
|