SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
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
30extern "C" {
31#endif
32
34#define BLE_NUS_MAX_PAYLOAD 244
35
37typedef 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 */
43
46typedef void (*ble_nus_rx_cb_t)(const uint8_t *data, size_t len, void *user_ctx);
47
49typedef void (*ble_nus_state_cb_t)(ble_nus_state_t state, void *user_ctx);
50
51typedef struct {
52 const char *device_name; /* Advertised name, e.g. "BENTO Buddy" */
55 void *user_ctx;
57
61
65int ble_nus_send(const uint8_t *data, size_t len);
66
71void ble_nus_deinit(void);
72
77
80
84const char *ble_nus_get_adv_name(void);
85
99void ble_nus_passkey_cb(const char *passkey_6_digits);
100
108typedef struct {
109 uint32_t disconnect_count; /* total disconnect events seen */
110 uint8_t last_disconnect_reason; /* p->connection_status.reason */
111 uint32_t advert_restart_attempts; /* total auto-readvertise attempts */
112 int last_advert_restart_result; /* return of last wiced_bt_start_advertisements */
113 uint8_t deinit_in_progress_at_last_disconnect; /* 0 or 1 — was the flag set when we disconnected? */
114 uint32_t boot_advert_attempts; /* total BTM_ENABLED-path start_advertisements calls */
115 int last_boot_advert_result; /* return of last boot-time advert start */
117
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif /* BLE_NUS_H */
void(*) ble_nus_state_cb_t(ble_nus_state_t state, void *user_ctx)
Definition ble_nus.h:49
ble_nus_state_t
Definition ble_nus.h:37
@ BLE_NUS_STATE_CONNECTED
Definition ble_nus.h:40
@ BLE_NUS_STATE_ERROR
Definition ble_nus.h:41
@ BLE_NUS_STATE_ADVERTISING
Definition ble_nus.h:39
@ BLE_NUS_STATE_OFF
Definition ble_nus.h:38
void(*) ble_nus_rx_cb_t(const uint8_t *data, size_t len, void *user_ctx)
Definition ble_nus.h:46
int ble_nus_send(const uint8_t *data, size_t len)
ส่งไบต์ออกทาง NUS TX คืน -1 เว้นแต่เชื่อมต่ออยู่และเปิด notification ไว้ มี weak stub อยู่แล้วตั้งแต่...
void ble_nus_passkey_cb(const char *passkey_6_digits)
callback แบบ weak สำหรับ passkey ของการจับคู่ (pairing) ยังไม่ถูกเรียกใช้ในบิลด์นี้
void ble_nus_rearm_advertising(void)
เปิดการกระจายสัญญาณใหม่บน stack ที่ init ไว้แล้ว เป็น idempotent จากทุกสถานะ
void ble_nus_get_diagnostics(ble_nus_diag_t *out)
เติม snapshot ข้อมูลวินิจฉัย (diagnostics) ที่ผู้เรียกเป็นเจ้าของ — คือบล็อก _diag....
bool ble_nus_init(const ble_nus_config_t *cfg)
เริ่มต้น AIROC stack แล้วเริ่มการกระจายสัญญาณ (advertising) การเรียกในช่วงบูตต้องเป็นของ task จ่ายไฟช...
void ble_nus_deinit(void)
หยุดแบบ soft: ยุติการกระจายสัญญาณและตัด link แต่คง AIROC host stack ไว้ให้ทำงานต่อ
ble_nus_state_t ble_nus_get_state(void)
อ่านค่า state โดยไม่ต้องจับ lock ปลอดภัยตั้งแต่ก่อน init เฟิร์มแวร์เลือกวนถามค่านี้แทนการเชื่อ callba...
const char * ble_nus_get_adv_name(void)
พอยน์เตอร์ไปยังชื่อ Bento-XXXX สำหรับการกระจายสัญญาณซึ่งเป็น static คืน NULL จนกว่าจะคลี่ค่า BD addre...
Definition ble_nus.h:51
void * user_ctx
Definition ble_nus.h:55
ble_nus_state_cb_t on_state
Definition ble_nus.h:54
const char * device_name
Definition ble_nus.h:52
ble_nus_rx_cb_t on_rx
Definition ble_nus.h:53
Definition ble_nus.h:108
int last_boot_advert_result
Definition ble_nus.h:115
uint8_t last_disconnect_reason
Definition ble_nus.h:110
uint8_t deinit_in_progress_at_last_disconnect
Definition ble_nus.h:113
uint32_t disconnect_count
Definition ble_nus.h:109
uint32_t advert_restart_attempts
Definition ble_nus.h:111
uint32_t boot_advert_attempts
Definition ble_nus.h:114
int last_advert_restart_result
Definition ble_nus.h:112