2020-08-13 20:53:35 +02:00
|
|
|
#include "ControllerBase.h"
|
2020-12-03 13:14:30 +01:00
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../subsystem/SubsystemBase.h"
|
|
|
|
#include "../ipc/QueueFactory.h"
|
|
|
|
#include "../action/HasActionsIF.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-03 13:14:30 +01:00
|
|
|
ControllerBase::ControllerBase(object_id_t setObjectId, object_id_t parentId,
|
2021-01-28 11:50:33 +01:00
|
|
|
size_t commandQueueDepth) :
|
|
|
|
SystemObject(setObjectId), parentId(parentId), mode(MODE_OFF),
|
|
|
|
submode(SUBMODE_NONE), modeHelper(this),
|
|
|
|
healthHelper(this, setObjectId) {
|
|
|
|
commandQueue = QueueFactory::instance()->createMessageQueue(
|
|
|
|
commandQueueDepth);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ControllerBase::~ControllerBase() {
|
2021-01-28 11:50:33 +01:00
|
|
|
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ControllerBase::initialize() {
|
2021-01-28 11:50:33 +01:00
|
|
|
ReturnValue_t result = SystemObject::initialize();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:50:33 +01:00
|
|
|
MessageQueueId_t parentQueue = 0;
|
|
|
|
if (parentId != objects::NO_OBJECT) {
|
|
|
|
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
|
|
|
|
if (parent == nullptr) {
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
parentQueue = parent->getCommandQueue();
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:50:33 +01:00
|
|
|
parent->registerChild(getObjectId());
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:50:33 +01:00
|
|
|
result = healthHelper.initialize(parentQueue);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:50:33 +01:00
|
|
|
result = modeHelper.initialize(parentQueue);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2021-01-28 11:50:33 +01:00
|
|
|
return RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t ControllerBase::getCommandQueue() const {
|
2021-01-28 11:50:33 +01:00
|
|
|
return commandQueue->getId();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerBase::handleQueue() {
|
2021-01-28 11:50:33 +01:00
|
|
|
CommandMessage command;
|
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
|
|
|
for (result = commandQueue->receiveMessage(&command);
|
|
|
|
result == RETURN_OK;
|
|
|
|
result = commandQueue->receiveMessage(&command)) {
|
|
|
|
|
|
|
|
result = modeHelper.handleModeCommand(&command);
|
|
|
|
if (result == RETURN_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = healthHelper.handleHealthCommand(&command);
|
|
|
|
if (result == RETURN_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
result = handleCommandMessage(&command);
|
|
|
|
if (result == RETURN_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
command.setToUnknownCommand();
|
|
|
|
commandQueue->reply(&command);
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerBase::startTransition(Mode_t mode, Submode_t submode) {
|
2021-01-28 11:50:33 +01:00
|
|
|
changeHK(this->mode, this->submode, false);
|
|
|
|
triggerEvent(CHANGING_MODE, mode, submode);
|
|
|
|
this->mode = mode;
|
|
|
|
this->submode = submode;
|
|
|
|
modeHelper.modeChanged(mode, submode);
|
|
|
|
modeChanged(mode, submode);
|
|
|
|
announceMode(false);
|
|
|
|
changeHK(this->mode, this->submode, true);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerBase::getMode(Mode_t* mode, Submode_t* submode) {
|
2021-01-28 11:50:33 +01:00
|
|
|
*mode = this->mode;
|
|
|
|
*submode = this->submode;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerBase::setToExternalControl() {
|
2021-01-28 11:50:33 +01:00
|
|
|
healthHelper.setHealth(EXTERNAL_CONTROL);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerBase::announceMode(bool recursive) {
|
2021-01-28 11:50:33 +01:00
|
|
|
triggerEvent(MODE_INFO, mode, submode);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t ControllerBase::performOperation(uint8_t opCode) {
|
2021-01-28 11:50:33 +01:00
|
|
|
handleQueue();
|
|
|
|
performControlOperation();
|
|
|
|
return RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerBase::modeChanged(Mode_t mode, Submode_t submode) {
|
2021-01-28 11:50:33 +01:00
|
|
|
return;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ControllerBase::setHealth(HealthState health) {
|
2021-01-28 11:50:33 +01:00
|
|
|
switch (health) {
|
|
|
|
case HEALTHY:
|
|
|
|
case EXTERNAL_CONTROL:
|
|
|
|
healthHelper.setHealth(health);
|
|
|
|
return RETURN_OK;
|
|
|
|
default:
|
|
|
|
return INVALID_HEALTH_STATE;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HasHealthIF::HealthState ControllerBase::getHealth() {
|
2021-01-28 11:50:33 +01:00
|
|
|
return healthHelper.getHealth();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2018-07-13 18:28:26 +02:00
|
|
|
void ControllerBase::setTaskIF(PeriodicTaskIF* task_){
|
2021-01-28 11:50:33 +01:00
|
|
|
executingTask = task_;
|
2018-07-13 18:28:26 +02:00
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
void ControllerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) {
|
|
|
|
}
|
2020-12-03 13:14:30 +01:00
|
|
|
|
|
|
|
ReturnValue_t ControllerBase::initializeAfterTaskCreation() {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|