rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
card_tree.h File Reference

The folders of the panel's SD (Secure Digital) card, and the files in them with a fixed name. More...

#include <stddef.h>

Go to the source code of this file.

Macros

#define CARD_ROOT   ""
 The card's root.
#define CARD_BENCH   "BENCH"
 The bench's own folder.
#define CARD_AUTO_LOGS   "BENCH/LOGS"
 The automatic logs: a log of each ARMED run and each supply run; the default of AUTO LOG FOLDER.
#define CARD_USER   "USER"
 The user's folder.
#define CARD_USER_LOGS   "USER/LOGS"
 The files of the tests a user starts: AUTOMATIC TEST and LIMIT RUN; the default of USER LOG FOLDER.
#define CARD_ESC_CONF   "BENCH/ESC/CONF"
 ESC profile overrides, <id>.json.
#define CARD_KST_CONF   "BENCH/KST/CONF"
 KST and Chaservo servo files, their backups and the write record.
#define CARD_HITEC_CONF   "BENCH/HITEC/CONF"
 The Hitec programmer's files.
#define CARD_FAULT_LOG   "BENCH/RCBENCH.LOG"
 The fault log: a line every 5s while the link to the IOmcu is down.
#define CARD_FAULT_OLD   "BENCH/RCBENCH.OLD"
 The fault log as it was when it reached FAULT_LOG_CAP (fault_log.h).
#define CARD_FAULT_TMP   "BENCH/RCBENCH.TMP"
 RCBENCH.OLD moved aside while the full fault log takes its name.
#define CARD_DIR_MAX   24
 Room for a folder path and its terminator: two folders of 8 characters and the "/" between them are 17, and the room is the settings store's string, SETTINGS_TEXT_MAX (24).
#define CARD_FOLDER_NAME_MAX   8
 The longest folder name a log folder takes, and how deep it goes.
#define CARD_FOLDER_DEPTH_MAX   2
 The most folders a log folder path holds.

Typedefs

typedef card_dir_t(*) card_make_fn(void *ctx, const char *level)
 Make the one folder level, a path from the root, whose parent is there.

Enumerations

enum  card_dir_t {
  CARD_DIR_OK = 0 , CARD_DIR_ARG , CARD_DIR_FILE , CARD_DIR_DENIED ,
  CARD_DIR_FAILED
}
 What making a folder came to. More...
enum  card_folder_t {
  CARD_FOLDER_OK = 0 , CARD_FOLDER_ARG , CARD_FOLDER_EMPTY , CARD_FOLDER_LONG ,
  CARD_FOLDER_DEEP , CARD_FOLDER_CHAR , CARD_FOLDER_RESERVED , CARD_FOLDER_BENCH
}
 What card_folder_check() says of a log folder. More...

Functions

card_dir_t card_make_dirs (const char *dir, card_make_fn make, void *ctx)
 Make folder dir one level at a time, the shortest first: for "BENCH/KST/CONF", "BENCH", then "BENCH/KST", then "BENCH/KST/CONF".
card_folder_t card_folder_check (const char *in, char *out, size_t n)
 Whether in names a folder the logs can be written to: 1 or 2 folders separated by "/", each 1 to 8 characters of A-Z, 0-9, "_" and "-", lower case taken as upper case.
const char * card_folder_use (const char *text, const char *fallback, char *out, size_t n)
 The folder a log is written to: text in upper case when card_folder_check() takes it, fallback otherwise.

Detailed Description

The folders of the panel's SD (Secure Digital) card, and the files in them with a fixed name.

Every path the panel spells on the card is here.

/BENCH/ what the bench writes or reads for itself LOGS/ automatic logs: SERVOnnn, MOTORnnn, SUPPLnnn (AUTO LOG FOLDER, the default) ESC/CONF/ ESC (electronic speed controller) profiles KST/CONF/ KST and Chaservo servo files HITEC/CONF/ Hitec servo files RCBENCH.LOG the fault log, at most 1MiB RCBENCH.OLD the fault log before the last 1MiB /USER/ LOGS/ user-started tests: ATESTnnn, LIMITnnn (USER LOG FOLDER, the default) / run logs of firmware 0.21.0 and older

Every folder name is upper case, 1 to 8 characters of A-Z, 0-9, "_" and "-", without an extension: a FAT (File Allocation Table) 8.3 short name, the same on every computer. A path is relative to the card's root, its folders separated by "/", with no "/" at either end; "" is the root.

The two log folders are settings (SETUP > SD CARD): any folder card_folder_check() takes, the defaults CARD_AUTO_LOGS and CARD_USER_LOGS. The other places are fixed.

The panel reads and writes these places only. Folders of firmware 0.21 and older, /ESC and /KST, and its /RCBENCH.LOG are neither read nor moved: their files are moved on a computer. CARD_HITEC_CONF is reserved for the Hitec programmer's files; nothing reads it yet.

A folder is made the first time something is written there, one level at a time (card_make_dirs()).

Pure C, no ESP-IDF (Espressif Internet-of-Things Development Framework).

SPDX-License-Identifier: MIT

Typedef Documentation

◆ card_make_fn

typedef card_dir_t(*) card_make_fn(void *ctx, const char *level)

Make the one folder level, a path from the root, whose parent is there.

A folder that is there already is CARD_DIR_OK.

Parameters
ctxContext the caller passed to card_make_dirs().
levelThe folder path to make, from the card's root.
Returns
The result of making the folder.

Enumeration Type Documentation

◆ card_dir_t

enum card_dir_t

What making a folder came to.

Enumerator
CARD_DIR_OK 

a folder now: made, or there before

CARD_DIR_ARG 

a NULL, or a path longer than CARD_DIR_MAX

CARD_DIR_FILE 

a file holds the name of a level

CARD_DIR_DENIED 

the card takes no folder: write-protected

CARD_DIR_FAILED 

any other failure: a full card, a read error

◆ card_folder_t

What card_folder_check() says of a log folder.

Enumerator
CARD_FOLDER_ARG 

a NULL, or an out shorter than the path

CARD_FOLDER_EMPTY 

"", or a leading, trailing or double "/"

CARD_FOLDER_LONG 

a folder over CARD_FOLDER_NAME_MAX

CARD_FOLDER_DEEP 

more than CARD_FOLDER_DEPTH_MAX folders

CARD_FOLDER_CHAR 

a character outside A-Z, 0-9, "_" and "-"

CARD_FOLDER_RESERVED 

a device name: CON, PRN, AUX, NUL, COM1 to COM9, LPT1 to LPT9

CARD_FOLDER_BENCH 

the bench's own: BENCH/ESC, BENCH/KST, BENCH/HITEC and below

Function Documentation

◆ card_folder_check()

card_folder_t card_folder_check ( const char * in,
char * out,
size_t n )

Whether in names a folder the logs can be written to: 1 or 2 folders separated by "/", each 1 to 8 characters of A-Z, 0-9, "_" and "-", lower case taken as upper case.

A device name is refused in either place, and so is a folder the bench keeps its own files in. Both log folders may be one folder. The first fault from the left is the answer.

On CARD_FOLDER_OK, out (when not NULL) takes the path in upper case; at most 17 characters and the terminator. Otherwise out is left as it was.

Parameters
inThe folder path to check.
outReceives the path in upper case when accepted, or NULL.
nSize of out, bytes.
Returns
CARD_FOLDER_OK, or the first fault found.

◆ card_folder_use()

const char * card_folder_use ( const char * text,
const char * fallback,
char * out,
size_t n )

The folder a log is written to: text in upper case when card_folder_check() takes it, fallback otherwise.

Written into out, CARD_DIR_MAX bytes or more, and returned. A stored folder that no longer passes the check is never written to.

Parameters
textThe stored folder path.
fallbackThe folder to use when text does not pass.
outReceives the chosen folder path.
nSize of out, bytes.
Returns
out, holding the chosen folder path.

◆ card_make_dirs()

card_dir_t card_make_dirs ( const char * dir,
card_make_fn make,
void * ctx )

Make folder dir one level at a time, the shortest first: for "BENCH/KST/CONF", "BENCH", then "BENCH/KST", then "BENCH/KST/CONF".

The first level that is not a folder afterwards ends it, and its answer is the result. CARD_ROOT makes nothing and is CARD_DIR_OK.

Parameters
dirThe folder path, from the card's root.
makeMakes one level.
ctxContext passed to make.
Returns
The result of the last level made, or CARD_DIR_OK for the root.