From f14fae801f4e007402b111069a08933244e1f98d Mon Sep 17 00:00:00 2001 From: Steve Meyer Date: Thu, 2 Sep 2021 11:48:57 -0700 Subject: [PATCH 1/6] with_link --- Cargo.lock | 1 + console_backend/Cargo.toml | 1 + console_backend/src/baseline_tab.rs | 10 +- console_backend/src/broadcaster.rs | 113 ++++-- console_backend/src/lib.rs | 22 +- console_backend/src/process_messages.rs | 390 ++++++++++--------- console_backend/src/solution_velocity_tab.rs | 8 +- 7 files changed, 309 insertions(+), 236 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91bce66f2..bac6fab76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -355,6 +355,7 @@ dependencies = [ "logtest", "ndarray", "ordered-float", + "parking_lot", "paste 1.0.5", "pyo3", "rand", diff --git a/console_backend/Cargo.toml b/console_backend/Cargo.toml index 763734b80..9ca50f042 100644 --- a/console_backend/Cargo.toml +++ b/console_backend/Cargo.toml @@ -39,6 +39,7 @@ crossbeam = "0.8.1" rand = "0.8.3" slotmap = "1.0.3" serde-pickle = { version = "0.6.2", optional = true } +parking_lot = "0.11.1" [target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies] serialport = "4.0.1" diff --git a/console_backend/src/baseline_tab.rs b/console_backend/src/baseline_tab.rs index 82bfdc5f9..84101b07c 100644 --- a/console_backend/src/baseline_tab.rs +++ b/console_backend/src/baseline_tab.rs @@ -53,7 +53,7 @@ pub(crate) struct BaselineTabButtons { /// - `utc_source`: The string equivalent for the source of the UTC updates. /// - `utc_time`: The stored monotonic Utc time. /// - `week`: The stored week value from GPS Time messages. -pub struct BaselineTab<'a, S: CapnProtoSender> { +pub struct BaselineTab { age_corrections: Option, client_sender: S, heading: Option, @@ -68,16 +68,16 @@ pub struct BaselineTab<'a, S: CapnProtoSender> { shared_state: SharedState, sln_cur_data: Vec>, sln_data: Vec>, - slns: HashMap<&'a str, Deque>, - table: HashMap<&'a str, String>, + slns: HashMap<&'static str, Deque>, + table: HashMap<&'static str, String>, utc_source: Option, utc_time: Option, week: Option, wtr: MsgSender, } -impl<'a, S: CapnProtoSender> BaselineTab<'a, S> { - pub fn new(shared_state: SharedState, client_sender: S, wtr: MsgSender) -> BaselineTab<'a, S> { +impl BaselineTab { + pub fn new(shared_state: SharedState, client_sender: S, wtr: MsgSender) -> BaselineTab { BaselineTab { age_corrections: None, client_sender, diff --git a/console_backend/src/broadcaster.rs b/console_backend/src/broadcaster.rs index bc5abc908..c65c2c2eb 100644 --- a/console_backend/src/broadcaster.rs +++ b/console_backend/src/broadcaster.rs @@ -1,11 +1,7 @@ -use std::{ - convert::TryInto, - marker::PhantomData, - sync::{Arc, Mutex}, - time::Duration, -}; +use std::{convert::TryInto, marker::PhantomData, sync::Arc, time::Duration}; use crossbeam::channel; +use parking_lot::Mutex; use sbp::{ messages::{ConcreteMessage, SBPMessage, SBP}, time::{GpsTime, GpsTimeError}, @@ -19,8 +15,6 @@ pub struct Broadcaster { } impl Broadcaster { - const CHANNELS_LOCK_FAILURE: &'static str = "failed to aquire lock on channels"; - pub fn new() -> Self { Self { channels: Arc::new(Mutex::new(HopSlotMap::with_key())), @@ -29,7 +23,7 @@ impl Broadcaster { pub fn send(&self, message: &SBP, gps_time: MaybeGpsTime) { let msg_type = message.get_message_type(); - let mut channels = self.channels.lock().expect(Self::CHANNELS_LOCK_FAILURE); + let mut channels = self.channels.lock(); channels.retain(|_, chan| { if chan.msg_types.iter().any(|ty| ty == &msg_type) { chan.inner.send((message.clone(), gps_time.clone())).is_ok() @@ -44,7 +38,7 @@ impl Broadcaster { E: Event, { let (tx, rx) = channel::unbounded(); - let mut channels = self.channels.lock().expect(Self::CHANNELS_LOCK_FAILURE); + let mut channels = self.channels.lock(); let key = channels.insert(Sender { inner: tx, msg_types: E::MESSAGE_TYPES, @@ -59,7 +53,7 @@ impl Broadcaster { } pub fn unsubscribe(&self, key: Key) { - let mut channels = self.channels.lock().expect(Self::CHANNELS_LOCK_FAILURE); + let mut channels = self.channels.lock(); channels.remove(key.inner); } @@ -206,9 +200,62 @@ where } } -struct Callback<'a> { - func: Box, - msg_types: &'static [u16], +enum Callback<'a> { + Id { + func: Box, + msg_type: u16, + }, + Event { + func: Box, + msg_types: &'static [u16], + }, +} + +impl<'a> Callback<'a> { + fn run(&mut self, msg: SBP, time: MaybeGpsTime) { + match self { + Callback::Id { func, .. } | Callback::Event { func, .. } => (func)(msg, time), + } + } + + fn should_run(&self, msg: u16) -> bool { + match self { + Callback::Id { msg_type, .. } => msg_type == &msg, + Callback::Event { msg_types, .. } => msg_types.contains(&msg), + } + } +} + +pub fn with_link<'env, F>(f: F) +where + F: FnOnce(&LinkSource<'env>), +{ + let source: LinkSource<'env> = LinkSource { link: Link::new() }; + f(&source); +} + +pub struct LinkSource<'env> { + link: Link<'env>, +} + +impl<'env> LinkSource<'env> { + pub fn link<'scope>(&self) -> Link<'scope> + where + 'env: 'scope, + { + let link: Link<'scope> = unsafe { std::mem::transmute(self.link.clone()) }; + link + } + + pub fn send(&self, message: &SBP, gps_time: MaybeGpsTime) -> bool { + self.link.send(message, gps_time) + } +} + +impl<'env> Drop for LinkSource<'env> { + fn drop(&mut self) { + self.link.callbacks.lock().clear(); + } } pub struct Link<'a> { @@ -216,8 +263,6 @@ pub struct Link<'a> { } impl<'a> Link<'a> { - const CB_LOCK_FAILURE: &'static str = "failed to aquire lock on callbacks"; - pub fn new() -> Self { Self { callbacks: Arc::new(Mutex::new(DenseSlotMap::with_key())), @@ -226,25 +271,35 @@ impl<'a> Link<'a> { pub fn send(&self, message: &SBP, gps_time: MaybeGpsTime) -> bool { let msg_type = message.get_message_type(); - let mut cbs = self.callbacks.lock().expect(Self::CB_LOCK_FAILURE); - let to_call = cbs - .values_mut() - .filter(|cb| cb.msg_types.is_empty() || cb.msg_types.iter().any(|ty| ty == &msg_type)); + let mut cbs = self.callbacks.lock(); + let to_call = cbs.values_mut().filter(|cb| cb.should_run(msg_type)); let mut called = false; for cb in to_call { - (cb.func)(message.clone(), gps_time.clone()); + cb.run(message.clone(), gps_time.clone()); called = true; } called } - pub fn register_cb(&mut self, mut handler: H) -> Key + pub fn register_cb_by_id(&self, id: u16, mut handler: H) -> Key + where + H: FnMut(SBP) + Send + 'a, + { + let mut cbs = self.callbacks.lock(); + let inner = cbs.insert(Callback::Id { + func: Box::new(move |msg, _time| (handler)(msg)), + msg_type: id, + }); + Key { inner } + } + + pub fn register_cb(&self, mut handler: H) -> Key where H: Handler + Send + 'a, E: Event, { - let mut cbs = self.callbacks.lock().expect(Self::CB_LOCK_FAILURE); - let inner = cbs.insert(Callback { + let mut cbs = self.callbacks.lock(); + let inner = cbs.insert(Callback::Event { func: Box::new(move |msg, time| { let event = E::from_sbp(msg); handler.run(event, time) @@ -255,7 +310,7 @@ impl<'a> Link<'a> { } pub fn unregister_cb(&self, key: Key) { - let mut cbs = self.callbacks.lock().expect(Self::CB_LOCK_FAILURE); + let mut cbs = self.callbacks.lock(); cbs.remove(key.inner); } } @@ -268,12 +323,6 @@ impl Clone for Link<'_> { } } -impl Default for Link<'_> { - fn default() -> Self { - Self::new() - } -} - #[cfg(test)] mod tests { use crossbeam::scope; @@ -296,7 +345,7 @@ mod tests { #[test] fn test_dispatcher() { - let mut d = Link::new(); + let d = Link::new(); let mut c = Counter { count: 0 }; d.register_cb(|obs| c.obs(obs)); d.send(&make_msg_obs(), None); diff --git a/console_backend/src/lib.rs b/console_backend/src/lib.rs index 36fa566be..468194fd0 100644 --- a/console_backend/src/lib.rs +++ b/console_backend/src/lib.rs @@ -42,24 +42,27 @@ use crate::{ tracking_signals_tab::TrackingSignalsTab, }; -struct Tabs<'a, S: types::CapnProtoSender> { +struct Tabs<'link, S: types::CapnProtoSender> { pub main: Mutex>, pub advanced_ins: Mutex>, pub advanced_magnetometer: Mutex>, - pub baseline: Mutex>, + pub baseline: Mutex>, pub tracking_signals: Mutex>, pub solution: Mutex>, pub observation: Mutex>, - pub solution_velocity: Mutex>, + pub solution_velocity: Mutex>, pub advanced_spectrum_analyzer: Mutex>, pub status_bar: Mutex>, + _link: broadcaster::Link<'link>, + // pub settings_tab: Mutex>, } -impl<'a, S: types::CapnProtoSender> Tabs<'a, S> { +impl<'link, S: types::CapnProtoSender> Tabs<'link, S> { fn new( shared_state: types::SharedState, client_sender: S, msg_sender: types::MsgSender, + link: broadcaster::Link<'link>, ) -> Self { Self { main: MainTab::new(shared_state.clone(), client_sender.clone()).into(), @@ -69,8 +72,12 @@ impl<'a, S: types::CapnProtoSender> Tabs<'a, S> { client_sender.clone(), ) .into(), - baseline: BaselineTab::new(shared_state.clone(), client_sender.clone(), msg_sender) - .into(), + baseline: BaselineTab::new( + shared_state.clone(), + client_sender.clone(), + msg_sender.clone(), + ) + .into(), tracking_signals: TrackingSignalsTab::new(shared_state.clone(), client_sender.clone()) .into(), observation: ObservationTab::new(shared_state.clone(), client_sender.clone()).into(), @@ -85,7 +92,8 @@ impl<'a, S: types::CapnProtoSender> Tabs<'a, S> { client_sender.clone(), ) .into(), - status_bar: StatusBar::new(shared_state, client_sender).into(), + status_bar: StatusBar::new(shared_state.clone(), client_sender.clone()).into(), + _link: link, } } } diff --git a/console_backend/src/process_messages.rs b/console_backend/src/process_messages.rs index e61c56f55..bab683d1a 100644 --- a/console_backend/src/process_messages.rs +++ b/console_backend/src/process_messages.rs @@ -16,18 +16,18 @@ use sbp::{ serialize::SbpSerialize, }; -use crate::broadcaster::Link; use crate::connection::Connection; use crate::constants::PAUSE_LOOP_SLEEP_DURATION_MS; -use crate::log_panel::handle_log_msg; use crate::types::*; use crate::utils::{close_frontend, refresh_navbar}; use crate::Tabs; +use crate::log_panel::handle_log_msg; +use crate::broadcaster::with_link; pub fn process_messages( conn: Connection, shared_state: SharedState, - mut client_send: S, + client_send: S, ) -> Result<()> where S: CapnProtoSender, @@ -38,199 +38,213 @@ where let msg_sender = MsgSender::new(wtr); shared_state.set_current_connection(conn.name()); refresh_navbar(&mut client_send.clone(), shared_state.clone()); - let tabs = Tabs::new(shared_state.clone(), client_send.clone(), msg_sender); - let messages = sbp::iter_messages(rdr) - .handle_errors(|e| { - debug!("{}", e); - match e { - sbp::Error::IoError(err) => { - if (*err).kind() == ErrorKind::TimedOut { - shared_state.set_running(false, client_send.clone()); + let messages = { + let state = shared_state.clone(); + let client = client_send.clone(); + sbp::iter_messages(rdr) + .handle_errors(move |e| { + debug!("{}", e); + match e { + sbp::Error::IoError(err) => { + if (*err).kind() == ErrorKind::TimedOut { + state.set_running(false, client.clone()); + } + ControlFlow::Break } - ControlFlow::Break + _ => ControlFlow::Continue, } - _ => ControlFlow::Continue, + }) + .with_rover_time() + }; + + with_link(|source| { + let tabs = Tabs::new( + shared_state.clone(), + client_send.clone(), + msg_sender, + source.link(), + ); + + let link = source.link(); + + link.register_cb(|msg: MsgAgeCorrections| { + tabs.baseline + .lock() + .unwrap() + .handle_age_corrections(msg.clone()); + tabs.solution + .lock() + .unwrap() + .handle_age_corrections(msg.clone()); + tabs.status_bar.lock().unwrap().handle_age_corrections(msg); + }); + + link.register_cb(|msg: MsgAngularRate| { + tabs.solution.lock().unwrap().handle_angular_rate(msg); + }); + + link.register_cb(|msg: MsgBaselineHeading| { + tabs.baseline.lock().unwrap().handle_baseline_heading(msg); + }); + + link.register_cb(|msg: BaselineNED| { + tabs.baseline + .lock() + .unwrap() + .handle_baseline_ned(msg.clone()); + tabs.status_bar.lock().unwrap().handle_baseline_ned(msg); + }); + + link.register_cb(|msg: Dops| { + tabs.solution.lock().unwrap().handle_dops(msg); + }); + + link.register_cb(|msg: GpsTime| { + tabs.baseline.lock().unwrap().handle_gps_time(msg.clone()); + tabs.solution.lock().unwrap().handle_gps_time(msg); + }); + + link.register_cb(|_: MsgHeartbeat| { + tabs.status_bar.lock().unwrap().handle_heartbeat(); + }); + + link.register_cb(|msg: MsgImuAux| { + tabs.advanced_ins.lock().unwrap().handle_imu_aux(msg); + }); + + link.register_cb(|msg: MsgImuRaw| { + tabs.advanced_ins.lock().unwrap().handle_imu_raw(msg); + }); + + link.register_cb(|msg: MsgInsStatus| { + tabs.solution.lock().unwrap().handle_ins_status(msg.clone()); + tabs.status_bar.lock().unwrap().handle_ins_status(msg); + }); + + link.register_cb(|msg: MsgInsUpdates| { + tabs.advanced_ins + .lock() + .unwrap() + .fusion_engine_status_bar + .handle_ins_updates(msg.clone()); + tabs.solution + .lock() + .unwrap() + .handle_ins_updates(msg.clone()); + tabs.status_bar.lock().unwrap().handle_ins_updates(msg); + }); + + link.register_cb(|msg: MsgMagRaw| { + tabs.advanced_magnetometer + .lock() + .unwrap() + .handle_mag_raw(msg); + }); + + link.register_cb(|msg: MsgMeasurementState| { + tabs.tracking_signals + .lock() + .unwrap() + .handle_msg_measurement_state(msg.states); + }); + + link.register_cb(|msg: ObservationMsg| { + tabs.tracking_signals + .lock() + .unwrap() + .handle_obs(msg.clone()); + tabs.observation.lock().unwrap().handle_obs(msg); + }); + + link.register_cb(|_: MsgObsDepA| { + println!("The message type, MsgObsDepA, is not handled in the Tracking->SignalsPlot or Observation tab."); + }); + + link.register_cb(|msg: MsgOrientEuler| { + tabs.solution.lock().unwrap().handle_orientation_euler(msg); + }); + + link.register_cb(|msg: PosLLH| { + tabs.solution.lock().unwrap().handle_pos_llh(msg.clone()); + tabs.status_bar.lock().unwrap().handle_pos_llh(msg); + }); + + link.register_cb(|msg: MsgPosLLHCov| { + tabs.solution.lock().unwrap().handle_pos_llh_cov(msg); + }); + + link.register_cb(|msg: Specan| { + tabs.advanced_spectrum_analyzer + .lock() + .unwrap() + .handle_specan(msg); + }); + + link.register_cb(|msg: MsgTrackingState| { + tabs.tracking_signals + .lock() + .unwrap() + .handle_msg_tracking_state(msg.states); + }); + + link.register_cb(|msg: VelNED| { + tabs.solution.lock().unwrap().handle_vel_ned(msg); + }); + + link.register_cb(|msg: MsgVelNED| { + // why does this tab not take both VelNED messages? + tabs.solution_velocity.lock().unwrap().handle_vel_ned(msg); + }); + + link.register_cb(|msg: MsgUtcTime| { + tabs.baseline.lock().unwrap().handle_utc_time(msg.clone()); + tabs.solution.lock().unwrap().handle_utc_time(msg); + }); + + link.register_cb(handle_log_msg); + + let shared_state = shared_state.clone(); + let mut client_send = client_send.clone(); + + for (message, gps_time) in messages { + if !shared_state.is_running() { + if let Err(e) = tabs.main.lock().unwrap().end_csv_logging() { + error!("Issue closing csv file, {}", e); + } + tabs.main.lock().unwrap().close_sbp(); + break; } - }) - .with_rover_time(); - - let mut link = Link::new(); - - link.register_cb(|msg: MsgAgeCorrections| { - tabs.baseline - .lock() - .unwrap() - .handle_age_corrections(msg.clone()); - tabs.solution - .lock() - .unwrap() - .handle_age_corrections(msg.clone()); - tabs.status_bar.lock().unwrap().handle_age_corrections(msg); - }); - - link.register_cb(|msg: MsgAngularRate| { - tabs.solution.lock().unwrap().handle_angular_rate(msg); - }); - - link.register_cb(|msg: MsgBaselineHeading| { - tabs.baseline.lock().unwrap().handle_baseline_heading(msg); - }); - - link.register_cb(|msg: BaselineNED| { - tabs.baseline - .lock() - .unwrap() - .handle_baseline_ned(msg.clone()); - tabs.status_bar.lock().unwrap().handle_baseline_ned(msg); - }); - - link.register_cb(|msg: Dops| { - tabs.solution.lock().unwrap().handle_dops(msg); - }); - - link.register_cb(|msg: GpsTime| { - tabs.baseline.lock().unwrap().handle_gps_time(msg.clone()); - tabs.solution.lock().unwrap().handle_gps_time(msg); - }); - - link.register_cb(|_: MsgHeartbeat| { - tabs.status_bar.lock().unwrap().handle_heartbeat(); - }); - - link.register_cb(|msg: MsgImuAux| { - tabs.advanced_ins.lock().unwrap().handle_imu_aux(msg); - }); - - link.register_cb(|msg: MsgImuRaw| { - tabs.advanced_ins.lock().unwrap().handle_imu_raw(msg); - }); - - link.register_cb(|msg: MsgInsStatus| { - tabs.solution.lock().unwrap().handle_ins_status(msg.clone()); - tabs.status_bar.lock().unwrap().handle_ins_status(msg); - }); - - link.register_cb(|msg: MsgInsUpdates| { - tabs.advanced_ins - .lock() - .unwrap() - .fusion_engine_status_bar - .handle_ins_updates(msg.clone()); - tabs.solution - .lock() - .unwrap() - .handle_ins_updates(msg.clone()); - tabs.status_bar.lock().unwrap().handle_ins_updates(msg); - }); - - link.register_cb(|msg: MsgMagRaw| { - tabs.advanced_magnetometer - .lock() - .unwrap() - .handle_mag_raw(msg); - }); - - link.register_cb(|msg: MsgMeasurementState| { - tabs.tracking_signals - .lock() - .unwrap() - .handle_msg_measurement_state(msg.states); - }); - - link.register_cb(|msg: ObservationMsg| { - tabs.tracking_signals - .lock() - .unwrap() - .handle_obs(msg.clone()); - tabs.observation.lock().unwrap().handle_obs(msg); - }); - - link.register_cb(|_: MsgObsDepA| { - println!("The message type, MsgObsDepA, is not handled in the Tracking->SignalsPlot or Observation tab."); - }); - - link.register_cb(|msg: MsgOrientEuler| { - tabs.solution.lock().unwrap().handle_orientation_euler(msg); - }); - - link.register_cb(|msg: PosLLH| { - tabs.solution.lock().unwrap().handle_pos_llh(msg.clone()); - tabs.status_bar.lock().unwrap().handle_pos_llh(msg); - }); - - link.register_cb(|msg: MsgPosLLHCov| { - tabs.solution.lock().unwrap().handle_pos_llh_cov(msg); - }); - - link.register_cb(|msg: Specan| { - tabs.advanced_spectrum_analyzer - .lock() - .unwrap() - .handle_specan(msg); - }); - - link.register_cb(|msg: MsgTrackingState| { - tabs.tracking_signals - .lock() - .unwrap() - .handle_msg_tracking_state(msg.states); - }); - - link.register_cb(|msg: VelNED| { - tabs.solution.lock().unwrap().handle_vel_ned(msg); - }); - - link.register_cb(|msg: MsgVelNED| { - // why does this tab not take both VelNED messages? - tabs.solution_velocity.lock().unwrap().handle_vel_ned(msg); - }); - - link.register_cb(|msg: MsgUtcTime| { - tabs.baseline.lock().unwrap().handle_utc_time(msg.clone()); - tabs.solution.lock().unwrap().handle_utc_time(msg); - }); - - link.register_cb(handle_log_msg); - - for (message, gps_time) in messages { - if !shared_state.is_running() { - if let Err(e) = tabs.main.lock().unwrap().end_csv_logging() { - error!("Issue closing csv file, {}", e); + if shared_state.is_paused() { + loop { + if !shared_state.is_paused() { + break; + } + sleep(Duration::from_millis(PAUSE_LOOP_SLEEP_DURATION_MS)); + } } - tabs.main.lock().unwrap().close_sbp(); - break; - } - if shared_state.is_paused() { - loop { - if !shared_state.is_paused() { - break; + let sent = source.send(&message, gps_time.clone()); + tabs.main.lock().unwrap().serialize_sbp(&message); + tabs.status_bar + .lock() + .unwrap() + .add_bytes(message.sbp_size()); + if let RealtimeDelay::On = realtime_delay { + if sent { + tabs.main.lock().unwrap().realtime_delay(gps_time); + } else { + debug!( + "Message, {}, ignored for realtime delay.", + message.get_message_name() + ); } - sleep(Duration::from_millis(PAUSE_LOOP_SLEEP_DURATION_MS)); } + log::logger().flush(); } - tabs.main.lock().unwrap().serialize_sbp(&message); - tabs.status_bar - .lock() - .unwrap() - .add_bytes(message.sbp_size()); - let sent = link.send(&message, gps_time.clone()); - if let RealtimeDelay::On = realtime_delay { - if sent { - tabs.main.lock().unwrap().realtime_delay(gps_time); - } else { - debug!( - "Message, {}, ignored for realtime delay.", - message.get_message_name() - ); - } + if conn.close_when_done() { + shared_state.set_running(false, client_send.clone()); + close_frontend(&mut client_send); } - log::logger().flush(); - } - - if conn.close_when_done() { - shared_state.set_running(false, client_send.clone()); - close_frontend(&mut client_send); - } + }); Ok(()) } diff --git a/console_backend/src/solution_velocity_tab.rs b/console_backend/src/solution_velocity_tab.rs index 825df59a3..9019012fe 100644 --- a/console_backend/src/solution_velocity_tab.rs +++ b/console_backend/src/solution_velocity_tab.rs @@ -22,8 +22,8 @@ use crate::utils::serialize_capnproto_builder; /// - `tow`: The GPS Time of Week. /// - `unit`: Currently displayed and converted to unit of measure. #[derive(Debug)] -pub struct SolutionVelocityTab<'a, S: CapnProtoSender> { - pub available_units: Vec<&'a str>, +pub struct SolutionVelocityTab { + pub available_units: Vec<&'static str>, pub client_sender: S, pub colors: Vec, pub max: f64, @@ -35,8 +35,8 @@ pub struct SolutionVelocityTab<'a, S: CapnProtoSender> { pub unit: VelocityUnits, } -impl<'a, S: CapnProtoSender> SolutionVelocityTab<'a, S> { - pub fn new(shared_state: SharedState, client_sender: S) -> SolutionVelocityTab<'a, S> { +impl SolutionVelocityTab { + pub fn new(shared_state: SharedState, client_sender: S) -> SolutionVelocityTab { SolutionVelocityTab { available_units: vec![ VelocityUnits::Mps.as_str(), From e5cda8531fcce5d845f7c1dafd93963de0bf3ab3 Mon Sep 17 00:00:00 2001 From: Steve Meyer Date: Thu, 2 Sep 2021 11:55:33 -0700 Subject: [PATCH 2/6] cleanup --- console_backend/src/lib.rs | 1 - console_backend/src/process_messages.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/console_backend/src/lib.rs b/console_backend/src/lib.rs index 468194fd0..057662329 100644 --- a/console_backend/src/lib.rs +++ b/console_backend/src/lib.rs @@ -54,7 +54,6 @@ struct Tabs<'link, S: types::CapnProtoSender> { pub advanced_spectrum_analyzer: Mutex>, pub status_bar: Mutex>, _link: broadcaster::Link<'link>, - // pub settings_tab: Mutex>, } impl<'link, S: types::CapnProtoSender> Tabs<'link, S> { diff --git a/console_backend/src/process_messages.rs b/console_backend/src/process_messages.rs index bab683d1a..bd850d77a 100644 --- a/console_backend/src/process_messages.rs +++ b/console_backend/src/process_messages.rs @@ -16,13 +16,13 @@ use sbp::{ serialize::SbpSerialize, }; +use crate::broadcaster::with_link; use crate::connection::Connection; use crate::constants::PAUSE_LOOP_SLEEP_DURATION_MS; +use crate::log_panel::handle_log_msg; use crate::types::*; use crate::utils::{close_frontend, refresh_navbar}; use crate::Tabs; -use crate::log_panel::handle_log_msg; -use crate::broadcaster::with_link; pub fn process_messages( conn: Connection, From 57df8ed86fc6fef84d7cfa604aba0e8625fc8bef Mon Sep 17 00:00:00 2001 From: Steve Meyer Date: Thu, 2 Sep 2021 12:15:26 -0700 Subject: [PATCH 3/6] lint --- console_backend/src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/console_backend/src/lib.rs b/console_backend/src/lib.rs index 057662329..fa14e394b 100644 --- a/console_backend/src/lib.rs +++ b/console_backend/src/lib.rs @@ -71,12 +71,8 @@ impl<'link, S: types::CapnProtoSender> Tabs<'link, S> { client_sender.clone(), ) .into(), - baseline: BaselineTab::new( - shared_state.clone(), - client_sender.clone(), - msg_sender.clone(), - ) - .into(), + baseline: BaselineTab::new(shared_state.clone(), client_sender.clone(), msg_sender) + .into(), tracking_signals: TrackingSignalsTab::new(shared_state.clone(), client_sender.clone()) .into(), observation: ObservationTab::new(shared_state.clone(), client_sender.clone()).into(), @@ -91,7 +87,7 @@ impl<'link, S: types::CapnProtoSender> Tabs<'link, S> { client_sender.clone(), ) .into(), - status_bar: StatusBar::new(shared_state.clone(), client_sender.clone()).into(), + status_bar: StatusBar::new(shared_state, client_sender).into(), _link: link, } } From 4157d38d6d24385e82edf7a3030774ecafa7ff5e Mon Sep 17 00:00:00 2001 From: Steve Meyer Date: Thu, 2 Sep 2021 12:45:20 -0700 Subject: [PATCH 4/6] default --- console_backend/src/broadcaster.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/console_backend/src/broadcaster.rs b/console_backend/src/broadcaster.rs index c65c2c2eb..3271da9bb 100644 --- a/console_backend/src/broadcaster.rs +++ b/console_backend/src/broadcaster.rs @@ -323,6 +323,12 @@ impl Clone for Link<'_> { } } +impl<'a> Default for Link<'a> { + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod tests { use crossbeam::scope; From f1f8385fb20c525c79358fa887023da50437fd8a Mon Sep 17 00:00:00 2001 From: Steve Meyer Date: Thu, 2 Sep 2021 13:41:54 -0700 Subject: [PATCH 5/6] try capnproto 0.8 on windows --- .github/workflows/main.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 91d776553..45f44ca05 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,7 +60,7 @@ jobs: elif [ "$RUNNER_OS" == "macOS" ]; then brew install capnp llvm elif [ "$RUNNER_OS" == "Windows" ]; then - choco install -y capnproto + choco install -y capnproto --version 0.8.0 fi - name: Pull Git LFS objects @@ -259,7 +259,8 @@ jobs: elif [ "$RUNNER_OS" == "macOS" ]; then brew install capnp llvm elif [ "$RUNNER_OS" == "Windows" ]; then - choco install capnproto nsis + choco install capnproto --version 0.8.0 + choco install nsis fi - name: Install stable Rust From dd346dbe95ae06527dbe058a3396f9c6e00c0efb Mon Sep 17 00:00:00 2001 From: Steve Meyer Date: Thu, 2 Sep 2021 13:49:03 -0700 Subject: [PATCH 6/6] Revert "try capnproto 0.8 on windows" This reverts commit f1f8385fb20c525c79358fa887023da50437fd8a. --- .github/workflows/main.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 45f44ca05..91d776553 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,7 +60,7 @@ jobs: elif [ "$RUNNER_OS" == "macOS" ]; then brew install capnp llvm elif [ "$RUNNER_OS" == "Windows" ]; then - choco install -y capnproto --version 0.8.0 + choco install -y capnproto fi - name: Pull Git LFS objects @@ -259,8 +259,7 @@ jobs: elif [ "$RUNNER_OS" == "macOS" ]; then brew install capnp llvm elif [ "$RUNNER_OS" == "Windows" ]; then - choco install capnproto --version 0.8.0 - choco install nsis + choco install capnproto nsis fi - name: Install stable Rust