2020-12-14 11:35:45 +01:00
|
|
|
#ifndef FSFW_SUBSYSTEM_SUBSYSTEMBASE_H_
|
|
|
|
#define FSFW_SUBSYSTEM_SUBSYSTEMBASE_H_
|
|
|
|
|
|
|
|
#include "modes/HasModeSequenceIF.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../container/HybridIterator.h"
|
|
|
|
#include "../health/HasHealthIF.h"
|
|
|
|
#include "../health/HealthHelper.h"
|
|
|
|
#include "../modes/HasModesIF.h"
|
|
|
|
#include "../objectmanager/SystemObject.h"
|
|
|
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
|
|
|
#include "../tasks/ExecutableObjectIF.h"
|
|
|
|
#include "../ipc/MessageQueueIF.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
#include <map>
|
|
|
|
|
2020-12-14 11:35:45 +01:00
|
|
|
/**
|
|
|
|
* @defgroup subsystems Subsystem Objects
|
|
|
|
* Contains all Subsystem and Assemblies
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
class SubsystemBase: public SystemObject,
|
|
|
|
public HasModesIF,
|
|
|
|
public HasHealthIF,
|
|
|
|
public HasReturnvaluesIF,
|
|
|
|
public ExecutableObjectIF {
|
|
|
|
public:
|
2018-07-12 16:29:32 +02:00
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::SUBSYSTEM_BASE;
|
2016-06-15 23:48:41 +02:00
|
|
|
static const ReturnValue_t CHILD_NOT_FOUND = MAKE_RETURN_CODE(0x01);
|
|
|
|
static const ReturnValue_t CHILD_INFO_UPDATED = MAKE_RETURN_CODE(0x02);
|
|
|
|
static const ReturnValue_t CHILD_DOESNT_HAVE_MODES = MAKE_RETURN_CODE(0x03);
|
|
|
|
static const ReturnValue_t COULD_NOT_INSERT_CHILD = MAKE_RETURN_CODE(0x04);
|
|
|
|
static const ReturnValue_t TABLE_CONTAINS_INVALID_OBJECT_ID =
|
|
|
|
MAKE_RETURN_CODE(0x05);
|
|
|
|
|
|
|
|
SubsystemBase(object_id_t setObjectId, object_id_t parent,
|
|
|
|
Mode_t initialMode = 0, uint16_t commandQueueDepth = 8);
|
|
|
|
virtual ~SubsystemBase();
|
|
|
|
|
2020-12-14 11:35:45 +01:00
|
|
|
virtual MessageQueueId_t getCommandQueue() const override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-04-20 22:01:56 +02:00
|
|
|
/**
|
|
|
|
* Function to register the child objects.
|
|
|
|
* Performs a checks if the child does implement HasHealthIF and/or HasModesIF
|
|
|
|
*
|
|
|
|
* Also adds them to the internal childrenMap.
|
|
|
|
*
|
|
|
|
* @param objectId
|
|
|
|
* @return RETURN_OK if successful
|
|
|
|
* CHILD_DOESNT_HAVE_MODES if Child is no HasHealthIF and no HasModesIF
|
|
|
|
* COULD_NOT_INSERT_CHILD If the Child could not be added to the ChildrenMap
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t registerChild(object_id_t objectId);
|
|
|
|
|
2020-12-14 11:35:45 +01:00
|
|
|
virtual ReturnValue_t initialize() override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-14 11:35:45 +01:00
|
|
|
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-14 11:35:45 +01:00
|
|
|
virtual ReturnValue_t setHealth(HealthState health) override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-14 11:35:45 +01:00
|
|
|
virtual HasHealthIF::HealthState getHealth() override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
struct ChildInfo {
|
|
|
|
MessageQueueId_t commandQueue;
|
|
|
|
Mode_t mode;
|
2018-07-12 16:29:32 +02:00
|
|
|
Submode_t submode;bool healthChanged;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Mode_t mode;
|
|
|
|
|
2021-04-20 20:45:15 +02:00
|
|
|
Submode_t submode = SUBMODE_NONE;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-04-20 20:45:15 +02:00
|
|
|
bool childrenChangedMode = false;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Always check this against <=0, so you are robust against too many replies
|
|
|
|
*/
|
2020-12-14 11:35:45 +01:00
|
|
|
int32_t commandsOutstanding = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-14 11:35:45 +01:00
|
|
|
MessageQueueIF* commandQueue = nullptr;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
HealthHelper healthHelper;
|
|
|
|
|
|
|
|
ModeHelper modeHelper;
|
|
|
|
|
|
|
|
const object_id_t parentId;
|
|
|
|
|
|
|
|
typedef std::map<object_id_t, ChildInfo> ChildrenMap;
|
|
|
|
ChildrenMap childrenMap;
|
|
|
|
|
|
|
|
void checkCommandQueue();
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
/**
|
|
|
|
* We need to know the target Submode, as children are able to inherit the submode
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t checkStateAgainstTable(
|
2018-07-12 16:29:32 +02:00
|
|
|
HybridIterator<ModeListEntry> tableIter, Submode_t targetSubmode);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
/**
|
|
|
|
* We need to know the target Submode, as children are able to inherit the submode
|
|
|
|
* Still, we have a default for all child implementations which do not use submode inheritance
|
|
|
|
*/
|
|
|
|
void executeTable(HybridIterator<ModeListEntry> tableIter,
|
|
|
|
Submode_t targetSubmode = SUBMODE_NONE);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
ReturnValue_t updateChildMode(MessageQueueId_t queue, Mode_t mode,
|
|
|
|
Submode_t submode);
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t updateChildChangedHealth(MessageQueueId_t queue,
|
|
|
|
bool changedHealth = true);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
virtual ReturnValue_t handleModeReply(CommandMessage *message);
|
|
|
|
|
|
|
|
void commandAllChildren(CommandMessage *message);
|
|
|
|
|
|
|
|
ReturnValue_t checkTable(HybridIterator<ModeListEntry> tableIter);
|
|
|
|
|
|
|
|
void replyToCommand(CommandMessage *message);
|
|
|
|
|
|
|
|
void setMode(Mode_t newMode, Submode_t newSubmode);
|
|
|
|
|
|
|
|
void setMode(Mode_t newMode);
|
|
|
|
|
|
|
|
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;
|
|
|
|
|
|
|
|
virtual void performChildOperation() = 0;
|
|
|
|
|
|
|
|
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
|
|
|
uint32_t *msToReachTheMode) = 0;
|
|
|
|
|
|
|
|
virtual void startTransition(Mode_t mode, Submode_t submode) = 0;
|
|
|
|
|
|
|
|
virtual void getMode(Mode_t *mode, Submode_t *submode);
|
|
|
|
|
|
|
|
virtual void setToExternalControl();
|
|
|
|
|
|
|
|
virtual void announceMode(bool recursive);
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
virtual void modeChanged();
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-12-14 11:35:45 +01:00
|
|
|
#endif /* FSFW_SUBSYSTEM_SUBSYSTEMBASE_H_ */
|