build: add support for stream decimation when generating sim data

This commit is contained in:
2026-01-03 14:45:37 +01:00
parent 461f17071f
commit 38251303b7

View File

@@ -108,7 +108,7 @@ impl FromRecord for IMUReading {
} }
} }
fn generate_sim_data<Event: EventRecord + FromRecord>(srcs: &[&Path], dest: &Path) { fn generate_sim_data<Event: EventRecord + FromRecord>(srcs: &[&Path], dest: &Path, skip_rate: usize) {
for src in srcs { for src in srcs {
println!("cargo::rerun-if-changed={}", src.to_str().unwrap()); println!("cargo::rerun-if-changed={}", src.to_str().unwrap());
@@ -151,6 +151,8 @@ fn generate_sim_data<Event: EventRecord + FromRecord>(srcs: &[&Path], dest: &Pat
reader.records() reader.records()
}).collect(); }).collect();
let mut skip_count = 0;
loop { loop {
let mut next: Vec<_> = all_records.iter_mut().map(|reader| { reader.next() }).collect(); let mut next: Vec<_> = all_records.iter_mut().map(|reader| { reader.next() }).collect();
@@ -162,16 +164,22 @@ fn generate_sim_data<Event: EventRecord + FromRecord>(srcs: &[&Path], dest: &Pat
let next: Vec<_> = next.iter_mut().map(|x| { x.take().unwrap().unwrap() }).collect(); let next: Vec<_> = next.iter_mut().map(|x| { x.take().unwrap().unwrap() }).collect();
let data = Event::from_record(next.as_slice(), headers.as_slice()); 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 this_timecode: f64 = next[0].get(headers[0]["seconds_elapsed"]).unwrap().parse().unwrap();
let next_delay = timestamp - last_stamp; let time_delta = this_timecode - last_stamp;
last_stamp = timestamp;
let record = StreamEvent { let record = StreamEvent {
timecode: next_delay, timecode: time_delta,
data data
}; };
if skip_count == 0 {
last_stamp = this_timecode;
record.write_rmp(&mut output).unwrap(); 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 annotation_output = output_path.join("annotations.msgpack");
let unified_output = output_path.join("unified.msgpack"); let unified_output = output_path.join("unified.msgpack");
generate_sim_data::<AnnotationReading>(&[&annotation_input], &annotation_output); generate_sim_data::<AnnotationReading>(&[&annotation_input], &annotation_output, 0);
generate_sim_data::<GPSReading>(&[&gps_input], &gps_output); generate_sim_data::<GPSReading>(&[&gps_input], &gps_output, 0);
generate_sim_data::<IMUReading>(&[&accel_input, &gyro_input], &motion_output); generate_sim_data::<IMUReading>(&[&accel_input, &gyro_input], &motion_output, 2);
let mut unified_fd = File::create(unified_output.clone()).unwrap(); 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 { if unified_fd.metadata().unwrap().len() as usize >= data_size {
// FIXME: Need to implement data resampling // 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(); let mut data_flash_script = File::create(output_path.join("flash-sim-data.sh")).unwrap();