Nordic UART Service

nRF5 SDK v12.2.0

Nordic UART Service implementation. More...

Data Structures

struct ble_nus_init_t
Nordic UART Service initialization structure. More...
struct ble_nus_s
Nordic UART Service structure. More...

Typedefs

typedef struct ble_nus_s ble_nus_t
typedef void(* ble_nus_data_handler_t )( ble_nus_t *p_nus, uint8_t *p_data, uint16_t length)
Nordic UART Service event handler type.

Functions

uint32_t ble_nus_init ( ble_nus_t *p_nus, const ble_nus_init_t *p_nus_init)
Function for initializing the Nordic UART Service. More...
void ble_nus_on_ble_evt ( ble_nus_t *p_nus, ble_evt_t *p_ble_evt)
Function for handling the Nordic UART Service's BLE events. More...
uint32_t ble_nus_string_send ( ble_nus_t *p_nus, uint8_t *p_string, uint16_t length)
Function for sending a string to the peer. More...

Detailed Description

Nordic UART Service implementation.

The Nordic UART Service is a simple GATT-based service with TX and RX characteristics. Data received from the peer is passed to the application, and the data received from the application of this service is sent to the peer as Handle Value Notifications. This module demonstrates how to implement a custom GATT-based service and characteristics using the SoftDevice. The service is used by the application to send and receive ASCII text strings to and from the peer.

Note
The application must propagate SoftDevice events to the Nordic UART Service module by calling the ble_nus_on_ble_evt() function from the ble_stack_handler callback.

Macro Definition Documentation

#define BLE_NUS_MAX_DATA_LEN   ( GATT_MTU_SIZE_DEFAULT - 3)

Maximum length of data (in bytes) that can be transmitted to the peer by the Nordic UART service module.

#define BLE_UUID_NUS_SERVICE   0x0001

The UUID of the Nordic UART Service.

Function Documentation

uint32_t ble_nus_init ( ble_nus_t * p_nus ,
const ble_nus_init_t * p_nus_init
)

Function for initializing the Nordic UART Service.

Parameters
[out] p_nus Nordic UART Service structure. This structure must be supplied by the application. It is initialized by this function and will later be used to identify this particular service instance.
[in] p_nus_init Information needed to initialize the service.
Return values
NRF_SUCCESS If the service was successfully initialized. Otherwise, an error code is returned.
NRF_ERROR_NULL If either of the pointers p_nus or p_nus_init is NULL.
void ble_nus_on_ble_evt ( ble_nus_t * p_nus ,
ble_evt_t * p_ble_evt
)

Function for handling the Nordic UART Service's BLE events.

The Nordic UART Service expects the application to call this function each time an event is received from the SoftDevice. This function processes the event if it is relevant and calls the Nordic UART Service event handler of the application if necessary.

Parameters
[in] p_nus Nordic UART Service structure.
[in] p_ble_evt Event received from the SoftDevice.
uint32_t ble_nus_string_send ( ble_nus_t * p_nus ,
uint8_t * p_string ,
uint16_t length
)

Function for sending a string to the peer.

This function sends the input string as an RX characteristic notification to the peer.

Parameters
[in] p_nus Pointer to the Nordic UART Service structure.
[in] p_string String to be sent.
[in] length Length of the string.
Return values
NRF_SUCCESS If the string was sent successfully. Otherwise, an error code is returned.