RocketLogger 2.1.1
rl.c File Reference
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
#include <zmq.h>
#include "log.h"
#include "sensor/sensor.h"
#include "rl.h"
+ Include dependency graph for rl.c:

Go to the source code of this file.

Macros

#define RL_JSON_BUFFER_SIZE   10000
 

Functions

void rl_config_print (rl_config_t const *const config)
 
void rl_config_print_cmd (rl_config_t const *const config)
 
void rl_config_print_json (rl_config_t const *const config)
 
char * rl_config_get_json (rl_config_t const *const config)
 
void rl_config_reset (rl_config_t *const config)
 
int rl_config_read_default (rl_config_t *const config)
 
int rl_config_write_default (rl_config_t const *const config)
 
int rl_config_validate (rl_config_t const *const config)
 
pid_t rl_pid_get (void)
 
int rl_pid_set (pid_t pid)
 
void rl_status_reset (rl_status_t *const status)
 
int rl_status_pub_init (void)
 
int rl_status_pub_deinit (void)
 
int rl_status_shm_init (void)
 
int rl_status_shm_deinit (void)
 
int rl_status_read (rl_status_t *const status)
 
int rl_status_write (rl_status_t *const status)
 
void rl_status_print (rl_status_t const *const status)
 
void rl_status_print_json (rl_status_t const *const status)
 
char * rl_status_get_json (rl_status_t const *const status)
 

Variables

const rl_config_t rl_config_default
 
const rl_status_t rl_status_default
 
char const *const RL_CHANNEL_NAMES [RL_CHANNEL_COUNT]
 RocketLogger channel names.
 
char const *const RL_CHANNEL_FORCE_NAMES [RL_CHANNEL_SWITCHED_COUNT]
 RocketLogger force range channel names.
 
char const *const RL_CHANNEL_DIGITAL_NAMES [RL_CHANNEL_DIGITAL_COUNT]
 RocketLogger digital channel names.
 
char const *const RL_CHANNEL_VALID_NAMES [RL_CHANNEL_SWITCHED_COUNT]
 RocketLogger valid channel names.
 
rl_status_t rl_status
 Global RocketLogger status variable.
 
void * zmq_status_context = NULL
 The ZeroMQ context for status publishing.
 
void * zmq_status_publisher = NULL
 The ZeroMQ status publisher.
 

Macro Definition Documentation

◆ RL_JSON_BUFFER_SIZE

#define RL_JSON_BUFFER_SIZE   10000

Definition at line 50 of file rl.c.

Function Documentation

◆ rl_config_get_json()

◆ rl_config_print()

◆ rl_config_print_cmd()

◆ rl_config_print_json()

void rl_config_print_json ( rl_config_t const *const  config)

Print RocketLogger configuration as JSON data structure.

Parameters
configThe measurement configuration to print

Definition at line 275 of file rl.c.

References rl_config_get_json().

Referenced by main().

+ Here is the call graph for this function:

◆ rl_config_read_default()

int rl_config_read_default ( rl_config_t *const  config)

Read default configuration from file.

Try to read user configuration otherwis fallback to system configuration.

Parameters
configThe measurement configuration structure to store the default to
Returns
Returns 0 on success, negative on failure with errno set accordingly
Todo:
drop once comment is stored together with default config

Definition at line 364 of file rl.c.

References rl_config::config_version, ERROR, rl_config::file_comment, RL_CONFIG_COMMENT_DEFAULT, rl_config_reset(), RL_CONFIG_SYSTEM_FILE, RL_CONFIG_USER_FILE, RL_CONFIG_VERSION, rl_log(), RL_LOG_ERROR, RL_LOG_WARNING, and SUCCESS.

Referenced by main().

+ Here is the call graph for this function:

◆ rl_config_reset()

void rl_config_reset ( rl_config_t *const  config)

Reset configuration to standard values.

Parameters
configThe measurement configuration to reset

Definition at line 360 of file rl.c.

References rl_config_default.

Referenced by adc_calibrate(), main(), and rl_config_read_default().

◆ rl_config_validate()

int rl_config_validate ( rl_config_t const *const  config)

Validate RocketLogger configuration.

Parameters
configThe measurement configuration to validate
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 431 of file rl.c.

References rl_config::background_enable, rl_config::config_version, ERROR, rl_config::file_comment, rl_config::file_size, rl_config::interactive_enable, is_printable_string(), RL_CONFIG_FILE_SIZE_MIN, RL_CONFIG_VERSION, rl_log(), RL_LOG_ERROR, RL_SAMPLE_RATE_MIN, rl_config::sample_rate, SUCCESS, and rl_config::update_rate.

Referenced by main().

+ Here is the call graph for this function:

◆ rl_config_write_default()

int rl_config_write_default ( rl_config_t const *const  config)

Write provided configuration as default to file.

Parameters
configThe measurement configuration write as default configuration
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 414 of file rl.c.

References ERROR, RL_CONFIG_USER_FILE, rl_log(), RL_LOG_ERROR, and SUCCESS.

Referenced by main().

+ Here is the call graph for this function:

◆ rl_pid_get()

pid_t rl_pid_get ( void  )

Get process ID (PID) of background sampling process.

Returns
If running in background the PID of the background or zero if not running, a negative value is returned on failure with errno set accordingly

Definition at line 508 of file rl.c.

References RL_PID_FILE.

Referenced by rl_stop().

◆ rl_pid_set()

int rl_pid_set ( pid_t  pid)

Store process ID (PID) of the RocketLogger process.

Parameters
pidThe PID of the running process to sture
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 521 of file rl.c.

References ERROR, rl_log(), RL_LOG_ERROR, RL_PID_FILE, and SUCCESS.

Referenced by pru_sample().

+ Here is the call graph for this function:

◆ rl_status_get_json()

char * rl_status_get_json ( rl_status_t const *const  status)

Get RocketLogger status as JSON data structure string.

Parameters
statusThe status data structure
Returns
The status as JSON formatted string

Definition at line 736 of file rl.c.

References rl_status::buffer_count, rl_status::calibration_file, rl_status::calibration_time, rl_status::config, rl_status::disk_free, rl_status::disk_free_permille, rl_status::disk_use_rate, rl_status::error, rl_config_get_json(), RL_JSON_BUFFER_SIZE, rl_status::sample_count, rl_status::sampling, rl_status::sensor_available, rl_status::sensor_count, SENSOR_REGISTRY, SENSOR_REGISTRY_SIZE, and snprintfcat().

Referenced by rl_status_print_json(), and rl_status_write().

+ Here is the call graph for this function:

◆ rl_status_print()

void rl_status_print ( rl_status_t const *const  status)

◆ rl_status_print_json()

void rl_status_print_json ( rl_status_t const *const  status)

Print RocketLogger status as JSON data structure.

Parameters
statusThe status data structure to print

Definition at line 731 of file rl.c.

References rl_status_get_json().

Referenced by main().

+ Here is the call graph for this function:

◆ rl_status_pub_deinit()

int rl_status_pub_deinit ( void  )

Deinitialize the RocketLogger status publishing.

Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 554 of file rl.c.

References SUCCESS, zmq_status_context, and zmq_status_publisher.

Referenced by rl_run().

◆ rl_status_pub_init()

int rl_status_pub_init ( void  )

Initialize the RocketLogger status publishing.

Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 539 of file rl.c.

References ERROR, rl_log(), RL_LOG_ERROR, RL_ZMQ_STATUS_SOCKET, SUCCESS, zmq_status_context, and zmq_status_publisher.

Referenced by rl_run().

+ Here is the call graph for this function:

◆ rl_status_read()

int rl_status_read ( rl_status_t *const  status)

Read the status of the RocketLogger from shared memory.

Parameters
statusThe status data structure to write the read status to
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 602 of file rl.c.

References rl_status::config, ERROR, rl_log(), RL_LOG_ERROR, RL_SHMEM_PERMISSIONS, RL_SHMEM_STATUS_KEY, and SUCCESS.

Referenced by adc_calibrate(), button_interrupt_handler(), main(), and rl_get_status().

+ Here is the call graph for this function:

◆ rl_status_reset()

void rl_status_reset ( rl_status_t *const  status)

Get the RocketLogger default status.

Parameters
statusThe status data structure to write the default value to

Definition at line 535 of file rl.c.

References rl_status_default.

Referenced by rl_get_status(), rl_is_sampling(), and rl_run().

◆ rl_status_shm_deinit()

int rl_status_shm_deinit ( void  )

Deinitialize and remove the shared memory for the RocketLogger status.

Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 579 of file rl.c.

References ERROR, rl_log(), RL_LOG_ERROR, RL_SHMEM_PERMISSIONS, RL_SHMEM_STATUS_KEY, and SUCCESS.

Referenced by main().

+ Here is the call graph for this function:

◆ rl_status_shm_init()

int rl_status_shm_init ( void  )

Create and initialize the shared memory for the RocketLogger status.

Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 565 of file rl.c.

References ERROR, rl_log(), RL_LOG_ERROR, RL_SHMEM_PERMISSIONS, RL_SHMEM_STATUS_KEY, and SUCCESS.

Referenced by main().

+ Here is the call graph for this function:

◆ rl_status_write()

int rl_status_write ( rl_status_t *const  status)

Write new status of the RocketLogger to shared memory.

Parameters
statusThe status data structure to copy to the shared memory
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 641 of file rl.c.

References rl_status::config, rl_status::disk_free, rl_status::disk_free_permille, ERROR, rl_config::file_name, fs_space_free(), fs_space_total(), RL_CONFIG_FILE_DIR_DEFAULT, rl_log(), RL_LOG_ERROR, RL_SHMEM_PERMISSIONS, RL_SHMEM_STATUS_KEY, rl_status_get_json(), SUCCESS, and zmq_status_publisher.

Referenced by adc_calibrate(), hw_deinit(), hw_init(), pru_sample(), and rl_run().

+ Here is the call graph for this function:

Variable Documentation

◆ RL_CHANNEL_DIGITAL_NAMES

char const* const RL_CHANNEL_DIGITAL_NAMES[RL_CHANNEL_DIGITAL_COUNT]
Initial value:
= {
"DI1", "DI2", "DI3", "DI4", "DI5", "DI6"}

RocketLogger digital channel names.

Definition at line 103 of file rl.c.

Referenced by meter_print_buffer(), and rl_file_setup_data_channels().

◆ RL_CHANNEL_FORCE_NAMES

char const* const RL_CHANNEL_FORCE_NAMES[RL_CHANNEL_SWITCHED_COUNT]
Initial value:
= {"I1H",
"I2H"}

RocketLogger force range channel names.

Definition at line 99 of file rl.c.

Referenced by rl_config_get_json(), and rl_config_print_cmd().

◆ RL_CHANNEL_NAMES

char const* const RL_CHANNEL_NAMES[RL_CHANNEL_COUNT]
Initial value:
= {
"V1", "V2", "V3", "V4", "I1L", "I1H", "I2L", "I2H", "DT"}

RocketLogger channel names.

RocketLogger channel names sorted by name.

Definition at line 95 of file rl.c.

Referenced by meter_print_buffer(), rl_config_get_json(), rl_config_print_cmd(), rl_file_setup_data_channels(), and rl_socket_metadata().

◆ RL_CHANNEL_VALID_NAMES

char const* const RL_CHANNEL_VALID_NAMES[RL_CHANNEL_SWITCHED_COUNT]
Initial value:
= {
"I1L_valid", "I2L_valid"}

RocketLogger valid channel names.

Definition at line 107 of file rl.c.

Referenced by rl_file_setup_data_channels().

◆ rl_config_default

const rl_config_t rl_config_default
Initial value:
= {
.config_version = RL_CONFIG_VERSION,
.background_enable = false,
.interactive_enable = false,
.sample_limit = 0,
.sample_rate = RL_SAMPLE_RATE_MIN,
.update_rate = 1,
.channel_force_range = RL_CONFIG_CHANNEL_FORCE_RANGE_DEFAULT,
.aggregation_mode = RL_AGGREGATION_MODE_DOWNSAMPLE,
.digital_enable = true,
.web_enable = true,
.calibration_ignore = false,
.ambient_enable = false,
.file_enable = true,
.file_name = RL_CONFIG_FILE_DEFAULT,
.file_format = RL_FILE_FORMAT_RLD,
.file_comment = RL_CONFIG_COMMENT_DEFAULT,
}
#define RL_CONFIG_VERSION
Default system configuration file path.
Definition rl.h:81
#define RL_CONFIG_CHANNEL_ENABLE_DEFAULT
Configuration channel enable default.
Definition rl.h:93
@ RL_FILE_FORMAT_RLD
CSV format.
Definition rl.h:143
#define RL_SAMPLE_RATE_MIN
Minimum native sample rate of the ADC in samples per second.
Definition rl.h:62
#define RL_CONFIG_COMMENT_DEFAULT
Configuration file comment default.
Definition rl.h:111
#define RL_CONFIG_CHANNEL_FORCE_RANGE_DEFAULT
Configuration channel force range default.
Definition rl.h:99
#define RL_CONFIG_FILE_DEFAULT
Configuration file name default.
Definition rl.h:105
#define RL_CONFIG_FILE_SIZE_DEFAULT
Configuration file size default.
Definition rl.h:109
@ RL_AGGREGATION_MODE_DOWNSAMPLE
Definition rl.h:129

RocketLogger reset configuration definition.

Definition at line 55 of file rl.c.

Referenced by rl_config_reset().

◆ rl_status

Initial value:
= {
.sampling = false,
.error = false,
.sample_count = 0,
.buffer_count = 0,
.calibration_time = 0,
.calibration_file = RL_CALIBRATION_SYSTEM_FILE,
.disk_free = 0,
.disk_free_permille = 0,
.disk_use_rate = 0,
.sensor_count = 0,
.sensor_available = {false},
.config = NULL,
}
#define RL_CALIBRATION_SYSTEM_FILE
Default system wide calibration file path.
Definition rl.h:72

Global RocketLogger status variable.

Definition at line 112 of file rl.c.

◆ rl_status_default

const rl_status_t rl_status_default
Initial value:
= {
.sampling = false,
.error = false,
.sample_count = 0,
.buffer_count = 0,
.calibration_time = 0,
.calibration_file = RL_CALIBRATION_SYSTEM_FILE,
.disk_free = 0,
.disk_free_permille = 0,
.disk_use_rate = 0,
.sensor_count = 0,
.sensor_available = {false},
.config = NULL,
}

RocketLogger reset status definition.

Definition at line 79 of file rl.c.

Referenced by rl_status_reset().

◆ zmq_status_context

void* zmq_status_context = NULL

The ZeroMQ context for status publishing.

Definition at line 128 of file rl.c.

Referenced by rl_status_pub_deinit(), and rl_status_pub_init().

◆ zmq_status_publisher

void* zmq_status_publisher = NULL

The ZeroMQ status publisher.

Definition at line 130 of file rl.c.

Referenced by rl_status_pub_deinit(), rl_status_pub_init(), and rl_status_write().