SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
Loading...
Searching...
No Matches
nus_folder_push.h
Go to the documentation of this file.
1/*******************************************************************************
2 * File Name: nus_folder_push.h
3 *
4 * Description: Folder-push state machine for the Bento Desktop Buddy
5 * (Bento forked this protocol under its own branding —
6 * see Bento_Buddy/SPEC.md §3.1.1 Not Anthropic-compatible).
7 * Consumes `cmd:char_begin | file | chunk | file_end | char_end`
8 * frames and streams base64-decoded file content into LittleFS
9 * at /buddy/<char_name>/<file_path>.
10 *
11 * Atomic commit: writes to /buddy/.staging/<name>/, then on
12 * successful char_end renames to /buddy/<name>/. Any failure
13 * deletes the staging folder and acks {ok:false}.
14 *
15 * Name and path rules are defined in nus_folder_push.c and are
16 * split into two labelled tiers. Tier 1 (no '/' or '\\', no
17 * leading '.', not empty) is security-critical: it is the only
18 * thing preventing a peer-supplied name from becoming an
19 * arbitrary filesystem path, and it is NOT interchangeable with
20 * the \xHH escaping that prevents Python injection. Tier 2
21 * (control bytes, UTF-8 well-formedness) is hygiene and may be
22 * relaxed. Read the block comment above validate_component()
23 * before changing either.
24 *
25 * THREADING CONTRACT
26 * ------------------
27 * This module is a SINGLE-INSTANCE, NON-REENTRANT state machine.
28 * Every function declared below shares file-scope mutable state:
29 * the current pack name, the current file path, the base64
30 * carry, the byte counters, and the script buffers handed to the
31 * MicroPython bridge.
32 *
33 * Callers MUST serialise all calls, including
34 * nus_fp_device_write_bytes(), which appends to whichever file
35 * handle the last nus_fp_file() opened. Two tasks driving a
36 * folder push concurrently will interleave into one another's
37 * pack — that was true before the script buffers existed
38 * (s_b64 and s_char_name have always been file-scope) and it is
39 * equally true now.
40 *
41 * In this firmware the requirement is met because every call
42 * originates from the single BLE dispatch context. A downstream
43 * consumer driving these entry points from a second task must
44 * provide its own mutex. This contract was previously
45 * undocumented; it is stated here and in dist/ble_nus/api.txt.
46 *
47 ******************************************************************************/
48
49#ifndef NUS_FOLDER_PUSH_H
50#define NUS_FOLDER_PUSH_H
51
52#include <stddef.h>
53#include <stdint.h>
54
55#include "vendor/jsmn.h"
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61/* Per-command entrypoints — called by nus_commands.c dispatcher.
62 * Each emits its own ack back to the desktop. */
63void nus_fp_char_begin(const char *json, const jsmntok_t *toks, int n);
64void nus_fp_file(const char *json, const jsmntok_t *toks, int n);
65void nus_fp_chunk(const char *json, const jsmntok_t *toks, int n);
66void nus_fp_file_end(const char *json, const jsmntok_t *toks, int n);
67void nus_fp_char_end(const char *json, const jsmntok_t *toks, int n);
68
69/* Query state (for debugging / status). */
71
72#ifdef __cplusplus
73}
74#endif
75
76#endif /* NUS_FOLDER_PUSH_H */
struct jsmntok jsmntok_t
Definition bento_fw.h:37
void nus_fp_file_end(const char *json, const jsmntok_t *toks, int n)
verb file_end: เขียนค่าที่ decoder ค้างไว้ลงจริงแล้วปิดไฟล์
void nus_fp_char_end(const char *json, const jsmntok_t *toks, int n)
verb char_end: commit แบบอะตอมิก — เปลี่ยนชื่อ staging เป็น /buddy/<name>/ หรือลบทิ้ง
void nus_fp_char_begin(const char *json, const jsmntok_t *toks, int n)
verb char_begin ของ folder-push: เปิดโฟลเดอร์ staging เรียกจาก dispatcher เท่านั้น
void nus_fp_file(const char *json, const jsmntok_t *toks, int n)
verb file: เริ่มไฟล์ใหม่ในโฟลเดอร์ staging การตรวจพาธปฏิเสธการไต่ไดเรกทอรี
int nus_fp_is_active(void)
คืนค่าที่ไม่ใช่ศูนย์ในช่วงระหว่าง char_begin กับ char_end ใช้เลื่อนงานหนักอื่นออกไประหว่างการโอนข้อมู...
void nus_fp_chunk(const char *json, const jsmntok_t *toks, int n)
verb chunk: สตรีมฟิลด์ base64 "d" ลง LittleFS ผ่าน decoder ที่เก็บสถานะไว้