rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
log_writer.h
Go to the documentation of this file.
1
16#pragma once
17
18#include <stdbool.h>
19#include <stddef.h>
20#include <stdint.h>
21
22#include "bench_state.h"
23#include "log_cols.h"
24#include "sense_link.h"
25#include "supply.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
34typedef struct {
36 int (*write)(void *ctx, const void *data, size_t len);
45 bool (*flush)(void *ctx);
46 void *ctx;
48
50#define LOG_WRITER_LINE_MAX 256
51
55typedef struct {
56 log_sink_t sink;
57 uint32_t rows;
58 uint32_t pending;
59 float last_s;
62 bool failed;
67 bool by_map;
68 log_cols_t cols;
75
76/*
77 * What a power cut costs.
78 *
79 * The writer commits every LOG_WRITER_FLUSH_ROWS rows, and again once
80 * LOG_WRITER_FLUSH_S have passed on the run's own clock, whichever comes
81 * first. At the panel's 20Hz sample rate the two are the same point: 20
82 * rows is 1000ms of run.
83 *
84 * A run interrupted at any moment therefore loses at most 20 rows, spanning
85 * less than 1.0s of its own clock. Twenty and not nineteen: the count
86 * reaches LOG_WRITER_FLUSH_ROWS before the commit is attempted and is
87 * cleared only once the commit has succeeded, so those twenty rows are not
88 * durable for as long as the sink takes. The price is one commit per second per
89 * run.
90 */
91#define LOG_WRITER_FLUSH_ROWS 20u
92#define LOG_WRITER_FLUSH_S 1.0f
93
102#define LOG_WRITER_SEP ';'
103
113#define LOG_WRITER_SRC_MEASURED "measured"
114#define LOG_WRITER_SRC_MODEL "model"
115
122void log_writer_init(log_writer_t *w, const log_sink_t *sink);
123
135void log_writer_set_cols(log_writer_t *w, const log_cols_t *cols);
136
147
174bool log_writer_row(log_writer_t *w, float t_s, const bench_state_t *b);
175
188typedef struct {
189 float v;
190 float i;
191 float p;
193 float energy_wh;
194 uint8_t ok;
195 uint8_t counted;
196 bool withheld;
197} log_rail_t;
198
214void log_rail_take(log_rail_t *out, const supply_state_t *s,
215 bool row_modelled);
216
234void log_rail_count(bench_totals_t *t, log_rail_t *r, float dt_s,
235 bool driving);
236
251void log_rail_take_ina(log_rail_t *out, const sense_link_win_t *win,
252 bool row_modelled);
253
257typedef struct {
258 float angle_deg;
259 uint16_t pulse_us;
260 bool pulse_ok;
261 bool angle_ok;
263
278uint32_t log_servo_pack(bool pulse_ok, uint16_t pulse_us, bool angle_ok,
279 float angle_deg);
280
289void log_servo_unpack(uint32_t packed, bool row_modelled, log_servo_t *out);
290
314bool log_writer_servo_row(log_writer_t *w, float t_s, const bench_state_t *b,
315 const log_rail_t *rail, const log_servo_t *sv);
316
334bool log_writer_supply_row(log_writer_t *w, float t_s,
335 const supply_state_t *s);
336
353
360static inline uint32_t log_writer_pending(const log_writer_t *w)
361{
362 return (w == NULL) ? 0u : w->pending;
363}
364
372static inline bool log_writer_failed(const log_writer_t *w)
373{
374 return w == NULL || w->failed;
375}
376
377#ifdef __cplusplus
378}
379#endif
The bench readings, in the units a person reads: V, A, W, rpm (revolutions per minute),...
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
The bench log's INA3221 columns with SENSE_MAP in force (protocol 4.25): one group of three per chann...
void log_writer_init(log_writer_t *w, const log_sink_t *sink)
Sets up a writer on a sink.
Definition log_writer.c:87
bool log_writer_supply_row(log_writer_t *w, float t_s, const supply_state_t *s)
Append one supply sample, for a run that is the supply's output being on.
Definition log_writer.c:316
bool log_writer_servo_row(log_writer_t *w, float t_s, const bench_state_t *b, const log_rail_t *rail, const log_servo_t *sv)
Append one sample of a run ARMED from SERVO: log_writer_row()'s row with voltage, current,...
Definition log_writer.c:575
#define LOG_WRITER_LINE_MAX
The longest bench row, terminator included.
Definition log_writer.h:50
bool log_writer_commit(log_writer_t *w)
Commit the rows written since the last commit.
Definition log_writer.c:130
void log_rail_count(bench_totals_t *t, log_rail_t *r, float dt_s, bool driving)
Count r's readings into the run's totals t over dt_s, and put the totals on r.
Definition log_writer.c:655
void log_rail_take_ina(log_rail_t *out, const sense_link_win_t *win, bool row_modelled)
The servo rail's INA3221 window for a SERVO run's row, into out, with nothing counted: while an INA32...
Definition log_writer.c:581
bool log_writer_header(log_writer_t *w)
Write the header row.
Definition log_writer.c:204
void log_servo_unpack(uint32_t packed, bool row_modelled, log_servo_t *out)
log_servo_pack()'s word back into out, for a row: no angle on a modelled row, whose figures the encod...
Definition log_writer.c:619
static uint32_t log_writer_pending(const log_writer_t *w)
Rows written and not yet committed: what a power cut would cost now.
Definition log_writer.h:360
bool log_writer_row(log_writer_t *w, float t_s, const bench_state_t *b)
Append one sample at t_s seconds, and commit when the row completes an interval.
Definition log_writer.c:570
uint32_t log_servo_pack(bool pulse_ok, uint16_t pulse_us, bool angle_ok, float angle_deg)
The pulse and the angle in one 32-bit word, for the render side to hand the control task in one atomi...
Definition log_writer.c:605
static bool log_writer_failed(const log_writer_t *w)
True once any write has failed: the file is incomplete, not merely short.
Definition log_writer.h:372
void log_rail_take(log_rail_t *out, const supply_state_t *s, bool row_modelled)
The supply's reading for a SERVO run's row, into out, with nothing counted.
Definition log_writer.c:635
void log_writer_set_cols(log_writer_t *w, const log_cols_t *cols)
The INA3221 columns of this file, before its header: with SENSE_MAP in force a group per watched targ...
Definition log_writer.c:138
The bench readings in the units a person reads: V, A, W and rpm, with their peaks.
Definition bench_state.h:54
A run's charge and energy, counted by the panel.
Definition bench_state.h:332
The log's columns: their number, targets and names.
Definition log_cols.h:45
The servo rail's supply on a SERVO run's row: the supply's last reading and the run's totals of it,...
Definition log_writer.h:188
uint8_t counted
Definition log_writer.h:195
uint8_t ok
Definition log_writer.h:194
float i
Definition log_writer.h:190
float p
Definition log_writer.h:191
bool withheld
Definition log_writer.h:196
float v
Definition log_writer.h:189
float energy_wh
Definition log_writer.h:193
float charge_mah
Definition log_writer.h:192
A SERVO run's commanded pulse and measured angle on its row.
Definition log_writer.h:257
bool pulse_ok
Definition log_writer.h:260
bool angle_ok
Definition log_writer.h:261
uint16_t pulse_us
Definition log_writer.h:259
float angle_deg
Definition log_writer.h:258
The byte sink a log writer writes to, with its commit.
Definition log_writer.h:34
int(*) write(void *ctx, const void *data, size_t len)
Returns bytes written, or a negative value on failure.
Definition log_writer.h:36
bool(*) flush(void *ctx)
Commit what has been written, so that a power cut keeps it.
Definition log_writer.h:45
A log writer: its sink, its counts and its latched failure.
Definition log_writer.h:55
float committed_s
Definition log_writer.h:60
bool header_done
Definition log_writer.h:61
bool by_map
The INA3221 columns go by cols (log_writer_set_cols()), not CH1 to CH3.
Definition log_writer.h:67
float last_s
Definition log_writer.h:59
uint32_t pending
Definition log_writer.h:58
char line[LOG_WRITER_LINE_MAX]
A bench row as it is built: up to 25 cells, here rather than on the stack of the task that writes the...
Definition log_writer.h:73
bool failed
Definition log_writer.h:62
A supply's readings, set points, mode and trip state.
Definition supply.h:69
A programmable supply: what it can be set to, what it was set to, and what it delivers.