2020-12-03 13:14:30 +01:00
|
|
|
#ifndef FSFW_CONTROLLER_CONTROLLERBASE_H_
|
|
|
|
#define FSFW_CONTROLLER_CONTROLLERBASE_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../health/HasHealthIF.h"
|
|
|
|
#include "../health/HealthHelper.h"
|
|
|
|
#include "../modes/HasModesIF.h"
|
|
|
|
#include "../modes/ModeHelper.h"
|
|
|
|
#include "../objectmanager/SystemObject.h"
|
|
|
|
#include "../tasks/ExecutableObjectIF.h"
|
2020-12-03 13:14:30 +01:00
|
|
|
#include "../tasks/PeriodicTaskIF.h"
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../datapool/HkSwitchHelper.h"
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2020-12-03 13:14:30 +01:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
class ControllerBase: public HasModesIF,
|
2021-01-28 11:47:28 +01:00
|
|
|
public HasHealthIF,
|
|
|
|
public ExecutableObjectIF,
|
|
|
|
public SystemObject,
|
|
|
|
public HasReturnvaluesIF {
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2021-01-28 11:47:28 +01:00
|
|
|
static const Mode_t MODE_NORMAL = 2;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
ControllerBase(object_id_t setObjectId, object_id_t parentId,
|
|
|
|
size_t commandQueueDepth = 3);
|
|
|
|
virtual ~ControllerBase();
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
/** SystemObject override */
|
|
|
|
virtual ReturnValue_t initialize() override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
virtual MessageQueueId_t getCommandQueue() const override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
/** HasHealthIF overrides */
|
|
|
|
virtual ReturnValue_t setHealth(HealthState health) override;
|
|
|
|
virtual HasHealthIF::HealthState getHealth() override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
/** ExecutableObjectIF overrides */
|
|
|
|
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
|
|
|
virtual void setTaskIF(PeriodicTaskIF* task) override;
|
|
|
|
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-03 13:14:30 +01:00
|
|
|
protected:
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
/**
|
|
|
|
* Implemented by child class. Handle command messages which are not
|
|
|
|
* mode or health messages.
|
|
|
|
* @param message
|
|
|
|
* @return
|
|
|
|
*/
|
2020-12-03 13:14:30 +01:00
|
|
|
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2020-12-03 13:14:30 +01:00
|
|
|
/**
|
|
|
|
* Periodic helper, implemented by child class.
|
|
|
|
*/
|
|
|
|
virtual void performControlOperation() = 0;
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2020-12-03 13:14:30 +01:00
|
|
|
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
|
|
|
uint32_t *msToReachTheMode) = 0;
|
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
const object_id_t parentId;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
Mode_t mode;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
Submode_t submode;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
MessageQueueIF* commandQueue = nullptr;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
ModeHelper modeHelper;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
HealthHelper healthHelper;
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2021-01-28 11:47:28 +01:00
|
|
|
/**
|
|
|
|
* Pointer to the task which executes this component,
|
|
|
|
* is invalid before setTaskIF was called.
|
|
|
|
*/
|
|
|
|
PeriodicTaskIF* executingTask = nullptr;
|
|
|
|
|
|
|
|
/** Handle mode and health messages */
|
|
|
|
virtual void handleQueue();
|
|
|
|
|
|
|
|
/** Mode helpers */
|
|
|
|
virtual void modeChanged(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 setToExternalControl();
|
|
|
|
virtual void announceMode(bool recursive);
|
|
|
|
/** HK helpers */
|
|
|
|
virtual void changeHK(Mode_t mode, Submode_t submode, bool enable);
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-12-03 13:14:30 +01:00
|
|
|
#endif /* FSFW_CONTROLLER_CONTROLLERBASE_H_ */
|