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

Taking a run's number in a folder of the card. More...

#include "log_take.h"
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>

Functions

void log_series_init (log_series_set_t *set)
 Every folder's numbering forgotten: the next take walks its folder.
void log_series_forget_all (void)
 Every set forgets every folder's numbering before its next take: the card's files were changed by another hand than the logger's (FILES' copy, move, rename, new entry or delete), so a folder may hold a higher number than a set handed out last.
static bool same_dir (const char *a, const char *b)
 Whether a and b name one folder: FAT compares without case.
bool log_series_follow (log_series_set_t *set, char *took, const char *want)
 One kind of file follows its folder setting: want is the folder of its next take, and took (CARD_DIR_MAX bytes) the folder of the last one.
log_series_t * log_series_of (log_series_set_t *set, const char *dir)
 The numbering of folder dir, case folded: its slot, or a free one, or the slot set gives up next, cleared.
static void take_highest (const char *name, void *ctx)
 The highest number a walk sees, under any prefix, a folder's name too: a folder called MOTOR003.CSV takes that number as a file does, because no file of that name can be created beside it.
static card_dir_t take_level (void *ctx, const char *level)
 One level of the folder, through the caller's make_dir().
static bool number_free (const log_take_io_t *io, const char *dir, int n)
 None of number n's LOG_NAME_FORMS names is in dir.
log_take_t log_take (log_series_set_t *set, const log_take_io_t *io, const char *dir, log_prefix_t prefix, bool report, int *number)
 Make folder dir, take the next free number of its series and create the run's file under prefix: the CSV, or with report the TXT. number takes the number on LOG_TAKE_OK and -1 otherwise.
bool log_marks_busy (const log_marks_t *marks, const char *dir, const char *name)
 Whether name in folder dir is a file the logger is still writing, or one whose deletion would remove such a file (log_name_busy()), by the marks of that folder alone: an open USER/LOGS/ATEST005.CSV does not hold back BENCH/LOGS/SERVO005.CSV.

Variables

static atomic_uint s_edits
 log_series_forget_all()'s count: written by any task, read by the one that takes.

Detailed Description

Taking a run's number in a folder of the card.

SPDX-License-Identifier: MIT

Function Documentation

◆ log_marks_busy()

bool log_marks_busy ( const log_marks_t * marks,
const char * dir,
const char * name )

Whether name in folder dir is a file the logger is still writing, or one whose deletion would remove such a file (log_name_busy()), by the marks of that folder alone: an open USER/LOGS/ATEST005.CSV does not hold back BENCH/LOGS/SERVO005.CSV.

Folders compare with case folded. With both kinds in one folder, both kinds' marks apply.

Parameters
marksThe open files.
dirThe folder of the file.
nameThe file name.
Returns
true when the file is busy.

◆ log_series_follow()

bool log_series_follow ( log_series_set_t * set,
char * took,
const char * want )

One kind of file follows its folder setting: want is the folder of its next take, and took (CARD_DIR_MAX bytes) the folder of the last one.

A folder other than took, case folded, is copied into it and forgets every folder's numbering in set, so the next take of each kind walks its folder and numbers from what that folder holds. A file already open stays in the folder it was opened in. True when the folder changed; false for the same folder, a NULL or a want that does not fit.

Parameters
setThe numbering set.
tookThe folder of the last take, CARD_DIR_MAX bytes.
wantThe folder of the next take.
Returns
true when the folder changed.

◆ log_series_forget_all()

void log_series_forget_all ( void )

Every set forgets every folder's numbering before its next take: the card's files were changed by another hand than the logger's (FILES' copy, move, rename, new entry or delete), so a folder may hold a higher number than a set handed out last.

A count, safe to call from any task: log_take() compares it with the set's own and walks the folder when it moved.

◆ log_series_init()

void log_series_init ( log_series_set_t * set)

Every folder's numbering forgotten: the next take walks its folder.

Parameters
setThe numbering set.

◆ log_series_of()

log_series_t * log_series_of ( log_series_set_t * set,
const char * dir )

The numbering of folder dir, case folded: its slot, or a free one, or the slot set gives up next, cleared.

Two kinds of run in one folder share one series. NULL for a NULL argument or a dir that does not fit CARD_DIR_MAX.

Parameters
setThe numbering set.
dirThe folder path.
Returns
The slot of the folder, or NULL.

◆ log_take()

log_take_t log_take ( log_series_set_t * set,
const log_take_io_t * io,
const char * dir,
log_prefix_t prefix,
bool report,
int * number )

Make folder dir, take the next free number of its series and create the run's file under prefix: the CSV, or with report the TXT. number takes the number on LOG_TAKE_OK and -1 otherwise.

prefix is one this firmware writes (below LOG_PREFIX_WRITTEN).

Parameters
setThe numbering set.
ioThe card functions.
dirThe folder, from the root.
prefixThe file prefix.
reporttrue for the TXT report, false for the CSV.
numberReceives the run number on LOG_TAKE_OK, else -1.
Returns
LOG_TAKE_OK, or the reason no number was taken.

◆ number_free()

bool number_free ( const log_take_io_t * io,
const char * dir,
int n )
static

None of number n's LOG_NAME_FORMS names is in dir.

Parameters
ioThe card functions.
dirThe folder path.
nThe run number.
Returns
true when no name of the number exists in the folder.

◆ same_dir()

bool same_dir ( const char * a,
const char * b )
static

Whether a and b name one folder: FAT compares without case.

Parameters
aThe first path; NULL counts as "".
bThe second path; NULL counts as "".
Returns
true when the paths are equal without regard to case.

◆ take_highest()

void take_highest ( const char * name,
void * ctx )
static

The highest number a walk sees, under any prefix, a folder's name too: a folder called MOTOR003.CSV takes that number as a file does, because no file of that name can be created beside it.

Parameters
nameAn entry name.
ctxPointer to the highest number so far, an int.

◆ take_level()

card_dir_t take_level ( void * ctx,
const char * level )
static

One level of the folder, through the caller's make_dir().

A card_make_fn, so its context stays a plain pointer.

Parameters
ctxThe log_take_io_t the caller passed.
levelThe folder path to make.
Returns
CARD_DIR_OK when the folder is there, else CARD_DIR_FAILED.