SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (ModusToolbox)
Toggle main menu visibility
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
58
extern
"C"
{
59
#endif
60
61
/* Per-command entrypoints — called by nus_commands.c dispatcher.
62
* Each emits its own ack back to the desktop. */
63
void
nus_fp_char_begin
(
const
char
*json,
const
jsmntok_t
*toks,
int
n);
64
void
nus_fp_file
(
const
char
*json,
const
jsmntok_t
*toks,
int
n);
65
void
nus_fp_chunk
(
const
char
*json,
const
jsmntok_t
*toks,
int
n);
66
void
nus_fp_file_end
(
const
char
*json,
const
jsmntok_t
*toks,
int
n);
67
void
nus_fp_char_end
(
const
char
*json,
const
jsmntok_t
*toks,
int
n);
68
69
/* Query state (for debugging / status). */
70
int
nus_fp_is_active
(
void
);
71
72
#ifdef __cplusplus
73
}
74
#endif
75
76
#endif
/* NUS_FOLDER_PUSH_H */
jsmntok_t
struct jsmntok jsmntok_t
Definition
bento_fw.h:37
nus_fp_file_end
void nus_fp_file_end(const char *json, const jsmntok_t *toks, int n)
verb file_end: เขียนค่าที่ decoder ค้างไว้ลงจริงแล้วปิดไฟล์
nus_fp_char_end
void nus_fp_char_end(const char *json, const jsmntok_t *toks, int n)
verb char_end: commit แบบอะตอมิก — เปลี่ยนชื่อ staging เป็น /buddy/<name>/ หรือลบทิ้ง
nus_fp_char_begin
void nus_fp_char_begin(const char *json, const jsmntok_t *toks, int n)
verb char_begin ของ folder-push: เปิดโฟลเดอร์ staging เรียกจาก dispatcher เท่านั้น
nus_fp_file
void nus_fp_file(const char *json, const jsmntok_t *toks, int n)
verb file: เริ่มไฟล์ใหม่ในโฟลเดอร์ staging การตรวจพาธปฏิเสธการไต่ไดเรกทอรี
nus_fp_is_active
int nus_fp_is_active(void)
คืนค่าที่ไม่ใช่ศูนย์ในช่วงระหว่าง char_begin กับ char_end ใช้เลื่อนงานหนักอื่นออกไประหว่างการโอนข้อมู...
nus_fp_chunk
void nus_fp_chunk(const char *json, const jsmntok_t *toks, int n)
verb chunk: สตรีมฟิลด์ base64 "d" ลง LittleFS ผ่าน decoder ที่เก็บสถานะไว้
dist
ble_nus
include
nus_folder_push.h
Generated by
1.18.0