nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
nus.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef BT_NUS_H_
8#define BT_NUS_H_
9
17#include <zephyr/types.h>
18#include <zephyr/bluetooth/conn.h>
19#include <zephyr/bluetooth/uuid.h>
20#include <zephyr/bluetooth/gatt.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
27#define BT_UUID_NUS_VAL \
28 BT_UUID_128_ENCODE(0x6e400001, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)
29
31#define BT_UUID_NUS_TX_VAL \
32 BT_UUID_128_ENCODE(0x6e400003, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)
33
35#define BT_UUID_NUS_RX_VAL \
36 BT_UUID_128_ENCODE(0x6e400002, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)
37
38#define BT_UUID_NUS_SERVICE BT_UUID_DECLARE_128(BT_UUID_NUS_VAL)
39#define BT_UUID_NUS_RX BT_UUID_DECLARE_128(BT_UUID_NUS_RX_VAL)
40#define BT_UUID_NUS_TX BT_UUID_DECLARE_128(BT_UUID_NUS_TX_VAL)
41
48};
49
51struct bt_nus_cb {
61 void (*received)(struct bt_conn *conn,
62 const uint8_t *const data, uint16_t len);
63
72 void (*sent)(struct bt_conn *conn);
73
80 void (*send_enabled)(enum bt_nus_send_status status);
81
82};
83
99int bt_nus_init(struct bt_nus_cb *callbacks);
100
114int bt_nus_send(struct bt_conn *conn, const uint8_t *data, uint16_t len);
115
122static inline uint32_t bt_nus_get_mtu(struct bt_conn *conn)
123{
124 /* According to 3.4.7.1 Handle Value Notification off the ATT protocol.
125 * Maximum supported notification is ATT_MTU - 3 */
126 return bt_gatt_get_mtu(conn) - 3;
127}
128
129#ifdef __cplusplus
130}
131#endif
132
137#endif /* BT_NUS_H_ */
int bt_nus_init(struct bt_nus_cb *callbacks)
Initialize the service.
bt_nus_send_status
NUS send status.
Definition: nus.h:43
@ BT_NUS_SEND_STATUS_DISABLED
Definition: nus.h:47
@ BT_NUS_SEND_STATUS_ENABLED
Definition: nus.h:45
int bt_nus_send(struct bt_conn *conn, const uint8_t *data, uint16_t len)
Send data.
static uint32_t bt_nus_get_mtu(struct bt_conn *conn)
Get maximum data length that can be used for bt_nus_send.
Definition: nus.h:122
void(* send_enabled)(enum bt_nus_send_status status)
Send state callback.
Definition: nus.h:80
void(* received)(struct bt_conn *conn, const uint8_t *const data, uint16_t len)
Data received callback.
Definition: nus.h:61
void(* sent)(struct bt_conn *conn)
Data sent callback.
Definition: nus.h:72
Pointers to the callback functions for service events.
Definition: nus.h:51