50#define RL_JSON_BUFFER_SIZE 10000
57 .background_enable =
false,
58 .interactive_enable =
false,
65 .digital_enable =
true,
67 .calibration_ignore =
false,
68 .ambient_enable =
false,
84 .calibration_time = 0,
87 .disk_free_permille = 0,
90 .sensor_available = {
false},
96 "V1",
"V2",
"V3",
"V4",
"I1L",
"I1H",
"I2L",
"I2H",
"DT"};
104 "DI1",
"DI2",
"DI3",
"DI4",
"DI5",
"DI6"};
108 "I1L_valid",
"I2L_valid"};
117 .calibration_time = 0,
120 .disk_free_permille = 0,
123 .sensor_available = {
false},
139static void print_config_line(
char const *
const description,
char const *format,
144 print_config_line(
"Run in background",
146 print_config_line(
"Interactive data display",
148 print_config_line(
"Sample limit",
"%llu", config->
sample_limit);
151 print_config_line(
"Sampling rate",
"%u Sps", config->
sample_rate);
154 print_config_line(
"Data aggregation",
"down sample");
158 print_config_line(
"Data aggregation",
"average samples");
161 print_config_line(
"Data aggregation",
"undefined");
167 "Channels enabled",
"V1: %s V2: %s V3: %s V4: %s",
173 "",
"I1L: %s I1H: %s I2L: %s I2H: %s DT: %s",
180 "Force High Channels",
"I1H: %s I2H: %s",
184 print_config_line(
"Digital inputs",
187 print_config_line(
"File storing",
189 print_config_line(
"File name", config->
file_name);
192 print_config_line(
"File format",
"RLD binary file");
196 print_config_line(
"File format",
"CSV text file");
199 print_config_line(
"File format",
"undefined");
202 print_config_line(
"Max. file size",
"%llu Bytes", config->
file_size);
204 print_config_line(
"Update rate",
"%u Hz", config->
update_rate);
205 print_config_line(
"Web server",
207 print_config_line(
"Calibration measurement",
213 printf(
"rocketlogger start");
217 printf(
" --background");
220 printf(
" --interactive");
230 printf(
" --channel=");
236 printf(
" --high-range=");
246 printf(
" --aggregate=average");
250 printf(
" --aggregate=downsample");
255 printf(
" --ambient=%s", config->
ambient_enable ?
"true" :
"false");
256 printf(
" --digital=%s", config->
digital_enable ?
"true" :
"false");
257 printf(
" --web=%s", config->
web_enable ?
"true" :
"false");
260 printf(
" --calibration");
265 printf(
" --output=%s", config->
file_name);
266 printf(
" --format=%s",
268 printf(
" --size=%llu", config->
file_size);
271 printf(
" --output=0\n");
277 printf(
"%s", config_json);
365 char *config_file = NULL;
384 FILE *file = fopen(config_file,
"r");
387 "failed to open configuration file '%s'; %d message: %s",
388 config_file, errno, strerror(errno));
405 "Old or invalid configuration file. Using default "
406 "config as fall back.");
419 "failed to create configuration file; %d message: %s", errno,
441 bool sample_rate_native =
447 (!sample_rate_native &&
450 "invalid sample rate (%u). Needs to be natively supported "
451 "value, or valid divisor of %u.",
460 "invalid update rate (%u). Needs to be a valid divisor of the "
469 "of the sample rate.");
476 "printable and white space characters.");
501 "enabling both background and interactive is unsupported.");
515 fscanf(file,
"%d", &pid);
529 fprintf(file,
"%d\n", pid);
546 "failed binding zeromq status publisher; %d message: %s", errno,
571 "failed creating shared status memory; %d message: %s", errno,
585 "failed getting shared memory id for removal; %d message: %s",
586 errno, strerror(errno));
591 int res = shmctl(shm_id, IPC_RMID, NULL);
594 "failed removing shared status memory; %d message: %s", errno,
608 "failed getting shared memory id for reading the "
609 "status; %d message: %s",
610 errno, strerror(errno));
616 if (shm_status == (
void *)-1) {
618 "failed mapping shared memory for reading the "
619 "status; %d message: %s",
620 errno, strerror(errno));
629 int res = shmdt(shm_status);
633 "failed detaching shared memory after status read; %d message: %s",
634 errno, strerror(errno));
647 "failed getting shared memory id for writing the status; %d "
649 errno, strerror(errno));
654 if (shm_status == (
void *)-1) {
656 "failed mapping shared memory for writing the status; %d "
658 errno, strerror(errno));
666 int res = shmdt(shm_status);
670 "failed detaching shared memory after status write; %d message: %s",
671 errno, strerror(errno));
678 int64_t disk_free = 0;
679 int64_t disk_total = 0;
680 if (status->
config != NULL) {
689 if (disk_total > 0) {
701 errno, strerror(errno));
710 print_config_line(
"Sampling", status->
sampling ?
"yes" :
"no");
711 print_config_line(
"Error", status->
error ?
"yes" :
"no");
712 print_config_line(
"Sample count",
"%llu", status->
sample_count);
713 print_config_line(
"Buffer count",
"%llu", status->
buffer_count);
718 print_config_line(
"Calibration file",
"calibration ignored!");
720 print_config_line(
"Disk free",
"%llu Bytes", status->
disk_free);
722 print_config_line(
"Disk use rate",
"%u Bytes/s", status->
disk_use_rate);
723 print_config_line(
"Sensors found",
"%u total", status->
sensor_count);
733 printf(
"%s", status_json);
741 status->
sampling ?
"true" :
"false");
743 status->
error ?
"true" :
"false");
755 "\"calibration_file\": null, ");
778 if (status->
config != NULL) {
788static void print_config_line(
char const *description,
char const *format,
791 va_start(args, format);
792 printf(
" %24s - ", description);
793 vprintf(format, args);
int rl_log(rl_log_level_t log_level, char const *const format,...)
char const *const RL_CHANNEL_NAMES[RL_CHANNEL_COUNT]
RocketLogger channel names.
void rl_status_print_json(rl_status_t const *const status)
void rl_status_reset(rl_status_t *const status)
char const *const RL_CHANNEL_FORCE_NAMES[RL_CHANNEL_SWITCHED_COUNT]
RocketLogger force range channel names.
char const *const RL_CHANNEL_VALID_NAMES[RL_CHANNEL_SWITCHED_COUNT]
RocketLogger valid channel names.
int rl_status_pub_init(void)
int rl_status_write(rl_status_t *const status)
void rl_config_print_json(rl_config_t const *const config)
void rl_config_reset(rl_config_t *const config)
int rl_status_read(rl_status_t *const status)
int rl_status_shm_init(void)
const rl_status_t rl_status_default
int rl_pid_set(pid_t pid)
void rl_config_print(rl_config_t const *const config)
int rl_config_read_default(rl_config_t *const config)
char * rl_config_get_json(rl_config_t const *const config)
const rl_config_t rl_config_default
char * rl_status_get_json(rl_status_t const *const status)
#define RL_JSON_BUFFER_SIZE
int rl_config_write_default(rl_config_t const *const config)
int rl_config_validate(rl_config_t const *const config)
void rl_status_print(rl_status_t const *const status)
int rl_status_shm_deinit(void)
void * zmq_status_context
The ZeroMQ context for status publishing.
void * zmq_status_publisher
The ZeroMQ status publisher.
void rl_config_print_cmd(rl_config_t const *const config)
int rl_status_pub_deinit(void)
char const *const RL_CHANNEL_DIGITAL_NAMES[RL_CHANNEL_DIGITAL_COUNT]
RocketLogger digital channel names.
#define RL_SHMEM_STATUS_KEY
Key for status shared memory (used for creation)
#define RL_CALIBRATION_SYSTEM_FILE
Default system wide calibration file path.
#define RL_CONFIG_CHANNEL_I1H
#define RL_CONFIG_CHANNEL_I2L
#define RL_CONFIG_VERSION
Default system configuration file path.
#define RL_CONFIG_CHANNEL_ENABLE_DEFAULT
Configuration channel enable default.
@ RL_FILE_FORMAT_RLD
CSV format.
#define RL_CONFIG_USER_FILE
User configuration file path.
#define RL_CONFIG_SYSTEM_FILE
Default system configuration file path.
#define RL_CONFIG_CHANNEL_I2H
#define RL_ZMQ_STATUS_SOCKET
ZeroMQ socket identifier for status publishing.
#define RL_PID_FILE
Process ID file for the RocketLogger process.
#define RL_CONFIG_FILE_DIR_DEFAULT
Configuration data file directory default.
#define RL_SAMPLE_RATE_MIN
Minimum native sample rate of the ADC in samples per second.
#define RL_CONFIG_CHANNEL_V4
#define ERROR
Function return value for errors (use errno to indicate the error)
#define RL_CONFIG_CHANNEL_V3
#define RL_SHMEM_PERMISSIONS
Permissions for shared memory.
#define RL_CONFIG_COMMENT_DEFAULT
Configuration file comment default.
#define RL_CONFIG_CHANNEL_FORCE_RANGE_DEFAULT
Configuration channel force range default.
#define RL_CONFIG_FILE_DEFAULT
Configuration file name default.
#define RL_CHANNEL_SWITCHED_COUNT
Number of RocketLogger switched channels (allowing to force range)
#define SUCCESS
Function return value for successful completion.
#define RL_CONFIG_FILE_SIZE_MIN
Minimum measurement split file size (5 MB to fit largest block at max rate)
#define RL_CONFIG_CHANNEL_I2
#define RL_CONFIG_CHANNEL_DT
#define RL_CHANNEL_DIGITAL_COUNT
Number of RocketLogger digital channels.
#define RL_CONFIG_CHANNEL_V2
#define RL_CONFIG_CHANNEL_I1L
#define RL_CONFIG_CHANNEL_I1
Configuration merged/forced channel indexes.
#define RL_CHANNEL_COUNT
Number of RocketLogger analog channels.
#define RL_CONFIG_FILE_SIZE_DEFAULT
Configuration file size default.
#define RL_CONFIG_CHANNEL_V1
Configuration channel indexes.
@ RL_AGGREGATION_MODE_AVERAGE
Aggregate using down sampling.
@ RL_AGGREGATION_MODE_DOWNSAMPLE
const rl_sensor_t SENSOR_REGISTRY[SENSOR_REGISTRY_SIZE]
#define SENSOR_REGISTRY_SIZE
Number of sensor registered.
bool channel_force_range[RL_CHANNEL_SWITCHED_COUNT]
Current channels to force to high range.
char file_name[PATH_MAX]
Data file name.
bool interactive_enable
Display measurement data interactively in CLI while sampling.
char const * file_comment
File comment.
uint64_t file_size
Maximum data file size.
rl_aggregation_mode_t aggregation_mode
Sample aggregation mode (for sampling rates below lowest native one)
bool background_enable
Put the measurement process in background after successful start.
bool ambient_enable
Enable logging of ambient sensor.
uint64_t sample_limit
Sample limit (0 for continuous)
bool web_enable
Enable web interface connection.
rl_file_format_t file_format
File format.
uint32_t sample_rate
Sampling rate.
bool channel_enable[RL_CHANNEL_COUNT]
Channels to sample.
uint8_t config_version
Configuration structure version.
uint32_t update_rate
Data update rate.
bool file_enable
Enable storing measurements to file.
bool digital_enable
Enable digital inputs.
bool calibration_ignore
Perform calibration measurement (ignore existing calibration)
uint64_t disk_free
Time stamp of last calibration run.
rl_config_t const * config
(local) reference to current config
uint64_t buffer_count
Number of buffers taken.
uint16_t disk_free_permille
Time stamp of last calibration run.
uint64_t calibration_time
Time stamp of last calibration run.
bool error
Whether the logger is in an error state.
bool sampling
Sampling state, true: sampling, false: idle.
uint32_t disk_use_rate
Disk space in bytes required per minute when sampling.
uint16_t sensor_count
Number of sensors found connected to the system.
bool sensor_available[RL_SENSOR_COUNT_MAX]
Identifiers of sensors found.
uint64_t sample_count
Number of samples taken.
char calibration_file[PATH_MAX]
Time stamp of last calibration run.
int64_t fs_space_free(char const *const path)
bool is_printable_string(char const *str)
int64_t fs_space_total(char const *const path)
int snprintfcat(char *const buffer, size_t length, char const *format,...)