rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
log_cadence.h
Go to the documentation of this file.
1
39#pragma once
40
41#include <stdbool.h>
42#include <stdint.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
49#define LOG_CADENCE_MODEL_MS 50u
50
57#define LOG_CADENCE_MODEL_MAX_MS 1000u
58
62typedef struct {
63 uint32_t model_ms;
64 uint32_t seen_ms;
65 uint64_t run_ms;
66 uint32_t sent;
67 uint32_t lost;
69
70/*
71 * Which run the log records. A run is one arming of the bench, or one
72 * switch-on of the supply's output while the bench is not armed; the bench
73 * takes the log. An armed run is LOG_RUN_MOTOR when MOTOR & ESC or ESC
74 * STICK armed the bench and LOG_RUN_SERVO when SERVO did; the two write the
75 * same rows to MOTORnnn.CSV and SERVOnnn.CSV, the supply run to
76 * SUPPLnnn.CSV (log_name.h).
77 */
78typedef enum {
79 LOG_RUN_NONE = 0,
80 LOG_RUN_SERVO,
81 LOG_RUN_SUPPLY,
82 LOG_RUN_MOTOR,
83} log_run_kind_t;
84
92static inline bool log_run_armed(log_run_kind_t kind)
93{
94 return kind == LOG_RUN_SERVO || kind == LOG_RUN_MOTOR;
95}
96
115log_run_kind_t log_cadence_wanted(bool auto_logs, bool armed, bool motor,
116 bool supply_on, log_run_kind_t now);
117
124void log_cadence_init(log_cadence_t *c, uint32_t now_ms);
125
143bool log_cadence_model_due(log_cadence_t *c, uint32_t now_ms, bool link_up,
144 float *step_s);
145
152void log_cadence_run_start(log_cadence_t *c, uint32_t now_ms);
153
165bool log_cadence_bench_run(bool bench_kind, bool servo_test);
166
183bool log_cadence_row(log_cadence_t *c, uint32_t now_ms, bool new_sample,
184 bool bench_run, float *t_s);
185
196unsigned log_cadence_rows(unsigned windows);
197
204void log_cadence_posted(log_cadence_t *c, bool taken);
205
212uint32_t log_cadence_sent(const log_cadence_t *c);
213
220uint32_t log_cadence_lost(const log_cadence_t *c);
221
222#ifdef __cplusplus
223}
224#endif
log_run_kind_t log_cadence_wanted(bool auto_logs, bool armed, bool motor, bool supply_on, log_run_kind_t now)
The run the log records now, from the run it records (now) and the bench: LOG_RUN_NONE while auto_log...
Definition log_cadence.c:86
void log_cadence_init(log_cadence_t *c, uint32_t now_ms)
Once, before the loop: both clocks at now_ms, no rows counted.
Definition log_cadence.c:10
void log_cadence_posted(log_cadence_t *c, bool taken)
What the logger's queue did with a row: taken, or refused as full.
Definition log_cadence.c:67
uint32_t log_cadence_lost(const log_cadence_t *c)
The run's rows the queue refused.
Definition log_cadence.c:81
bool log_cadence_model_due(log_cadence_t *c, uint32_t now_ms, bool link_up, float *step_s)
The model's gate, once per pass.
Definition log_cadence.c:16
static bool log_run_armed(log_run_kind_t kind)
Whether kind is a run of the armed bench, whichever screen armed it.
Definition log_cadence.h:92
bool log_cadence_bench_run(bool bench_kind, bool servo_test)
Whether the bench log records in this pass: the log's run is an armed bench's (bench_kind) and no aut...
Definition log_cadence.c:43
uint32_t log_cadence_sent(const log_cadence_t *c)
The run's rows the queue took.
Definition log_cadence.c:76
bool log_cadence_row(log_cadence_t *c, uint32_t now_ms, bool new_sample, bool bench_run, float *t_s)
Whether this pass writes a bench row, once per pass and on every pass, with now_ms never behind the c...
Definition log_cadence.c:48
void log_cadence_run_start(log_cadence_t *c, uint32_t now_ms)
A run starts: its time is 0 at now_ms and its row counts are 0.
Definition log_cadence.c:35
unsigned log_cadence_rows(unsigned windows)
How many rows a pass writes that log_cadence_row() granted: one for each of the windows INA3221 windo...
Definition log_cadence.c:62
The cadence state of the run log: its clocks and row counts.
Definition log_cadence.h:62
uint32_t sent
Definition log_cadence.h:66
uint32_t seen_ms
Definition log_cadence.h:64
uint32_t model_ms
Definition log_cadence.h:63
uint64_t run_ms
Definition log_cadence.h:65
uint32_t lost
Definition log_cadence.h:67