Skip to content

Commit 31d913e

Browse files
[CPP-140]Status Bar (#60)
* Initial design for statusbar + heartbeat. * Backend seemingly works need to clean it up a bunch. * Most backend functionality working need to do frontend now. * StatusBar frontend. * Respond to review requests. * Respond to review requests. * Respond to review requests.
1 parent 2839bf6 commit 31d913e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1586
-66
lines changed

console_backend/src/constants.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub const SBAS_LABEL: &str = "SBAS";
8282
pub const NO_FIX: &str = "No Fix";
8383
pub const SPP: &str = "SPP";
8484
pub const DGNSS: &str = "DGPS";
85+
pub const RTK: &str = "RTK";
8586
pub const FLOAT: &str = "Float RTK";
8687
pub const FIXED: &str = "Fixed RTK";
8788
pub const DR: &str = "Dead Reckoning";
@@ -123,7 +124,6 @@ pub const NON_VOLATILE_MEMORY: &str = "Non Volatile Memory";
123124
pub const DECODED_THIS_SESSION: &str = "Decoded this Session";
124125
pub const UNKNOWN: &str = "Unknown";
125126

126-
pub const EMPTY_STR: &str = "--";
127127
pub const GPS_WEEK: &str = "GPS Week";
128128
pub const GPS_TOW: &str = "GPS TOW";
129129
pub const GPS_TIME: &str = "GPS Time";
@@ -188,3 +188,10 @@ pub const MPH: &str = "mph";
188188
pub const KPH: &str = "kph";
189189
pub const MPS2MPH: f64 = 2.236934;
190190
pub const MPS2KPH: f64 = 3.600000;
191+
192+
// Status Bar constants.
193+
pub const UPDATE_TOLERANCE_SECONDS: f64 = 1.2;
194+
pub const UNKNOWN_ERROR: &str = "Unk Error";
195+
pub const UNKNOWN_ERROR_SHORT: &str = "unk";
196+
pub const ODO_POSTFIX: &str = "+Odo";
197+
pub const INS_POSTFIX: &str = "+INS";

console_backend/src/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub const HEARTBEAT_LOCK_MUTEX_FAILURE: &str = "unable to lock heartbeat mutex";
2+
pub const SHARED_STATE_LOCK_MUTEX_FAILURE: &str = "unable to lock shared_state mutex";
3+
pub const CAP_N_PROTO_SERIALIZATION_FAILURE: &str = "unable to serialize capnproto message";

console_backend/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod console_backend_capnp {
55
pub mod common_constants;
66
pub mod constants;
77
pub mod date_conv;
8+
pub mod errors;
89
pub mod formatters;
910
pub mod log_panel;
1011
pub mod main_tab;
@@ -17,6 +18,7 @@ pub mod process_messages;
1718
pub mod server;
1819
pub mod solution_tab;
1920
pub mod solution_velocity_tab;
21+
pub mod status_bar;
2022
pub mod tracking_signals_tab;
2123
pub mod types;
2224
pub mod utils;

console_backend/src/main_tab.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{result::Result, thread::sleep, time::Instant};
55
use crate::observation_tab::ObservationTab;
66
use crate::solution_tab::SolutionTab;
77
use crate::solution_velocity_tab::SolutionVelocityTab;
8+
use crate::status_bar::StatusBar;
89
use crate::tracking_signals_tab::TrackingSignalsTab;
910
use crate::types::*;
1011

@@ -15,6 +16,7 @@ pub struct MainTab<'a, S: MessageSender> {
1516
pub solution_tab: SolutionTab<S>,
1617
pub observation_tab: ObservationTab<S>,
1718
pub solution_velocity_tab: SolutionVelocityTab<'a, S>,
19+
pub status_bar: StatusBar<S>,
1820
}
1921

2022
impl<'a, S: MessageSender> MainTab<'a, S> {
@@ -28,7 +30,11 @@ impl<'a, S: MessageSender> MainTab<'a, S> {
2830
),
2931
observation_tab: ObservationTab::new(shared_state.clone(), client_sender.clone()),
3032
solution_tab: SolutionTab::new(shared_state.clone(), client_sender.clone()),
31-
solution_velocity_tab: SolutionVelocityTab::new(shared_state, client_sender),
33+
solution_velocity_tab: SolutionVelocityTab::new(
34+
shared_state.clone(),
35+
client_sender.clone(),
36+
),
37+
status_bar: StatusBar::new(shared_state, client_sender),
3238
}
3339
}
3440

console_backend/src/piksi_tools_constants.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ lazy_static! {
362362
.collect::<HashMap<_, _>>();
363363
}
364364
lazy_static! {
365-
static ref rtk_mode_dict: HashMap<i32, &'static str> =
365+
pub static ref rtk_mode_dict: HashMap<i32, &'static str> =
366366
[(FLOAT_MODE, "Float"), (FIXED_MODE, "Fixed")]
367367
.iter()
368368
.cloned()
@@ -373,7 +373,7 @@ pub const DYNAMICALLY_ALIGNING: i32 = 1;
373373
pub const READY: i32 = 2;
374374
pub const GNSS_OUTAGE_MAX: i32 = 3;
375375
lazy_static! {
376-
static ref ins_mode_dict: HashMap<i32, &'static str> = [
376+
pub static ref ins_mode_dict: HashMap<i32, &'static str> = [
377377
(AWAITING_INITIALIZATION, "Init"),
378378
(DYNAMICALLY_ALIGNING, "Align"),
379379
(READY, "Ready"),
@@ -387,7 +387,7 @@ pub const IMU_DATA_ERROR: i32 = 1;
387387
pub const IMU_LICENSE_ERROR: i32 = 2;
388388
pub const IMU_CALIBRATION_ERROR: i32 = 3;
389389
lazy_static! {
390-
static ref ins_error_dict: HashMap<i32, &'static str> = [
390+
pub static ref ins_error_dict: HashMap<i32, &'static str> = [
391391
(IMU_DATA_ERROR, "Data Error"),
392392
(IMU_LICENSE_ERROR, "License Error"),
393393
(IMU_CALIBRATION_ERROR, "Cal Error")
@@ -399,10 +399,11 @@ lazy_static! {
399399
pub const SMOOTHPOSE: i32 = 0;
400400
pub const DR_RUNNER: i32 = 1;
401401
lazy_static! {
402-
static ref ins_type_dict: HashMap<i32, &'static str> = [(SMOOTHPOSE, "SP"), (DR_RUNNER, "DR")]
403-
.iter()
404-
.cloned()
405-
.collect::<HashMap<_, _>>();
402+
pub static ref ins_type_dict: HashMap<i32, &'static str> =
403+
[(SMOOTHPOSE, "SP"), (DR_RUNNER, "DR")]
404+
.iter()
405+
.cloned()
406+
.collect::<HashMap<_, _>>();
406407
}
407408
lazy_static! {
408409
static ref gps_codes: HashSet<i32> = [

console_backend/src/process_messages.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use log::debug;
22
use sbp::{
33
messages::{SBPMessage, SBP},
4+
serialize::SbpSerialize,
45
time::GpsTime,
56
};
67
use std::{thread::sleep, time::Duration};
@@ -30,10 +31,20 @@ pub fn process_messages<S: MessageSender, T>(
3031
}
3132
}
3233
let msg_name = message.get_message_name();
34+
main.status_bar.add_bytes(message.sbp_size());
3335
let mut attempt_delay = true;
3436
match message {
3537
SBP::MsgAgeCorrections(msg) => {
36-
main.solution_tab.handle_age_corrections(msg);
38+
main.solution_tab.handle_age_corrections(msg.clone());
39+
main.status_bar.handle_age_corrections(msg);
40+
}
41+
SBP::MsgBaselineNED(msg) => {
42+
main.status_bar
43+
.handle_baseline_ned(BaselineNED::MsgBaselineNED(msg));
44+
}
45+
SBP::MsgBaselineNEDDepA(msg) => {
46+
main.status_bar
47+
.handle_baseline_ned(BaselineNED::MsgBaselineNEDDepA(msg));
3748
}
3849
SBP::MsgDops(msg) => {
3950
main.solution_tab.handle_dops(Dops::MsgDops(msg));
@@ -44,11 +55,16 @@ pub fn process_messages<S: MessageSender, T>(
4455
SBP::MsgGPSTime(msg) => {
4556
main.solution_tab.handle_gps_time(msg);
4657
}
58+
SBP::MsgHeartbeat(_) => {
59+
main.status_bar.handle_heartbeat();
60+
}
4761
SBP::MsgInsStatus(msg) => {
48-
main.solution_tab.handle_ins_status(msg);
62+
main.solution_tab.handle_ins_status(msg.clone());
63+
main.status_bar.handle_ins_status(msg);
4964
}
5065
SBP::MsgInsUpdates(msg) => {
51-
main.solution_tab.handle_ins_updates(msg);
66+
main.solution_tab.handle_ins_updates(msg.clone());
67+
main.status_bar.handle_ins_updates(msg);
5268
}
5369
SBP::MsgMeasurementState(msg) => {
5470
main.tracking_signals_tab
@@ -81,10 +97,14 @@ pub fn process_messages<S: MessageSender, T>(
8197
main.observation_tab.handle_obs(ObservationMsg::MsgOsr(msg));
8298
}
8399
SBP::MsgPosLLH(msg) => {
84-
main.solution_tab.handle_pos_llh(PosLLH::MsgPosLLH(msg));
100+
main.solution_tab
101+
.handle_pos_llh(PosLLH::MsgPosLLH(msg.clone()));
102+
main.status_bar.handle_pos_llh(PosLLH::MsgPosLLH(msg));
85103
}
86104
SBP::MsgPosLLHDepA(msg) => {
87-
main.solution_tab.handle_pos_llh(PosLLH::MsgPosLLHDepA(msg));
105+
main.solution_tab
106+
.handle_pos_llh(PosLLH::MsgPosLLHDepA(msg.clone()));
107+
main.status_bar.handle_pos_llh(PosLLH::MsgPosLLHDepA(msg));
88108
}
89109
SBP::MsgTrackingState(msg) => {
90110
main.tracking_signals_tab

console_backend/src/solution_tab.rs

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::console_backend_capnp as m;
1313
use crate::constants::*;
1414
use crate::date_conv::*;
1515
use crate::output::CsvSerializer;
16+
use crate::piksi_tools_constants::EMPTY_STR;
1617
use crate::types::{
1718
Deque, Dops, GnssModes, MessageSender, PosLLH, PosLLHLog, SharedState, UtcDateTime, VelLog,
1819
VelNED,
@@ -400,40 +401,19 @@ impl<S: MessageSender> SolutionTab<S> {
400401
/// Need to validate logging.
401402
pub fn handle_pos_llh(&mut self, msg: PosLLH) {
402403
self.last_pos_mode = msg.mode();
403-
let (flags, h_accuracy, v_accuracy, tow, lat, lon, height, n_sats) = match msg {
404-
PosLLH::MsgPosLLH(msg_) => (
405-
msg_.flags,
406-
mm_to_m(msg_.h_accuracy as f64),
407-
mm_to_m(msg_.v_accuracy as f64),
408-
msg_.tow as f64,
409-
msg_.lat,
410-
msg_.lon,
411-
msg_.height,
412-
msg_.n_sats,
413-
),
414-
PosLLH::MsgPosLLHDepA(msg_) => (
415-
msg_.flags,
416-
mm_to_m(msg_.h_accuracy as f64),
417-
mm_to_m(msg_.v_accuracy as f64),
418-
msg_.tow as f64,
419-
msg_.lat,
420-
msg_.lon,
421-
msg_.height,
422-
msg_.n_sats,
423-
),
424-
};
404+
let pos_llh_fields = msg.fields();
425405
let gnss_mode = GnssModes::from(self.last_pos_mode);
426406
let mode_string = gnss_mode.to_string();
427407
if self.last_pos_mode != 0 {
428408
if !self.pending_draw_modes.contains(&mode_string) {
429409
self.pending_draw_modes.push(mode_string.clone());
430410
}
431-
self._update_sln_data_by_mode(lat, lon, mode_string);
411+
self._update_sln_data_by_mode(pos_llh_fields.lat, pos_llh_fields.lon, mode_string);
432412
} else {
433413
self._append_empty_sln_data(None);
434414
}
435-
self.ins_used = ((flags & 0x8) >> 3) == 1;
436-
let mut tow = tow * 1.0e-3_f64;
415+
self.ins_used = ((pos_llh_fields.flags & 0x8) >> 3) == 1;
416+
let mut tow = pos_llh_fields.tow * 1.0e-3_f64;
437417
if let Some(nsec) = self.nsec {
438418
tow += nsec as f64 * 1.0e-9_f64;
439419
}
@@ -469,13 +449,13 @@ impl<S: MessageSender> SolutionTab<S> {
469449
pc_time,
470450
gps_time,
471451
tow_s: Some(tow),
472-
latitude_d: Some(lat),
473-
longitude_d: Some(lon),
474-
altitude_m: Some(height),
475-
h_accuracy_m: Some(h_accuracy),
476-
v_accuracy_m: Some(v_accuracy),
477-
n_sats,
478-
flags,
452+
latitude_d: Some(pos_llh_fields.lat),
453+
longitude_d: Some(pos_llh_fields.lon),
454+
altitude_m: Some(pos_llh_fields.height),
455+
h_accuracy_m: Some(pos_llh_fields.h_accuracy),
456+
v_accuracy_m: Some(pos_llh_fields.v_accuracy),
457+
n_sats: pos_llh_fields.n_sats,
458+
flags: pos_llh_fields.flags,
479459
}) {
480460
eprintln!("Unable to to write to pos llh log, error {}.", err);
481461
}
@@ -515,17 +495,24 @@ impl<S: MessageSender> SolutionTab<S> {
515495
self.table.insert(UTC_TIME, String::from(EMPTY_STR));
516496
self.table.insert(UTC_SRC, String::from(EMPTY_STR));
517497
}
518-
self.table.insert(SATS_USED, n_sats.to_string());
519-
self.table.insert(LAT, format!("{:.12}", lat));
520-
self.table.insert(LNG, format!("{:.12}", lon));
521-
self.table.insert(HEIGHT, format!("{:.3}", height));
522-
self.table.insert(HORIZ_ACC, format!("{:.3}", h_accuracy));
523-
self.table.insert(VERT_ACC, format!("{:.3}", v_accuracy));
524-
self.lats.add(lat);
525-
self.lngs.add(lon);
498+
self.table
499+
.insert(SATS_USED, pos_llh_fields.n_sats.to_string());
500+
self.table
501+
.insert(LAT, format!("{:.12}", pos_llh_fields.lat));
502+
self.table
503+
.insert(LNG, format!("{:.12}", pos_llh_fields.lon));
504+
self.table
505+
.insert(HEIGHT, format!("{:.3}", pos_llh_fields.height));
506+
self.table
507+
.insert(HORIZ_ACC, format!("{:.3}", pos_llh_fields.h_accuracy));
508+
self.table
509+
.insert(VERT_ACC, format!("{:.3}", pos_llh_fields.v_accuracy));
510+
self.lats.add(pos_llh_fields.lat);
511+
self.lngs.add(pos_llh_fields.lon);
526512
self.modes.add(self.last_pos_mode);
527513
}
528-
self.table.insert(POS_FLAGS, format!("0x{:<03x}", flags));
514+
self.table
515+
.insert(POS_FLAGS, format!("0x{:<03x}", pos_llh_fields.flags));
529516
self.table.insert(INS_USED, self.ins_used.to_string());
530517
self.table.insert(POS_FIX_MODE, self.ins_used.to_string());
531518
if let Some(age_corrections_) = self.age_corrections {

0 commit comments

Comments
 (0)