26 #ifndef TASK_GATT_LOG_LEVEL
27 #define TASK_GATT_LOG_LEVEL RI_LOG_LEVEL_INFO
30 static inline void LOGD (
const char *
const msg)
35 static inline void LOGDHEX (
const uint8_t *
const msg,
const size_t len)
41 static bool m_is_init;
42 static bool m_nus_is_init;
43 static bool m_dis_is_init;
44 static bool m_dfu_is_init;
45 static bool m_nus_is_connected;
55 static inline size_t safe_strlen (
const char * s,
size_t maxlen)
59 for (i = 0; (i < maxlen) && (
'\0' != s[i]); ++i);
65 void rt_gatt_mock_state_reset()
67 m_on_connected = NULL;
68 m_on_disconnected = NULL;
72 m_nus_is_init =
false;
73 m_dfu_is_init =
false;
74 m_dis_is_init =
false;
75 m_nus_is_connected =
false;
77 memset (m_name, 0,
sizeof (m_name));
103 void * p_data,
size_t data_len)
109 m_nus_is_connected =
true;
110 (NULL != m_on_connected) ? m_on_connected (p_data, data_len) :
false;
114 m_nus_is_connected =
false;
115 (NULL != m_on_disconnected) ? m_on_disconnected (p_data, data_len) :
false;
119 (NULL != m_on_sent) ? m_on_sent (p_data, data_len) :
false;
124 LOGDHEX (p_data, data_len);
126 (NULL != m_on_received) ? m_on_received (p_data, data_len) :
false;
167 m_channel.
on_evt = rt_gatt_on_nus_isr;
168 m_nus_is_init =
true;
206 const size_t name_length = safe_strlen (name,
sizeof (m_name));
208 if (
sizeof (m_name) > name_length)
211 memcpy (m_name, name, name_length);
212 m_name[name_length] =
'\0';
250 memset (&m_channel, 0,
sizeof (m_channel));
253 m_dis_is_init =
false;
254 m_nus_is_init =
false;
255 m_dfu_is_init =
false;
305 return m_nus_is_connected && (NULL != m_channel.
send);
325 err_code |= m_channel.
send (p_msg);
356 m_on_disconnected = cb;
371 return m_nus_is_init;
#define RD_ERROR_NULL
Null Pointer.
#define RD_ERROR_FATAL
Program should always reset after this.
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_INVALID_LENGTH
Invalid Length.
#define RD_ERROR_CHECK(error, mask)
Shorthand macro for calling the rd_error_check with current file & line.
#define RD_ERROR_NOT_ENABLED
Driver is not enabled.
#define RD_ERROR_RESOURCES
Not enough resources for operation.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_NO_MEM
No Memory for operation.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
void ri_log_hex(const ri_log_severity_t severity, const uint8_t *const bytes, size_t byte_length)
Queues bytes to be logged out as a hex string.
void ri_log(const ri_log_severity_t severity, const char *const message)
Queues messages into log.
rd_status_t ri_radio_get_modulation(ri_radio_modulation_t *const p_modulation)
Get the modulation used by application.
rd_status_t ri_radio_init(const ri_radio_modulation_t modulation)
Enable radio stack for an user. This function also starts radio activity callbacks internally.
rd_status_t ri_radio_uninit()
Release radio stack.
ri_radio_modulation_t
type of radio modulation to be used.
@ RI_RADIO_BLE_1MBPS
"Normal" BLE 4 modulation
rd_status_t rt_adv_connectability_set(const bool enable, const char *const device_name)
Start advertising BLE GATT connection.
bool rt_adv_is_init(void)
check if advertisement is initialized
#define SCAN_RSP_NAME_MAX_LEN
Longer name gets truncated when advertised with UUID.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
void(* ri_comm_cb_t)(void *p_data, size_t data_len)
ri_comm_evt_t
Communication event type.
@ 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_DISCONNECTED
Connection lost, cannot send, may not receive data.
rd_status_t ri_gatt_init(void)
Initializes GATT stack. Uses default values from sdk_config.h, these can be overridden in nrf5_sdk15_...
rd_status_t ri_gatt_dfu_init(void)
Initialize BLE4 Device firmware update service.
rd_status_t ri_gatt_uninit(void)
Uninitializes GATT stack.
rd_status_t ri_gatt_nus_init(ri_comm_channel_t *const channel)
Initialize Nordic UART Service as a communication channel. ri_communication_radio_init(RI_COMMUNICATI...
rd_status_t ri_gatt_dis_init(const ri_comm_dis_init_t *const dis)
Initialize BLE4 Device Information service.
Interface functions to scheduler.
Helper functions for communication.
rd_status_t rt_gatt_dfu_init(void)
Initialize Device Firmware Update service.
bool rt_gatt_is_nus_enabled(void)
Check if Nordic UART Service is enabled.
void rt_gatt_set_on_disconn_isr(const ri_comm_cb_t cb)
Setup disconnection event handler.
rd_status_t rt_gatt_adv_enable()
Start advertising GATT connection to devices.
rd_status_t rt_gatt_dis_init(const ri_comm_dis_init_t *const dis)
Initialize Device Information Update service.
rd_status_t rt_gatt_adv_disable()
Stop advertising GATT connection to devices.
rd_status_t rt_gatt_init(const char *const name)
Initialize GATT. Must be called as a first function in rt_gatt.
void rt_gatt_set_on_sent_isr(const ri_comm_cb_t cb)
Setup data sent event handler.
bool rt_gatt_is_init()
check if GATT task is initialized
void rt_gatt_set_on_connected_isr(const ri_comm_cb_t cb)
Setup connection event handler.
rd_status_t rt_gatt_nus_init()
Initialize Nordic UART Service.
rd_status_t rt_gatt_send_asynchronous(ri_comm_message_t *const p_msg)
Send given message via NUS.
void rt_gatt_set_on_received_isr(const ri_comm_cb_t cb)
Setup data received event handler.
bool rt_gatt_nus_is_connected()
check if NUS is connected, i.e. central has registered to TX notifications.
rd_status_t rt_gatt_uninit(void)
Uninitialize GATT.
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.
Application message structure used for communication.
uint8_t data[RI_COMM_MESSAGE_MAX_LENGTH]
Data payload.
uint8_t data_length
Length of data.