fsfw/src/fsfw/subsystem/SubsystemBase.h

156 lines
5.3 KiB
C
Raw Normal View History

2020-12-14 11:35:45 +01:00
#ifndef FSFW_SUBSYSTEM_SUBSYSTEMBASE_H_
#define FSFW_SUBSYSTEM_SUBSYSTEMBASE_H_
2022-02-02 10:29:30 +01:00
#include <map>
2022-09-29 19:21:24 +02:00
#include "fsfw/container/HybridIterator.h"
#include "fsfw/health/HasHealthIF.h"
#include "fsfw/health/HealthHelper.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/modes/HasModesIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/subsystem/HasModeTreeChildrenIF.h"
2022-09-30 15:05:32 +02:00
#include "fsfw/subsystem/ModeTreeConnectionIF.h"
2022-09-29 19:21:24 +02:00
#include "fsfw/tasks/ExecutableObjectIF.h"
2022-02-02 10:29:30 +01:00
#include "modes/HasModeSequenceIF.h"
2020-12-14 11:35:45 +01:00
/**
* @defgroup subsystems Subsystem Objects
2022-03-21 09:12:56 +01:00
* All Subsystem and Assemblies can derive from this class. It contains helper classes to
* perform mode and health handling, which allows OBSW developers to build a mode tree for
2022-03-22 16:10:20 +01:00
* the whole satellite.
*
* Aside from setting up a mode tree and being able to executing mode tables, this class does not
* provide an implementation on what to do with the features. To build a mode tree, helper classes
* like the #AssemblyBase or the #Subsystem class extend and use the functionality of the base
* class.
2020-12-14 11:35:45 +01:00
*/
2022-02-02 10:29:30 +01:00
class SubsystemBase : public SystemObject,
public HasModesIF,
public HasHealthIF,
2022-09-29 19:21:24 +02:00
public HasModeTreeChildrenIF,
2022-09-29 19:39:37 +02:00
public ModeTreeConnectionIF,
public ModeTreeChildIF,
2022-02-02 10:29:30 +01:00
public ExecutableObjectIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::SUBSYSTEM_BASE;
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);
2022-09-29 19:39:37 +02:00
SubsystemBase(object_id_t setObjectId, Mode_t initialMode = 0, uint16_t commandQueueDepth = 8);
2022-02-02 10:29:30 +01:00
virtual ~SubsystemBase();
2022-02-02 10:29:30 +01:00
virtual MessageQueueId_t getCommandQueue() const override;
2022-09-29 19:39:37 +02:00
ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF &parent) override;
2022-09-30 15:05:32 +02:00
ModeTreeChildIF &getModeTreeChildIF() override;
2022-09-29 19:39:37 +02:00
2022-02-02 10:29:30 +01:00
/**
* Function to register the child objects.
* Performs a checks if the child does implement HasHealthIF and/or HasModesIF
*
2022-09-29 19:39:37 +02:00
* Also adds them to the internal childrenMap.
2022-02-02 10:29:30 +01:00
*
* @param objectId
2022-08-16 12:12:21 +02:00
* @return returnvalue::OK if successful
2022-09-29 19:39:37 +02:00
* 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
2022-02-02 10:29:30 +01:00
*/
2022-09-29 19:39:37 +02:00
ReturnValue_t registerChild(const ModeTreeChildIF &child) override;
ReturnValue_t initialize() override;
ReturnValue_t performOperation(uint8_t opCode) override;
ReturnValue_t setHealth(HealthState health) override;
HasHealthIF::HealthState getHealth() override;
2022-02-02 10:29:30 +01:00
protected:
struct ChildInfo {
MessageQueueId_t commandQueue;
Mode_t mode;
Submode_t submode;
bool healthChanged;
};
2022-02-02 10:29:30 +01:00
Mode_t mode;
2022-02-02 10:29:30 +01:00
Submode_t submode = SUBMODE_NONE;
2022-02-02 10:29:30 +01:00
bool childrenChangedMode = false;
2022-02-02 10:29:30 +01:00
/**
* Always check this against <=0, so you are robust against too many replies
*/
int32_t commandsOutstanding = 0;
2022-02-02 10:29:30 +01:00
MessageQueueIF *commandQueue = nullptr;
2022-02-02 10:29:30 +01:00
HealthHelper healthHelper;
2022-02-02 10:29:30 +01:00
ModeHelper modeHelper;
2022-02-02 10:29:30 +01:00
typedef std::map<object_id_t, ChildInfo> ChildrenMap;
ChildrenMap childrenMap;
2022-02-02 10:29:30 +01:00
void checkCommandQueue();
2022-02-02 10:29:30 +01:00
/**
* We need to know the target Submode, as children are able to inherit the submode
*/
ReturnValue_t checkStateAgainstTable(HybridIterator<ModeListEntry> tableIter,
Submode_t targetSubmode);
2022-02-02 10:29:30 +01:00
/**
2022-03-22 16:10:20 +01:00
* This function takes care of sending all according mode commands specified inside a mode table.
2022-02-02 10:29:30 +01: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);
2022-02-02 10:29:30 +01:00
ReturnValue_t updateChildMode(MessageQueueId_t queue, Mode_t mode, Submode_t submode);
2022-02-02 10:29:30 +01:00
ReturnValue_t updateChildChangedHealth(MessageQueueId_t queue, bool changedHealth = true);
2022-02-02 10:29:30 +01:00
virtual ReturnValue_t handleModeReply(CommandMessage *message);
2022-02-02 10:29:30 +01:00
void commandAllChildren(CommandMessage *message);
2022-02-02 10:29:30 +01:00
ReturnValue_t checkTable(HybridIterator<ModeListEntry> tableIter);
2022-02-02 10:29:30 +01:00
void replyToCommand(CommandMessage *message);
2022-02-02 10:29:30 +01:00
void setMode(Mode_t newMode, Submode_t newSubmode);
2022-02-02 10:29:30 +01:00
void setMode(Mode_t newMode);
2022-02-02 10:29:30 +01:00
virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0;
2022-02-02 10:29:30 +01:00
virtual void performChildOperation() = 0;
2022-02-02 10:29:30 +01:00
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
2022-03-21 09:12:56 +01:00
uint32_t *msToReachTheMode) override = 0;
2022-03-21 09:12:56 +01:00
virtual void startTransition(Mode_t mode, Submode_t submode) override = 0;
2022-03-21 09:12:56 +01:00
virtual void getMode(Mode_t *mode, Submode_t *submode) override;
2022-09-29 19:39:37 +02:00
object_id_t getObjectId() const override;
const HasHealthIF *getOptHealthIF() const override;
const HasModesIF &getModeIF() const override;
2022-04-30 19:02:41 +02:00
virtual void setToExternalControl() override;
2022-05-01 17:48:49 +02:00
virtual void announceMode(bool recursive) override;
2022-02-02 10:29:30 +01:00
virtual void modeChanged();
};
2020-12-14 11:35:45 +01:00
#endif /* FSFW_SUBSYSTEM_SUBSYSTEMBASE_H_ */