1
0
forked from fsfw/fsfw

form improvements DHB

This commit is contained in:
2020-10-12 18:18:41 +02:00
parent 335e146735
commit 140aa3ab42
19 changed files with 403 additions and 303 deletions

View File

@ -1,12 +1,11 @@
#ifndef FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
#define FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
#include "DeviceHandlerIF.h"
#include "DeviceCommunicationIF.h"
#include "DeviceHandlerFailureIsolation.h"
#include "../objectmanager/SystemObject.h"
#include "../tasks/PeriodicTaskIF.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../action/HasActionsIF.h"
@ -14,10 +13,13 @@
#include "../modes/HasModesIF.h"
#include "../power/PowerSwitchIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../tasks/PeriodicTaskIF.h"
#include "../action/ActionHelper.h"
#include "../health/HealthHelper.h"
#include "../parameters/ParameterHelper.h"
#include "../datapool/HkSwitchHelper.h"
#include "../datapoollocal/HasLocalDataPoolIF.h"
#include "../datapoollocal/LocalDataPoolManager.h"
#include <map>
@ -38,17 +40,16 @@ class StorageManagerIF;
* Documentation: Dissertation Baetz p.138,139, p.141-149
*
* It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink,
* communication with physical devices, using the @link DeviceCommunicationIF @endlink,
* and communication with commanding objects.
* It inherits SystemObject and thus can be created by the ObjectManagerIF.
* communication with physical devices, using the
* @link DeviceCommunicationIF @endlink, and communication with commanding
* objects. It inherits SystemObject and thus can be created by the
* ObjectManagerIF.
*
* This class uses the opcode of ExecutableObjectIF to perform a step-wise execution.
* For each step an RMAP action is selected and executed.
* If data has been received (GET_READ), the data will be interpreted.
* The action for each step can be defined by the child class but as most
* device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure,
* a default implementation is provided.
* NOTE: RMAP is a standard which is used for FLP.
* This class uses the opcode of ExecutableObjectIF to perform a
* step-wise execution. For each step a different action is selected and
* executed. Currently, the device handler base performs a 4-step
* execution related to 4 communication steps (based on RMAP).
* NOTE: RMAP is a standard which is used for Flying Laptop.
* RMAP communication is not mandatory for projects implementing the FSFW.
* However, the communication principles are similar to RMAP as there are
* two write and two send calls involved.
@ -69,9 +70,6 @@ class StorageManagerIF;
*
* Other important virtual methods with a default implementation
* are the getTransitionDelayMs() function and the getSwitches() function.
* Please ensure that getSwitches() returns DeviceHandlerIF::NO_SWITCHES if
* power switches are not implemented yet. Otherwise, the device handler will
* not transition to MODE_ON, even if setMode(MODE_ON) is called.
* If a transition to MODE_ON is desired without commanding, override the
* intialize() function and call setMode(_MODE_START_UP) before calling
* DeviceHandlerBase::initialize().
@ -85,20 +83,18 @@ class DeviceHandlerBase: public DeviceHandlerIF,
public HasModesIF,
public HasHealthIF,
public HasActionsIF,
public ReceivesParameterMessagesIF {
public ReceivesParameterMessagesIF,
public HasLocalDataPoolIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
* The constructor passes the objectId to the SystemObject().
*
* @param setObjectId the ObjectId to pass to the SystemObject() Constructor
* @param maxDeviceReplyLen the length the RMAP getRead call will be sent with
* @param setDeviceSwitch the switch the device is connected to,
* for devices using two switches, overwrite getSwitches()
* @param deviceCommuncation Communcation Interface object which is used
* to implement communication functions
* @param thermalStatePoolId
* @param thermalRequestPoolId
* @param comCookie This object will be passed to the communication inter-
* face and can contain user-defined information about the communication.
* @param fdirInstance
* @param cmdQueueSize
*/
@ -106,8 +102,21 @@ public:
CookieIF * comCookie, FailureIsolationBase* fdirInstance = nullptr,
size_t cmdQueueSize = 20);
void setHkDestination(object_id_t hkDestination);
void setThermalStateRequestPoolIds(uint32_t thermalStatePoolId,
uint32_t thermalRequestPoolId);
/**
* @brief Helper function to ease device handler development.
* This will instruct the transition to MODE_ON immediately
* (leading to doStartUp() being called for the transition to the ON mode),
* so external mode commanding is not necessary anymore.
*
* This has to be called before the task is started!
* (e.g. in the task factory). This is only a helper function for
* development. Regular mode commanding should be performed by commanding
* the AssemblyBase or Subsystem objects resposible for the device handler.
*/
void setStartUpImmediately();
/**
* @brief This function is the device handler base core component and is
@ -153,6 +162,14 @@ public:
* @return
*/
virtual ReturnValue_t initialize();
/**
* @brief Intialization steps performed after all tasks have been created.
* This function will be called by the executing task.
* @return
*/
virtual ReturnValue_t initializeAfterTaskCreation() override;
/** Destructor. */
virtual ~DeviceHandlerBase();
@ -320,6 +337,8 @@ protected:
* @param packet
* @return
* - @c RETURN_OK when the reply was interpreted.
* - @c IGNORE_REPLY_DATA Ignore the reply and don't reset reply cycle
* counter.
* - @c RETURN_FAILED when the reply could not be interpreted,
* e.g. logical errors or range violations occurred
*/
@ -347,22 +366,10 @@ protected:
* set to the maximum expected number of PST cycles between two replies
* (also a tolerance should be added, as an FDIR message will be
* generated if it is missed).
*
* (Robin) This part confuses me. "must do as soon as" implies that
* the developer must do something somewhere else in the code. Is
* that really the case? If I understood correctly, DHB performs
* almost everything (e.g. in erirm function) as long as the commands
* are inserted correctly.
*
* As soon as the replies are enabled, DeviceCommandInfo.periodic must
* be set to true, DeviceCommandInfo.delayCycles to
* DeviceCommandInfo.maxDelayCycles.
* From then on, the base class handles the reception.
* Then, scanForReply returns the id of the reply or the placeholder id
* and the base class will take care of checking that all replies are
* received and the interval is correct.
* When the replies are disabled, DeviceCommandInfo.periodic must be set
* to 0, DeviceCommandInfo.delayCycles to 0;
*
* - Aperiodic, unrequested replies. These are replies that are sent
* by the device without any preceding command and not in a defined
@ -376,13 +383,17 @@ protected:
* @param deviceCommand Identifier of the command to add.
* @param maxDelayCycles The maximum number of delay cycles the command
* waits until it times out.
* @param replyLen Will be supplied to the requestReceiveMessage call of
* the communication interface.
* @param periodic Indicates if the command is periodic (i.e. it is sent
* by the device repeatedly without request) or not. Default is aperiodic (0)
* @return - @c RETURN_OK when the command was successfully inserted,
* - @c RETURN_FAILED else.
*/
ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand,
uint16_t maxDelayCycles, size_t replyLen = 0, bool periodic = false,
uint16_t maxDelayCycles,
LocalPoolDataSetBase* replyDataSet = nullptr,
size_t replyLen = 0, bool periodic = false,
bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0);
/**
@ -396,7 +407,8 @@ protected:
* - @c RETURN_FAILED else.
*/
ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand,
uint16_t maxDelayCycles, size_t replyLen = 0, bool periodic = false);
uint16_t maxDelayCycles, LocalPoolDataSetBase* dataSet = nullptr,
size_t replyLen = 0, bool periodic = false);
/**
* @brief A simple command to add a command to the commandList.
@ -424,6 +436,9 @@ protected:
uint16_t delayCycles, uint16_t maxDelayCycles,
bool periodic = false);
ReturnValue_t setReplyDataset(DeviceCommandId_t replyId,
LocalPoolDataSetBase* dataset);
/**
* @brief Can be implemented by child handler to
* perform debugging
@ -477,18 +492,22 @@ protected:
* @param localDataPoolMap
* @return
*/
//virtual ReturnValue_t initializePoolEntries(
// LocalDataPool& localDataPoolMap) override;
virtual ReturnValue_t initializeLocalDataPool(LocalDataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
/** Get the HK manager object handle */
//virtual LocalDataPoolManager* getHkManagerHandle() override;
virtual LocalDataPoolManager* getHkManagerHandle() override;
/**
* @brief Hook function for child handlers which is called once per
* performOperation(). Default implementation is empty.
*/
virtual void performOperationHook();
public:
/** Explicit interface implementation of getObjectId */
virtual object_id_t getObjectId() const override;
/**
* @param parentQueueId
*/
@ -608,7 +627,7 @@ protected:
/** Action helper for HasActionsIF */
ActionHelper actionHelper;
/** Housekeeping Manager */
//LocalDataPoolManager hkManager;
LocalDataPoolManager hkManager;
/**
* @brief Information about commands
@ -647,7 +666,7 @@ protected:
//! The dataset used to access housekeeping data related to the
//! respective device reply. Will point to a dataset held by
//! the child handler (if one is specified)
// DataSetIF* dataSet = nullptr;
LocalPoolDataSetBase* dataSet;
//! The command that expects this reply.
DeviceCommandMap::iterator command;
};
@ -689,14 +708,18 @@ protected:
uint32_t deviceThermalRequestPoolId = PoolVariableIF::NO_PARAMETER;
/**
* Optional Error code
* Can be set in doStartUp(), doShutDown() and doTransition() to signal cause for Transition failure.
* Optional Error code. Can be set in doStartUp(), doShutDown() and
* doTransition() to signal cause for Transition failure.
*/
ReturnValue_t childTransitionFailure;
uint32_t ignoreMissedRepliesCount = 0; //!< Counts if communication channel lost a reply, so some missed replys can be ignored.
/** Counts if communication channel lost a reply, so some missed
* replys can be ignored. */
uint32_t ignoreMissedRepliesCount = 0;
FailureIsolationBase* fdirInstance; //!< Pointer to the used FDIR instance. If not provided by child, default class is instantiated.
/** Pointer to the used FDIR instance. If not provided by child,
* default class is instantiated. */
FailureIsolationBase* fdirInstance;
HkSwitchHelper hkSwitcher;
@ -944,14 +967,17 @@ protected:
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode);
virtual void startTransition(Mode_t mode, Submode_t submode);
virtual void setToExternalControl();
virtual void announceMode(bool recursive);
/* HasModesIF overrides */
virtual void startTransition(Mode_t mode, Submode_t submode) override;
virtual void setToExternalControl() override;
virtual void announceMode(bool recursive) override;
virtual ReturnValue_t letChildHandleMessage(CommandMessage *message);
/**
* Overwrites SystemObject::triggerEvent in order to inform FDIR"Helper" faster about executed events.
* Overwrites SystemObject::triggerEvent in order to inform FDIR"Helper"
* faster about executed events.
* This is a bit sneaky, but improves responsiveness of the device FDIR.
* @param event The event to be thrown
* @param parameter1 Optional parameter 1
@ -1034,12 +1060,17 @@ private:
/** the object used to set power switches */
PowerSwitchIF *powerSwitcher = nullptr;
/** HK destination can also be set individually */
object_id_t hkDestination = objects::NO_OBJECT;
/**
* @brief Used for timing out mode transitions.
* Set when setMode() is called.
*/
uint32_t timeoutStart = 0;
bool setStartupImmediately = false;
/**
* Delay for the current mode transition, used for time out
*/
@ -1080,11 +1111,6 @@ private:
void buildRawDeviceCommand(CommandMessage* message);
void buildInternalCommand(void);
// /**
// * Send a reply with the current mode and submode.
// */
// void announceMode(void);
/**
* Decrement the counter for the timout of replies.
*
@ -1111,10 +1137,14 @@ private:
/**
* Build and send a command to the device.
*
* This routine checks whether a raw or direct command has been received, checks the content of the received command and
* calls buildCommandFromCommand() for direct commands or sets #rawpacket to the received raw packet.
* If no external command is received or the received command is invalid and the current mode is @c MODE_NORMAL or a transitional mode,
* it asks the child class to build a command (via getNormalDeviceCommand() or getTransitionalDeviceCommand() and buildCommand()) and
* This routine checks whether a raw or direct command has been received,
* checks the content of the received command and calls
* buildCommandFromCommand() for direct commands or sets #rawpacket
* to the received raw packet.
* If no external command is received or the received command is invalid and
* the current mode is @c MODE_NORMAL or a transitional mode, it asks the
* child class to build a command (via getNormalDeviceCommand() or
* getTransitionalDeviceCommand() and buildCommand()) and
* sends the command via RMAP.
*/
void doSendWrite(void);
@ -1159,7 +1189,6 @@ private:
ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data,
uint32_t *len);
/**
* @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW NOTHING ELSE!!!
*/
@ -1170,25 +1199,14 @@ private:
*/
void callChildStatemachine();
/**
* Switches the channel of the cookie used for the communication
*
*
* @param newChannel the object Id of the channel to switch to
* @return
* - @c RETURN_OK when cookie was changed
* - @c RETURN_FAILED when cookies could not be changed, eg because the newChannel is not enabled
* - @c returnvalues of RMAPChannelIF::isActive()
*/
ReturnValue_t switchCookieChannel(object_id_t newChannelId);
ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message);
virtual ReturnValue_t initializeAfterTaskCreation() override;
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
void parseReply(const uint8_t* receivedData,
size_t receivedDataLen);
virtual dur_millis_t getPeriodicOperationFrequency() const override;
void parseReply(const uint8_t* receivedData,
size_t receivedDataLen);
};
#endif /* FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */