SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (ModusToolbox)
Toggle main menu visibility
Loading...
Searching...
No Matches
bento_time.h
Go to the documentation of this file.
1
/*******************************************************************************
2
* File Name: bento_time.h
3
*
4
* Description: Wall-clock for the BentoClaw firmware.
5
*
6
* The PSE84 has no battery-backed RTC on the AI Kit / Eva Kit
7
* boards (no coin cell), so we cannot keep real wall-clock
8
* time across a power cycle. Instead the firmware accepts a
9
* one-shot "boot epoch" push from the desktop side at BLE
10
* connect time and extrapolates the current wall-clock from
11
* there using the FreeRTOS tick counter:
12
*
13
* wall_clock_ms = boot_epoch_ms + uptime_ms
14
*
15
* `bento.time.sync` (Buddy → firmware)
16
* body: {"cmd":"bento.time.sync","epoch_ms":1747085730000}
17
* effect: stores `epoch_ms - current_uptime_ms` as the
18
* boot epoch so subsequent now() returns are
19
* monotonic relative to the host's clock.
20
* ack: {"ack":"bento.time.sync","ok":true,
21
* "boot_epoch_ms":1747085728766}
22
*
23
* `bento.time.now` (LLM / desktop → firmware)
24
* body: {"cmd":"bento.time.now"}
25
* ack (synced):
26
* {"ack":"bento.time.now","ok":true,"synced":true,
27
* "epoch_ms":1747086000123,
28
* "iso8601":"2026-05-11T20:20:00Z",
29
* "year":2026,"month":5,"day":11,
30
* "hour":20,"minute":20,"second":0,
31
* "uptime_ms":271357}
32
* ack (never synced):
33
* {"ack":"bento.time.now","ok":true,"synced":false,
34
* "epoch_ms":null,"iso8601":null,
35
* "uptime_ms":271357}
36
*
37
* Date formatting uses a self-contained gmtime equivalent
38
* (libc <time.h> is not pulled into this build) so the
39
* firmware can return year / month / day / hour / minute /
40
* second fields directly without the LLM having to compute
41
* them.
42
*
43
******************************************************************************/
44
45
#ifndef BENTO_TIME_H
46
#define BENTO_TIME_H
47
48
#include <stdbool.h>
49
#include <stddef.h>
50
#include <stdint.h>
51
52
#include "vendor/jsmn.h"
53
54
#ifdef __cplusplus
55
extern
"C"
{
56
#endif
57
58
/* Handler for `bento.time.sync`. Parses `epoch_ms` from the JSON body
59
* and stores the implied boot epoch. Emits an ack with the recorded
60
* boot_epoch_ms so the desktop can verify the round trip. */
61
void
bento_time_handle_sync
(
const
char
*json,
const
jsmntok_t
*toks,
int
n_toks);
62
63
/* Handler for `bento.time.now`. Emits the current wall-clock view +
64
* uptime + a `synced` flag. Always responds, even before the desktop
65
* has pushed a sync. */
66
void
bento_time_handle_now
(
const
char
*json,
const
jsmntok_t
*toks,
int
n_toks);
67
68
#ifdef __cplusplus
69
}
70
#endif
71
72
#endif
/* BENTO_TIME_H */
jsmntok_t
struct jsmntok jsmntok_t
Definition
bento_fw.h:37
bento_time_handle_sync
void bento_time_handle_sync(const char *json, const jsmntok_t *toks, int n_toks)
bento_time_handle_now
void bento_time_handle_now(const char *json, const jsmntok_t *toks, int n_toks)
dist
ble_nus
include
bento_time.h
Generated by
1.18.0