SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
Toggle main menu visibility
Loading...
Searching...
No Matches
nus_protocol.h
Go to the documentation of this file.
1
/*******************************************************************************
2
* File Name: nus_protocol.h
3
*
4
* Description: Public API of the Bento Desktop Buddy NUS wire protocol layer.
5
* Bento forked this wire protocol under its own branding; it is
6
* not Anthropic-compatible.
7
*
8
* The protocol layer sits between ble_nus (AIROC BLE transport)
9
* and the CM55 UI (via IPC). It does:
10
* - newline-framed assembler with 4 KB overflow + RESYNC
11
* - jsmn-based JSON parse with 256-token ceiling
12
* - dispatch table for heartbeat / turn event / cmd / time frames
13
* - IPC emit to CM55 for state/prompt/message/tokens
14
* - ack/permission TX back to desktop via ble_nus_send
15
* - passive 30-s keepalive watchdog
16
*
17
******************************************************************************/
18
19
#ifndef NUS_PROTOCOL_H
20
#define NUS_PROTOCOL_H
21
22
#include <stddef.h>
23
#include <stdint.h>
24
25
#ifdef __cplusplus
26
extern
"C"
{
27
#endif
28
29
/* Call once at ble_nus_init time (after BLE stack init). */
30
void
nus_protocol_init
(
void
);
31
32
/* Feed RX bytes from the NUS RX characteristic. May deliver one full frame,
33
* a partial frame, or multiple concatenated frames. Non-blocking. */
34
void
nus_on_rx_bytes
(
const
uint8_t *buf,
size_t
len);
35
36
/* Passive watchdog tick — call periodically (e.g., from UI render at ~10 Hz).
37
* Emits BUDDY_UI_STATE=SLEEP via IPC if 30 s have passed without a parseable
38
* frame and the link is still considered connected. */
39
void
nus_protocol_tick
(uint32_t now_ms);
40
41
/* Called from ble_nus when Approve/Deny button pressed.
42
* decision_approve: true = "once", false = "deny". Emits the permission JSON
43
* frame on NUS TX with the stored prompt id. */
44
void
nus_protocol_send_permission
(
const
char
*
id
,
size_t
id_len,
int
decision_approve);
45
46
/* Called from ble_nus BTM_ENCRYPTION_STATUS_EVT handler.
47
* When true, status ack's data.sec field reports "sec":true. */
48
void
nus_protocol_set_link_encrypted
(
int
encrypted);
49
50
#ifdef __cplusplus
51
}
52
#endif
53
54
#endif
/* NUS_PROTOCOL_H */
nus_on_rx_bytes
void nus_on_rx_bytes(const uint8_t *buf, size_t len)
ป้อนไบต์จาก NUS RX ให้ตัวประกอบเฟรม ใช้ newline คั่นเฟรม ล้นที่ 4 KB แล้ว RESYNC
nus_protocol_send_permission
void nus_protocol_send_permission(const char *id, size_t id_len, int decision_approve)
ส่งเฟรม permission ของ id คำถามยืนยันที่เก็บไว้ หลังจากมีการตัดสินใจของมนุษย์แล้ว ไม่มีผู้เรียกที่ใดเ...
nus_protocol_set_link_encrypted
void nus_protocol_set_link_encrypted(int encrypted)
เป็นของภายใน stack: ถูกตั้งค่าจาก handler ของ BTM_ENCRYPTION_STATUS_EVT
nus_protocol_tick
void nus_protocol_tick(uint32_t now_ms)
watchdog แบบ keepalive 30 s ที่ทำงานเชิงรับ ให้เรียกที่ราว 10 Hz ไม่มีผู้เรียกที่ใดเลย
nus_protocol_init
void nus_protocol_init(void)
init ครั้งเดียวสำหรับใช้ภายใน — ble_nus_init() ทำให้แล้ว ห้ามเรียกโดยตรง
dist
ble_nus
include
nus_protocol.h
Generated by
1.18.0