RocketLogger 2.1.0
rl_file.c File Reference
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>
#include <time.h>
#include "log.h"
#include "pru.h"
#include "rl.h"
#include "rl_file.h"
#include "sensor/sensor.h"
#include "util.h"
+ Include dependency graph for rl_file.c:

Go to the source code of this file.

Functions

void rl_file_setup_data_channels (rl_file_header_t *const header, rl_config_t const *const config)
 
void rl_file_setup_ambient_channels (rl_file_header_t *const header)
 
char * rl_unit_to_string (rl_unit_t const unit)
 
char * rl_file_get_ambient_file_name (char const *const data_file_name)
 
void rl_file_setup_data_lead_in (rl_file_lead_in_t *const lead_in, rl_config_t const *const config)
 
void rl_file_setup_ambient_lead_in (rl_file_lead_in_t *const lead_in, rl_config_t const *const config)
 
void rl_file_setup_data_header (rl_file_header_t *const header, rl_config_t const *const config)
 
void rl_file_setup_ambient_header (rl_file_header_t *const header, rl_config_t const *const config)
 
void rl_file_store_header_bin (FILE *file_handle, rl_file_header_t *const file_header)
 
void rl_file_store_header_csv (FILE *file_handle, rl_file_header_t const *const file_header)
 
void rl_file_update_header_bin (FILE *file_handle, rl_file_header_t const *const file_header)
 
void rl_file_update_header_csv (FILE *file_handle, rl_file_header_t const *const file_header)
 
int rl_file_add_data_block (FILE *data_file, int32_t const *analog_buffer, uint32_t const *digital_buffer, size_t buffer_size, rl_timestamp_t const *const timestamp_realtime, rl_timestamp_t const *const timestamp_monotonic, rl_config_t const *const config)
 
int rl_file_add_ambient_block (FILE *ambient_file, int32_t const *ambient_buffer, size_t buffer_size, rl_timestamp_t const *const timestamp_realtime, rl_timestamp_t const *const timestamp_monotonic, rl_config_t const *const config)
 

Variables

char * RL_UNIT_NAMES []
 
int i1l_valid_channel = 0
 Global variable to determine i1l valid channel index. More...
 
int i2l_valid_channel = 0
 Global variable to determine i2l valid channel index. More...
 

Function Documentation

◆ rl_file_add_ambient_block()

int rl_file_add_ambient_block ( FILE *  ambient_file,
int32_t const *  ambient_buffer,
size_t  buffer_size,
rl_timestamp_t const *const  timestamp_realtime,
rl_timestamp_t const *const  timestamp_monotonic,
rl_config_t const *const  config 
)

Handle the sensor data buffer to add a new block to the ambient file.

Parameters
ambient_fileAmbient file to write to
ambient_bufferAmbient sensor data buffer to process
buffer_sizeNumber of sensor samples in the buffer
timestamp_realtimeTimestamp sampled from realtime clock
timestamp_monotonicTimestamp sampled from monotonic clock
configCurrent measurement configuration
Returns
Returns the number of data blocks written to the file, negative on failure with errno set accordingly

Definition at line 521 of file rl_file.c.

Referenced by pru_sample().

◆ rl_file_add_data_block()

int rl_file_add_data_block ( FILE *  data_file,
int32_t const *  analog_buffer,
uint32_t const *  digital_buffer,
size_t  buffer_size,
rl_timestamp_t const *const  timestamp_realtime,
rl_timestamp_t const *const  timestamp_monotonic,
rl_config_t const *const  config 
)

Handle the sampling data buffer to add a new block to the data file.

Parameters
data_fileData file to write to
analog_bufferAnalog data buffer to process
digital_bufferDigital data buffer to process
buffer_sizeNumber of data samples in the buffer
timestamp_realtimeTimestamp sampled from realtime clock
timestamp_monotonicTimestamp sampled from monotonic clock
configCurrent measurement configuration
Returns
Returns the number of data blocks written to the file, negative on failure with errno set accordingly

Definition at line 351 of file rl_file.c.

References rl_config::aggregation_mode, rl_config::channel_enable, data, rl_config::digital_enable, ERROR, rl_config::file_enable, rl_config::file_format, rl_timestamp::nsec, PRU_DIGITAL_I1L_VALID_MASK, PRU_DIGITAL_I2L_VALID_MASK, PRU_DIGITAL_INPUT1_MASK, PRU_DIGITAL_INPUT_MASK, RL_AGGREGATION_MODE_AVERAGE, RL_AGGREGATION_MODE_DOWNSAMPLE, RL_CHANNEL_COUNT, RL_CHANNEL_DIGITAL_COUNT, RL_CONFIG_CHANNEL_I1L, RL_CONFIG_CHANNEL_I2L, RL_FILE_CSV_DELIMITER, RL_FILE_FORMAT_CSV, RL_FILE_FORMAT_RLD, rl_log(), RL_LOG_ERROR, RL_LOG_WARNING, RL_SAMPLE_RATE_MIN, rl_config::sample_rate, and rl_timestamp::sec.

Referenced by pru_sample().

+ Here is the call graph for this function:

◆ rl_file_get_ambient_file_name()

char * rl_file_get_ambient_file_name ( char const *const  data_file_name)

Derive the ambient file name from the data file name.

Parameters
data_file_nameThe data file name
Returns
Pointer to the buffer of the derived ambient file name

Definition at line 95 of file rl_file.c.

References RL_FILE_AMBIENT_SUFFIX.

Referenced by hw_sample(), and pru_sample().

◆ rl_file_setup_ambient_channels()

void rl_file_setup_ambient_channels ( rl_file_header_t *const  header)

◆ rl_file_setup_ambient_header()

void rl_file_setup_ambient_header ( rl_file_header_t *const  file_header,
rl_config_t const *const  config 
)

Set up ambient file header with current configuration.

Parameters
file_headerThe file header data structure to set up
configCurrent measurement configuration

Definition at line 207 of file rl_file.c.

References rl_file_header::comment, rl_config::file_comment, and rl_file_setup_ambient_channels().

Referenced by pru_sample().

+ Here is the call graph for this function:

◆ rl_file_setup_ambient_lead_in()

◆ rl_file_setup_data_channels()

◆ rl_file_setup_data_header()

void rl_file_setup_data_header ( rl_file_header_t *const  file_header,
rl_config_t const *const  config 
)

Set up data file header with current configuration.

Parameters
file_headerThe file header data structure to set up
configCurrent measurement configuration

Definition at line 196 of file rl_file.c.

References rl_file_header::comment, rl_config::file_comment, and rl_file_setup_data_channels().

Referenced by pru_sample().

+ Here is the call graph for this function:

◆ rl_file_setup_data_lead_in()

◆ rl_file_store_header_bin()

void rl_file_store_header_bin ( FILE *  file_handle,
rl_file_header_t *const  file_header 
)

Store file header to file (in binary format).

Parameters
file_handleData file to write to
file_headerThe file header data structure to store to the file

Definition at line 218 of file rl_file.c.

References rl_file_header::channel, rl_file_lead_in::channel_bin_count, rl_file_lead_in::channel_count, rl_file_header::comment, rl_file_lead_in::comment_length, rl_file_lead_in::header_length, rl_file_header::lead_in, and RL_FILE_COMMENT_ALIGNMENT_BYTES.

Referenced by pru_sample().

◆ rl_file_store_header_csv()

◆ rl_file_update_header_bin()

void rl_file_update_header_bin ( FILE *  file_handle,
rl_file_header_t const *const  file_header 
)

Update file with new header lead-in (to write current sample count) in binary format.

Parameters
file_handleData file to write to
file_headerThe file header data structure to store to the file

Definition at line 325 of file rl_file.c.

References rl_file_header::lead_in.

Referenced by pru_sample().

◆ rl_file_update_header_csv()

void rl_file_update_header_csv ( FILE *  file_handle,
rl_file_header_t const *const  file_header 
)

Update file with new header lead-in (to write current sample count) in CSV format.

Parameters
file_handleData file to write to
file_headerThe file header data structure to store to the file

Definition at line 335 of file rl_file.c.

References rl_file_lead_in::data_block_count, rl_file_lead_in::data_block_size, rl_file_lead_in::file_version, rl_file_header::lead_in, and rl_file_lead_in::sample_count.

Referenced by pru_sample().

◆ rl_unit_to_string()

char * rl_unit_to_string ( rl_unit_t  unit)

Get the string representing the unit.

Parameters
unitThe unit to convert into a string
Returns
Pointer to the unit string or NULL if unit not defined

Definition at line 86 of file rl_file.c.

References RL_UNIT_NAMES.

Referenced by rl_socket_metadata().

Variable Documentation

◆ i1l_valid_channel

int i1l_valid_channel = 0

Global variable to determine i1l valid channel index.

Definition at line 82 of file rl_file.c.

Referenced by rl_file_setup_data_channels(), and rl_file_setup_data_lead_in().

◆ i2l_valid_channel

int i2l_valid_channel = 0

Global variable to determine i2l valid channel index.

Definition at line 84 of file rl_file.c.

Referenced by rl_file_setup_data_channels(), and rl_file_setup_data_lead_in().

◆ RL_UNIT_NAMES

char* RL_UNIT_NAMES[]
Initial value:
= {
"",
"V",
"A",
"",
"",
"lx",
"C",
"",
"%",
"P",
"s",
}

Definition at line 50 of file rl_file.c.

Referenced by rl_unit_to_string().