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

The logger: the runlog task, which makes every card call of a run, a servo test and the fault log. A run is written to AUTO LOG FOLDER, a test to USER LOG FOLDER (SETUP > SD CARD; CARD_AUTO_LOGS and CARD_USER_LOGS by default, card_tree.h), each under its folder's next number (log_take.h). The control task's side, which numbers the runs and posts the rows, is in main.c. More...

#include <errno.h>
#include <stdint.h>
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "card_tree.h"
#include "fault_log.h"
#include "log_name.h"
#include "log_take.h"
#include "log_viewer_screen.h"
#include "log_writer.h"
#include "panel.h"
#include "panel_trial.h"
#include "storage.h"
#include "ui_card_text.h"
#include "ui_text.h"

Data Structures

struct  take_ctx_t
struct  take_walk_t

Macros

#define LOG_TICK_MS   20u
#define LOG_QUIET_MS   1000u
#define NOTE_PATH_MAX   (sizeof(STORAGE_MOUNT_POINT) + CARD_DIR_MAX)

Functions

void log_set_folder (log_folder_t kind, const char *dir)
static void folder_take (log_folder_t kind, char *dir)
void log_open_marks (log_marks_t *marks, char *run_dir, char *test_dir)
static bool take_mounted (void *ctx)
static void take_path (const char *dir, const char *name, char *path, size_t n)
card_dir_t panel_card_make_dir (void *ctx, const char *level)
static bool take_make_dir (void *ctx, const char *dir)
static void take_walk_entry (const storage_entry_t *entry, void *ctx)
static bool take_walk (void *ctx, const char *dir, log_take_visit_fn visit, void *visit_ctx)
static bool take_exists (void *ctx, const char *dir, const char *name)
static bool take_create (void *ctx, const char *dir, const char *name, int number)
static log_take_t take (const char *dir, log_prefix_t prefix, bool report, FILE **fp, atomic_uint *mark, int tab, int *number)
static void take_alert (log_take_t r, const char *dir, const char *other)
static int file_write (void *ctx, const void *data, size_t len)
static bool file_flush (void *ctx)
static log_prefix_t run_prefix (log_run_kind_t kind)
static void log_open (uint32_t run, log_run_kind_t kind)
static void log_close (void)
static void log_drop (void)
static void test_path (log_prefix_t prefix, int number, bool txt, char *path, size_t n)
 Run number's file in the test folder as a path on the card: ATESTnnn.CSV, ATESTnnn.TXT or LIMITnnn.TXT.
static void test_close (void)
 Close the open test file, if any, and say so on the console with the lines it holds: "closed" when every write and the close went through, "closed short" otherwise.
static void test_open (bool txt)
 A run's OPEN: the folder's next number, as log_open() takes one.
static void test_write (const test_line_t *l)
 One line from the render loop: an OPEN, an END, or a line of the open run's CSV or report.
bool log_fault_busy (void)
 Whether the logger may write a fault log line now: one queued in s_note_q, or under way. The file manager's bench reads it (fm_bench_t.fault_busy).
void log_fault_lock (void)
 Take the fault log's lock, which the logger holds across each line's open, write and close. The file manager holds it across an unlink and a rename: FatFs runs without its file lock (CONFIG_FATFS_FS_LOCK 0) and removes a file open for append. Neither holder takes another lock under it.
void log_fault_unlock (void)
 Give the fault log's lock back.
static bool note_mounted (void *ctx)
static int32_t note_size (void *ctx, const char *path)
static bool note_remove (void *ctx, const char *path)
static bool note_rename (void *ctx, const char *from, const char *to)
static bool note_append (void *ctx, const char *path, const char *line)
static void log_note (const char *line)
void log_task (void *arg)
 Everything that touches the card.

Variables

static const char * TAG = "rcbench"
QueueHandle_t s_log_q
QueueHandle_t s_note_q
SemaphoreHandle_t s_note_mx
 The fault log's lock (log_fault_lock()).
atomic_uint s_log_run_now
static FILE * s_log_file
static uint32_t s_log_run_id
static log_series_set_t s_series
static unsigned s_series_mount
static portMUX_TYPE s_dir_mux = portMUX_INITIALIZER_UNLOCKED
static char s_dir_want [LOG_FOLDERS][CARD_DIR_MAX]
static char s_dir_open [LOG_FOLDERS][CARD_DIR_MAX]
static char s_dir_took [LOG_FOLDERS][CARD_DIR_MAX]
atomic_uint s_card_written
atomic_int s_card_written_tab = LOG_TAB_BENCH
static log_writer_t s_log
static uint32_t s_log_last_row_ms
QueueHandle_t s_test_q
atomic_uint s_test_opens_sent
atomic_uint s_test_opens_done
unsigned s_test_ends_sent
atomic_uint s_test_ends_done
atomic_int s_test_file
atomic_bool s_test_report
static FILE * s_test_fp
static int s_test_num
static bool s_test_txt
static unsigned s_test_lines
static bool s_test_failed
static bool s_test_txt_bad
static char s_test_dir [CARD_DIR_MAX]
static char s_test_path [64]
 The open test file's path, for the console lines.
static unsigned s_test_count
 The lines written to the open test file.
static bool s_test_file_bad
 A write to the open test file failed.
static bool s_note_held
static atomic_bool s_note_writing
 Set from before the logger takes a queued line until the last one is written (log_fault_busy()).

Detailed Description

The logger: the runlog task, which makes every card call of a run, a servo test and the fault log. A run is written to AUTO LOG FOLDER, a test to USER LOG FOLDER (SETUP > SD CARD; CARD_AUTO_LOGS and CARD_USER_LOGS by default, card_tree.h), each under its folder's next number (log_take.h). The control task's side, which numbers the runs and posts the rows, is in main.c.

SPDX-License-Identifier: MIT

Function Documentation

◆ log_fault_busy()

bool log_fault_busy ( void )

Whether the logger may write a fault log line now: one queued in s_note_q, or under way. The file manager's bench reads it (fm_bench_t.fault_busy).

Returns
true while a line waits or is written

◆ log_task()

void log_task ( void * arg)

Everything that touches the card.

On the control task's core and below it in priority: the control task blocks for CONTROL_PERIOD_MS (5ms) every pass and inside every receive window of a link exchange, and this runs in those gaps. It touches no PSRAM, so it does not share bandwidth with the display's scan-out.

Parameters
argUnused.

◆ test_open()

void test_open ( bool txt)
static

A run's OPEN: the folder's next number, as log_open() takes one.

The file's path goes to the console as take_create() opens it, "logging to ..."; a take that opens no file logs why.

Parameters
txttrue for a report alone (SERVO_TEST_OUT_OPEN_TXT, the limit run): its LIMITnnn.TXT is opened under the number, and no CSV. false for the AUTOMATIC TEST's ATESTnnn.CSV.

◆ test_path()

void test_path ( log_prefix_t prefix,
int number,
bool txt,
char * path,
size_t n )
static

Run number's file in the test folder as a path on the card: ATESTnnn.CSV, ATESTnnn.TXT or LIMITnnn.TXT.

Parameters
prefixLOG_PREFIX_ATEST or LOG_PREFIX_LIMIT.
numberThe run's number.
txttrue for the .TXT report, false for the CSV.
pathReceives the path.
nSize of path, bytes.

◆ test_write()

void test_write ( const test_line_t * l)
static

One line from the render loop: an OPEN, an END, or a line of the open run's CSV or report.

The report's ATESTnnn.TXT opens at its first line, after the CSV closes, and its path goes to the console as it opens.

Parameters
lThe line.

Variable Documentation

◆ s_dir_open

char s_dir_open[LOG_FOLDERS][CARD_DIR_MAX]
static
Initial value:
#define CARD_USER_LOGS
The files of the tests a user starts: AUTOMATIC TEST and LIMIT RUN; the default of USER LOG FOLDER.
Definition card_tree.h:76
#define CARD_AUTO_LOGS
The automatic logs: a log of each ARMED run and each supply run; the default of AUTO LOG FOLDER.
Definition card_tree.h:65

◆ s_dir_took

char s_dir_took[LOG_FOLDERS][CARD_DIR_MAX]
static
Initial value:

◆ s_dir_want

char s_dir_want[LOG_FOLDERS][CARD_DIR_MAX]
static
Initial value:

◆ s_log_q

QueueHandle_t s_log_q

control task -> logger, one row each

◆ s_note_q

QueueHandle_t s_note_q

control task -> logger, one line each

◆ s_test_q

QueueHandle_t s_test_q

render loop -> logger