ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_task_gatt.h File Reference

Go to the source code of this file.

Functions

rd_status_t rt_gatt_send_asynchronous (ri_comm_message_t *const msg)
 Send given message via NUS. More...
 
rd_status_t rt_gatt_dfu_init (void)
 Initialize Device Firmware Update service. More...
 
rd_status_t rt_gatt_dis_init (const ri_comm_dis_init_t *const dis)
 Initialize Device Information Update service. More...
 
rd_status_t rt_gatt_nus_init ()
 Initialize Nordic UART Service. More...
 
rd_status_t rt_gatt_init (const char *const name)
 Initialize GATT. Must be called as a first function in rt_gatt. More...
 
rd_status_t rt_gatt_uninit (void)
 Uninitialize GATT. More...
 
rd_status_t rt_gatt_adv_enable ()
 Start advertising GATT connection to devices. More...
 
rd_status_t rt_gatt_adv_disable ()
 Stop advertising GATT connection to devices. More...
 
bool rt_gatt_is_init ()
 check if GATT task is initialized More...
 
bool rt_gatt_nus_is_connected ()
 check if NUS is connected, i.e. central has registered to TX notifications. More...
 
bool rt_gatt_is_nus_enabled ()
 Check if Nordic UART Service is enabled. More...
 
void rt_gatt_set_on_connected_isr (const ri_comm_cb_t cb)
 Setup connection event handler. More...
 
void rt_gatt_set_on_disconn_isr (const ri_comm_cb_t cb)
 Setup disconnection event handler. More...
 
void rt_gatt_set_on_received_isr (const ri_comm_cb_t cb)
 Setup data received event handler. More...
 
void rt_gatt_set_on_sent_isr (const ri_comm_cb_t cb)
 Setup data sent event handler. More...
 

Detailed Description

Author
Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net
Date
2020-01-27

Definition in file ruuvi_task_gatt.h.

Function Documentation

◆ rt_gatt_adv_disable()

rd_status_t rt_gatt_adv_disable ( )

Stop advertising GATT connection to devices.

Calling this function is not enough to stop advertising connection, you must also update advertised data to remove the scan response from data being advertised. This makes sure that advertised data stays valid. This function has not effect if called while already disabled

Return values
RD_SUCCESSon success
RD_ERROR_INVALID_STATEif GATT is not initialized.

Definition at line 406 of file ruuvi_task_gatt.c.

◆ rt_gatt_adv_enable()

rd_status_t rt_gatt_adv_enable ( )

Start advertising GATT connection to devices.

Calling this function is not enough to let users to connect, you must also update advertised data to add the scan response to data being advertised. This makes sure that advertised data stays valid. This function has no effect if called while already enabled.

Return values
RD_SUCCESSon success
RD_ERROR_INVALID_STATEif GATT is not initialized.

Definition at line 401 of file ruuvi_task_gatt.c.

◆ rt_gatt_dfu_init()

rd_status_t rt_gatt_dfu_init ( void  )

Initialize Device Firmware Update service.

GATT must be initialized before calling this function, and once initialized the DFU service cannot be uninitialized.

Call will return successfully even if the device doesn't have useable bootloader, however program will reboot if user tries to enter bootloader in that case.

To use the DFU service advertisement module must send connectable (and preferably scannable) advertisements.

Return values
RD_SUCCESSGATT was initialized successfully
RD_ERROR_INVALID_STATEDFU was already initialized or GATT is not initialized

Definition at line 381 of file ruuvi_task_gatt.c.

◆ rt_gatt_dis_init()

rd_status_t rt_gatt_dis_init ( const ri_comm_dis_init_t *const  dis)

Initialize Device Information Update service.

GATT must be initialized before calling this function, and once initialized the DIS service cannot be uninitialized.

DIS service lets user read basic information, such as firmware version and hardware model over GATT in a standard format.

To use the DIS service advertisement module must send connectable (and preferably scannable) advertisements.

Parameters
[in]disstructure containing data to be copied into DIS, can be freed after call finishes.
Return values
RD_SUCCESSGATT was initialized successfully
RD_ERROR_NULLif given NULL as the information.
RD_ERROR_INVALID_STATEDIS was already initialized or GATT is not initialized

Definition at line 386 of file ruuvi_task_gatt.c.

◆ rt_gatt_init()

rd_status_t rt_gatt_init ( const char *const  name)

Initialize GATT. Must be called as a first function in rt_gatt.

After calling this function underlying software stack is ready to setup GATT services.

Parameters
[in]nameFull name of device to be advertised in scan responses. Maximum 11 chars + trailing NULL. Must not be NULL, 0-length string is valid.
Return values
RD_SUCCESSon success.
RD_ERROR_NULLif name is NULL (use 0-length string instead)
RD_ERROR_INVALID_LENGTHif name is longer than SCAN_RSP_NAME_MAX_LEN
RD_ERROR_INVALID_STATEif GATT is already initialized or advertisements are not initialized.

Definition at line 396 of file ruuvi_task_gatt.c.

◆ rt_gatt_is_init()

bool rt_gatt_is_init ( )

check if GATT task is initialized

Returns
true if GATT is initialized, false otherwise.

Definition at line 411 of file ruuvi_task_gatt.c.

◆ rt_gatt_is_nus_enabled()

bool rt_gatt_is_nus_enabled ( )

Check if Nordic UART Service is enabled.

The event handler has signature of

void(*rt_gatt_cb_t)(void* p_event_data, uint16_t event_size)

where event data is NULL and event_size is 0. The event handler is called in interrupt context.

Returns
true if GATT is initialized and ready to accept connection, false otherwise.

Definition at line 437 of file ruuvi_task_gatt.c.

◆ rt_gatt_nus_init()

rd_status_t rt_gatt_nus_init ( )

Initialize Nordic UART Service.

GATT must be initialized before calling this function, and once initialized the NUS service cannot be uninitialized.

NUS service lets user do bidirectional communication with the application.

To use the NUS service advertisement module must send connectable (and preferably scannable) advertisements.

Return values
RD_SUCCESSGATT was initialized successfully
RD_ERROR_NULLif given NULL as the information.
RD_ERROR_INVALID_STATEDIS was already initialized or GATT is not initialized
Note
To actually use the data in application, user must setup at least data received callback with rt_gatt_set_on_received_isr

Definition at line 391 of file ruuvi_task_gatt.c.

◆ rt_gatt_nus_is_connected()

bool rt_gatt_nus_is_connected ( )

check if NUS is connected, i.e. central has registered to TX notifications.

Returns
true if NUS is connected is initialized, false otherwise.

◆ rt_gatt_send_asynchronous()

rd_status_t rt_gatt_send_asynchronous ( ri_comm_message_t *const  p_msg)

Send given message via NUS.

This function queues a message to be sent and returns immediately. There is no guarantee on when the data is actually sent, and there is no acknowledgement or callback after the data has been sent.

Return values
RD_SUCCESSif data was placed in send buffer
RD_ERROR_INVALID_STATEif NUS is not connected
RD_ERROR_NO_MEMif tx buffer is full
errorcode from stack on other error

Ruuvi Firmware 3.x GATT tasks.

License: BSD-3 Author: Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net

Definition at line 375 of file ruuvi_task_gatt.c.

◆ rt_gatt_set_on_connected_isr()

void rt_gatt_set_on_connected_isr ( const ri_comm_cb_t  cb)

Setup connection event handler.

The event handler has signature of

void(*rt_gatt_cb_t)(void* p_event_data, uint16_t event_size)

where event data is NULL and event_size is 0. The event handler is called in interrupt context.

Parameters
[in]cbCallback which gets called on connection in interrupt context.

Definition at line 416 of file ruuvi_task_gatt.c.

◆ rt_gatt_set_on_disconn_isr()

void rt_gatt_set_on_disconn_isr ( const ri_comm_cb_t  cb)

Setup disconnection event handler.

The event handler has signature of

void(*rt_gatt_cb_t)(void* p_event_data, uint16_t event_size)

where event data is NULL and event_size is 0. The event handler is called in interrupt context.

Parameters
[in]cbCallback which gets called on disconnection in interrupt context.

Definition at line 422 of file ruuvi_task_gatt.c.

◆ rt_gatt_set_on_received_isr()

void rt_gatt_set_on_received_isr ( const ri_comm_cb_t  cb)

Setup data received event handler.

The event handler has signature of

void(*rt_gatt_cb_t)(void* p_event_data, uint16_t event_size)

where event data is pointer to raw bytes and event_size is length of received data. The event handler is called in interrupt context.

Parameters
[in]cbCallback which gets called on data received in interrupt context.

Definition at line 427 of file ruuvi_task_gatt.c.

◆ rt_gatt_set_on_sent_isr()

void rt_gatt_set_on_sent_isr ( const ri_comm_cb_t  cb)

Setup data sent event handler.

The event handler has signature of

void(*rt_gatt_cb_t)(void* p_event_data, uint16_t event_size)

where event data is NULL and event_size is 0. The event handler is called in interrupt context.

Parameters
[in]cbCallback which gets called on data sent in interrupt context.

Definition at line 432 of file ruuvi_task_gatt.c.

◆ rt_gatt_uninit()

rd_status_t rt_gatt_uninit ( void  )

Uninitialize GATT.

After calling this function callbacks, characteristics and services are cleared.

Note
Nordic SDK requires radio uninitialization to reset GATT service states. If any other task is using radio, this function will return error. This function will re-initialize radio after GATT is uninitialized with original modulation.
Return values
RD_SUCCESSon success.
RD_ERROR_INVALID_STATEif GATT cannot be uninitialized.