Implements all the other signal parsing blocks.
This commit is contained in:
169
src/headproc.rs
169
src/headproc.rs
@@ -1,4 +1,4 @@
|
||||
use std::{u64, vec};
|
||||
use std::{collections::HashMap, u64, vec};
|
||||
|
||||
use crate::SignalFormat;
|
||||
|
||||
@@ -134,6 +134,14 @@ impl Record {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, Hash, PartialEq)]
|
||||
enum AdcBlockKeys {
|
||||
Gain,
|
||||
Baseline,
|
||||
Units
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct SignalSpec {
|
||||
filename: String,
|
||||
@@ -142,12 +150,12 @@ struct SignalSpec {
|
||||
skew: Option<u64>,
|
||||
offset: Option<u64>,
|
||||
adc_gain: Option<f64>,
|
||||
baseline: Option<u64>,
|
||||
baseline: Option<i64>,
|
||||
units: Option<String>,
|
||||
adc_resolution: Option<u64>,
|
||||
adc_zero: Option<u64>,
|
||||
initial_val: Option<u64>,
|
||||
checksum: Option<u64>,
|
||||
adc_zero: i64,
|
||||
initial_val: Option<i64>,
|
||||
checksum: Option<i64>,
|
||||
blocksize: Option<u64>,
|
||||
desc: Option<String>
|
||||
}
|
||||
@@ -170,15 +178,15 @@ impl SignalSpec {
|
||||
let samples_frame: Option<u64> = None;
|
||||
let skew: Option<u64> = None;
|
||||
let offset: Option<u64> = None;
|
||||
let adc_gain: Option<f64> = None;
|
||||
let baseline: Option<u64> = None;
|
||||
let units: Option<String> = None;
|
||||
let adc_resolution: Option<u64> = None;
|
||||
let adc_zero: Option<u64> = None;
|
||||
let initial_val: Option<u64> = None;
|
||||
let checksum: Option<u64> = None;
|
||||
let blocksize: Option<u64> = None;
|
||||
let desc: Option<String> = None;
|
||||
let mut adc_gain: Option<f64> = None;
|
||||
let mut baseline: Option<i64> = None;
|
||||
let mut units: Option<String> = None;
|
||||
let mut adc_resolution: Option<u64> = None;
|
||||
let mut adc_zero:i64 = 0;
|
||||
let mut initial_val: Option<i64> = None;
|
||||
let mut checksum: Option<i64> = None;
|
||||
let mut blocksize: Option<u64> = None;
|
||||
let mut desc: Option<String> = None;
|
||||
|
||||
// TODO: implement samplesperframe, skew, and offset
|
||||
match args[1].parse::<u64>() {
|
||||
@@ -196,13 +204,142 @@ impl SignalSpec {
|
||||
}
|
||||
|
||||
{
|
||||
let bracket_split: Vec<&str> = args[2].split("(").collect();
|
||||
let mut results: HashMap<AdcBlockKeys, String> = HashMap::new();
|
||||
let mut buffer: String = String::new();
|
||||
let mut found_baseline = false;
|
||||
let mut found_units = false;
|
||||
|
||||
// Parse through all the characters and get the individual parts
|
||||
for character in args[2].chars() {
|
||||
loop {
|
||||
if !found_baseline && !found_units && character == '(' {
|
||||
found_baseline = true;
|
||||
results.insert(AdcBlockKeys::Gain, buffer);
|
||||
buffer = String::new();
|
||||
break;
|
||||
}
|
||||
else if found_baseline && character == ')' {
|
||||
results.insert(AdcBlockKeys::Baseline, buffer);
|
||||
buffer = String::new();
|
||||
break;
|
||||
}
|
||||
else if !found_units && character == '/' {
|
||||
found_units = true;
|
||||
if !found_baseline {
|
||||
results.insert(AdcBlockKeys::Gain, buffer);
|
||||
}
|
||||
buffer = String::new();
|
||||
break;
|
||||
}
|
||||
buffer.push(character);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if found_units {
|
||||
results.insert(AdcBlockKeys::Units, buffer);
|
||||
}
|
||||
|
||||
// Try and get the actual values out of the results
|
||||
match results.get(&AdcBlockKeys::Gain) {
|
||||
Some(value ) => {
|
||||
match value.parse::<f64>() {
|
||||
Ok(parsed) => {
|
||||
adc_gain = Some(parsed);
|
||||
},
|
||||
Err(_) => {
|
||||
return Err("error: Signal contains adc gain block with invalid entry");
|
||||
}
|
||||
}
|
||||
},
|
||||
None => {
|
||||
return Err("error: Signal contains adc gain block but the block is empty.");
|
||||
}
|
||||
}
|
||||
|
||||
match results.get(&AdcBlockKeys::Baseline) {
|
||||
Some(value) => {
|
||||
match value.parse::<i64>() {
|
||||
Ok(parsed) => {
|
||||
baseline = Some(parsed);
|
||||
},
|
||||
Err(_) => {
|
||||
return Err("error: Unable to parse baseline from signal");
|
||||
}
|
||||
}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
match results.get(&AdcBlockKeys::Units) {
|
||||
Some(value) => {
|
||||
units = Some(value.clone());
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
if args.len() <= 3 {
|
||||
|
||||
break;
|
||||
}
|
||||
match args[3].parse::<u64>() {
|
||||
Ok(value) => {
|
||||
adc_resolution = Some(value);
|
||||
},
|
||||
Err(_) => {
|
||||
return Err("error: unable to parse resolution from signal");
|
||||
}
|
||||
}
|
||||
|
||||
if args.len() <= 4 {
|
||||
break;
|
||||
}
|
||||
match args[4].parse::<i64>() {
|
||||
Ok(value) => {
|
||||
adc_zero = value;
|
||||
},
|
||||
Err(_) => {
|
||||
adc_zero = 0; // Standard: If this field is missing, a value of zero is assumed.
|
||||
}
|
||||
}
|
||||
|
||||
if args.len() <= 5 {
|
||||
break;
|
||||
}
|
||||
match args[5].parse::<i64>() {
|
||||
Ok(value) => {
|
||||
initial_val = Some(value);
|
||||
},
|
||||
Err(_) => {} // Standard: If this field is missing, adc_zero value is presumed.
|
||||
// We do this on the data parsing part.
|
||||
}
|
||||
|
||||
if args.len() <= 6 {
|
||||
break;
|
||||
}
|
||||
match args[6].parse::<i64>() {
|
||||
Ok(value) => {
|
||||
checksum = Some(value);
|
||||
},
|
||||
Err(_) => {
|
||||
return Err("error: unable to parse checksum from signal");
|
||||
}
|
||||
}
|
||||
|
||||
if args.len() <= 7 {
|
||||
break;
|
||||
}
|
||||
match args[7].parse::<u64>() {
|
||||
Ok(value) => {
|
||||
blocksize = Some(value);
|
||||
},
|
||||
Err(_) => {
|
||||
return Err("error: unable to parse block size from signal");
|
||||
}
|
||||
}
|
||||
|
||||
if args.len() <= 8 {
|
||||
break;
|
||||
}
|
||||
desc = Some(args[8].to_string());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user