Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Gherghescu <[email protected]>
  • Loading branch information
andrei-ng committed Jan 9, 2025
1 parent 4358bf7 commit b00a6bc
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 115 deletions.
10 changes: 5 additions & 5 deletions examples/tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(),
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tui/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand Down
42 changes: 15 additions & 27 deletions examples/tui/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<&str>>()
pkg.software_version(),
pkg.hardware_version(),
pkg.extension().collect::<Vec<&str>>()
);
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();
Expand All @@ -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) {
Expand All @@ -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();
Expand Down
129 changes: 47 additions & 82 deletions examples/tui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,85 +92,66 @@ 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"),
Cow::Owned(app.pvt_state.speed_over_ground.to_string()),
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"),
Expand All @@ -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 = [
Expand Down

0 comments on commit b00a6bc

Please sign in to comment.