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