SDK for TESAIoT Dev Kit
API reference & tutorials (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)
Feed NUS RX bytes to the framer; newline framed, 4 KB overflow with RESYNC.
void nus_protocol_send_permission(const char *id, size_t id_len, int decision_approve)
Emit the permission frame for a stored prompt id after a human decision. No caller anywhere.
void nus_protocol_set_link_encrypted(int encrypted)
Stack-internal: set from the BTM_ENCRYPTION_STATUS_EVT handler.
void nus_protocol_tick(uint32_t now_ms)
Passive 30 s keepalive watchdog; call at about 10 Hz. No caller anywhere.
void nus_protocol_init(void)
Internal one-time init โ€” ble_nus_init() does it; never call directly.