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

What a column means, from what it is called. More...

#include "log_fields.h"
#include <ctype.h>
#include <stddef.h>
#include <string.h>

Data Structures

struct  rule_t
 One naming rule: how to match, and the group and unit it gives. More...

Enumerations

enum  match_kind_t { M_PREFIX = 0 , M_EXACT , M_PREFIX_CI , M_ANY_OF }
 How a rule's pattern is matched against a column name. More...

Functions

static bool starts_with (const char *s, const char *prefix, bool fold)
 Whether a name starts with a prefix.
static bool any_of (const char *s, const char *list)
 Whether a name equals one of a '|'-separated list.
log_field_meta_t log_field_meta (const char *name)
 Group and unit for a channel name.
static int numeric_column (const log_analysis_t *an, const char *name)
 The index of the numeric column named name, not the time axis.
static bool picked (const int *picks, int n, int c)
 Whether c is among the first n of picks.
int log_fields_picks (const log_analysis_t *an, int *out, int max)
 The columns LOGS plots in a file before the operator picks any.

Variables

static const rule_t k_rules []
 Order matters: the first match wins.

Detailed Description

What a column means, from what it is called.

A log names its columns but not their roles: "Time(ms)", "t", "timestamp" and "Zeit" are all the x-axis, and "V", "Volt" and "Spannung" are all a voltage. This maps a header name to a role and a unit by matching the names that actually appear in the field, case-folded, so the plot knows which column is time and what each trace is measured in without being told.

SPDX-License-Identifier: MIT

Enumeration Type Documentation

◆ match_kind_t

How a rule's pattern is matched against a column name.

Enumerator
M_PREFIX 

name starts with pattern

M_EXACT 

name equals pattern

M_PREFIX_CI 

starts with, case-insensitively

M_ANY_OF 

equals one of a '|'-separated list

Function Documentation

◆ any_of()

bool any_of ( const char * s,
const char * list )
static

Whether a name equals one of a '|'-separated list.

Parameters
sThe column name.
listThe names, separated by '|'.
Returns
true when s equals one entry of list.

◆ log_field_meta()

log_field_meta_t log_field_meta ( const char * name)

Group and unit for a channel name.

Never NULL; "Other"/"" when unknown.

Parameters
nameThe channel name.
Returns
The group and unit of the channel.

◆ log_fields_picks()

int log_fields_picks ( const log_analysis_t * an,
int * out,
int max )

The columns LOGS plots in a file before the operator picks any.

In a file with a numeric pulse column, a SERVO run's, its pulse, angle, current and voltage first, each where it is numeric; then, and in any other file, the first numeric columns in file order. Never the time axis, and no column twice.

Parameters
anThe file's analysis.
outReceives the column indices.
maxThe most columns to pick.
Returns
The number of columns picked; 0 with an or out NULL.

◆ numeric_column()

int numeric_column ( const log_analysis_t * an,
const char * name )
static

The index of the numeric column named name, not the time axis.

Parameters
anThe file's analysis.
nameThe column name.
Returns
The column's index, or -1.

◆ picked()

bool picked ( const int * picks,
int n,
int c )
static

Whether c is among the first n of picks.

Parameters
picksThe columns picked.
nHow many.
cThe column.
Returns
true when c is picked.

◆ starts_with()

bool starts_with ( const char * s,
const char * prefix,
bool fold )
static

Whether a name starts with a prefix.

Parameters
sThe column name.
prefixThe prefix to find.
foldtrue to compare letters without regard to case.
Returns
true when s starts with prefix.