SDK for TESAIoT Dev Kit
API reference & tutorials (ModusToolbox)
Toggle main menu visibility
Loading...
Searching...
No Matches
ble_nus.h
Go to the documentation of this file.
1
/*******************************************************************************
2
* File Name: ble_nus.h
3
*
4
* Description: Nordic UART Service (NUS) transport for BENTO Bento Desktop
5
* Buddy. Runs on CM33_NS over AIROC CYW55500 BLE host stack.
6
* Wire protocol: JSON messages framed by NUS RX/TX characteristics
7
* (see https://github.com/anthropics/claude-desktop-buddy REFERENCE.md
8
* for the original protocol source — Bento forked this protocol
9
* under its own branding; see Bento_Buddy/SPEC.md §3.1.1 Not
10
* Anthropic-compatible).
11
*
12
* Exclusive with WiFi: CYW55500 has a single RF transceiver.
13
* When BLE is active, the WiFi stack must not be initialized.
14
*
15
* NUS UUIDs (128-bit, Nordic-defined):
16
* Service: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E
17
* RX char: 6E400002-... (host -> device, WRITE/WRITE_NO_RSP)
18
* TX char: 6E400003-... (device -> host, NOTIFY)
19
*
20
*******************************************************************************/
21
22
#ifndef BLE_NUS_H
23
#define BLE_NUS_H
24
25
#include <stdbool.h>
26
#include <stddef.h>
27
#include <stdint.h>
28
29
#ifdef __cplusplus
30
extern
"C"
{
31
#endif
32
34
#define BLE_NUS_MAX_PAYLOAD 244
35
37
typedef
enum
{
38
BLE_NUS_STATE_OFF
= 0,
/* stack not initialized */
39
BLE_NUS_STATE_ADVERTISING
,
/* broadcasting, waiting for Bento Desktop Buddy */
40
BLE_NUS_STATE_CONNECTED
,
/* paired, NUS exchanging data */
41
BLE_NUS_STATE_ERROR
,
42
}
ble_nus_state_t
;
43
46
typedef
void (*
ble_nus_rx_cb_t
)(
const
uint8_t *data,
size_t
len,
void
*user_ctx);
47
49
typedef
void (*
ble_nus_state_cb_t
)(
ble_nus_state_t
state,
void
*user_ctx);
50
51
typedef
struct
{
52
const
char
*
device_name
;
/* Advertised name, e.g. "BENTO Buddy" */
53
ble_nus_rx_cb_t
on_rx
;
54
ble_nus_state_cb_t
on_state
;
55
void
*
user_ctx
;
56
}
ble_nus_config_t
;
57
60
bool
ble_nus_init
(
const
ble_nus_config_t
*cfg);
61
65
int
ble_nus_send
(
const
uint8_t *data,
size_t
len);
66
80
#ifndef BLE_NUS_ADV_INTERVAL_MS
81
#define BLE_NUS_ADV_INTERVAL_MS 100
82
#endif
83
86
#ifndef BLE_NUS_ADV_FAST_SECONDS
87
#define BLE_NUS_ADV_FAST_SECONDS 30
88
#endif
89
93
#define BLE_NUS_METER_PAYLOAD_MAX 24
94
99
void
ble_nus_deinit
(
void
);
100
104
void
ble_nus_rearm_advertising
(
void
);
105
107
ble_nus_state_t
ble_nus_get_state
(
void
);
108
112
const
char
*
ble_nus_get_adv_name
(
void
);
113
127
void
ble_nus_passkey_cb
(
const
char
*passkey_6_digits);
128
136
typedef
struct
{
137
uint32_t
disconnect_count
;
/* total disconnect events seen */
138
uint8_t
last_disconnect_reason
;
/* p->connection_status.reason */
139
uint32_t
advert_restart_attempts
;
/* total auto-readvertise attempts */
140
int
last_advert_restart_result
;
/* return of last wiced_bt_start_advertisements */
141
uint8_t
deinit_in_progress_at_last_disconnect
;
/* 0 or 1 — was the flag set when we disconnected? */
142
uint32_t
boot_advert_attempts
;
/* total BTM_ENABLED-path start_advertisements calls */
143
int
last_boot_advert_result
;
/* return of last boot-time advert start */
144
}
ble_nus_diag_t
;
145
146
void
ble_nus_get_diagnostics
(
ble_nus_diag_t
*out);
147
148
#ifdef __cplusplus
149
}
150
#endif
151
152
#endif
/* BLE_NUS_H */
ble_nus_state_cb_t
void(*) ble_nus_state_cb_t(ble_nus_state_t state, void *user_ctx)
Definition
ble_nus.h:49
ble_nus_state_t
ble_nus_state_t
Definition
ble_nus.h:37
BLE_NUS_STATE_CONNECTED
@ BLE_NUS_STATE_CONNECTED
Definition
ble_nus.h:40
BLE_NUS_STATE_ERROR
@ BLE_NUS_STATE_ERROR
Definition
ble_nus.h:41
BLE_NUS_STATE_ADVERTISING
@ BLE_NUS_STATE_ADVERTISING
Definition
ble_nus.h:39
BLE_NUS_STATE_OFF
@ BLE_NUS_STATE_OFF
Definition
ble_nus.h:38
ble_nus_rx_cb_t
void(*) ble_nus_rx_cb_t(const uint8_t *data, size_t len, void *user_ctx)
Definition
ble_nus.h:46
ble_nus_send
int ble_nus_send(const uint8_t *data, size_t len)
Send bytes over NUS TX; -1 unless connected with notifications on. Weak stub exists pre-init.
ble_nus_passkey_cb
void ble_nus_passkey_cb(const char *passkey_6_digits)
Weak pairing-passkey callback — not reached in this build.
ble_nus_rearm_advertising
void ble_nus_rearm_advertising(void)
Re-arm advertising on an already-initialised stack; idempotent from any state.
ble_nus_get_diagnostics
void ble_nus_get_diagnostics(ble_nus_diag_t *out)
Fill a caller-owned diagnostics snapshot — the _diag.ble block of bento.fw.query.
ble_nus_init
bool ble_nus_init(const ble_nus_config_t *cfg)
Initialise the AIROC stack and start advertising; the chip-power task must own the boot call.
ble_nus_deinit
void ble_nus_deinit(void)
Soft-stop: drops advertising and the link, keeps the AIROC host stack alive.
ble_nus_get_state
ble_nus_state_t ble_nus_get_state(void)
Lock-free state read, safe before init; the firmware polls it rather than trusting the callback.
ble_nus_get_adv_name
const char * ble_nus_get_adv_name(void)
Pointer to the static Bento-XXXX advertising name; NULL until the BD address resolves.
ble_nus_config_t
Definition
ble_nus.h:51
ble_nus_config_t::user_ctx
void * user_ctx
Definition
ble_nus.h:55
ble_nus_config_t::on_state
ble_nus_state_cb_t on_state
Definition
ble_nus.h:54
ble_nus_config_t::device_name
const char * device_name
Definition
ble_nus.h:52
ble_nus_config_t::on_rx
ble_nus_rx_cb_t on_rx
Definition
ble_nus.h:53
ble_nus_diag_t
Definition
ble_nus.h:136
ble_nus_diag_t::last_boot_advert_result
int last_boot_advert_result
Definition
ble_nus.h:143
ble_nus_diag_t::last_disconnect_reason
uint8_t last_disconnect_reason
Definition
ble_nus.h:138
ble_nus_diag_t::deinit_in_progress_at_last_disconnect
uint8_t deinit_in_progress_at_last_disconnect
Definition
ble_nus.h:141
ble_nus_diag_t::disconnect_count
uint32_t disconnect_count
Definition
ble_nus.h:137
ble_nus_diag_t::advert_restart_attempts
uint32_t advert_restart_attempts
Definition
ble_nus.h:139
ble_nus_diag_t::boot_advert_attempts
uint32_t boot_advert_attempts
Definition
ble_nus.h:142
ble_nus_diag_t::last_advert_restart_result
int last_advert_restart_result
Definition
ble_nus.h:140
dist
ble_nus
include
ble_nus.h
Generated by
1.18.0