SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (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; it is not Anthropic-compatible).
10
*
11
* Exclusive with WiFi: CYW55500 has a single RF transceiver.
12
* When BLE is active, the WiFi stack must not be initialized.
13
*
14
* NUS UUIDs (128-bit, Nordic-defined):
15
* Service: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E
16
* RX char: 6E400002-... (host -> device, WRITE/WRITE_NO_RSP)
17
* TX char: 6E400003-... (device -> host, NOTIFY)
18
*
19
*******************************************************************************/
20
21
#ifndef BLE_NUS_H
22
#define BLE_NUS_H
23
24
#include <stdbool.h>
25
#include <stddef.h>
26
#include <stdint.h>
27
28
#ifdef __cplusplus
29
extern
"C"
{
30
#endif
31
33
#define BLE_NUS_MAX_PAYLOAD 244
34
36
typedef
enum
{
37
BLE_NUS_STATE_OFF
= 0,
/* stack not initialized */
38
BLE_NUS_STATE_ADVERTISING
,
/* broadcasting, waiting for Bento Desktop Buddy */
39
BLE_NUS_STATE_CONNECTED
,
/* paired, NUS exchanging data */
40
BLE_NUS_STATE_ERROR
,
41
}
ble_nus_state_t
;
42
45
typedef
void (*
ble_nus_rx_cb_t
)(
const
uint8_t *data,
size_t
len,
void
*user_ctx);
46
48
typedef
void (*
ble_nus_state_cb_t
)(
ble_nus_state_t
state,
void
*user_ctx);
49
50
typedef
struct
{
51
const
char
*
device_name
;
/* Advertised name, e.g. "BENTO Buddy" */
52
ble_nus_rx_cb_t
on_rx
;
53
ble_nus_state_cb_t
on_state
;
54
void
*
user_ctx
;
55
}
ble_nus_config_t
;
56
59
bool
ble_nus_init
(
const
ble_nus_config_t
*cfg);
60
64
int
ble_nus_send
(
const
uint8_t *data,
size_t
len);
65
72
#ifndef BLE_NUS_ADV_INTERVAL_MS
73
#define BLE_NUS_ADV_INTERVAL_MS 100
74
#endif
75
78
#ifndef BLE_NUS_ADV_FAST_SECONDS
79
#define BLE_NUS_ADV_FAST_SECONDS 30
80
#endif
81
85
#define BLE_NUS_METER_PAYLOAD_MAX 24
86
91
void
ble_nus_deinit
(
void
);
92
96
void
ble_nus_rearm_advertising
(
void
);
97
99
ble_nus_state_t
ble_nus_get_state
(
void
);
100
104
const
char
*
ble_nus_get_adv_name
(
void
);
105
119
void
ble_nus_passkey_cb
(
const
char
*passkey_6_digits);
120
126
typedef
struct
{
127
uint32_t
disconnect_count
;
/* disconnects seen */
128
uint8_t
last_disconnect_reason
;
/* reason code of the latest disconnect */
129
uint32_t
advert_restart_attempts
;
/* automatic re-advertising attempts */
130
int
last_advert_restart_result
;
/* result of the latest such attempt */
131
uint8_t
deinit_in_progress_at_last_disconnect
;
/* 1 if the link dropped while BLE was shutting down */
132
uint32_t
boot_advert_attempts
;
/* advertising starts when the stack came up */
133
int
last_boot_advert_result
;
/* result of the latest of those */
134
}
ble_nus_diag_t
;
135
136
void
ble_nus_get_diagnostics
(
ble_nus_diag_t
*out);
137
138
#ifdef __cplusplus
139
}
140
#endif
141
142
#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:48
ble_nus_state_t
ble_nus_state_t
Definition
ble_nus.h:36
BLE_NUS_STATE_CONNECTED
@ BLE_NUS_STATE_CONNECTED
Definition
ble_nus.h:39
BLE_NUS_STATE_ERROR
@ BLE_NUS_STATE_ERROR
Definition
ble_nus.h:40
BLE_NUS_STATE_ADVERTISING
@ BLE_NUS_STATE_ADVERTISING
Definition
ble_nus.h:38
BLE_NUS_STATE_OFF
@ BLE_NUS_STATE_OFF
Definition
ble_nus.h:37
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:45
ble_nus_send
int ble_nus_send(const uint8_t *data, size_t len)
ส่งไบต์ออกทาง NUS TX คืน -1 เว้นแต่เชื่อมต่ออยู่และเปิด notification ไว้ มี weak stub อยู่แล้วตั้งแต่...
ble_nus_passkey_cb
void ble_nus_passkey_cb(const char *passkey_6_digits)
callback แบบ weak สำหรับ passkey ของการจับคู่ (pairing) ยังไม่ถูกเรียกใช้ในบิลด์นี้
ble_nus_rearm_advertising
void ble_nus_rearm_advertising(void)
เปิดการกระจายสัญญาณใหม่บน stack ที่ init ไว้แล้ว เป็น idempotent จากทุกสถานะ
ble_nus_get_diagnostics
void ble_nus_get_diagnostics(ble_nus_diag_t *out)
เติม snapshot ข้อมูลวินิจฉัย (diagnostics) ที่ผู้เรียกเป็นเจ้าของ — คือบล็อก _diag....
ble_nus_init
bool ble_nus_init(const ble_nus_config_t *cfg)
เริ่มต้น AIROC stack แล้วเริ่มการกระจายสัญญาณ (advertising) การเรียกในช่วงบูตต้องเป็นของ task จ่ายไฟช...
ble_nus_deinit
void ble_nus_deinit(void)
หยุดแบบ soft: ยุติการกระจายสัญญาณและตัด link แต่คง AIROC host stack ไว้ให้ทำงานต่อ
ble_nus_get_state
ble_nus_state_t ble_nus_get_state(void)
อ่านค่า state โดยไม่ต้องจับ lock ปลอดภัยตั้งแต่ก่อน init เฟิร์มแวร์เลือกวนถามค่านี้แทนการเชื่อ callba...
ble_nus_get_adv_name
const char * ble_nus_get_adv_name(void)
พอยน์เตอร์ไปยังชื่อ Bento-XXXX สำหรับการกระจายสัญญาณซึ่งเป็น static คืน NULL จนกว่าจะคลี่ค่า BD addre...
ble_nus_config_t
Definition
ble_nus.h:50
ble_nus_config_t::user_ctx
void * user_ctx
Definition
ble_nus.h:54
ble_nus_config_t::on_state
ble_nus_state_cb_t on_state
Definition
ble_nus.h:53
ble_nus_config_t::device_name
const char * device_name
Definition
ble_nus.h:51
ble_nus_config_t::on_rx
ble_nus_rx_cb_t on_rx
Definition
ble_nus.h:52
ble_nus_diag_t
Definition
ble_nus.h:126
ble_nus_diag_t::last_boot_advert_result
int last_boot_advert_result
Definition
ble_nus.h:133
ble_nus_diag_t::last_disconnect_reason
uint8_t last_disconnect_reason
Definition
ble_nus.h:128
ble_nus_diag_t::deinit_in_progress_at_last_disconnect
uint8_t deinit_in_progress_at_last_disconnect
Definition
ble_nus.h:131
ble_nus_diag_t::disconnect_count
uint32_t disconnect_count
Definition
ble_nus.h:127
ble_nus_diag_t::advert_restart_attempts
uint32_t advert_restart_attempts
Definition
ble_nus.h:129
ble_nus_diag_t::boot_advert_attempts
uint32_t boot_advert_attempts
Definition
ble_nus.h:132
ble_nus_diag_t::last_advert_restart_result
int last_advert_restart_result
Definition
ble_nus.h:130
dist
ble_nus
include
ble_nus.h
Generated by
1.18.0