Nordic UART Service implementation.
More...
|
#define | BLE_NUS_DEF(_name) |
| 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.
|
|
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:
#define BLE_NUS_DEF |
( |
|
_name | ) |
|
Macro for defining a ble_nus instance.
- Parameters
-
_name | Name of the instance. |
#define BLE_UUID_NUS_SERVICE 0x0001 |
The UUID of the Nordic UART Service.
Nordic UART Service event types.
Enumerator |
---|
BLE_NUS_EVT_RX_DATA |
Data received.
|
BLE_NUS_EVT_TX_RDY |
Service is ready to accept new data to be transmitted.
|
BLE_NUS_EVT_COMM_STARTED |
Notification has been enabled.
|
BLE_NUS_EVT_COMM_STOPPED |
Notification has been disabled.
|
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. |
uint32_t ble_nus_string_send |
( |
ble_nus_t * |
p_nus, |
|
|
uint8_t * |
p_string, |
|
|
uint16_t * |
p_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,out] | p_length | Pointer Length of the string. Amount of sent bytes. |
- Return values
-
NRF_SUCCESS | If the string was sent successfully. Otherwise, an error code is returned. |