ruuvi.drivers.c ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
Loading...
Searching...
No Matches
ruuvi_interface_communication.h
Go to the documentation of this file.
1#ifndef RUUVI_INTERFACE_COMMUNICATION_H
2#define RUUVI_INTERFACE_COMMUNICATION_H
5
16#if RI_COMM_ENABLED
17# define RUUVI_NRF5_SDK15_COMMUNICATION_ENABLED RUUVI_NRF5_SDK15_ENABLED
18#endif
19
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdint.h>
23
25#define RI_COMM_DIS_STRLEN 48
26
30#define RI_COMM_MSG_REPEAT_FOREVER (0U)
31
32#if defined(RI_ADV_EXTENDED_ENABLED) && RI_ADV_EXTENDED_ENABLED
33# if !defined(RI_COMM_BLE_PAYLOAD_MAX_LENGTH)
34# error "RI_COMM_BLE_PAYLOAD_MAX_LENGTH must be defined when RI_ADV_EXTENDED_ENABLED=1"
35# endif
36#else
37#if defined(RI_RE_CA_UART_ENABLED) && RI_RE_CA_UART_ENABLED
40# define RI_COMM_BLE_PAYLOAD_MAX_LENGTH (31U)
41#else
44# define RI_COMM_BLE_PAYLOAD_MAX_LENGTH (24U)
45#endif
46#endif
47
48#if defined(RI_RE_CA_UART_ENABLED) && RI_RE_CA_UART_ENABLED
55#define RI_COMM_MESSAGE_MAX_LENGTH (20 + RI_COMM_BLE_PAYLOAD_MAX_LENGTH)
56#else
61#define RI_COMM_MESSAGE_MAX_LENGTH (RI_COMM_BLE_PAYLOAD_MAX_LENGTH)
62#endif
63
79typedef struct ri_comm_message_t
80{
81 _Static_assert (RI_COMM_MESSAGE_MAX_LENGTH <= UINT8_MAX,
82 "Data length must fit in uint8_t");
84 uint8_t data_length;
85 uint8_t repeat_count;
86 // RI_COMM_MSG_REPEAT_FOREVER for infinite sends, 1 for send once.
88
99
100typedef struct
101{
102 char fw_version[RI_COMM_DIS_STRLEN];
103 char model[RI_COMM_DIS_STRLEN];
104 char hw_version[RI_COMM_DIS_STRLEN];
105 char manufacturer[RI_COMM_DIS_STRLEN];
106 char deviceid[RI_COMM_DIS_STRLEN];
107 char deviceaddr[RI_COMM_DIS_STRLEN];
109
116
118
119/* @brief Callback handler for communication events */
120typedef void (*ri_comm_cb_t) (void * p_data, size_t data_len);
121
134 msg);
135
144
154 evt, void * p_data, size_t data_len);
155
166
176rd_status_t ri_comm_id_get (uint64_t * const id);
177
178#endif
uint32_t rd_status_t
bitfield for representing errors
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
rd_status_t(* ri_comm_xfer_fp_t)(ri_comm_message_t *const msg)
Asynchronous transfer function. Puts/gets message in driver queue.
#define RI_COMM_MESSAGE_MAX_LENGTH
The maximum length for the application message for sending over BLE, which depends on whether extende...
void(* ri_comm_cb_t)(void *p_data, size_t data_len)
rd_status_t(* ri_comm_init_fp_t)(ri_comm_channel_t *const channel)
(Un-)Initialization function.
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.
rd_status_t ri_comm_id_get(uint64_t *const id)
#define RI_COMM_DIS_STRLEN
Maximum length for device information strings.
ri_comm_evt_t
Communication event type.
@ RI_COMM_TIMEOUT
Operation timed out.
@ RI_COMM_CONNECTED
Connection established, OK to send, may receive data.
@ RI_COMM_RECEIVED
New data received, available to read with read function.
@ RI_COMM_SENT
One queued message was sent with all repetitions.
@ RI_COMM_ABORTED
Operation aborted, e.g. advertising on connection.
@ RI_COMM_DISCONNECTED
Connection lost, cannot send, may not receive data.
control API for communication via outside world
ri_comm_evt_handler_fp_t on_evt
Callback to application-level event handler, must be set in application.
ri_comm_xfer_fp_t send
Asynchronous send function.
ri_comm_init_fp_t init
Initialize and populate channel api control.
ri_comm_init_fp_t uninit
Uninitialize and depopulate channel api control.
ri_comm_xfer_fp_t read
Asynchronous read function.
Application message structure used for communication.
uint8_t data[RI_COMM_MESSAGE_MAX_LENGTH]
Data payload.
uint8_t repeat_count
Number of times to repeat the message,.
uint8_t data_length
Length of data.