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

The fault log under its cap. More...

#include "fault_log.h"
#include <string.h>

Functions

static card_dir_t fault_level (void *ctx, const char *dir)
 One level of BENCH, through the caller's make_dir().
static fault_log_t clear_tmp (const fault_log_io_t *io)
 A RCBENCH.TMP still standing: left by a power cut during a rotation, or by a removal the card refused.
static fault_log_t rotate (const fault_log_io_t *io)
 The full file renamed to RCBENCH.OLD, with no TMP standing.
fault_log_t fault_log_note (const fault_log_io_t *io, const char *line, bool *rotated)
 Append line to the fault log, renamed to RCBENCH.OLD first when the line and its line feed would take it past FAULT_LOG_CAP. rotated, when not NULL, says whether that rename happened.

Detailed Description

The fault log under its cap.

See fault_log.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ clear_tmp()

fault_log_t clear_tmp ( const fault_log_io_t * io)
static

A RCBENCH.TMP still standing: left by a power cut during a rotation, or by a removal the card refused.

With an OLD beside it the TMP is the older of the two and goes; without one it is the OLD and takes the name. Until it is gone no line is written, so the card holds at most the OLD and the TMP, 2MiB.

Parameters
ioThe card functions.
Returns
FAULT_LOG_OK when no TMP stands, else the reason it could not go.

◆ fault_level()

card_dir_t fault_level ( void * ctx,
const char * dir )
static

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

A card_make_fn, so its context stays a plain pointer.

Parameters
ctxThe fault_log_io_t the caller passed.
dirThe folder path to make.
Returns
The result of make_dir().

◆ fault_log_note()

fault_log_t fault_log_note ( const fault_log_io_t * io,
const char * line,
bool * rotated )

Append line to the fault log, renamed to RCBENCH.OLD first when the line and its line feed would take it past FAULT_LOG_CAP. rotated, when not NULL, says whether that rename happened.

Parameters
ioThe card functions.
lineThe line to append, without its line feed.
rotatedReceives true when the file was renamed, or NULL.
Returns
FAULT_LOG_OK, or the reason the line was not written.

◆ rotate()

fault_log_t rotate ( const fault_log_io_t * io)
static

The full file renamed to RCBENCH.OLD, with no TMP standing.

FAT renames onto no file, so the old OLD is moved to RCBENCH.TMP first and removed only after the rename has gone through; a rename that fails gives it its name back. A TMP the card does not remove fails the rotation after the fact: the line waits for clear_tmp().

Parameters
ioThe card functions.
Returns
FAULT_LOG_OK when the rotation completed, else the reason it did not.