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

The fault log, BENCH/RCBENCH.LOG: one line every 5s while the link to the IOmcu is down, written whatever SETUP > SD CARD says. More...

#include <stdbool.h>
#include <stdint.h>
#include "card_tree.h"

Go to the source code of this file.

Data Structures

struct  fault_log_io_t
 The card. More...

Macros

#define FAULT_SIZE_NONE   (-1)
 size()'s answers that are no size.
#define FAULT_SIZE_UNREAD   (-2)
 size() answer: the size does not read, or a folder has the name.
#define FAULT_LOG_CAP   1048576u
 The most bytes BENCH/RCBENCH.LOG holds.

Enumerations

enum  fault_log_t {
  FAULT_LOG_OK = 0 , FAULT_LOG_ARG , FAULT_LOG_NO_CARD , FAULT_LOG_NO_FOLDER ,
  FAULT_LOG_NO_ROOM , FAULT_LOG_UNREAD , FAULT_LOG_WRITE
}
 What a line came to. More...

Functions

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, BENCH/RCBENCH.LOG: one line every 5s while the link to the IOmcu is down, written whatever SETUP > SD CARD says.

The file is held to FAULT_LOG_CAP, 1MiB (1,048,576 bytes). A line that would take it past the cap first renames it to BENCH/RCBENCH.OLD, replacing the old one, and starts a new BENCH/RCBENCH.LOG with that line. The card holds at most 2MiB of fault log; at 208 bytes a line every 5s, one file is about 7 hours of link loss.

A file that ends at the cap exactly is kept: the cap is the most bytes the file holds. A line that does not fit an empty file is refused. When the rename fails the line is not written, so the file never passes the cap, and a file whose size does not read takes no line either.

The old RCBENCH.OLD gives way only once the full file has its name. It is first renamed to BENCH/RCBENCH.TMP; a rename of the full file that fails gives it its name back. A TMP that stands at a line, left by a power cut or by a removal the card refused, is RCBENCH.OLD again when no OLD stands and is removed when one does; until it is gone no line is written.

Each line is appended on its own, opened and closed around it, so a line is on the card before the next fault can happen. BENCH is made the first time (card_make_dirs()).

The card is reached through fault_log_io_t, functions the caller supplies, so the rules run on a host without a card. Pure C, no ESP-IDF (Espressif Internet-of-Things Development Framework).

SPDX-License-Identifier: MIT

Enumeration Type Documentation

◆ fault_log_t

What a line came to.

Enumerator
FAULT_LOG_ARG 

a NULL, or a line longer than the cap

FAULT_LOG_NO_CARD 

no card is mounted

FAULT_LOG_NO_FOLDER 

BENCH cannot be made

FAULT_LOG_NO_ROOM 

the full file could not be renamed, or the old one not moved aside

FAULT_LOG_UNREAD 

the size of a file does not read

FAULT_LOG_WRITE 

the append failed

Function Documentation

◆ 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.