ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_interface_communication.h File Reference
#include "ruuvi_driver_enabled_modules.h"
#include "ruuvi_driver_error.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ri_comm_message_t
 Application message structure used for communication. More...
 
struct  ri_comm_dis_init_t
 
struct  ri_comm_channel_t
 control API for communication via outside world More...
 

Macros

#define RI_COMM_DIS_STRLEN   48
 Maximum length for device information strings. More...
 
#define RI_COMM_MSG_REPEAT_FOREVER   (0U)
 Set ri_comm_message_t->repeat_count to this value to e.g. advertise fixed data until explicitly stopped. More...
 
#define RI_COMM_BLE_PAYLOAD_MAX_LENGTH   (24U)
 Standard BLE advertisement manufacturer specific data payload length is the maximum length. More...
 
#define RI_COMM_MESSAGE_MAX_LENGTH   (RI_COMM_BLE_PAYLOAD_MAX_LENGTH)
 The maximum length for the application message for sending over BLE, which depends on whether extended advertising is enabled or not. More...
 

Typedefs

typedef struct ri_comm_message_t ri_comm_message_t
 Application message structure used for communication. More...
 
typedef struct ri_comm_channel_t ri_comm_channel_t
 
typedef void(* ri_comm_cb_t) (void *p_data, size_t data_len)
 
typedef rd_status_t(* ri_comm_xfer_fp_t) (ri_comm_message_t *const msg)
 Asynchronous transfer function. Puts/gets message in driver queue. More...
 
typedef rd_status_t(* ri_comm_init_fp_t) (ri_comm_channel_t *const channel)
 (Un-)Initialization function. More...
 
typedef rd_status_t(* ri_comm_evt_handler_fp_t) (const ri_comm_evt_t evt, void *p_data, size_t data_len)
 Application event handler for communication events. More...
 

Enumerations

enum  ri_comm_evt_t {
  RI_COMM_CONNECTED , RI_COMM_DISCONNECTED , RI_COMM_SENT , RI_COMM_RECEIVED ,
  RI_COMM_TIMEOUT , RI_COMM_ABORTED
}
 Communication event type. More...
 
enum  ri_gatt_params_t { RI_GATT_TURBO , RI_GATT_STANDARD , RI_GATT_LOW_POWER }
 

Functions

rd_status_t ri_comm_id_get (uint64_t *const id)
 

Detailed Description

Author
Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net
Date
2020-03-26

Commmon definitions and functions for all radio operations.

Definition in file ruuvi_interface_communication.h.

Macro Definition Documentation

◆ RI_COMM_BLE_PAYLOAD_MAX_LENGTH

#define RI_COMM_BLE_PAYLOAD_MAX_LENGTH   (24U)

Standard BLE advertisement manufacturer specific data payload length is the maximum length.

Definition at line 44 of file ruuvi_interface_communication.h.

◆ RI_COMM_DIS_STRLEN

#define RI_COMM_DIS_STRLEN   48

Maximum length for device information strings.

Definition at line 25 of file ruuvi_interface_communication.h.

◆ RI_COMM_MESSAGE_MAX_LENGTH

#define RI_COMM_MESSAGE_MAX_LENGTH   (RI_COMM_BLE_PAYLOAD_MAX_LENGTH)

The maximum length for the application message for sending over BLE, which depends on whether extended advertising is enabled or not.

Definition at line 61 of file ruuvi_interface_communication.h.

◆ RI_COMM_MSG_REPEAT_FOREVER

#define RI_COMM_MSG_REPEAT_FOREVER   (0U)

Set ri_comm_message_t->repeat_count to this value to e.g. advertise fixed data until explicitly stopped.

Definition at line 30 of file ruuvi_interface_communication.h.

Typedef Documentation

◆ ri_comm_cb_t

typedef void(* ri_comm_cb_t) (void *p_data, size_t data_len)

Definition at line 120 of file ruuvi_interface_communication.h.

◆ ri_comm_channel_t

Definition at line 1 of file ruuvi_interface_communication.h.

◆ ri_comm_evt_handler_fp_t

typedef rd_status_t(* ri_comm_evt_handler_fp_t) (const ri_comm_evt_t evt, void *p_data, size_t data_len)

Application event handler for communication events.

Parameters
[in]evtType of event, ri_comm_evt_t.
[in]p_dataData associated with the event. May be NULL.
[in]data_lenLength of event data. Must be 0 if data is NULL. Must be at maximum RI_COMM_MESSAGE_MAX_LENGTH.
Returns
RD_SUCCESS if operation was successful.
error driver from stack on other error

Definition at line 153 of file ruuvi_interface_communication.h.

◆ ri_comm_init_fp_t

typedef rd_status_t(* ri_comm_init_fp_t) (ri_comm_channel_t *const channel)

(Un-)Initialization function.

Parameters
[in,out]channelA control API. Event handler must be set by application.
Returns
RD_SUCCESS if operation was successful.
RD_ERROR_NULL if API is NULL.
error driver from stack on other error

Definition at line 143 of file ruuvi_interface_communication.h.

◆ ri_comm_message_t

Application message structure used for communication.

This structure is used for both UART and BLE messages.

Note
When data is sent over UART, the data is sent in the encoded format, which includes a 20 byte overhead for the ADV_RPRT2 message. See ruuvi.endpoints.c library, function re_ca_uart_encode for details.
The length of messages for BLE should not exceed RI_COMM_BLE_PAYLOAD_MAX_LENGTH.

The structure includes a static assertion to ensure the data length fits within a uint8_t type.

◆ ri_comm_xfer_fp_t

typedef rd_status_t(* ri_comm_xfer_fp_t) (ri_comm_message_t *const msg)

Asynchronous transfer function. Puts/gets message in driver queue.

Parameters
[in,out]msgA message to put/get to/from driver queue
Returns
RD_MORE_AVAILABLE if data was read from queue and there is more data available.
RD_SUCCESS if queue operation was successful.
RD_ERROR_NULL if message is NULL.
RD_ERROR_DATA_SIZE if message length is larger than queue supports.
RD_ERROR_NO_MEM if queue is full and new data cannot be queued.
RD_ERROR_NOT_FOUND if queue is empty and no more data can be read.

Definition at line 133 of file ruuvi_interface_communication.h.

Enumeration Type Documentation

◆ ri_comm_evt_t

Communication event type.

Enumerator
RI_COMM_CONNECTED 

Connection established, OK to send, may receive data.

RI_COMM_DISCONNECTED 

Connection lost, cannot send, may not receive data.

RI_COMM_SENT 

One queued message was sent with all repetitions.

RI_COMM_RECEIVED 

New data received, available to read with read function.

RI_COMM_TIMEOUT 

Operation timed out.

RI_COMM_ABORTED 

Operation aborted, e.g. advertising on connection.

Definition at line 90 of file ruuvi_interface_communication.h.

◆ ri_gatt_params_t

Enumerator
RI_GATT_TURBO 
RI_GATT_STANDARD 
RI_GATT_LOW_POWER 

Definition at line 110 of file ruuvi_interface_communication.h.

Function Documentation

◆ ri_comm_id_get()

rd_status_t ri_comm_id_get ( uint64_t *const  id)

Writes maximum 64-bit unique id of the device to the pointer. This ID must remain same across reboots and reflashes of the device

param id: Output, value of id. return RD_SUCCESS on success return RD_ERROR_NOT_SUPPORTED if ID cannot be returned on given platform