nRF Connect SDK Bare Metal API 2.0.99
Loading...
Searching...
No Matches
ble_nus_client.h
1/*
2 * Copyright (c) 2012 - 2026 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
15#ifndef BLE_NUS_CLIENT_H__
16#define BLE_NUS_CLIENT_H__
17
18#include <stdint.h>
19#include <bm/bluetooth/ble_common.h>
20#include <bm/bluetooth/ble_db_discovery.h>
21#include <bm/bluetooth/ble_gq.h>
22#include <bm/softdevice_handler/nrf_sdh_ble.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
33#define BLE_NUS_CLIENT_DEF(_name) \
34 static struct ble_nus_client _name; \
35 NRF_SDH_BLE_OBSERVER(_name##_obs, ble_nus_client_on_ble_evt, &_name, HIGH)
36
38#define BLE_NUS_UUID_BASE { 0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, \
39 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E }
40
42#define BLE_UUID_NUS_SERVICE 0x0001
44#define BLE_UUID_NUS_RX_CHARACTERISTIC 0x0002
46#define BLE_UUID_NUS_TX_CHARACTERISTIC 0x0003
47
52#define BLE_NUS_CLIENT_MAX_DATA_LEN_CALC(mtu_size) ((mtu_size) - ATT_OPCODE_LEN - ATT_HANDLE_LEN)
53
58#ifndef BLE_NUS_CLIENT_MAX_DATA_LEN
59#define BLE_NUS_CLIENT_MAX_DATA_LEN \
60 (BLE_NUS_CLIENT_MAX_DATA_LEN_CALC(CONFIG_NRF_SDH_BLE_GATT_MAX_MTU_SIZE))
61#endif
62
76
88
98 uint16_t conn_handle;
99 union {
101 struct {
106 struct {
108 uint8_t *data;
110 uint16_t length;
113 struct {
115 uint32_t reason;
118 struct {
120 uint32_t reason;
122 };
123};
124
125/* Forward declaration of the ble_nus_client type. */
126struct ble_nus_client;
127
129typedef void (*ble_nus_client_evt_handler_t)(struct ble_nus_client *ble_nus_c,
130 const struct ble_nus_client_evt *evt);
131
132/*
133 * @brief Nordic UART Service Client configuration structure.
134 *
135 * @details This structure contains the initialization information for the service. The application
136 * must fill this structure and pass it to the service using the @ref ble_nus_client_init
137 * function.
138 */
147
165
181uint32_t ble_nus_client_init(struct ble_nus_client *nus_client,
182 const struct ble_nus_client_config *nus_client_config);
183
198 const struct ble_db_discovery_evt *evt);
199
213void ble_nus_client_on_ble_evt(const ble_evt_t *ble_evt, void *ble_nus_client);
214
229
244
261uint32_t ble_nus_client_string_send(struct ble_nus_client *nus_client, const uint8_t *string,
262 uint16_t length);
263
282uint32_t ble_nus_client_handles_assign(struct ble_nus_client *nus_client, uint16_t conn_handle,
283 const struct ble_nus_client_handles *peer_handles);
284
285#ifdef __cplusplus
286}
287#endif
288
289#endif
uint32_t ble_nus_client_init(struct ble_nus_client *nus_client, const struct ble_nus_client_config *nus_client_config)
Initialize the Nordic UART client service.
uint32_t ble_nus_client_tx_notif_disable(struct ble_nus_client *nus_client)
Request the peer to stop sending notification of TX characteristic.
uint32_t ble_nus_client_handles_assign(struct ble_nus_client *nus_client, uint16_t conn_handle, const struct ble_nus_client_handles *peer_handles)
Assign handles to this instance of the service.
ble_nus_client_evt_type
NUS Client event type.
Definition ble_nus_client.h:66
@ BLE_NUS_CLIENT_EVT_DISCOVERY_COMPLETE
Definition ble_nus_client.h:68
@ BLE_NUS_CLIENT_EVT_ERROR
Definition ble_nus_client.h:74
@ BLE_NUS_CLIENT_EVT_DISCONNECTED
Definition ble_nus_client.h:72
@ BLE_NUS_CLIENT_EVT_TX_DATA
Definition ble_nus_client.h:70
uint32_t ble_nus_client_tx_notif_enable(struct ble_nus_client *nus_client)
Request the peer to start sending notification of TX characteristic.
uint32_t ble_nus_client_string_send(struct ble_nus_client *nus_client, const uint8_t *string, uint16_t length)
Send a string to the server.
void(* ble_nus_client_evt_handler_t)(struct ble_nus_client *ble_nus_c, const struct ble_nus_client_evt *evt)
Nordic UART Service Client event handler type.
Definition ble_nus_client.h:129
void ble_nus_client_on_ble_evt(const ble_evt_t *ble_evt, void *ble_nus_client)
Bluetooth LE event handler for the Nordic UART Service Client.
void ble_nus_client_on_db_disc_evt(struct ble_nus_client *nus_client, const struct ble_db_discovery_evt *evt)
Handle events from the Database Discovery library.
Bluetooth LE database discovery event.
Definition ble_db_discovery.h:61
Bluetooth LE database discovery.
Definition ble_db_discovery.h:122
Bluetooth LE GATT Queue.
Definition ble_gq.h:238
ble_nus_client_evt_handler_t evt_handler
Definition ble_nus_client.h:141
struct ble_db_discovery * db_discovery
Definition ble_nus_client.h:145
const struct ble_gq * gatt_queue
Definition ble_nus_client.h:143
Definition ble_nus_client.h:139
enum ble_nus_client_evt_type evt_type
Definition ble_nus_client.h:96
struct ble_nus_client_evt::@118::@121 tx_data
uint32_t reason
Definition ble_nus_client.h:115
struct ble_nus_client_evt::@118::@122 disconnected
struct ble_nus_client_evt::@118::@123 error
uint8_t * data
Definition ble_nus_client.h:108
uint16_t conn_handle
Definition ble_nus_client.h:98
struct ble_nus_client_handles handles
Definition ble_nus_client.h:103
struct ble_nus_client_evt::@118::@120 discovery_complete
uint16_t length
Definition ble_nus_client.h:110
Nordic UART Service Client event structure.
Definition ble_nus_client.h:94
uint16_t nus_tx_handle
Definition ble_nus_client.h:82
uint16_t nus_rx_handle
Definition ble_nus_client.h:86
uint16_t nus_tx_cccd_handle
Definition ble_nus_client.h:84
Handles of the connected peer device, as provided by a discovery.
Definition ble_nus_client.h:80
struct ble_nus_client_handles handles
Definition ble_nus_client.h:159
const struct ble_gq * gatt_queue
Definition ble_nus_client.h:163
uint16_t conn_handle
Definition ble_nus_client.h:157
ble_nus_client_evt_handler_t evt_handler
Definition ble_nus_client.h:161
uint8_t uuid_type
Definition ble_nus_client.h:153
NUS Client structure.
Definition ble_nus_client.h:151