RocketLogger 2.1.1
rl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * * Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef RL_H_
33#define RL_H_
34
35#include <stdbool.h>
36#include <stdint.h>
37
38#include <linux/limits.h>
39#include <sys/types.h>
40
41#include "version.h"
42
44#define SUCCESS (0)
46#define ERROR (-1)
47
49#define RL_MEASUREMENT_LOG_FILE "/var/log/rocketlogger/rocketlogger.log"
51#define RL_DAEMON_LOG_FILE "/var/log/rocketlogger/rocketloggerd.log"
53#define RL_PID_FILE "/run/rocketlogger.pid"
54
56#define RL_CHANNEL_COUNT 9
58#define RL_CHANNEL_SWITCHED_COUNT 2
60#define RL_CHANNEL_DIGITAL_COUNT 6
62#define RL_SAMPLE_RATE_MIN 1000
64#define RL_SENSOR_COUNT_MAX 128
66#define RL_SENSOR_SAMPLE_RATE 1
67
69#define RL_CALIBRATION_USER_FILE \
70 "/home/rocketlogger/.config/rocketlogger/calibration.dat"
72#define RL_CALIBRATION_SYSTEM_FILE "/etc/rocketlogger/calibration.dat"
73
75#define RL_CONFIG_USER_FILE \
76 "/home/rocketlogger/.config/rocketlogger/settings.dat"
78#define RL_CONFIG_SYSTEM_FILE "/etc/rocketlogger/settings.dat"
79
81#define RL_CONFIG_VERSION 0x03
83#define RL_CONFIG_CHANNEL_V1 0
84#define RL_CONFIG_CHANNEL_V2 1
85#define RL_CONFIG_CHANNEL_V3 2
86#define RL_CONFIG_CHANNEL_V4 3
87#define RL_CONFIG_CHANNEL_I1L 4
88#define RL_CONFIG_CHANNEL_I1H 5
89#define RL_CONFIG_CHANNEL_I2L 6
90#define RL_CONFIG_CHANNEL_I2H 7
91#define RL_CONFIG_CHANNEL_DT 8
93#define RL_CONFIG_CHANNEL_ENABLE_DEFAULT \
94 { true, true, true, true, true, true, true, true, false }
96#define RL_CONFIG_CHANNEL_I1 0
97#define RL_CONFIG_CHANNEL_I2 1
99#define RL_CONFIG_CHANNEL_FORCE_RANGE_DEFAULT \
100 { false, false }
101
103#define RL_CONFIG_FILE_DIR_DEFAULT "/home/rocketlogger/data"
105#define RL_CONFIG_FILE_DEFAULT RL_CONFIG_FILE_DIR_DEFAULT "/data.rld"
107#define RL_CONFIG_FILE_SIZE_MIN (5UL * 1000UL * 1000UL)
109#define RL_CONFIG_FILE_SIZE_DEFAULT (1000UL * 1000UL * 1000UL)
111#define RL_CONFIG_COMMENT_DEFAULT "Sampled using the RocketLogger"
112
114#define RL_SHMEM_STATUS_KEY 1111
116#define RL_SHMEM_DATA_KEY 4443
118#define RL_SHMEM_PERMISSIONS 0666
119
121#define RL_ZMQ_STATUS_SOCKET "tcp://127.0.0.1:8276"
123#define RL_ZMQ_DATA_SOCKET "tcp://127.0.0.1:8277"
124
131};
132
137
144};
145
150
154struct rl_config {
162 uint64_t sample_limit;
164 uint32_t sample_rate;
166 uint32_t update_rate;
184 char file_name[PATH_MAX];
188 uint64_t file_size;
190 char const *file_comment;
191};
192
196typedef struct rl_config rl_config_t;
197
201struct rl_status {
205 bool error;
207 uint64_t sample_count;
209 uint64_t buffer_count;
213 char calibration_file[PATH_MAX];
215 uint64_t disk_free;
221 uint16_t sensor_count;
226};
227
231typedef struct rl_status rl_status_t;
232
234extern char const *const RL_CHANNEL_NAMES[RL_CHANNEL_COUNT];
235
237extern char const *const RL_CHANNEL_FORCE_NAMES[RL_CHANNEL_SWITCHED_COUNT];
238
240extern char const *const RL_CHANNEL_DIGITAL_NAMES[RL_CHANNEL_DIGITAL_COUNT];
241
243extern char const *const RL_CHANNEL_VALID_NAMES[RL_CHANNEL_SWITCHED_COUNT];
244
250void rl_config_print(rl_config_t const *const config);
251
258void rl_config_print_cmd(rl_config_t const *const config);
259
265void rl_config_print_json(rl_config_t const *const config);
266
273char *rl_config_get_json(rl_config_t const *const config);
274
281
291
299
306int rl_config_validate(rl_config_t const *const config);
307
314pid_t rl_pid_get(void);
315
322int rl_pid_set(pid_t pid);
323
329void rl_status_reset(rl_status_t *const status);
330
336int rl_status_pub_init(void);
337
343int rl_status_pub_deinit(void);
344
350int rl_status_shm_init(void);
351
357int rl_status_shm_deinit(void);
358
365int rl_status_read(rl_status_t *const status);
366
373int rl_status_write(rl_status_t *const status);
374
380void rl_status_print(rl_status_t const *const status);
381
387void rl_status_print_json(rl_status_t const *const status);
388
395char *rl_status_get_json(rl_status_t const *const status);
396
399
400#endif /* RL_H_ */
char const *const RL_CHANNEL_NAMES[RL_CHANNEL_COUNT]
RocketLogger channel names sorted by name.
Definition rl.c:95
void rl_status_print_json(rl_status_t const *const status)
Definition rl.c:731
void rl_status_reset(rl_status_t *const status)
Definition rl.c:535
char const *const RL_CHANNEL_FORCE_NAMES[RL_CHANNEL_SWITCHED_COUNT]
RocketLogger force range channel names.
Definition rl.c:99
char const *const RL_CHANNEL_VALID_NAMES[RL_CHANNEL_SWITCHED_COUNT]
RocketLogger valid channel names.
Definition rl.c:107
int rl_status_pub_init(void)
Definition rl.c:539
int rl_status_write(rl_status_t *const status)
Definition rl.c:641
rl_file_format
Definition rl.h:141
@ RL_FILE_FORMAT_RLD
CSV format.
Definition rl.h:143
@ RL_FILE_FORMAT_CSV
Definition rl.h:142
void rl_config_print_json(rl_config_t const *const config)
Definition rl.c:275
void rl_config_reset(rl_config_t *const config)
Definition rl.c:360
int rl_status_read(rl_status_t *const status)
Definition rl.c:602
enum rl_aggregation_mode rl_aggregation_mode_t
Definition rl.h:136
int rl_status_shm_init(void)
Definition rl.c:565
int rl_pid_set(pid_t pid)
Definition rl.c:521
void rl_config_print(rl_config_t const *const config)
Definition rl.c:142
int rl_config_read_default(rl_config_t *const config)
Definition rl.c:364
char * rl_config_get_json(rl_config_t const *const config)
Definition rl.c:280
char * rl_status_get_json(rl_status_t const *const status)
Definition rl.c:736
pid_t rl_pid_get(void)
Definition rl.c:508
int rl_config_write_default(rl_config_t const *const config)
Definition rl.c:414
#define RL_CHANNEL_SWITCHED_COUNT
Number of RocketLogger switched channels (allowing to force range)
Definition rl.h:58
int rl_config_validate(rl_config_t const *const config)
Definition rl.c:431
void rl_status_print(rl_status_t const *const status)
Definition rl.c:709
int rl_status_shm_deinit(void)
Definition rl.c:579
#define RL_CHANNEL_DIGITAL_COUNT
Number of RocketLogger digital channels.
Definition rl.h:60
enum rl_file_format rl_file_format_t
Definition rl.h:149
#define RL_CHANNEL_COUNT
Number of RocketLogger analog channels.
Definition rl.h:56
void rl_config_print_cmd(rl_config_t const *const config)
Definition rl.c:211
int rl_status_pub_deinit(void)
Definition rl.c:554
char const *const RL_CHANNEL_DIGITAL_NAMES[RL_CHANNEL_DIGITAL_COUNT]
RocketLogger digital channel names.
Definition rl.c:103
#define RL_SENSOR_COUNT_MAX
Maximum number of sensors that can be connected to the system.
Definition rl.h:64
rl_aggregation_mode
Definition rl.h:128
@ RL_AGGREGATION_MODE_AVERAGE
Aggregate using down sampling.
Definition rl.h:130
@ RL_AGGREGATION_MODE_DOWNSAMPLE
Definition rl.h:129
bool channel_force_range[RL_CHANNEL_SWITCHED_COUNT]
Current channels to force to high range.
Definition rl.h:170
char file_name[PATH_MAX]
Data file name.
Definition rl.h:184
bool interactive_enable
Display measurement data interactively in CLI while sampling.
Definition rl.h:160
char const * file_comment
File comment.
Definition rl.h:190
uint64_t file_size
Maximum data file size.
Definition rl.h:188
rl_aggregation_mode_t aggregation_mode
Sample aggregation mode (for sampling rates below lowest native one)
Definition rl.h:172
bool background_enable
Put the measurement process in background after successful start.
Definition rl.h:158
bool ambient_enable
Enable logging of ambient sensor.
Definition rl.h:180
uint64_t sample_limit
Sample limit (0 for continuous)
Definition rl.h:162
bool web_enable
Enable web interface connection.
Definition rl.h:176
rl_file_format_t file_format
File format.
Definition rl.h:186
uint32_t sample_rate
Sampling rate.
Definition rl.h:164
bool channel_enable[RL_CHANNEL_COUNT]
Channels to sample.
Definition rl.h:168
uint8_t config_version
Configuration structure version.
Definition rl.h:156
uint32_t update_rate
Data update rate.
Definition rl.h:166
bool file_enable
Enable storing measurements to file.
Definition rl.h:182
bool digital_enable
Enable digital inputs.
Definition rl.h:174
bool calibration_ignore
Perform calibration measurement (ignore existing calibration)
Definition rl.h:178
uint64_t disk_free
Time stamp of last calibration run.
Definition rl.h:215
rl_config_t const * config
(local) reference to current config
Definition rl.h:225
uint64_t buffer_count
Number of buffers taken.
Definition rl.h:209
uint16_t disk_free_permille
Time stamp of last calibration run.
Definition rl.h:217
uint64_t calibration_time
Time stamp of last calibration run.
Definition rl.h:211
bool error
Whether the logger is in an error state.
Definition rl.h:205
bool sampling
Sampling state, true: sampling, false: idle.
Definition rl.h:203
uint32_t disk_use_rate
Disk space in bytes required per minute when sampling.
Definition rl.h:219
uint16_t sensor_count
Number of sensors found connected to the system.
Definition rl.h:221
bool sensor_available[RL_SENSOR_COUNT_MAX]
Identifiers of sensors found.
Definition rl.h:223
uint64_t sample_count
Number of samples taken.
Definition rl.h:207
char calibration_file[PATH_MAX]
Time stamp of last calibration run.
Definition rl.h:213