Skip to content

Commit

Permalink
extend esf packets api
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
  • Loading branch information
andrei-ng committed Jan 16, 2025
1 parent 4e3a465 commit 185ebbc
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 17 deletions.
7 changes: 7 additions & 0 deletions examples/adr-message-parsing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ impl Device {

pub fn wait_for_ack<T: UbxPacketMeta>(&mut self) -> std::io::Result<()> {
let mut found_packet = false;
let start = std::time::SystemTime::now();
let timeout = Duration::from_secs(3);
while !found_packet {
self.update(|packet| {
if let PacketRef::AckAck(ack) = packet {
Expand All @@ -279,6 +281,11 @@ impl Device {
}
}
})?;

if start.elapsed().unwrap().as_millis() > timeout.as_millis() {
eprintln!("Did not receive ACK message for request");
break;
}
}
Ok(())
}
Expand Down
7 changes: 7 additions & 0 deletions examples/basic-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ impl Device {

pub fn wait_for_ack<T: UbxPacketMeta>(&mut self) -> std::io::Result<()> {
let mut found_packet = false;
let start = std::time::SystemTime::now();
let timeout = Duration::from_secs(3);
while !found_packet {
self.update(|packet| {
if let PacketRef::AckAck(ack) = packet {
Expand All @@ -458,6 +460,11 @@ impl Device {
}
}
})?;

if start.elapsed().unwrap().as_millis() > timeout.as_millis() {
error!("Did not receive ACK message for request");
break;
}
}
Ok(())
}
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 @@ -34,7 +34,7 @@ pub fn parse_args() -> clap::ArgMatches {
.short('p')
.long("port")
.required(true)
.help("Serial port to open"),
.help("Serial port to open. E.g., /dev/ttyACM0"),
)
.arg(
Arg::new("baud")
Expand Down
7 changes: 4 additions & 3 deletions examples/tui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ fn main() -> Result<(), Box<dyn Error>> {
let cli = cli::parse_args();

if cli.get_flag("debug-mode") {
debug_mode(&cli);
device_debug_mode(&cli);
} else {
crate::tui::run(&cli)?;
let log_file = logging::initialize(&cli)?;
crate::tui::run(&cli, log_file)?;
}
Ok(())
}

fn debug_mode(cli: &ArgMatches) {
fn device_debug_mode(cli: &ArgMatches) {
use log::error;
env_logger::Builder::new()
.filter_level(log::LevelFilter::Info)
Expand Down
6 changes: 3 additions & 3 deletions examples/tui/src/tui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
error::Error,
io,
path::PathBuf,
sync::mpsc::{channel, Receiver},
time::{Duration, Instant},
};
Expand All @@ -24,11 +25,10 @@ use tracing::{debug, info, instrument};
use crate::{
app::{App, UbxStatus},
device::Device,
logging, ui,
ui,
};

pub fn run(cli: &ArgMatches) -> Result<(), Box<dyn Error>> {
let log_file = logging::initialize(cli)?;
pub fn run(cli: &ArgMatches, log_file: PathBuf) -> Result<(), Box<dyn Error>> {
let tick_rate: u64 = *cli.get_one("tui-rate").ok_or("Missing tui-rate cli arg")?;
let tick_rate = Duration::from_millis(tick_rate);

Expand Down
67 changes: 57 additions & 10 deletions ublox/src/ubx_packets/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3479,6 +3479,7 @@ impl core::iter::Iterator for EsfRawDataIter<'_> {
}
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EsfAlgStatus {
Expand Down Expand Up @@ -3524,6 +3525,9 @@ struct EsfAlg {
pub struct EsfAlgFlags(u8);

impl EsfAlgFlags {
pub fn flags_raw(&self) -> u8 {
self.0
}
pub fn auto_imu_mount_alg_on(self) -> bool {
(self.0) & 0x1 != 0
}
Expand Down Expand Up @@ -3653,8 +3657,12 @@ pub enum EsfStatusFusionMode {
pub struct EsfInitStatus1(u8);

impl EsfInitStatus1 {
const WHEEL_TICK_MASK: u8 = 0x03;
const MOUNTING_ANGLE_STATUS_MASK: u8 = 0x07;
const INS_STATUS_MASK: u8 = 0x03;

pub fn wheel_tick_init_status(self) -> EsfStatusWheelTickInit {
let bits = (self.0) & 0x03;
let bits = (self.0) & Self::WHEEL_TICK_MASK;
match bits {
0 => EsfStatusWheelTickInit::Off,
1 => EsfStatusWheelTickInit::Initializing,
Expand All @@ -3665,8 +3673,12 @@ impl EsfInitStatus1 {
}
}

pub fn wheel_tick_init_status_raw(self) -> u8 {
self.wheel_tick_init_status() as u8
}

pub fn mounting_angle_status(self) -> EsfStatusMountAngle {
let bits = (self.0 >> 2) & 0x07;
let bits = (self.0 >> 2) & Self::MOUNTING_ANGLE_STATUS_MASK;
match bits {
0 => EsfStatusMountAngle::Off,
1 => EsfStatusMountAngle::Initializing,
Expand All @@ -3678,8 +3690,12 @@ impl EsfInitStatus1 {
}
}

pub fn mount_angle_status_raw(self) -> u8 {
self.mounting_angle_status() as u8
}

pub fn ins_initialization_status(self) -> EsfStatusInsInit {
let bits = (self.0 >> 5) & 0x03;
let bits = (self.0 >> 5) & Self::INS_STATUS_MASK;
match bits {
0 => EsfStatusInsInit::Off,
1 => EsfStatusInsInit::Initializing,
Expand All @@ -3689,6 +3705,10 @@ impl EsfInitStatus1 {
},
}
}

pub fn ins_initialization_status_raw(self) -> u8 {
self.ins_initialization_status() as u8
}
}

impl fmt::Debug for EsfInitStatus1 {
Expand All @@ -3701,6 +3721,7 @@ impl fmt::Debug for EsfInitStatus1 {
}
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EsfStatusWheelTickInit {
Expand All @@ -3709,6 +3730,7 @@ pub enum EsfStatusWheelTickInit {
Initialized = 2,
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EsfStatusMountAngle {
Expand All @@ -3717,6 +3739,7 @@ pub enum EsfStatusMountAngle {
Initialized = 2,
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EsfStatusInsInit {
Expand All @@ -3731,6 +3754,10 @@ pub enum EsfStatusInsInit {
pub struct EsfInitStatus2(u8);

impl EsfInitStatus2 {
pub fn imu_init_status_raw(self) -> u8 {
self.imu_init_status() as u8
}

pub fn imu_init_status(self) -> EsfStatusImuInit {
let bits = (self.0) & 0x02;
match bits {
Expand All @@ -3752,6 +3779,7 @@ impl fmt::Debug for EsfInitStatus2 {
}
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EsfStatusImuInit {
Expand All @@ -3778,10 +3806,18 @@ impl EsfSensorStatus {
self.faults
}

pub fn faults_raw(&self) -> u8 {
self.faults().into_raw()
}

pub fn sensor_type(&self) -> EsfSensorType {
self.sens_status1.sensor_type
}

pub fn sensor_type_raw(&self) -> u8 {
self.sensor_type() as u8
}

pub fn sensor_used(&self) -> bool {
self.sens_status1.used
}
Expand All @@ -3794,9 +3830,17 @@ impl EsfSensorStatus {
self.sens_status2.calibration_status
}

pub fn calibration_status_raw(&self) -> u8 {
self.calibration_status() as u8
}

pub fn time_status(&self) -> EsfSensorStatusTime {
self.sens_status2.time_status
}

pub fn time_status_raw(&self) -> u8 {
self.time_status() as u8
}
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -3846,6 +3890,7 @@ impl From<u8> for SensorStatus1 {
}
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub enum EsfSensorType {
Expand Down Expand Up @@ -3908,6 +3953,7 @@ impl From<u8> for SensorStatus2 {
}
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub enum EsfSensorStatusCalibration {
Expand All @@ -3927,6 +3973,7 @@ impl From<u8> for EsfSensorStatusCalibration {
}
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub enum EsfSensorStatusTime {
Expand All @@ -3951,13 +3998,13 @@ impl From<u8> for EsfSensorStatusTime {
#[ubx_extend_bitflags]
#[ubx(from, into_raw, rest_reserved)]
bitflags! {
#[derive(Debug, Default, Clone, Copy)]
pub struct EsfSensorFaults: u8 {
const BAD_MEASUREMENT = 1;
const BAD_TIME_TAG = 2;
const MISSING_MEASUREMENT = 4;
const NOISY_MEASUREMENT = 8;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct EsfSensorFaults: u8 {
const BAD_MEASUREMENT = 1;
const BAD_TIME_TAG = 2;
const MISSING_MEASUREMENT = 4;
const NOISY_MEASUREMENT = 8;
}
}

impl From<u8> for EsfSensorFaults {
Expand Down

0 comments on commit 185ebbc

Please sign in to comment.