|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
Run log names, and the order a bounded listing keeps them in. More...
#include "log_name.h"#include <ctype.h>#include <stdbool.h>#include <stdio.h>#include <string.h>Functions | |
| static bool | prefix_matches (const char *name, const char *pat, size_t pat_len) |
Does name open with pat, case folded? name holds at least pat_len characters; the caller checks its length first. | |
| int | log_name_case_cmp (const char *a, const char *b) |
Compare two names with case folded: negative when a sorts first, as the browse list orders what it draws. | |
| void | log_name_build (char *out, size_t out_size, log_prefix_t prefix, int number, bool report) |
Write the name of run number by writer prefix: "ATEST001.CSV", or with report its report "ATEST001.TXT". | |
| log_prefix_t | log_name_armed_prefix (bool asked, bool asked_throttle, bool throttle_armed) |
| The writer of an ARMED run's log, by the screen that armed the bench. | |
| void | log_run_name (char *out, size_t out_size, int number) |
| log_name_build() for LOG_PREFIX_BENCH: "BENCH001.CSV" to "BENCH999.CSV", the name firmware 0.21.0 and older gave a run in the root. | |
| void | log_report_name (char *out, size_t out_size, int number) |
| A run's report beside its log: "ATEST001.TXT", and "SERVO001.TXT" or "BENCH001.TXT" in the root of a card written by firmware 0.21.0 or older. log_report_number() reads any prefix, with the same rules for the number and the case as log_run_number(); log_report_name() is log_name_build() for LOG_PREFIX_BENCH with the report suffix. | |
| static int | numbered (const char *name, const char *suffix, int *prefix) |
The number in name under suffix, any prefix, or -1; prefix, when not NULL, takes the prefix's index. | |
| int | log_run_number (const char *name) |
The run number in name, or -1 when the name is not a run log under any of the 7 prefixes. | |
| int | log_report_number (const char *name) |
| Run number of a report name. | |
| int | log_name_number (const char *name) |
The number name takes from its folder's series: a run log's or a report's, under any of the 7 prefixes, or -1 for a name that takes none. | |
| int | log_name_parse (const char *name, log_prefix_t *prefix, bool *report) |
| The writer, the kind and the number of a run log's or a report's name: "LIMIT004.TXT" is LOG_PREFIX_LIMIT, a report, 4. | |
| void | log_name_form (char *out, size_t out_size, int number, int form) |
Write the form'th of the LOG_NAME_FORMS names number number can be carried by, 0 to LOG_NAME_FORMS - 1: form / 2 is the written prefix and form % 2 the report. | |
| int | log_name_next (int highest) |
The first number a run may take on a card whose highest number, by log_name_number(), is highest (below LOG_RUN_FIRST for a card that holds none): one above it. | |
| void | log_name_report_of (char *out, size_t out_size, const char *run_name) |
Write the report that goes with run log run_name: the same prefix and number, ".TXT", in upper case. | |
| bool | log_name_busy (const char *name, unsigned open_run, unsigned open_test, unsigned open_txt) |
Whether name is a file the logger is still writing, or one whose deletion would remove such a file: a run log whose number is open_run (the armed or supply run), open_test (an AUTOMATIC TEST's CSV) or open_txt (a test's or a limit run's report, which a deleted run takes with it), or a report whose number is open_txt. 0 is no file open. | |
| int | log_name_rank (const char *a, const char *b) |
| Order two listed names by which one a full list keeps. | |
Variables | |
| static const char *const | k_prefix [LOG_PREFIX_COUNT] |
| The writers' prefixes, in log_prefix_t order. | |
Run log names, and the order a bounded listing keeps them in.
SPDX-License-Identifier: MIT
| log_prefix_t log_name_armed_prefix | ( | bool | asked, |
| bool | asked_throttle, | ||
| bool | throttle_armed ) |
The writer of an ARMED run's log, by the screen that armed the bench.
asked: the arm recorded the roles it asked for (arming_roles() is not 0). asked_throttle: those roles hold the throttle, as MOTOR & ESC and ESC STICK ask for; SERVO asks for the surfaces alone. An arm that asked is LOG_PREFIX_MOTOR or LOG_PREFIX_SERVO by asked_throttle, whatever an IOmcu older than protocol 4.18 armed beside them. An arm with nothing recorded is LOG_PREFIX_MOTOR while throttle_armed and LOG_PREFIX_SERVO otherwise. A supply run is LOG_PREFIX_SUPPL.
| asked | The arm recorded the roles it asked for. |
| asked_throttle | Those roles hold the throttle. |
| throttle_armed | The throttle outputs are armed. |
| void log_name_build | ( | char * | out, |
| size_t | out_size, | ||
| log_prefix_t | prefix, | ||
| int | number, | ||
| bool | report ) |
Write the name of run number by writer prefix: "ATEST001.CSV", or with report its report "ATEST001.TXT".
A number outside LOG_RUN_FIRST to LOG_RUN_LAST, a prefix outside the table, or an out_size under LOG_RUN_NAME_MAX, writes an empty string rather than a name that would name a different file.
| out | Receives the name. |
| out_size | Size of out, bytes. |
| prefix | The writer. |
| number | The run number. |
| report | true for the ".TXT" report, false for the ".CSV" log. |
| bool log_name_busy | ( | const char * | name, |
| unsigned | open_run, | ||
| unsigned | open_test, | ||
| unsigned | open_txt ) |
Whether name is a file the logger is still writing, or one whose deletion would remove such a file: a run log whose number is open_run (the armed or supply run), open_test (an AUTOMATIC TEST's CSV) or open_txt (a test's or a limit run's report, which a deleted run takes with it), or a report whose number is open_txt. 0 is no file open.
The numbers are one series in a folder, so the prefix does not enter into it; the caller passes 0 for a file open in another folder (log_marks_busy() in log_take.h).
| name | The file name. |
| open_run | Number of the open armed or supply run, or 0. |
| open_test | Number of the open AUTOMATIC TEST CSV, or 0. |
| open_txt | Number of the open report, or 0. |
| int log_name_case_cmp | ( | const char * | a, |
| const char * | b ) |
Compare two names with case folded: negative when a sorts first, as the browse list orders what it draws.
A card written on a computer holds "bench042.csv" and one written here holds "BENCH042.CSV", and the two are one file.
| a | The first name. |
| b | The second name. |
a sorts before, with or after b. | void log_name_form | ( | char * | out, |
| size_t | out_size, | ||
| int | number, | ||
| int | form ) |
Write the form'th of the LOG_NAME_FORMS names number number can be carried by, 0 to LOG_NAME_FORMS - 1: form / 2 is the written prefix and form % 2 the report.
An empty string for a form or a number outside them. The logger probes each before it takes a number.
| out | Receives the name. |
| out_size | Size of out, bytes. |
| number | The run number. |
| form | Index of the name, 0 to LOG_NAME_FORMS - 1. |
| int log_name_next | ( | int | highest | ) |
The first number a run may take on a card whose highest number, by log_name_number(), is highest (below LOG_RUN_FIRST for a card that holds none): one above it.
Above LOG_RUN_LAST when the card holds 999: the card is full, and a lower free number is not taken.
| highest | The highest number the card holds. |
| int log_name_number | ( | const char * | name | ) |
The number name takes from its folder's series: a run log's or a report's, under any of the 7 prefixes, or -1 for a name that takes none.
What the numbering walk reads.
| name | The file name. |
| int log_name_parse | ( | const char * | name, |
| log_prefix_t * | prefix, | ||
| bool * | report ) |
The writer, the kind and the number of a run log's or a report's name: "LIMIT004.TXT" is LOG_PREFIX_LIMIT, a report, 4.
The same rules for the number and the case as log_run_number().
| name | The name to read. |
| prefix | Takes the writer's prefix; may be NULL. |
| report | Takes true for a ".TXT" report, false for a ".CSV" log; may be NULL. |
prefix and report are left as they were. | int log_name_rank | ( | const char * | a, |
| const char * | b ) |
Order two listed names by which one a full list keeps.
Negative when a is kept ahead of b, positive when b is. Runs come first, by number, the newest first, whichever writer made them: MOTOR043.CSV ranks ahead of SERVO042.CSV. A report ranks by its number as a run does (log_name_number()), so LIMIT044.TXT, a limit run's only file, ranks ahead of MOTOR043.CSV. An operator opening a log is almost always after a recent one, and a run is the only entry whose age is known. Everything else follows the runs by name, case folded.
The order is strict: zero only for one name, compared with case folded (log_name_case_cmp()). Two names with one number, a run and its report or, on a card edited on a computer, two runs under different prefixes, follow by name: ATEST042.CSV, then ATEST042.TXT, then MOTOR042.CSV. Paging needs that (log_select.h): a name that ranked equal to a page's edge would be on neither side of it.
A card holding as many runs as a page has room for therefore leaves no room on the first page for a file the bench did not write; the browse panel says how many entries the card holds.
| a | A name; NULL ranks as "". |
| b | A name; NULL ranks as "". |
a ranks ahead, positive when b does, 0 for one name. | void log_name_report_of | ( | char * | out, |
| size_t | out_size, | ||
| const char * | run_name ) |
Write the report that goes with run log run_name: the same prefix and number, ".TXT", in upper case.
An empty string when run_name is not a run log. Deleting a run deletes this file with it.
| out | Receives the name. |
| out_size | Size of out, bytes. |
| run_name | The run log's file name. |
| void log_report_name | ( | char * | out, |
| size_t | out_size, | ||
| int | number ) |
A run's report beside its log: "ATEST001.TXT", and "SERVO001.TXT" or "BENCH001.TXT" in the root of a card written by firmware 0.21.0 or older. log_report_number() reads any prefix, with the same rules for the number and the case as log_run_number(); log_report_name() is log_name_build() for LOG_PREFIX_BENCH with the report suffix.
A number belongs to a run while either file carries it: the logger takes one above both, so a report whose CSV was deleted is never overwritten by the next run's.
| out | Receives the name. |
| out_size | Size of out, bytes. |
| number | The run number. |
| int log_report_number | ( | const char * | name | ) |
Run number of a report name.
| name | The file name. |
| void log_run_name | ( | char * | out, |
| size_t | out_size, | ||
| int | number ) |
log_name_build() for LOG_PREFIX_BENCH: "BENCH001.CSV" to "BENCH999.CSV", the name firmware 0.21.0 and older gave a run in the root.
| out | Receives the name. |
| out_size | Size of out, bytes. |
| number | The run number. |
| int log_run_number | ( | const char * | name | ) |
The run number in name, or -1 when the name is not a run log under any of the 7 prefixes.
Case is ignored, so a card taken to a computer and written back in lower case still lists in run order. The name has to be one of the prefixes, exactly three digits in range, and the suffix, with nothing after it: "BENCH12.CSV", "BENCH000.CSV", "SERVO001.CSV.BAK" and "ESCAPE01.CSV" are not run logs.
| name | The file name. |
|
static |
The number in name under suffix, any prefix, or -1; prefix, when not NULL, takes the prefix's index.
| name | The file name. |
| suffix | The suffix the name must end with. |
| prefix | Receives the index of the prefix, or NULL. |
|
static |
Does name open with pat, case folded? name holds at least pat_len characters; the caller checks its length first.
Case folded, because the same rule has to hold for a card taken to a computer and written back as bench042.csv.
| name | The file name. |
| pat | The prefix. |
| pat_len | Length of pat, characters. |
pat_len characters match.
|
static |
The writers' prefixes, in log_prefix_t order.