Merge pull request 'controller base update' (#290) from KSat/fsfw:mueller/controller-update into development
Reviewed-on: fsfw/fsfw#290
This commit is contained in:
commit
3dafdc9071
@ -1,16 +1,16 @@
|
|||||||
#include "../subsystem/SubsystemBase.h"
|
|
||||||
#include "ControllerBase.h"
|
#include "ControllerBase.h"
|
||||||
|
|
||||||
#include "../subsystem/SubsystemBase.h"
|
#include "../subsystem/SubsystemBase.h"
|
||||||
#include "../ipc/QueueFactory.h"
|
#include "../ipc/QueueFactory.h"
|
||||||
#include "../action/HasActionsIF.h"
|
#include "../action/HasActionsIF.h"
|
||||||
|
|
||||||
ControllerBase::ControllerBase(uint32_t setObjectId, uint32_t parentId,
|
ControllerBase::ControllerBase(object_id_t setObjectId, object_id_t parentId,
|
||||||
size_t commandQueueDepth) :
|
size_t commandQueueDepth) :
|
||||||
SystemObject(setObjectId), parentId(parentId), mode(MODE_OFF), submode(
|
SystemObject(setObjectId), parentId(parentId), mode(MODE_OFF),
|
||||||
SUBMODE_NONE), commandQueue(NULL), modeHelper(
|
submode(SUBMODE_NONE), modeHelper(this),
|
||||||
this), healthHelper(this, setObjectId),hkSwitcher(this),executingTask(NULL) {
|
healthHelper(this, setObjectId) {
|
||||||
commandQueue = QueueFactory::instance()->createMessageQueue(commandQueueDepth);
|
commandQueue = QueueFactory::instance()->createMessageQueue(
|
||||||
|
commandQueueDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerBase::~ControllerBase() {
|
ControllerBase::~ControllerBase() {
|
||||||
@ -24,9 +24,9 @@ ReturnValue_t ControllerBase::initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MessageQueueId_t parentQueue = 0;
|
MessageQueueId_t parentQueue = 0;
|
||||||
if (parentId != 0) {
|
if (parentId != objects::NO_OBJECT) {
|
||||||
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
|
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
|
||||||
if (parent == NULL) {
|
if (parent == nullptr) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
parentQueue = parent->getCommandQueue();
|
parentQueue = parent->getCommandQueue();
|
||||||
@ -44,10 +44,6 @@ ReturnValue_t ControllerBase::initialize() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = hkSwitcher.initialize();
|
|
||||||
if (result != RETURN_OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,26 +52,27 @@ MessageQueueId_t ControllerBase::getCommandQueue() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ControllerBase::handleQueue() {
|
void ControllerBase::handleQueue() {
|
||||||
CommandMessage message;
|
CommandMessage command;
|
||||||
ReturnValue_t result;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
for (result = commandQueue->receiveMessage(&message); result == RETURN_OK;
|
for (result = commandQueue->receiveMessage(&command);
|
||||||
result = commandQueue->receiveMessage(&message)) {
|
result == RETURN_OK;
|
||||||
|
result = commandQueue->receiveMessage(&command)) {
|
||||||
|
|
||||||
result = modeHelper.handleModeCommand(&message);
|
result = modeHelper.handleModeCommand(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = healthHelper.handleHealthCommand(&message);
|
result = healthHelper.handleHealthCommand(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result = handleCommandMessage(&message);
|
result = handleCommandMessage(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
message.setToUnknownCommand();
|
command.setToUnknownCommand();
|
||||||
commandQueue->reply(&message);
|
commandQueue->reply(&command);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -106,7 +103,6 @@ void ControllerBase::announceMode(bool recursive) {
|
|||||||
|
|
||||||
ReturnValue_t ControllerBase::performOperation(uint8_t opCode) {
|
ReturnValue_t ControllerBase::performOperation(uint8_t opCode) {
|
||||||
handleQueue();
|
handleQueue();
|
||||||
hkSwitcher.performOperation();
|
|
||||||
performControlOperation();
|
performControlOperation();
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -135,3 +131,7 @@ void ControllerBase::setTaskIF(PeriodicTaskIF* task_){
|
|||||||
|
|
||||||
void ControllerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) {
|
void ControllerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t ControllerBase::initializeAfterTaskCreation() {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef CONTROLLERBASE_H_
|
#ifndef FSFW_CONTROLLER_CONTROLLERBASE_H_
|
||||||
#define CONTROLLERBASE_H_
|
#define FSFW_CONTROLLER_CONTROLLERBASE_H_
|
||||||
|
|
||||||
#include "../health/HasHealthIF.h"
|
#include "../health/HasHealthIF.h"
|
||||||
#include "../health/HealthHelper.h"
|
#include "../health/HealthHelper.h"
|
||||||
@ -7,73 +7,88 @@
|
|||||||
#include "../modes/ModeHelper.h"
|
#include "../modes/ModeHelper.h"
|
||||||
#include "../objectmanager/SystemObject.h"
|
#include "../objectmanager/SystemObject.h"
|
||||||
#include "../tasks/ExecutableObjectIF.h"
|
#include "../tasks/ExecutableObjectIF.h"
|
||||||
|
#include "../tasks/PeriodicTaskIF.h"
|
||||||
#include "../datapool/HkSwitchHelper.h"
|
#include "../datapool/HkSwitchHelper.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generic base class for controller classes
|
||||||
|
* @details
|
||||||
|
* Implements common interfaces for controllers, which generally have
|
||||||
|
* a mode and a health state. This avoids boilerplate code.
|
||||||
|
*/
|
||||||
class ControllerBase: public HasModesIF,
|
class ControllerBase: public HasModesIF,
|
||||||
public HasHealthIF,
|
public HasHealthIF,
|
||||||
public ExecutableObjectIF,
|
public ExecutableObjectIF,
|
||||||
public SystemObject,
|
public SystemObject,
|
||||||
public HasReturnvaluesIF {
|
public HasReturnvaluesIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const Mode_t MODE_NORMAL = 2;
|
static const Mode_t MODE_NORMAL = 2;
|
||||||
|
|
||||||
ControllerBase(uint32_t setObjectId, uint32_t parentId,
|
ControllerBase(object_id_t setObjectId, object_id_t parentId,
|
||||||
size_t commandQueueDepth = 3);
|
size_t commandQueueDepth = 3);
|
||||||
virtual ~ControllerBase();
|
virtual ~ControllerBase();
|
||||||
|
|
||||||
ReturnValue_t initialize();
|
/** SystemObject override */
|
||||||
|
virtual ReturnValue_t initialize() override;
|
||||||
|
|
||||||
virtual MessageQueueId_t getCommandQueue() const;
|
virtual MessageQueueId_t getCommandQueue() const override;
|
||||||
|
|
||||||
virtual ReturnValue_t performOperation(uint8_t opCode);
|
/** HasHealthIF overrides */
|
||||||
|
virtual ReturnValue_t setHealth(HealthState health) override;
|
||||||
virtual ReturnValue_t setHealth(HealthState health);
|
virtual HasHealthIF::HealthState getHealth() override;
|
||||||
|
|
||||||
virtual HasHealthIF::HealthState getHealth();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of ExecutableObjectIF function
|
|
||||||
*
|
|
||||||
* Used to setup the reference of the task, that executes this component
|
|
||||||
* @param task_ Pointer to the taskIF of this task
|
|
||||||
*/
|
|
||||||
virtual void setTaskIF(PeriodicTaskIF* task_);
|
|
||||||
|
|
||||||
|
/** ExecutableObjectIF overrides */
|
||||||
|
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
||||||
|
virtual void setTaskIF(PeriodicTaskIF* task) override;
|
||||||
|
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const uint32_t parentId;
|
|
||||||
|
/**
|
||||||
|
* Implemented by child class. Handle command messages which are not
|
||||||
|
* mode or health messages.
|
||||||
|
* @param message
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Periodic helper, implemented by child class.
|
||||||
|
*/
|
||||||
|
virtual void performControlOperation() = 0;
|
||||||
|
|
||||||
|
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||||
|
uint32_t *msToReachTheMode) = 0;
|
||||||
|
|
||||||
|
const object_id_t parentId;
|
||||||
|
|
||||||
Mode_t mode;
|
Mode_t mode;
|
||||||
|
|
||||||
Submode_t submode;
|
Submode_t submode;
|
||||||
|
|
||||||
MessageQueueIF* commandQueue;
|
MessageQueueIF* commandQueue = nullptr;
|
||||||
|
|
||||||
ModeHelper modeHelper;
|
ModeHelper modeHelper;
|
||||||
|
|
||||||
HealthHelper healthHelper;
|
HealthHelper healthHelper;
|
||||||
|
|
||||||
HkSwitchHelper hkSwitcher;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pointer to the task which executes this component, is invalid before setTaskIF was called.
|
* Pointer to the task which executes this component,
|
||||||
|
* is invalid before setTaskIF was called.
|
||||||
*/
|
*/
|
||||||
PeriodicTaskIF* executingTask;
|
PeriodicTaskIF* executingTask = nullptr;
|
||||||
|
|
||||||
void handleQueue();
|
/** Handle mode and health messages */
|
||||||
|
virtual void handleQueue();
|
||||||
|
|
||||||
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;
|
/** Mode helpers */
|
||||||
virtual void performControlOperation() = 0;
|
|
||||||
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
|
||||||
uint32_t *msToReachTheMode) = 0;
|
|
||||||
virtual void modeChanged(Mode_t mode, Submode_t submode);
|
virtual void modeChanged(Mode_t mode, Submode_t submode);
|
||||||
virtual void startTransition(Mode_t mode, Submode_t submode);
|
virtual void startTransition(Mode_t mode, Submode_t submode);
|
||||||
virtual void getMode(Mode_t *mode, Submode_t *submode);
|
virtual void getMode(Mode_t *mode, Submode_t *submode);
|
||||||
virtual void setToExternalControl();
|
virtual void setToExternalControl();
|
||||||
virtual void announceMode(bool recursive);
|
virtual void announceMode(bool recursive);
|
||||||
|
/** HK helpers */
|
||||||
virtual void changeHK(Mode_t mode, Submode_t submode, bool enable);
|
virtual void changeHK(Mode_t mode, Submode_t submode, bool enable);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONTROLLERBASE_H_ */
|
#endif /* FSFW_CONTROLLER_CONTROLLERBASE_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user