Nordic UART Service implementation. More...
Data Structures |
|
| struct | ble_nus_evt_rx_data_t |
|
Nordic UART Service
BLE_NUS_EVT_RX_DATA
event data.
More...
|
|
| struct | ble_nus_client_context_t |
|
Nordic UART Service client context structure.
More...
|
|
| struct | ble_nus_evt_t |
|
Nordic UART Service event structure.
More...
|
|
| struct | ble_nus_init_t |
|
Nordic UART Service initialization structure.
More...
|
|
| struct | ble_nus_s |
|
Nordic UART Service structure.
More...
|
|
Macros |
|
| #define | BLE_NUS_DEF (_name, _nus_max_clients) |
|
Macro for defining a ble_nus instance.
More...
|
|
| #define | BLE_UUID_NUS_SERVICE 0x0001 |
| #define | OPCODE_LENGTH 1 |
| #define | HANDLE_LENGTH 2 |
| #define | BLE_NUS_MAX_DATA_LEN (BLE_GATT_MTU_SIZE_DEFAULT - OPCODE_LENGTH - HANDLE_LENGTH) |
|
Maximum length of data (in bytes) that can be transmitted to the peer by the Nordic UART service module.
|
|
Typedefs |
|
| typedef struct ble_nus_s | ble_nus_t |
| typedef void(* | ble_nus_data_handler_t )( ble_nus_evt_t *p_evt) |
|
Nordic UART Service event handler type.
|
|
Enumerations |
|
| enum |
ble_nus_evt_type_t
{
BLE_NUS_EVT_RX_DATA , BLE_NUS_EVT_TX_RDY , BLE_NUS_EVT_COMM_STARTED , BLE_NUS_EVT_COMM_STOPPED } |
|
Nordic UART Service event types.
More...
|
|
Functions |
|
| uint32_t | ble_nus_init ( ble_nus_t *p_nus, ble_nus_init_t const *p_nus_init) |
|
Function for initializing the Nordic UART Service.
More...
|
|
| void | ble_nus_on_ble_evt ( ble_evt_t const *p_ble_evt, void *p_context) |
|
Function for handling the Nordic UART Service's BLE events.
More...
|
|
| uint32_t | ble_nus_data_send ( ble_nus_t *p_nus, uint8_t *p_data, uint16_t *p_length, uint16_t conn_handle) |
|
Function for sending a data 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 register this module as BLE event observer using the NRF_SDH_BLE_OBSERVER macro. Example:
ble_nus_t instance;NRF_SDH_BLE_OBSERVER (anything, BLE_NUS_BLE_OBSERVER_PRIO ,ble_nus_on_ble_evt , &instance);
Macro Definition Documentation
| #define BLE_NUS_DEF | ( | _name, | |
| _nus_max_clients | |||
| ) |
Macro for defining a ble_nus instance.
- Parameters
-
_name Name of the instance. [in] _nus_max_clients Maximum number of NUS clients connected at a time.
| #define BLE_UUID_NUS_SERVICE 0x0001 |
The UUID of the Nordic UART Service.
Enumeration Type Documentation
| enum ble_nus_evt_type_t |
Function Documentation
| uint32_t ble_nus_data_send | ( | ble_nus_t * | p_nus , |
| uint8_t * | p_data , | ||
| uint16_t * | p_length , | ||
| uint16_t | conn_handle | ||
| ) |
Function for sending a data 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_data String to be sent. [in,out] p_length Pointer Length of the string. Amount of sent bytes. [in] conn_handle Connection Handle of the destination client.
- Return values
-
NRF_SUCCESS If the string was sent successfully. Otherwise, an error code is returned.
| uint32_t ble_nus_init | ( | ble_nus_t * | p_nus , |
| ble_nus_init_t const * | 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_evt_t const * | p_ble_evt , |
| void * | p_context | ||
| ) |
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_ble_evt Event received from the SoftDevice. [in] p_context Nordic UART Service structure.