diff --git a/src/gui/panels/simulation.rs b/src/gui/panels/simulation.rs index 22331e6..c544e83 100644 --- a/src/gui/panels/simulation.rs +++ b/src/gui/panels/simulation.rs @@ -30,13 +30,12 @@ impl SimulationPanel { ui.add_space(20.0); let changed = data_source.settings != old_settings; - let released = false; ui.horizontal(|ui| { if ui.button("Reset").clicked() { data_source.settings = SimulationSettings::default(); } - if ui.button("↻ Rerun").clicked() || (changed && released) { + if ui.button("↻ Rerun").clicked() || changed { data_source.reset(); } }); diff --git a/src/gui/simulation_settings.rs b/src/gui/simulation_settings.rs index c56afcb..21ece63 100644 --- a/src/gui/simulation_settings.rs +++ b/src/gui/simulation_settings.rs @@ -20,7 +20,7 @@ impl SimulationSettingsUiExt for SimulationSettings { .selected_text(self.replication_log_index.map(|i| ARCHIVE[i].0).unwrap_or("None")) .show_ui(ui, |ui| { ui.selectable_value(&mut self.replication_log_index, None, "None"); - for (i, (name, _, f)) in ARCHIVE.iter().enumerate() { + for (i, (name, _, f, _)) in ARCHIVE.iter().enumerate() { if f.is_none() { continue; } diff --git a/src/gui/windows/archive.rs b/src/gui/windows/archive.rs index 3715880..e8179fc 100644 --- a/src/gui/windows/archive.rs +++ b/src/gui/windows/archive.rs @@ -14,25 +14,43 @@ use log::*; use crate::data_source::LogFileDataSource; +#[cfg(all(not(target_os = "wasm"), not(target_os = "android")))] +const FLASH_DARE_A: Option<&[u8]> = Some(include_bytes!("../../../archive/dare_launch_a_flash_filtered.json").as_slice()); +#[cfg(any(target_os = "wasm", target_os = "android"))] +const FLASH_DARE_A: Option<&[u8]> = None; + +#[cfg(all(not(target_os = "wasm"), not(target_os = "android")))] +const FLASH_DARE_B: Option<&[u8]> = Some(include_bytes!("../../../archive/dare_launch_b_flash_filtered.json").as_slice()); +#[cfg(any(target_os = "wasm", target_os = "android"))] +const FLASH_DARE_B: Option<&[u8]> = None; + +#[cfg(all(not(target_os = "wasm"), not(target_os = "android")))] +const FLASH_EUROC_2023: Option<&[u8]> = Some(include_bytes!("../../../archive/euroc_2023_flash_filtered.json").as_slice()); +#[cfg(any(target_os = "wasm", target_os = "android"))] +const FLASH_EUROC_2023: Option<&[u8]> = None; + // Log files included with the application. // TODO: migrate old launches -pub const ARCHIVE: [(&str, Option<&'static str>, Option<&'static str>); 5] = [ - ("Zülpich #1", None, None), - ("Zülpich #2", None, None), +pub const ARCHIVE: [(&str, Option<&'static str>, Option<&'static str>, Option<&'static [u8]>); 5] = [ + ("Zülpich #1", None, None, None), + ("Zülpich #2", None, None, None), ( "DARE (FC A)", Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/dare_launch_a_telem_filtered.json"), Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/dare_launch_a_flash_filtered.json"), + FLASH_DARE_A, ), ( "DARE (FC B)", Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/dare_launch_b_telem_filtered.json"), Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/dare_launch_b_flash_filtered.json"), + FLASH_DARE_B, ), ( "EuRoC 2023 (ÆSIR Signý)", Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/euroc_2023_telem_filtered.json"), Some("https://raw.githubusercontent.com/tudsat-rocket/sam/main/archive/euroc_2023_flash_filtered.json"), + FLASH_EUROC_2023, ), ]; @@ -150,7 +168,7 @@ impl ArchiveWindow { .show(ctx, |ui| { ui.add_space(10.0); - for (i, (title, telem, flash)) in ARCHIVE.iter().enumerate() { + for (i, (title, telem, flash_url, _flash_bytes)) in ARCHIVE.iter().enumerate() { if i != 0 { ui.separator(); } @@ -158,8 +176,8 @@ impl ArchiveWindow { ui.horizontal(|ui| { ui.label(*title); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { - if ui.add_enabled(flash.is_some(), Button::new("🖴 Flash")).clicked() { - self.open_log(ctx, flash.unwrap()); + if ui.add_enabled(flash_url.is_some(), Button::new("🖴 Flash")).clicked() { + self.open_log(ctx, flash_url.unwrap()); } if ui.add_enabled(telem.is_some(), Button::new("📡 Telemetry")).clicked() { diff --git a/src/simulation.rs b/src/simulation.rs index 2b98f43..9223657 100644 --- a/src/simulation.rs +++ b/src/simulation.rs @@ -115,15 +115,7 @@ pub struct SimulationState { } impl SimulationState { - async fn load_archive_log(url: &str) -> Result, reqwest::Error> { - let res = reqwest::Client::new().get(url).send().await?; - Ok(res.bytes().await?.to_vec()) - } - - #[cfg(not(target_arch = "wasm32"))] - fn load_log_states(url: &str) -> Result, reqwest::Error> { - let rt = tokio::runtime::Builder::new_current_thread().enable_io().enable_time().build().unwrap(); - let bytes = rt.block_on(Self::load_archive_log(url))?; + fn load_log_states(bytes: &[u8]) -> Result, reqwest::Error> { let msgs = serde_json::from_slice::>(&bytes).unwrap(); Ok(msgs.into_iter().map(|x| x.into()).collect()) } @@ -147,9 +139,9 @@ impl SimulationState { .replication_log_index .map(|i| ARCHIVE.get(i)) .flatten() - .map(|(_, _, flash)| *flash) + .map(|(_, _, _, flash_bytes)| *flash_bytes) .flatten() - .map(|url| Self::load_log_states(url).unwrap()) + .map(|bytes| Self::load_log_states(bytes).unwrap()) .unwrap_or_default(); #[cfg(target_arch = "wasm32")] @@ -179,6 +171,7 @@ impl SimulationState { let mut accelerometer1 = None; let mut accelerometer2 = None; let mut magnetometer = None; + let mut pressure_baro = None; let mut altitude_baro = None; if let Some(first) = remaining_replication_states.pop_front() { time = first.time; @@ -187,7 +180,8 @@ impl SimulationState { accelerometer1 = first.accelerometer1; accelerometer2 = first.accelerometer2; magnetometer = first.magnetometer; - altitude_baro = first.pressure_baro.map(|p| 44307.694 * (1.0 - (p / 1013.25).powf(0.190284))); + pressure_baro = first.pressure_baro; + altitude_baro = pressure_baro.map(|p| 44307.694 * (1.0 - (p / 1013.25).powf(0.190284))); state_estimator.altitude_ground = altitude_baro.unwrap(); } @@ -215,6 +209,7 @@ impl SimulationState { accelerometer1, accelerometer2, magnetometer, + pressure_baro, altitude_baro, remaining_replication_states, @@ -332,11 +327,11 @@ impl SimulationState { self.magnetometer.unwrap() + (next.magnetometer.unwrap() - self.magnetometer.unwrap()) / delta_time as f32, ); - let altitude_baro = next.pressure_baro.map(|p| 44307.694 * (1.0 - (p / 1013.25).powf(0.190284))); - self.altitude_baro = Some( - self.altitude_baro.unwrap() - + (altitude_baro.unwrap() - self.altitude_baro.unwrap()) / delta_time as f32, + self.pressure_baro = Some( + self.pressure_baro.unwrap() + + (next.pressure_baro.unwrap() - self.pressure_baro.unwrap()) / delta_time as f32, ); + self.altitude_baro = self.pressure_baro.map(|p| 44307.694 * (1.0 - (p / 1013.25).powf(0.190284))); } false @@ -477,6 +472,7 @@ impl From<&SimulationState> for VehicleState { accelerometer1: ss.accelerometer1, accelerometer2: ss.accelerometer2, magnetometer: ss.magnetometer, + pressure_baro: ss.pressure_baro, ..Default::default() } } else {