SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
Toggle main menu visibility
Loading...
Searching...
No Matches
nus_events.h
Go to the documentation of this file.
1
/*******************************************************************************
2
* File Name: nus_events.h
3
*
4
* Description: Device -> Desktop NUS event emitter. Separates device-originated
5
* frames (media / system commands, user acks, reply text) from
6
* the desktop -> device command dispatcher in nus_commands.c.
7
*
8
* All outbound event JSON is line-delimited — this module owns
9
* the framing so callers never need to remember to append '\n'.
10
*
11
* Also owns the pending-ack FIFO for ack_required=true
12
* notifications (SPEC §7.5). nus_commands.c pushes ids when a
13
* bento.notify.show lands; CM55 LCD taps drain them back via
14
* nus_events_drain_pending_ack().
15
*
16
* Reference: TESAIoT_PLAN/2026-4/Bento_Buddy/SPEC.md §5.2.
17
*
18
******************************************************************************/
19
20
#ifndef NUS_EVENTS_H
21
#define NUS_EVENTS_H
22
23
#include <stdbool.h>
24
#include <stddef.h>
25
#include <stdint.h>
26
27
#ifdef __cplusplus
28
extern
"C"
{
29
#endif
30
31
/* Emit a NUS event frame. Appends '\n' (line delimiter) then writes to BLE
32
* via ble_nus_send(). `json` must be a NUL-terminated JSON object. Returns
33
* 0 on success, -1 on transport error or disconnected link. */
34
int
nus_emit_event
(
const
char
*json);
35
36
/* Pending-ack FIFO for notifications with ack_required=true. Called from
37
* nus_commands.c:cmd_bento_notify_show. Dedups; evicts oldest when full. */
38
void
nus_events_push_pending_ack
(
const
char
*
id
);
39
40
/* Drain an id from the pending-ack FIFO. Returns true if found (and removed),
41
* false otherwise. Called from ipc_bento_buddy_bridge.c when an
42
* IPC_CMD_BUDDY_DEVICE_CMD carrying a bento.user.ack is received from CM55. */
43
bool
nus_events_drain_pending_ack
(
const
char
*
id
);
44
45
/* Number of ids currently in the pending-ack FIFO. Exposed for telemetry +
46
* host unit tests. */
47
size_t
nus_events_pending_ack_count
(
void
);
48
49
#ifdef __cplusplus
50
}
51
#endif
52
53
#endif
/* NUS_EVENTS_H */
nus_events_drain_pending_ack
bool nus_events_drain_pending_ack(const char *id)
เอา id ออกจาก FIFO คืน true เมื่อพบ — เป็นเส้นทาง bento.user.ack ของการแตะบน CM55
nus_emit_event
int nus_emit_event(const char *json)
ส่งเฟรม event แบบ JSON หนึ่งเฟรม (ห้ามใส่ newline ปิดท้าย — ฟังก์ชันเติม LF ให้เอง) คืนค่า 0/-1 เท่าน...
nus_events_push_pending_ack
void nus_events_push_pending_ack(const char *id)
ใส่ id ของ notification ลงใน FIFO ของ ack ที่ค้างอยู่ ตัดรายการซ้ำ และนำรายการเก่าสุดออกเมื่อเต็ม
nus_events_pending_ack_count
size_t nus_events_pending_ack_count(void)
จำนวน id ที่อยู่ใน FIFO ใช้กับ telemetry และ unit test บนเครื่อง host ไม่มีผู้เรียกที่ใดเลย
dist
ble_nus
include
nus_events.h
Generated by
1.18.0