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