fsfw/controller/ControllerBase.h

95 lines
2.6 KiB
C
Raw Normal View History

2020-08-28 18:33:29 +02:00
#ifndef FSFW_CONTROLLER_CONTROLLERBASE_H_
#define FSFW_CONTROLLER_CONTROLLERBASE_H_
#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-09-26 16:38:07 +02:00
#include "../tasks/PeriodicTaskIF.h"
2020-08-28 18:33:29 +02:00
#include "../datapool/HkSwitchHelper.h"
/**
2020-10-10 20:04:01 +02:00
* @brief Generic base class for controller classes
2020-08-28 18:33:29 +02:00
* @details
2020-10-10 20:04:01 +02:00
* Implements common interfaces for controllers, which generally have
* a mode and a health state. This avoids boilerplate code.
2020-08-28 18:33:29 +02:00
*/
class ControllerBase: public HasModesIF,
public HasHealthIF,
public ExecutableObjectIF,
public SystemObject,
public HasReturnvaluesIF {
public:
static const Mode_t MODE_NORMAL = 2;
ControllerBase(object_id_t setObjectId, object_id_t parentId,
size_t commandQueueDepth = 3);
virtual ~ControllerBase();
2020-10-10 20:04:01 +02:00
/** SystemObject override */
2020-08-28 18:33:29 +02:00
virtual ReturnValue_t initialize() override;
virtual MessageQueueId_t getCommandQueue() const override;
2020-10-10 20:04:01 +02:00
/** HasHealthIF overrides */
2020-08-28 18:33:29 +02:00
virtual ReturnValue_t setHealth(HealthState health) override;
virtual HasHealthIF::HealthState getHealth() override;
2020-10-10 20:04:01 +02:00
/** ExecutableObjectIF overrides */
virtual ReturnValue_t performOperation(uint8_t opCode) override;
virtual void setTaskIF(PeriodicTaskIF* task) override;
2020-08-28 18:33:29 +02:00
virtual ReturnValue_t initializeAfterTaskCreation() override;
protected:
/**
* Implemented by child class. Handle command messages which are not
* mode or health messages.
* @param message
* @return
*/
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;
2020-10-10 20:04:01 +02:00
/**
* Periodic helper, implemented by child class.
*/
2020-08-28 18:33:29 +02:00
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;
Submode_t submode;
MessageQueueIF* commandQueue = nullptr;
ModeHelper modeHelper;
HealthHelper healthHelper;
/**
* Pointer to the task which executes this component,
* is invalid before setTaskIF was called.
*/
PeriodicTaskIF* executingTask = nullptr;
2020-10-10 20:04:01 +02:00
/** Handle mode and health messages */
virtual void handleQueue();
2020-08-28 18:33:29 +02:00
2020-10-10 20:04:01 +02:00
/** Mode helpers */
2020-08-28 18:33:29 +02:00
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);
2020-10-10 20:04:01 +02:00
/** HK helpers */
2020-08-28 18:33:29 +02:00
virtual void changeHK(Mode_t mode, Submode_t submode, bool enable);
};
#endif /* FSFW_CONTROLLER_CONTROLLERBASE_H_ */