RocketLogger 2.1.1
rl_file.h File Reference
#include <stdint.h>
#include <stdio.h>
#include "pru.h"
#include "rl.h"
#include "util.h"
+ Include dependency graph for rl_file.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  rl_file_lead_in
 
struct  rl_file_channel
 
struct  rl_file_header
 

Macros

#define RL_FILE_MAGIC   0x444C5225
 File header magic number (ascii RLD)
 
#define RL_FILE_VERSION   0x04
 File format version of current implementation.
 
#define RL_FILE_CHANNEL_NAME_LENGTH   16
 Maximum channel description length.
 
#define RL_FILE_CHANNEL_NO_LINK   (UINT16_MAX)
 No additional range valid information available.
 
#define RL_FILE_COMMENT_ALIGNMENT_BYTES   sizeof(uint32_t)
 Comment alignment in bytes.
 
#define RL_FILE_CSV_DELIMITER   ","
 CSV value delimiter character.
 
#define RL_FILE_AMBIENT_SUFFIX   "-ambient"
 Ambient sensor data file name suffix.
 
#define RL_FILE_AMBIENT_DATA_BLOCK_SIZE   1
 Ambient sensor data file block size in measurements.
 
#define RL_SCALE_PICO   -12
 
#define RL_SCALE_TEN_PICO   -11
 
#define RL_SCALE_NANO   -9
 
#define RL_SCALE_TEN_NANO   -8
 
#define RL_SCALE_MICRO   -6
 
#define RL_SCALE_MILLI   -3
 
#define RL_SCALE_UNIT   0
 
#define RL_SCALE_KILO   3
 
#define RL_SCALE_MEGA   6
 
#define RL_SCALE_GIGA   9
 
#define RL_SCALE_TERA   12
 

Typedefs

typedef enum rl_unit rl_unit_t
 
typedef struct rl_file_lead_in rl_file_lead_in_t
 
typedef struct rl_file_channel rl_file_channel_t
 
typedef struct rl_file_header rl_file_header_t
 

Enumerations

enum  rl_unit {
  RL_UNIT_UNITLESS = 0 , RL_UNIT_VOLT = 1 , RL_UNIT_AMPERE = 2 , RL_UNIT_BINARY = 3 ,
  RL_UNIT_RANGE_VALID = 4 , RL_UNIT_LUX = 5 , RL_UNIT_DEG_C = 6 , RL_UNIT_INTEGER = 7 ,
  RL_UNIT_PERCENT = 8 , RL_UNIT_PASCAL = 9 , RL_UNIT_SECOND = 10 , RL_UNIT_UNDEFINED = (int)0xffffffff
}
 

Functions

char * rl_unit_to_string (rl_unit_t 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 file_header, rl_config_t const *const config)
 
void rl_file_setup_ambient_header (rl_file_header_t *const file_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)
 

Macro Definition Documentation

◆ RL_FILE_AMBIENT_DATA_BLOCK_SIZE

#define RL_FILE_AMBIENT_DATA_BLOCK_SIZE   1

Ambient sensor data file block size in measurements.

Definition at line 64 of file rl_file.h.

◆ RL_FILE_AMBIENT_SUFFIX

#define RL_FILE_AMBIENT_SUFFIX   "-ambient"

Ambient sensor data file name suffix.

Definition at line 61 of file rl_file.h.

◆ RL_FILE_CHANNEL_NAME_LENGTH

#define RL_FILE_CHANNEL_NAME_LENGTH   16

Maximum channel description length.

Definition at line 49 of file rl_file.h.

◆ RL_FILE_CHANNEL_NO_LINK

#define RL_FILE_CHANNEL_NO_LINK   (UINT16_MAX)

No additional range valid information available.

Definition at line 52 of file rl_file.h.

◆ RL_FILE_COMMENT_ALIGNMENT_BYTES

#define RL_FILE_COMMENT_ALIGNMENT_BYTES   sizeof(uint32_t)

Comment alignment in bytes.

Definition at line 55 of file rl_file.h.

◆ RL_FILE_CSV_DELIMITER

#define RL_FILE_CSV_DELIMITER   ","

CSV value delimiter character.

Definition at line 58 of file rl_file.h.

◆ RL_FILE_MAGIC

#define RL_FILE_MAGIC   0x444C5225

File header magic number (ascii RLD)

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 43 of file rl_file.h.

◆ RL_FILE_VERSION

#define RL_FILE_VERSION   0x04

File format version of current implementation.

Definition at line 46 of file rl_file.h.

◆ RL_SCALE_GIGA

#define RL_SCALE_GIGA   9

Definition at line 78 of file rl_file.h.

◆ RL_SCALE_KILO

#define RL_SCALE_KILO   3

Definition at line 76 of file rl_file.h.

◆ RL_SCALE_MEGA

#define RL_SCALE_MEGA   6

Definition at line 77 of file rl_file.h.

◆ RL_SCALE_MICRO

#define RL_SCALE_MICRO   -6

Definition at line 73 of file rl_file.h.

◆ RL_SCALE_MILLI

#define RL_SCALE_MILLI   -3

Definition at line 74 of file rl_file.h.

◆ RL_SCALE_NANO

#define RL_SCALE_NANO   -9

Definition at line 71 of file rl_file.h.

◆ RL_SCALE_PICO

#define RL_SCALE_PICO   -12

Channel scaling definitions

Definition at line 69 of file rl_file.h.

◆ RL_SCALE_TEN_NANO

#define RL_SCALE_TEN_NANO   -8

Definition at line 72 of file rl_file.h.

◆ RL_SCALE_TEN_PICO

#define RL_SCALE_TEN_PICO   -11

Definition at line 70 of file rl_file.h.

◆ RL_SCALE_TERA

#define RL_SCALE_TERA   12

Definition at line 79 of file rl_file.h.

◆ RL_SCALE_UNIT

#define RL_SCALE_UNIT   0

Definition at line 75 of file rl_file.h.

Typedef Documentation

◆ rl_file_channel_t

Typedef for RocketLogger file header channel description.

Definition at line 158 of file rl_file.h.

◆ rl_file_header_t

Typedef for RocketLogger file header.

Definition at line 175 of file rl_file.h.

◆ rl_file_lead_in_t

Typedef for RocketLogger file head lead in

Definition at line 137 of file rl_file.h.

◆ rl_unit_t

typedef enum rl_unit rl_unit_t

Type definition for RocketLogger data unit.

Definition at line 102 of file rl_file.h.

Enumeration Type Documentation

◆ rl_unit

enum rl_unit

Data unit definition

Enumerator
RL_UNIT_UNITLESS 

Unitless.

RL_UNIT_VOLT 

Voltage (electric)

RL_UNIT_AMPERE 

Current (electric)

RL_UNIT_BINARY 

Binary signal.

RL_UNIT_RANGE_VALID 

Range valid information.

RL_UNIT_LUX 

Lux (illuminance)

RL_UNIT_DEG_C 

Degree celsius (temperature)

RL_UNIT_INTEGER 

Integer channel (numeric)

RL_UNIT_PERCENT 

Percent (numeric, humidity)

RL_UNIT_PASCAL 

Pascal (pressure)

RL_UNIT_SECOND 

Second (time delta)

RL_UNIT_UNDEFINED 

Undefined unit.

Definition at line 84 of file rl_file.h.

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_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_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().