build: add annotations to event stream packages

This commit is contained in:
2025-12-23 19:55:08 +01:00
parent af021676db
commit 36f232f43c

View File

@@ -71,11 +71,38 @@ fn write_sim_data() {
let gps_input = test_data_path.join("LocationGps.csv"); let gps_input = test_data_path.join("LocationGps.csv");
let gyro_input = test_data_path.join("GyroscopeUncalibrated.csv"); let gyro_input = test_data_path.join("GyroscopeUncalibrated.csv");
let accel_input = test_data_path.join("AccelerometerUncalibrated.csv"); let accel_input = test_data_path.join("AccelerometerUncalibrated.csv");
let annotation_input = test_data_path.join("Annotation.csv");
let gps_output = output_path.join("gps_test_data.msgpack"); let gps_output = output_path.join("gps_test_data.msgpack");
let motion_output = output_path.join("motion_test_data.msgpack"); let motion_output = output_path.join("motion_test_data.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");
{
let mut annotation_data = Reader::from_reader(File::open(annotation_input.clone()).unwrap());
let record_count = annotation_data.records().count() as u32;
let mut annotation_data = Reader::from_reader(File::open(annotation_input).unwrap());
let headers = annotation_data.headers().unwrap();
let (timestamp_idx, text_idx) = (
headers.iter().position(|x| { x == "seconds_elapsed" }).unwrap(),
headers.iter().position(|x| { x == "text" }).unwrap(),
);
let mut annotation_output = File::create(annotation_output.clone()).unwrap();
rmp::encode::write_array_len(&mut annotation_output, record_count).unwrap();
let mut last_stamp = 0.0;
for record in annotation_data.records().flatten() {
let (timestamp, text) = (
record.get(timestamp_idx).unwrap().parse().unwrap(),
record.get(text_idx).unwrap()
);
let next_delay = timestamp - last_stamp;
last_stamp = timestamp;
rmp::encode::write_array_len(&mut annotation_output, 3).unwrap();
rmp::encode::write_f64(&mut annotation_output, next_delay).unwrap();
rmp::encode::write_str(&mut annotation_output, text).unwrap();
}
}
println!("cargo::rerun-if-changed={}", gps_input.to_str().unwrap()); println!("cargo::rerun-if-changed={}", gps_input.to_str().unwrap());
if !gps_output.exists() || gps_output.metadata().unwrap().modified().unwrap() < gps_input.metadata().unwrap().modified().unwrap() { if !gps_output.exists() || gps_output.metadata().unwrap().modified().unwrap() < gps_input.metadata().unwrap().modified().unwrap() {
let mut gps_data = Reader::from_reader(File::open(gps_input.clone()).unwrap()); let mut gps_data = Reader::from_reader(File::open(gps_input.clone()).unwrap());
@@ -173,10 +200,11 @@ fn write_sim_data() {
let mut unified_fd = File::create(unified_output.clone()).unwrap(); let mut unified_fd = File::create(unified_output.clone()).unwrap();
// Write out the stream index, which will be 2 (motion + gps) // Write out the stream index, which will be 2 (motion + gps)
rmp::encode::write_array_len(&mut unified_fd, 2).unwrap(); rmp::encode::write_array_len(&mut unified_fd, 3).unwrap();
let mut motion_output = File::open(motion_output).unwrap(); let mut motion_output = File::open(motion_output).unwrap();
let mut gps_output = File::open(gps_output).unwrap(); let mut gps_output = File::open(gps_output).unwrap();
let mut annotation_output = File::open(annotation_output).unwrap();
rmp::encode::write_ext_meta(&mut unified_fd, motion_output.metadata().unwrap().len() as u32, 1).unwrap(); rmp::encode::write_ext_meta(&mut unified_fd, motion_output.metadata().unwrap().len() as u32, 1).unwrap();
let mut buf = Vec::new(); let mut buf = Vec::new();
motion_output.read_to_end(&mut buf).unwrap(); motion_output.read_to_end(&mut buf).unwrap();
@@ -187,6 +215,11 @@ fn write_sim_data() {
gps_output.read_to_end(&mut buf).unwrap(); gps_output.read_to_end(&mut buf).unwrap();
unified_fd.write_all(buf.as_slice()).unwrap(); unified_fd.write_all(buf.as_slice()).unwrap();
rmp::encode::write_ext_meta(&mut unified_fd, annotation_output.metadata().unwrap().len() as u32, 3).unwrap();
let mut buf = Vec::new();
annotation_output.read_to_end(&mut buf).unwrap();
unified_fd.write_all(buf.as_slice()).unwrap();
let mut partitions = Reader::from_reader(File::open("partitions.csv").unwrap()); let mut partitions = Reader::from_reader(File::open("partitions.csv").unwrap());
let mut data_offset = 0x9000; // Assumes default bootloader size (0x7000) plus partition table (0x2000) let mut data_offset = 0x9000; // Assumes default bootloader size (0x7000) plus partition table (0x2000)
let mut data_size = 0; let mut data_size = 0;