42 "I2H",
"I2L",
"V3",
"V4"};
64 uint16_t channel_bin_count = 0;
111 memset(file_header->
channel, 0,
189 if (comment == NULL) {
192 file_header->
comment = comment;
211 int comment_length = strlen(file_header->
comment) + 1;
212 int comment_unaligned_bytes =
217 comment_unaligned_bytes;
227 fwrite(file_header->comment, comment_length, 1, data_file);
228 if (comment_unaligned_bytes > 0) {
237 total_channel_count, data_file);
249 fprintf(data_file,
"RocketLogger CSV File\n");
250 fprintf(data_file,
"File Version,%u\n",
252 fprintf(data_file,
"Block Size,%u\n",
254 fprintf(data_file,
"Block Count,%-20u\n",
256 fprintf(data_file,
"Sample Count,%-20llu\n",
258 fprintf(data_file,
"Sample Rate,%u\n",
260 fprintf(data_file,
"MAC Address,%02x",
264 fprintf(data_file,
":%02x",
267 fprintf(data_file,
"\n");
270 fprintf(data_file,
"Start Time,%s", ctime(&time));
271 fprintf(data_file,
"Comment,%s\n", file_header->
comment);
272 fprintf(data_file,
"\n");
278 fprintf(data_file,
",%s", file_header->
channel[i].
name);
281 fprintf(data_file,
" [m");
284 fprintf(data_file,
" [u");
287 fprintf(data_file,
" [10n");
290 fprintf(data_file,
" [n");
293 fprintf(data_file,
" [10p");
300 fprintf(data_file,
"V]");
303 fprintf(data_file,
"A]");
309 fprintf(data_file,
"\n");
327 fseek(data_file, 0, SEEK_END);
339 fprintf(data_file,
"RocketLogger CSV File\n");
340 fprintf(data_file,
"File Version,%u\n",
342 fprintf(data_file,
"Block Size,%u\n",
344 fprintf(data_file,
"Block Count,%-20u\n",
346 fprintf(data_file,
"Sample Count,%-20llu\n",
349 fseek(data_file, 0, SEEK_END);
363 uint32_t sample_data_size, uint32_t samples_count,
370 fwrite(timestamp_realtime,
sizeof(
struct time_stamp), 1, data_file);
371 fwrite(timestamp_monotonic,
sizeof(
struct time_stamp), 1, data_file);
373 fprintf(data_file,
"%lli.%09lli", timestamp_realtime->
sec,
374 timestamp_realtime->
nsec);
383 uint32_t aggregate_bin_data = 0xffffffff;
386 for (uint32_t i = 0; i < samples_count; i++) {
393 uint8_t bin_adc1 = (*((int8_t*)(buffer_addr)));
394 uint8_t bin_adc2 = (*((int8_t*)(buffer_addr + 1)));
403 if (sample_data_size == 4) {
405 *((int32_t*)(buffer_addr + sample_data_size * j));
408 *((int16_t*)(buffer_addr + sample_data_size * j));
416 buffer_addr += NUM_CHANNELS * sample_data_size;
435 bin_data = bin_data | (valid1 << bin_channel_pos);
439 bin_data = bin_data | (valid2 << bin_channel_pos);
448 rl_log(
ERROR,
"Low sampling rates not supported without " 449 "data aggregation.");
455 if ((i + 1) % aggregate_count > 0) {
457 aggregate_channel_data[i] += channel_data[i];
459 aggregate_bin_data = aggregate_bin_data & bin_data;
466 aggregate_channel_data[i] / aggregate_count;
467 aggregate_channel_data[i] = 0;
470 bin_data = aggregate_bin_data;
471 aggregate_bin_data = 0xffffffff;
476 if (i % aggregate_count > 0) {
485 if (bin_channel_pos > 0) {
487 fwrite(&bin_data,
sizeof(uint32_t), 1, data_file);
489 uint32_t MASK = 0x01;
490 for (
int j = 0; j < bin_channel_pos; j++) {
492 (bin_data & MASK) > 0);
500 fwrite(channel_data,
sizeof(int32_t), num_channels, data_file);
505 fprintf(data_file,
"\n");
int offsets[NUM_CHANNELS]
Channel offsets (in bit)
int is_low_current(int index)
#define NUM_DIGITAL_INPUTS
Number of RocketLogger digital channels.
double scales[NUM_CHANNELS]
Channel scalings.
#define BINARY_MASK
Mask for binary inputs read from PRU.
void file_handle_data(FILE *data_file, void *buffer_addr, uint32_t sample_data_size, uint32_t samples_count, struct time_stamp *timestamp_realtime, struct time_stamp *timestamp_monotonic, struct rl_conf *conf)
void file_store_header_bin(FILE *data_file, struct rl_file_header *file_header)
uint16_t data_size
Datum size in bytes (for voltage and current)
uint16_t header_length
Total size of the header in bytes.
struct time_stamp start_time
Start time of the measurement in UNIX time, UTC.
void file_update_header_bin(FILE *data_file, struct rl_file_header *file_header)
#define MAC_ADDRESS_LENGTH
MAC address length in bytes.
int64_t sec
Seconds in UNIX time (UTC)
int i1l_valid_channel
Global variable to determine i1l valid channel.
int i2l_valid_channel
Global variable to determine i2l valid channel.
void file_setup_channels(struct rl_file_header *file_header, struct rl_conf *conf)
void rl_log(rl_log_type type, const char *format,...)
int digital_inputs
En-/disable digital inputs.
uint64_t sample_count
Total sample count.
uint16_t channel_bin_count
Binary channel count.
void file_setup_header(struct rl_file_header *file_header, struct rl_conf *conf, char *comment)
#define RL_FILE_MAGIC
File header magic number (ascii RLD)
void file_update_header_csv(FILE *data_file, struct rl_file_header *file_header)
uint16_t file_version
File version number.
void file_setup_lead_in(struct rl_file_lead_in *lead_in, struct rl_conf *conf)
Aggregate by averaging data.
#define VALID_MASK
Mask for valid bit read from PRU.
#define RL_SCALE_TEN_PICO
#define NUM_I_CHANNELS
Maximum number of RocketLogger current channels.
Aggregate using downsampling.
rl_unit unit
Channel unit.
#define NUM_CHANNELS
Maximum number of RocketLogger channels.
#define CHANNEL_ENABLED
Channel sampling enabled.
void get_mac_addr(uint8_t mac_address[MAC_ADDRESS_LENGTH])
#define PRU_DIG_SIZE
Size of PRU digital information in bytes.
void create_time_stamp(struct time_stamp *timestamp_realtime, struct time_stamp *timestamp_monotonic)
#define NO_VALID_DATA
No additional range valid information available.
int channels[NUM_CHANNELS]
Channels to sample.
const char * digital_input_names[NUM_DIGITAL_INPUTS]
Digital input names.
uint16_t channel_count
Analog channel count.
void file_store_header_csv(FILE *data_file, struct rl_file_header *file_header)
int is_current(int index)
uint32_t comment_length
Comment length.
rl_file_format file_format
File format.
uint32_t magic
File magic constant.
int update_rate
Data update rate.
uint32_t data_block_size
Size of the data blocks in the file in rows.
char name[RL_FILE_CHANNEL_NAME_LENGTH]
Channel name/description.
uint16_t sample_rate
Sampling rate of the measurement.
#define RL_FILE_VERSION
File format version of current implementation.
int sample_rate
Sampling rate.
#define CSV_DELIMITER
CSV value delimiter character.
int32_t channel_scale
Channel scale (in power of ten, for voltage and current)
uint16_t valid_data_channel
Link to channel valid data (for low-range current channels)
int count_channels(int channels[NUM_CHANNELS])
#define MIN_ADC_RATE
Minimal ADC sampling rate.
const char * valid_info_names[NUM_I_CHANNELS]
Valid channel names.
int8_t num_channels
Number of channels sampled.
uint32_t data_block_count
Number of data blocks stored in the file.
#define RL_FILE_COMMENT_ALIGNMENT_BYTES
Comment alignment in bytes.
rl_aggregation aggregation
Aggregation mode (for sampling rates below lowest native one)
#define RL_SCALE_TEN_NANO
uint8_t mac_address[MAC_ADDRESS_LENGTH]
Instrument ID (mac address)
#define DIGITAL_INPUTS_ENABLED
Digital input sampling ensabled.
const char * channel_names[NUM_CHANNELS]
Channel names.
struct rl_calibration calibration
Calibration data.