diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 4f98dd6d..1e307b6c 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -2,17 +2,13 @@ #define DEVICECOMMUNICATIONIF_H_ #include +#include #include /** * @defgroup interfaces Interfaces * @brief Communication interfaces for flight software objects */ -/** - * Physical address type - */ -typedef uint32_t address_t; - /** * @brief This is an interface to decouple device communication from * the device handler to allow reuse of these components. @@ -47,14 +43,20 @@ public: /** * Open a connection. Define a communication specific cookie which can * be used to store information about the communication. + * The two optional parameter provide additional flexibility to + * set up the communication interface as desired. If there are a lot of + * variables to set, a store ID to the parameters stored in the IPC store + * can also be passed. * - * @param cookie [in/out] This data class stores information about the communication. + * @param cookie [out] This data class stores information about the communication. * @param address Logical device address * @param maxReplyLen Maximum length of expected reply + * @param comParameter1 Arbitrary parameter which can be used to set up the cookie or comIF. + * @param comParameter2 Arbitrary parameter which can be used to set up the cookie or comIF. * @return */ virtual ReturnValue_t open(Cookie **cookie, address_t address, - uint32_t maxReplyLen, uint32_t comParameter = 0) = 0; + uint32_t maxReplyLen, uint32_t comParameter1, uint32_t comParameter2) = 0; /** * Use an existing cookie to open a connection to a new DeviceCommunication. @@ -68,7 +70,7 @@ public: * previous connection */ virtual ReturnValue_t reOpen(Cookie *cookie, address_t address, - uint32_t maxReplyLen, uint32_t comParameter = 0) = 0; + uint32_t maxReplyLen, uint32_t comParameter1, uint32_t comParameter2) = 0; /** * Closing call of connection. Don't forget to free memory of cookie. diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index e7b4c684..ca883e83 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -106,7 +106,7 @@ ReturnValue_t DeviceHandlerBase::initialize() { } result = communicationInterface->open(&cookie, logicalAddress, - maxDeviceReplyLen); + maxDeviceReplyLen, comParameter1, comParameter2); if (result != RETURN_OK) { return result; } @@ -691,7 +691,7 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len, //Default child implementations -DeviceHandlerBase::RmapAction_t DeviceHandlerBase::getRmapAction() { +DeviceHandlerBase::CommunicationAction_t DeviceHandlerBase::getRmapAction() { switch (pstStep) { case 0: return SEND_WRITE; @@ -757,7 +757,7 @@ ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) { if (newCommunication != NULL) { ReturnValue_t result = newCommunication->reOpen(cookie, logicalAddress, - maxDeviceReplyLen); + maxDeviceReplyLen, comParameter1, comParameter2); if (result != RETURN_OK) { return result; } diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 60e8888e..868412ed 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -418,6 +418,22 @@ protected: */ uint32_t rawPacketLen; +// /** +// * This union (or std::variant) type can be used to set comParameters which +// * are passed in the open() and reOpen() calls to the communication +// * interface +// * TODO: I don't know if we should use C++17 features but if we do we propably +// * should also write a function to get either a storeId handle +// * or an array handle so these values can be set conveniently. +// * The good think is that if there are many parameters, they can +// * be stored in the IPC pool. But maybe two uint32_t parameters are enough. +// * Simple = Good. It is downwards compatible and one can still store +// * 4 bytes of parameters AND a store ID. +// */ +// comParameters_t comParameters; + uint32_t comParameter1 = 0; + uint32_t comParameter2 = 0; + /** * The mode the device handler is currently in. * @@ -548,6 +564,28 @@ protected: static object_id_t rawDataReceiverId; //!< Object which receives RAW data by default. static object_id_t defaultFDIRParentId; //!< Object which may be the root cause of an identified fault. + + /** + * Set the device handler mode + * + * Sets #timeoutStart with every call. + * + * Sets #transitionTargetMode if necessary so transitional states can be entered from everywhere without breaking the state machine + * (which relies on a correct #transitionTargetMode). + * + * The submode is left unchanged. + * + * + * @param newMode + */ + void setMode(Mode_t newMode); + + /** + * @overload + * @param submode + */ + void setMode(Mode_t newMode, Submode_t submode); + /** * Helper function to report a missed reply * @@ -576,27 +614,6 @@ protected: */ void replyToCommand(ReturnValue_t status, uint32_t parameter = 0); - /** - * Set the device handler mode - * - * Sets #timeoutStart with every call. - * - * Sets #transitionTargetMode if necessary so transitional states can be entered from everywhere without breaking the state machine - * (which relies on a correct #transitionTargetMode). - * - * The submode is left unchanged. - * - * - * @param newMode - */ - void setMode(Mode_t newMode); - - /** - * @overload - * @param submode - */ - void setMode(Mode_t newMode, Submode_t submode); - /** * Do the transition to the main modes (MODE_ON, MODE_NORMAL and MODE_RAW). * @@ -645,7 +662,7 @@ protected: * * @return The Rmap action to execute in this step */ - virtual RmapAction_t getRmapAction(); + virtual CommunicationAction_t getRmapAction(); /** * Build the device command to send for raw mode. diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index cce40349..c453e7e8 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -7,6 +7,33 @@ #include #include +#if __cplusplus >= 201703L +#include +#include +#endif + +/** + * Physical address type + */ +typedef uint32_t address_t; + +///** +// * This type safe union cold be used if C++17 or newer is used to transfer +// * comIF settings to the communication interface object. +// */ +// +//#if __cplusplus >= 201703L +//using comParameterArray_t = std::array; +//using comParameters_t = std::variant; +//#else +//using comParameters_t = union comParameters { +// comParameters() = default; +// comParameters(uint32_t initValue): storeIdRaw(initValue) {} +// uint32_t storeIdRaw; +// uint8_t comParameter[4]; +// }; +//#endif + /** * This is the Interface used to communicate with a device handler. * @@ -87,17 +114,18 @@ public: MAKE_RETURN_CODE(0xD1); /** - * RMAP Action that will be executed. + * Communication action that will be executed. * * This is used by the child class to tell the base class what to do. */ - enum RmapAction_t { + enum CommunicationAction_t: uint8_t { SEND_WRITE,//!< RMAP send write GET_WRITE, //!< RMAP get write SEND_READ, //!< RMAP send read GET_READ, //!< RMAP get read NOTHING //!< Do nothing. }; + /** * Default Destructor */