2016-06-15 23:48:41 +02:00
|
|
|
#ifndef DEVICECOMMUNICATIONIF_H_
|
|
|
|
#define DEVICECOMMUNICATIONIF_H_
|
|
|
|
|
|
|
|
#include <framework/devicehandlers/Cookie.h>
|
|
|
|
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
2020-01-03 15:39:32 +01:00
|
|
|
/**
|
|
|
|
* @defgroup interfaces Interfaces
|
|
|
|
* @brief Communication interfaces for flight software objects
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-03-19 00:49:47 +01:00
|
|
|
/**
|
|
|
|
* Physical address type
|
|
|
|
*/
|
|
|
|
typedef uint32_t address_t;
|
|
|
|
|
2019-10-29 19:31:18 +01:00
|
|
|
/**
|
2019-12-05 12:21:06 +01:00
|
|
|
* @brief This is an interface to decouple device communication from
|
2019-10-29 19:31:18 +01:00
|
|
|
* the device handler to allow reuse of these components.
|
2019-12-05 12:21:06 +01:00
|
|
|
* @details
|
|
|
|
* Documentation: Dissertation Baetz p.138
|
2019-10-29 19:31:18 +01:00
|
|
|
* It works with the assumption that received data
|
|
|
|
* is polled by a component. There are four generic steps of device communication:
|
|
|
|
*
|
|
|
|
* 1. Send data to a device
|
|
|
|
* 2. Get acknowledgement for sending
|
|
|
|
* 3. Request reading data from a device
|
|
|
|
* 4. Read received data
|
|
|
|
*
|
|
|
|
* To identify different connection over a single interface can return so-called cookies to components.
|
2020-03-03 21:20:08 +01:00
|
|
|
* The CommunicationMessage message type can be used to extend the functionality of the
|
|
|
|
* ComIF if a separate polling task is required.
|
2019-10-29 19:31:18 +01:00
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
class DeviceCommunicationIF: public HasReturnvaluesIF {
|
|
|
|
public:
|
2018-07-12 16:29:32 +02:00
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x01);
|
|
|
|
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x02);
|
|
|
|
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0x03);
|
|
|
|
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x04);
|
|
|
|
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x05);
|
|
|
|
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x06);
|
|
|
|
static const ReturnValue_t CANT_CHANGE_REPLY_LEN = MAKE_RETURN_CODE(0x07);
|
|
|
|
|
2020-02-27 19:00:51 +01:00
|
|
|
virtual ~DeviceCommunicationIF() {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-03-19 00:49:47 +01:00
|
|
|
/**
|
|
|
|
* Open a connection. Define a communication specific cookie which can
|
|
|
|
* be used to store information about the communication.
|
|
|
|
*
|
|
|
|
* @param cookie [in/out] This data class stores information about the communication.
|
|
|
|
* @param address Logical device address
|
|
|
|
* @param maxReplyLen Maximum length of expected reply
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t open(Cookie **cookie, address_t address,
|
2020-03-20 22:47:07 +01:00
|
|
|
uint32_t maxReplyLen, uint32_t comParameter = 0) = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use an existing cookie to open a connection to a new DeviceCommunication.
|
|
|
|
* The previous connection must not be closed.
|
|
|
|
*
|
|
|
|
* @param cookie
|
|
|
|
* @param address
|
|
|
|
* @param maxReplyLen
|
2020-03-19 00:49:47 +01:00
|
|
|
* @return -@c RETURN_OK New communication set up successfully
|
|
|
|
* - Everything else: Cookie is unchanged and can be used with
|
|
|
|
* previous connection
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2020-03-19 00:49:47 +01:00
|
|
|
virtual ReturnValue_t reOpen(Cookie *cookie, address_t address,
|
2020-03-20 22:47:07 +01:00
|
|
|
uint32_t maxReplyLen, uint32_t comParameter = 0) = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-03-19 00:49:47 +01:00
|
|
|
/**
|
|
|
|
* Closing call of connection. Don't forget to free memory of cookie.
|
|
|
|
* @param cookie
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual void close(Cookie *cookie) = 0;
|
|
|
|
|
2019-10-29 19:31:18 +01:00
|
|
|
/**
|
|
|
|
* Called by DHB in the SEND_WRITE doSendWrite().
|
|
|
|
* This function is used to send data to the physical device
|
|
|
|
* by implementing and calling related drivers or wrapper functions.
|
|
|
|
* @param cookie
|
|
|
|
* @param data
|
|
|
|
* @param len
|
2020-03-19 00:49:47 +01:00
|
|
|
* @return -@c RETURN_OK for successfull send
|
|
|
|
* -Everything else triggers sending failed event with
|
|
|
|
* returnvalue as parameter 1
|
2019-10-29 19:31:18 +01:00
|
|
|
*/
|
2020-03-19 00:49:47 +01:00
|
|
|
virtual ReturnValue_t sendMessage(Cookie *cookie, const uint8_t *data,
|
2016-06-15 23:48:41 +02:00
|
|
|
uint32_t len) = 0;
|
|
|
|
|
|
|
|
virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0;
|
|
|
|
|
2020-03-04 23:07:54 +01:00
|
|
|
/**
|
|
|
|
* Called by DHB in the SEND_WRITE doSendRead().
|
2020-03-19 00:49:47 +01:00
|
|
|
* Instructs the Communication Interface to prepare
|
2020-03-04 23:07:54 +01:00
|
|
|
* @param cookie
|
|
|
|
* @return
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual ReturnValue_t requestReceiveMessage(Cookie *cookie) = 0;
|
|
|
|
|
2019-10-29 19:31:18 +01:00
|
|
|
/**
|
2020-03-04 23:07:54 +01:00
|
|
|
* Called by DHB in the GET_WRITE doGetRead().
|
2019-10-29 19:31:18 +01:00
|
|
|
* This function is used to receive data from the physical device
|
|
|
|
* by implementing and calling related drivers or wrapper functions.
|
|
|
|
* @param cookie
|
|
|
|
* @param data
|
|
|
|
* @param len
|
2019-11-29 19:56:05 +01:00
|
|
|
* @return @c RETURN_OK for successfull receive
|
|
|
|
* Everything else triggers receiving failed with returnvalue as parameter 1
|
2019-10-29 19:31:18 +01:00
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer,
|
|
|
|
uint32_t *size) = 0;
|
|
|
|
|
2020-03-19 00:49:47 +01:00
|
|
|
virtual ReturnValue_t setAddress(Cookie *cookie, address_t address) = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-03-19 00:49:47 +01:00
|
|
|
virtual address_t getAddress(Cookie *cookie) = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-02-27 19:00:51 +01:00
|
|
|
/**
|
|
|
|
* Can be used by DeviceHandlerBase getParameter() call to set DeviceComIF parameters
|
|
|
|
* @param cookie
|
|
|
|
* @param parameter
|
|
|
|
* @return
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual ReturnValue_t setParameter(Cookie *cookie, uint32_t parameter) = 0;
|
|
|
|
|
2020-02-27 19:00:51 +01:00
|
|
|
/**
|
|
|
|
* Can be used by DeviceHandlerBase getParameter() call to set DeviceComIF parameters
|
|
|
|
* @param cookie
|
|
|
|
* @param parameter
|
|
|
|
* @return
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual uint32_t getParameter(Cookie *cookie) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* DEVICECOMMUNICATIONIF_H_ */
|