From b00a6bc5f1552fe3a51b1fe54253abc86e671b52 Mon Sep 17 00:00:00 2001 From: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:47:36 +0100 Subject: [PATCH] wip Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> --- examples/tui/src/app.rs | 10 +-- examples/tui/src/cli.rs | 2 +- examples/tui/src/device.rs | 42 +++++------- examples/tui/src/ui.rs | 129 ++++++++++++++----------------------- 4 files changed, 68 insertions(+), 115 deletions(-) diff --git a/examples/tui/src/app.rs b/examples/tui/src/app.rs index 158090d..1a614df 100644 --- a/examples/tui/src/app.rs +++ b/examples/tui/src/app.rs @@ -4,7 +4,7 @@ use std::vec; use ublox::{ EsfAlgStatus, EsfSensorFaults, EsfSensorStatusCalibration, EsfSensorStatusTime, EsfSensorType, EsfStatusFusionMode, EsfStatusImuInit, EsfStatusInsInit, EsfStatusMountAngle, - EsfStatusWheelTickInit, + EsfStatusWheelTickInit, GpsFix, NavPvtFlags, }; pub struct TabsState<'a> { @@ -63,8 +63,8 @@ pub struct NavPvtWidgetState { pub pdop: f64, pub satellites_used: u8, - pub position_fix_type: String, - pub fix_flags: String, + pub position_fix_type: GpsFix, + pub fix_flags: NavPvtFlags, pub time_date_confirmation: String, pub invalid_llh: bool, pub position_accuracy: (f64, f64), @@ -94,8 +94,8 @@ impl Default for NavPvtWidgetState { velocity_accuracy: f64::NAN, heading_accuracy: f64::NAN, magnetic_declination_accuracy: f64::NAN, - position_fix_type: "No Fix".to_string(), - fix_flags: "???".to_string(), + position_fix_type: GpsFix::NoFix, + fix_flags: NavPvtFlags::empty(), utc_date_time: "N/A".to_string(), time_date_confirmation: "Date: ?, Time: ?".to_string(), } diff --git a/examples/tui/src/cli.rs b/examples/tui/src/cli.rs index bbe2c45..34b99de 100644 --- a/examples/tui/src/cli.rs +++ b/examples/tui/src/cli.rs @@ -10,7 +10,7 @@ pub fn parse_args() -> clap::ArgMatches { .value_name("tui-rate") .long("tui-rate") .required(false) - .default_value("250") + .default_value("100") .value_parser(value_parser!(u64)) .help("TUI refresh rate in milliseconds"), ) diff --git a/examples/tui/src/device.rs b/examples/tui/src/device.rs index c45af7e..5cb3ae5 100644 --- a/examples/tui/src/device.rs +++ b/examples/tui/src/device.rs @@ -225,18 +225,20 @@ impl Device { info!("Opened uBlox device, waiting for messages..."); thread::spawn(move || loop { let res = self.update(|packet| match packet { - PacketRef::MonVer(packet) => { - trace!("{:?}", packet); + PacketRef::MonVer(pkg) => { + trace!("{:?}", pkg); info!( "SW version: {} HW version: {}; Extensions: {:?}", - packet.software_version(), - packet.hardware_version(), - packet.extension().collect::>() + pkg.software_version(), + pkg.hardware_version(), + pkg.extension().collect::>() ); - let mut state = MonVersionState::default(); - state.software_version = packet.software_version().to_string(); - state.hardware_version = packet.hardware_version().to_string(); - for s in packet.extension() { + let mut state = MonVersionState { + software_version: pkg.software_version().to_string(), + hardware_version: pkg.hardware_version().to_string(), + ..Default::default() + }; + for s in pkg.extension() { state.extensions.push_str(s); } sender.send(UbxStatus::MonVer(Box::new(state))).unwrap(); @@ -254,9 +256,9 @@ impl Device { } if pkg.flags2().contains(NavPvtFlags2::CONFIRMED_TIME) { - state.time_date_confirmation.push_str(",Time: CONFIRMED"); + state.time_date_confirmation.push_str(", Time: CONFIRMED"); } else { - state.time_date_confirmation.push_str(",Time: ?"); + state.time_date_confirmation.push_str(", Time: ?"); } if pkg.flags2().contains(NavPvtFlags2::CONFIRMED_AVAI) { @@ -274,22 +276,8 @@ impl Device { state.utc_time_accuracy = pkg.time_accuracy(); } - state.position_fix_type = match pkg.fix_type() { - GpsFix::DeadReckoningOnly => "DR", - GpsFix::Fix2D => "2D Fix", - GpsFix::Fix3D => "3D Fix", - GpsFix::GPSPlusDeadReckoning => "3D + DR", - GpsFix::TimeOnlyFix => "Time Only", - _ => "No Fix", - } - .to_string(); - - if pkg.flags().contains(NavPvtFlags::GPS_FIX_OK) { - state.fix_flags = "FixOK".to_string(); - } - if pkg.flags().contains(NavPvtFlags::DIFF_SOLN) { - state.fix_flags.push_str(" + DGNSS"); - } + state.position_fix_type = pkg.fix_type(); + state.fix_flags = pkg.flags(); state.lat = pkg.lat_degrees(); state.lon = pkg.lon_degrees(); diff --git a/examples/tui/src/ui.rs b/examples/tui/src/ui.rs index b6be12a..9cf8475 100644 --- a/examples/tui/src/ui.rs +++ b/examples/tui/src/ui.rs @@ -14,7 +14,7 @@ use ratatui::{ use ublox::{ EsfAlgStatus, EsfSensorFaults, EsfSensorStatusCalibration, EsfSensorStatusTime, EsfSensorType, EsfStatusFusionMode, EsfStatusImuInit, EsfStatusInsInit, EsfStatusMountAngle, - EsfStatusWheelTickInit, + EsfStatusWheelTickInit, GpsFix, NavPvtFlags, }; use crate::app::App; @@ -92,70 +92,51 @@ fn render_pvt_state(frame: &mut Frame, area: Rect, app: &mut App) { app.pvt_state.magnetic_declination, app.pvt_state.magnetic_declination_accuracy ); + let gps_fix = match app.pvt_state.position_fix_type { + GpsFix::DeadReckoningOnly => "DR", + GpsFix::Fix2D => "2D Fix", + GpsFix::Fix3D => "3D Fix", + GpsFix::GPSPlusDeadReckoning => "3D + DR", + GpsFix::TimeOnlyFix => "Time Only", + _ => "No Fix", + }; + + let mut fix_flags = String::default(); + if app.pvt_state.fix_flags.contains(NavPvtFlags::GPS_FIX_OK) { + fix_flags = "FixOK".to_string(); + } + if app.pvt_state.fix_flags.contains(NavPvtFlags::DIFF_SOLN) { + fix_flags.push_str(" + DGNSS"); + } + let rows = [ + Row::new(["GPS Time Tag", &time_tag, "[s]"]), + Row::new(["UTC Date Time", &app.pvt_state.utc_date_time, ""]), Row::new([ - Cow::Borrowed("GPS Time Tag"), - Cow::Borrowed(&time_tag), - Cow::Borrowed("[s]"), - ]), - Row::new([ - Cow::Borrowed("UTC Date Time"), - Cow::Borrowed(&app.pvt_state.utc_date_time), - Cow::Borrowed(""), - ]), - Row::new([ - Cow::Borrowed("UTC Date Time Confirmation"), - Cow::Borrowed(&app.pvt_state.time_date_confirmation), - Cow::Borrowed(""), + "UTC Date Time Confirmation", + &app.pvt_state.time_date_confirmation, + "", ]), + Row::new(["UTC Time Accuracy", &time_accuracy, "[ns]"]), + Row::new(["Position Fix Type", gps_fix, ""]), + Row::new(["Fix Flags", &fix_flags, ""]), + Row::new(["PSM State", "n/a", ""]), + Row::new(["Lat,Lon,Height,MSL", &position, "[deg,deg,m,m]"]), Row::new([ - Cow::Borrowed("UTC Time Accuracy"), - Cow::Borrowed(&time_accuracy), - Cow::Borrowed("[ns]"), - ]), - Row::new([ - Cow::Borrowed("Position Fix Type"), - Cow::Borrowed(&app.pvt_state.position_fix_type), - Cow::Borrowed(""), - ]), - Row::new([ - Cow::Borrowed("Fix Flags"), - Cow::Borrowed(&app.pvt_state.fix_flags), - Cow::Borrowed(""), - ]), - Row::new([ - Cow::Borrowed("PSM State"), - Cow::Borrowed("n/a"), - Cow::Borrowed(""), - ]), - Row::new([ - Cow::Borrowed("Lat,Lon,Height,MSL"), - Cow::Borrowed(&position), - Cow::Borrowed("[deg,deg,m,m]"), - ]), - Row::new([ - Cow::Borrowed("Invalid Position"), - Cow::Borrowed(if app.pvt_state.invalid_llh { + "Invalid Position", + if app.pvt_state.invalid_llh { "Yes" } else { "No" - }), - Cow::Borrowed(""), - ]), - Row::new([ - Cow::Borrowed("Position Accuracy Horiz, Vert"), - Cow::Borrowed(&position_accuracy), - Cow::Borrowed("[m,m]"), - ]), - Row::new([ - Cow::Borrowed("Velocity NED"), - Cow::Borrowed(&velocity_ned), - Cow::Borrowed("[m/s,m/s,m/s]"), + }, + "", ]), + Row::new(["Position Accuracy Horiz, Vert", &position_accuracy, "[m,m]"]), + Row::new(["Velocity NED", &velocity_ned, "[m/s,m/s,m/s]"]), Row::new([ - Cow::Borrowed("Velocity, Heading Accuracy"), - Cow::Borrowed(&velocity_heading_acc), - Cow::Borrowed("[m/s, deg]"), + "Velocity, Heading Accuracy", + &velocity_heading_acc, + "[m/s, deg]", ]), Row::new([ Cow::Borrowed("Speed over Ground"), @@ -163,14 +144,14 @@ fn render_pvt_state(frame: &mut Frame, area: Rect, app: &mut App) { Cow::Borrowed("[m/s]"), ]), Row::new([ - Cow::Borrowed("Heading Motion, Heading Vehicle"), - Cow::Borrowed(&heading_info), - Cow::Borrowed("[deg,deg]"), + "Heading Motion, Heading Vehicle", + &heading_info, + "[deg,deg]", ]), Row::new([ - Cow::Borrowed("Magnetic Declination, Declination Accuracy"), - Cow::Borrowed(&magnetic_declination), - Cow::Borrowed("[deg,deg]"), + "Magnetic Declination, Declination Accuracy", + &magnetic_declination, + "[deg,deg]", ]), Row::new([ Cow::Borrowed("PDOP"), @@ -182,26 +163,10 @@ fn render_pvt_state(frame: &mut Frame, area: Rect, app: &mut App) { Cow::Owned(app.pvt_state.satellites_used.to_string()), Cow::Borrowed(""), ]), - Row::new([ - Cow::Borrowed("Carrier Range Status"), - Cow::Borrowed("Not used"), - Cow::Borrowed(""), - ]), - Row::new([ - Cow::Borrowed("Age of recent differential correction"), - Cow::Borrowed("???"), - Cow::Borrowed("[sec]"), - ]), - Row::new([ - Cow::Borrowed("NMA Fix Status"), - Cow::Borrowed("???"), - Cow::Borrowed(""), - ]), - Row::new([ - Cow::Borrowed("Time Authentication Status"), - Cow::Borrowed("???"), - Cow::Borrowed(""), - ]), + Row::new(["Carrier Range Status", "Not used", ""]), + Row::new(["Age of recent differential correction", "???", "[sec]"]), + Row::new(["NMA Fix Status", "???", ""]), + Row::new(["Time Authentication Status", "???", ""]), ]; let widths = [