replaced std::variant by two uint32 parameters

This commit is contained in:
Robin Müller 2020-03-23 13:14:23 +01:00
parent af6d18d60b
commit c50d9d90d6
4 changed files with 82 additions and 35 deletions

View File

@ -2,17 +2,13 @@
#define DEVICECOMMUNICATIONIF_H_ #define DEVICECOMMUNICATIONIF_H_
#include <framework/devicehandlers/Cookie.h> #include <framework/devicehandlers/Cookie.h>
#include <framework/devicehandlers/DeviceHandlerIF.h>
#include <framework/returnvalues/HasReturnvaluesIF.h> #include <framework/returnvalues/HasReturnvaluesIF.h>
/** /**
* @defgroup interfaces Interfaces * @defgroup interfaces Interfaces
* @brief Communication interfaces for flight software objects * @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 * @brief This is an interface to decouple device communication from
* the device handler to allow reuse of these components. * the device handler to allow reuse of these components.
@ -47,14 +43,20 @@ public:
/** /**
* Open a connection. Define a communication specific cookie which can * Open a connection. Define a communication specific cookie which can
* be used to store information about the communication. * 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 address Logical device address
* @param maxReplyLen Maximum length of expected reply * @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 * @return
*/ */
virtual ReturnValue_t open(Cookie **cookie, address_t address, 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. * Use an existing cookie to open a connection to a new DeviceCommunication.
@ -68,7 +70,7 @@ public:
* previous connection * previous connection
*/ */
virtual ReturnValue_t reOpen(Cookie *cookie, address_t address, 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. * Closing call of connection. Don't forget to free memory of cookie.

View File

@ -106,7 +106,7 @@ ReturnValue_t DeviceHandlerBase::initialize() {
} }
result = communicationInterface->open(&cookie, logicalAddress, result = communicationInterface->open(&cookie, logicalAddress,
maxDeviceReplyLen); maxDeviceReplyLen, comParameter1, comParameter2);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
@ -691,7 +691,7 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
//Default child implementations //Default child implementations
DeviceHandlerBase::RmapAction_t DeviceHandlerBase::getRmapAction() { DeviceHandlerBase::CommunicationAction_t DeviceHandlerBase::getRmapAction() {
switch (pstStep) { switch (pstStep) {
case 0: case 0:
return SEND_WRITE; return SEND_WRITE;
@ -757,7 +757,7 @@ ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) {
if (newCommunication != NULL) { if (newCommunication != NULL) {
ReturnValue_t result = newCommunication->reOpen(cookie, logicalAddress, ReturnValue_t result = newCommunication->reOpen(cookie, logicalAddress,
maxDeviceReplyLen); maxDeviceReplyLen, comParameter1, comParameter2);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }

View File

@ -418,6 +418,22 @@ protected:
*/ */
uint32_t rawPacketLen; 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. * 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 rawDataReceiverId; //!< Object which receives RAW data by default.
static object_id_t defaultFDIRParentId; //!< Object which may be the root cause of an identified fault. 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 * Helper function to report a missed reply
* *
@ -576,27 +614,6 @@ protected:
*/ */
void replyToCommand(ReturnValue_t status, uint32_t parameter = 0); 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). * 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 * @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. * Build the device command to send for raw mode.

View File

@ -7,6 +7,33 @@
#include <framework/modes/HasModesIF.h> #include <framework/modes/HasModesIF.h>
#include <framework/ipc/MessageQueueSenderIF.h> #include <framework/ipc/MessageQueueSenderIF.h>
#if __cplusplus >= 201703L
#include <array>
#include <variant>
#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<uint8_t, 4>;
//using comParameters_t = std::variant<store_address_t, comParameterArray_t>;
//#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. * This is the Interface used to communicate with a device handler.
* *
@ -87,17 +114,18 @@ public:
MAKE_RETURN_CODE(0xD1); 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. * 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 SEND_WRITE,//!< RMAP send write
GET_WRITE, //!< RMAP get write GET_WRITE, //!< RMAP get write
SEND_READ, //!< RMAP send read SEND_READ, //!< RMAP send read
GET_READ, //!< RMAP get read GET_READ, //!< RMAP get read
NOTHING //!< Do nothing. NOTHING //!< Do nothing.
}; };
/** /**
* Default Destructor * Default Destructor
*/ */