Skip to content

Commit

Permalink
implemented rendering of actual ubx data
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 002de67 commit 4358bf7
Show file tree
Hide file tree
Showing 9 changed files with 1,418 additions and 248 deletions.
3 changes: 2 additions & 1 deletion examples/tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ clap = { version = "4.5.23", features = ["derive", "cargo"] }
serde_json = "1.0"
serialport = "4.2"
ublox = { path = "../../ublox" }

log = "0.4"
ratatui = "0.29"
crossterm = { version = "0.28", features = ["event-stream"] }
unicode-width = "0.2"
anyhow = "1.0"
strum = { version = "0.26", features = ["derive"] }
dirs = "5.0"
env_logger = "0.11"

rand = "0.8.5"

Expand Down
271 changes: 198 additions & 73 deletions examples/tui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
use core::f64;
use std::vec;

use ublox::{
EsfAlgStatus, EsfSensorFaults, EsfSensorStatusCalibration, EsfSensorStatusTime, EsfSensorType,
EsfStatusFusionMode, EsfStatusImuInit, EsfStatusInsInit, EsfStatusMountAngle,
EsfStatusWheelTickInit,
};

pub struct TabsState<'a> {
pub titles: Vec<&'a str>,
pub index: usize,
Expand Down Expand Up @@ -27,85 +36,180 @@ pub struct Server<'a> {
pub status: &'a str,
}

#[derive(Debug, Default)]
pub enum UbxStatus {
Pvt(Box<NavPvtWidgetState>),
MonVer(Box<MonVersionState>),
EsfAlgImu(EsfAlgImuAlignmentWidgetState),
EsfAlgSensors(EsfSensorsWidgetState),
EsfAlgStatus(EsfAlgStatusWidgetState),
}

#[derive(Debug)]
#[allow(dead_code)]
pub struct NavPvtState {
pub itow: u32,
pub year: u16,
pub month: u8,
pub day: u8,
pub hour: u8,
pub min: u8,
pub sec: u8,
pub valid: u8,
pub time_accuracy: u32,
pub nanosecond: i32,
pub gps_fix_type: u8,
pub num_satellites: u8,
pub lon: i32,
pub lat: i32,
pub height_meters: i32,
pub height_msl: i32,
pub horiz_accuracy: u32,
pub vert_accuracy: u32,
pub vel_ned: [f64; 3],
pub ground_speed: u32,
pub heading: i32,
pub speed_accuracy_estimate: u32,
pub heading_accuracy_estimate: u32,
pub pdop: u16,
pub heading_of_vehicle: i32,
pub magnetic_declination: i16,
pub magnetic_declination_accuracy: u16,
pub struct NavPvtWidgetState {
pub time_tag: f64,
pub utc_date_time: String,
pub utc_time_accuracy: u32,
pub lat: f64,
pub lon: f64,
pub height: f64,
pub msl: f64,
pub vel_ned: (f64, f64, f64),
pub speed_over_ground: f64,
pub heading_motion: f64,
pub heading_vehicle: f64,
pub magnetic_declination: f64,

pub pdop: f64,
pub satellites_used: u8,

pub position_fix_type: String,
pub fix_flags: String,
pub time_date_confirmation: String,
pub invalid_llh: bool,
pub position_accuracy: (f64, f64),
pub velocity_accuracy: f64,
pub heading_accuracy: f64,
pub magnetic_declination_accuracy: f64,
}

impl Default for NavPvtWidgetState {
fn default() -> Self {
Self {
time_tag: f64::NAN,
lat: f64::NAN,
lon: f64::NAN,
height: f64::NAN,
msl: f64::NAN,
vel_ned: (f64::NAN, f64::NAN, f64::NAN),
speed_over_ground: f64::NAN,
heading_motion: f64::NAN,
heading_vehicle: f64::NAN,
magnetic_declination: f64::NAN,
pdop: f64::NAN,
satellites_used: 0,
utc_time_accuracy: 0,
invalid_llh: true,
position_accuracy: (f64::NAN, f64::NAN),
velocity_accuracy: f64::NAN,
heading_accuracy: f64::NAN,
magnetic_declination_accuracy: f64::NAN,
position_fix_type: "No Fix".to_string(),
fix_flags: "???".to_string(),
utc_date_time: "N/A".to_string(),
time_date_confirmation: "Date: ?, Time: ?".to_string(),
}
}
}

#[derive(Debug, Default)]
pub struct EsfSensorsWidgetState {
pub sensors: Vec<EsfSensorWidget>,
}

#[derive(Debug, Clone)]
pub struct EsfSensorWidget {
pub sensor_type: EsfSensorType,
pub calib_status: EsfSensorStatusCalibration,
pub time_status: EsfSensorStatusTime,
pub freq: u16,
pub faults: EsfSensorFaults,
}

impl Default for EsfSensorWidget {
fn default() -> Self {
Self {
sensor_type: EsfSensorType::Unknown,
calib_status: EsfSensorStatusCalibration::NotCalibrated,
time_status: EsfSensorStatusTime::NoData,
freq: 0,
faults: EsfSensorFaults::default(),
}
}
}

pub struct EsfAlgStatusWidgetState {
pub time_tag: f64,
pub fusion_mode: EsfStatusFusionMode,
pub imu_status: EsfStatusImuInit,
pub wheel_tick_sensor_status: EsfStatusWheelTickInit,
pub ins_status: EsfStatusInsInit,
pub imu_mount_alignment_status: EsfStatusMountAngle,
}

impl Default for EsfAlgStatusWidgetState {
fn default() -> Self {
Self {
time_tag: f64::NAN,
fusion_mode: EsfStatusFusionMode::Disabled,
imu_status: EsfStatusImuInit::Off,
wheel_tick_sensor_status: EsfStatusWheelTickInit::Off,
ins_status: EsfStatusInsInit::Off,
imu_mount_alignment_status: EsfStatusMountAngle::Off,
}
}
}
#[derive(Debug)]
pub struct EsfAlgImuAlignmentWidgetState {
pub time_tag: f64,
pub auto_alignment: bool,
pub alignment_status: EsfAlgStatus,
pub angle_singularity: bool,
pub roll: f64,
pub pitch: f64,
pub yaw: f64,
}

impl Default for EsfAlgImuAlignmentWidgetState {
fn default() -> Self {
Self {
time_tag: f64::NAN,
auto_alignment: false,
alignment_status: EsfAlgStatus::UserDefinedAngles,
angle_singularity: false,
roll: f64::NAN,
pitch: f64::NAN,
yaw: f64::NAN,
}
}
}

#[derive(Debug, Default)]
pub struct MonVersionState {
pub software_version: String,
pub hardware_version: String,
pub extensions: String,
}

pub struct App<'a> {
pub title: &'a str,
pub navpvtstate: NavPvtState,
pub pvt_state: NavPvtWidgetState,
pub mon_ver_state: MonVersionState,
pub esf_sensors_state: EsfSensorsWidgetState,
pub esf_alg_state: EsfAlgStatusWidgetState,
pub esf_alg_imu_alignment_state: EsfAlgImuAlignmentWidgetState,
pub should_quit: bool,
pub tabs: TabsState<'a>,
pub show_chart: bool,
pub progress: f64,
pub servers: Vec<Server<'a>>,
pub enhanced_graphics: bool,
}

impl<'a> App<'a> {
pub fn new(title: &'a str, enhanced_graphics: bool) -> Self {
pub fn new(title: &'a str) -> Self {
App {
title,
navpvtstate: NavPvtState::default(),
pvt_state: NavPvtWidgetState::default(),
mon_ver_state: MonVersionState::default(),
esf_sensors_state: EsfSensorsWidgetState::default(),
esf_alg_state: EsfAlgStatusWidgetState::default(),
esf_alg_imu_alignment_state: EsfAlgImuAlignmentWidgetState::default(),
should_quit: false,
tabs: TabsState::new(vec!["PVT & ESF Status", "Sensor Graphs", "World Map"]),
show_chart: true,
progress: 0.0,
servers: vec![
Server {
name: "NorthAmerica-1",
location: "New York City",
coords: (40.71, -74.00),
status: "Up",
},
Server {
name: "Europe-1",
location: "Paris",
coords: (48.85, 2.35),
status: "Failure",
},
Server {
name: "SouthAmerica-1",
location: "São Paulo",
coords: (-23.54, -46.62),
status: "Up",
},
Server {
name: "Asia-1",
location: "Singapore",
coords: (1.35, 103.86),
status: "Up",
},
],
enhanced_graphics,
tabs: TabsState::new(vec![
"PVT & ESF Status",
"Version Info",
"Sensor Graphs",
"World Map",
]),
servers: Self::dummy_servers(),
}
}

Expand All @@ -122,18 +226,39 @@ impl<'a> App<'a> {
'q' => {
self.should_quit = true;
},
't' => {
self.show_chart = !self.show_chart;
'Q' => {
self.should_quit = true;
},
_ => {},
}
}

pub fn on_tick(&mut self) {
// Update progress
self.progress += 0.001;
if self.progress > 1.0 {
self.progress = 0.0;
}
fn dummy_servers() -> Vec<Server<'a>> {
vec![
Server {
name: "NorthAmerica-1",
location: "New York City",
coords: (40.71, -74.00),
status: "Up",
},
Server {
name: "Europe-1",
location: "Paris",
coords: (48.85, 2.35),
status: "Failure",
},
Server {
name: "SouthAmerica-1",
location: "São Paulo",
coords: (-23.54, -46.62),
status: "Up",
},
Server {
name: "Asia-1",
location: "Singapore",
coords: (1.35, 103.86),
status: "Up",
},
]
}
}
Loading

0 comments on commit 4358bf7

Please sign in to comment.