From 38251303b71f0b87047538e71a44ea32e835bf99 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sat, 3 Jan 2026 14:45:37 +0100 Subject: [PATCH] build: add support for stream decimation when generating sim data --- build.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/build.rs b/build.rs index f487be5..73d264e 100644 --- a/build.rs +++ b/build.rs @@ -108,7 +108,7 @@ impl FromRecord for IMUReading { } } -fn generate_sim_data(srcs: &[&Path], dest: &Path) { +fn generate_sim_data(srcs: &[&Path], dest: &Path, skip_rate: usize) { for src in srcs { println!("cargo::rerun-if-changed={}", src.to_str().unwrap()); @@ -151,6 +151,8 @@ fn generate_sim_data(srcs: &[&Path], dest: &Pat reader.records() }).collect(); + let mut skip_count = 0; + loop { let mut next: Vec<_> = all_records.iter_mut().map(|reader| { reader.next() }).collect(); @@ -162,16 +164,22 @@ fn generate_sim_data(srcs: &[&Path], dest: &Pat let next: Vec<_> = next.iter_mut().map(|x| { x.take().unwrap().unwrap() }).collect(); let data = Event::from_record(next.as_slice(), headers.as_slice()); - eprintln!("next={next:?} headers={headers:?}"); + //eprintln!("next={next:?} headers={headers:?}"); - let timestamp = next[0].get(headers[0]["seconds_elapsed"]).unwrap().parse().unwrap(); - let next_delay = timestamp - last_stamp; - last_stamp = timestamp; + let this_timecode: f64 = next[0].get(headers[0]["seconds_elapsed"]).unwrap().parse().unwrap(); + let time_delta = this_timecode - last_stamp; let record = StreamEvent { - timecode: next_delay, + timecode: time_delta, data }; - record.write_rmp(&mut output).unwrap(); + + if skip_count == 0 { + last_stamp = this_timecode; + record.write_rmp(&mut output).unwrap(); + skip_count = skip_rate; + } else { + skip_count -= 1; + } } } @@ -188,9 +196,9 @@ fn write_sim_data() { let annotation_output = output_path.join("annotations.msgpack"); let unified_output = output_path.join("unified.msgpack"); - generate_sim_data::(&[&annotation_input], &annotation_output); - generate_sim_data::(&[&gps_input], &gps_output); - generate_sim_data::(&[&accel_input, &gyro_input], &motion_output); + generate_sim_data::(&[&annotation_input], &annotation_output, 0); + generate_sim_data::(&[&gps_input], &gps_output, 0); + generate_sim_data::(&[&accel_input, &gyro_input], &motion_output, 2); let mut unified_fd = File::create(unified_output.clone()).unwrap(); @@ -230,7 +238,7 @@ fn write_sim_data() { if unified_fd.metadata().unwrap().len() as usize >= data_size { // FIXME: Need to implement data resampling - //panic!("Simulation data is too big! Cannot fit {:#x} bytes into a partition with a size of {data_size:#x} bytes.", unified_fd.metadata().unwrap().len()); + panic!("Simulation data is too big! Cannot fit {:#x} bytes into a partition with a size of {data_size:#x} bytes.", unified_fd.metadata().unwrap().len()); } let mut data_flash_script = File::create(output_path.join("flash-sim-data.sh")).unwrap();