fsfw/devicehandlers/DeviceCommunicationIF.h

118 lines
4.4 KiB
C
Raw Normal View History

#ifndef DEVICECOMMUNICATIONIF_H_
#define DEVICECOMMUNICATIONIF_H_
2020-04-01 12:41:54 +02:00
#include <framework/devicehandlers/CookieIF.h>
#include <framework/devicehandlers/DeviceHandlerIF.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
/**
* @defgroup interfaces Interfaces
* @brief Interfaces for flight software objects
*/
/**
2020-03-28 19:42:24 +01:00
* @defgroup comm Communication
* @brief Communication software components.
*/
2019-10-29 19:31:18 +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.
* @details
2020-03-28 19:42:24 +01:00
* 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.
* @ingroup interfaces
* @ingroup comm
2019-10-29 19:31:18 +01:00
*/
class DeviceCommunicationIF: public HasReturnvaluesIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
//!< This is used if no read request is to be made by the device handler.
static const ReturnValue_t NO_READ_REQUEST = MAKE_RETURN_CODE(0x01);
//! General protocol error. Define more concrete errors in child handler
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02);
//! If cookie is a null pointer
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x03);
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x04);
// is this needed if there is no open/close call?
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05);
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x06);
2020-02-27 19:00:51 +01:00
virtual ~DeviceCommunicationIF() {}
/**
* @brief Device specific initialization, using the cookie.
* @details
* The cookie is already prepared in the factory. If the communication
* interface needs to be set up in some way and requires cookie information,
* this can be performed in this function, which is called on device handler
* initialization.
* @param cookie
* @return -@c RETURN_OK if initialization was successfull
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t initializeInterface(CookieIF * 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 failure event with returnvalue as parameter 1
2019-10-29 19:31:18 +01:00
*/
virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData,
size_t sendLen) = 0;
/**
* Called by DHB in the GET_WRITE doGetWrite().
* Get send confirmation that the data in sendMessage() was sent successfully.
* @param cookie
* @return -@c RETURN_OK if data was sent successfull
* - Everything else triggers falure event with returnvalue as parameter 1
*/
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
2020-03-04 23:07:54 +01:00
/**
* Called by DHB in the SEND_WRITE doSendRead().
2020-04-01 12:41:54 +02:00
* It is assumed that it is always possible to request a reply
* from a device. If a requestLen of 0 is supplied, no reply was enabled
* and communication specific action should be taken (e.g. read nothing
* or read everything).
*
2020-03-04 23:07:54 +01:00
* @param cookie
2020-04-01 12:41:54 +02:00
* @param requestLen Size of data to read
* @return -@c RETURN_OK to confirm the request for data has been sent.
* - Everything else triggers failure event with returnvalue as parameter 1
2020-03-04 23:07:54 +01:00
*/
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 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
* @return @c RETURN_OK for successfull receive
* - Everything else triggers failure event with returnvalue as parameter 1
2019-10-29 19:31:18 +01:00
*/
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) = 0;
};
#endif /* DEVICECOMMUNICATIONIF_H_ */