From fd87904d6d936be1ee914706185bb7366097b084 Mon Sep 17 00:00:00 2001 From: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:06:20 +0100 Subject: [PATCH] add CfgEsfWt message - this message is available on Series 8 devices - for series 9 it is considered legacy and there is no gurantee according to the manual that it will work. Series 9 devices introduced a new set of messages specific for ADR produts. See reference manual from uBlox. - this messages has been tested for Vehicle Speed configuration on F9R devices and it worked Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> --- CHANGELOG.md | 1 + examples/adr-message-parsing/src/main.rs | 50 +++++++++++--- ublox/src/ubx_packets/packets.rs | 84 ++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c406dd..9cd003b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [0.1.0] - 2025-xx-xx ### Added +- [[#28](https://github.com/andrei-ng/u-blox.rs/pull/28)] Add UBX-CFG-ESFWT message - [[#27](https://github.com/andrei-ng/u-blox.rs/pull/27)] Merge [ublox-rs/ublox/pull/24](https://github.com/ublox-rs/ublox/pull/24) PR that adds `UBX-NAV-RELPOSNED` into this repository. - remove duplicate package definition `MgaGpsEph` - add features flags to differentiate between uBlox Series 8 and uBlox Series 9 devices; As `UBX-NAV-RELPOSNED` has different lengths depending on the protocol /series. \ No newline at end of file diff --git a/examples/adr-message-parsing/src/main.rs b/examples/adr-message-parsing/src/main.rs index 43a0b0b..b46493e 100644 --- a/examples/adr-message-parsing/src/main.rs +++ b/examples/adr-message-parsing/src/main.rs @@ -128,12 +128,6 @@ fn main() { ) .expect("Could not configure ports for UBX-CFG-ESFALG"); - device - .write_all( - &CfgMsgAllPortsBuilder::set_rate_for::([0, 1, 0, 1, 0, 0]).into_packet_bytes(), - ) - .expect("Could not configure ports for UBX-ESF-INS"); - device .write_all( &CfgMsgAllPortsBuilder::set_rate_for::([0, 0, 0, 0, 0, 0]).into_packet_bytes(), @@ -173,12 +167,40 @@ fn main() { ) .expect("Could not write UBX-CFG-ESFALG msg due to: {e}"); - // Send packet request to read the new CfgEsfAlg device .write_all(&UbxPacketRequest::request_for::().into_packet_bytes()) .expect("Unable to write request/poll for UBX-CFG-ESFALG message"); - // Start reading data + device + .write_all( + &CfgMsgAllPortsBuilder::set_rate_for::([0, 1, 0, 1, 0, 0]) + .into_packet_bytes(), + ) + .expect("Could not configure ports for UBX-ESF-INS"); + + // Configure Wheel Speed for ESF + device + .write_all( + &ublox::CfgEsfWtBuilder { + flags1: CfgEsfWtFlags1::USE_WHEEL_TICK_SPEED, + wt_frequency: 13, + ..Default::default() + } + .into_packet_bytes(), + ) + .expect("Could not write UBX-CFG-ESFALG msg due to: {e}"); + + device + .write_all(&UbxPacketRequest::request_for::().into_packet_bytes()) + .expect("Unable to write request/poll for UBX-CFG-ESFALG message"); + + device + .write_all( + &CfgMsgAllPortsBuilder::set_rate_for::([0, 1, 0, 1, 0, 0]) + .into_packet_bytes(), + ) + .expect("Could not configure ports for UBX-ESF-INS"); + println!("Opened uBlox device, waiting for messages..."); loop { device @@ -191,6 +213,14 @@ fn main() { packet.extension().collect::>() ); }, + PacketRef::CfgEsfWt(msg) => { + println!("Received: {:?}", msg); + }, + PacketRef::CfgEsfAlg(msg) => { + println!("Received: {:?}", msg); + }, + + PacketRef::EsfStatus(status) => { println!( "EsfStatus: tow: {}, version: {}, {:?},{:?}, fusion_mode: {:?}, num_sens: {}", @@ -215,9 +245,9 @@ fn main() { } println!("calib_tag: {:?}", msg.calib_tag()); }, - + _ => { - println!("{:?}", packet); + {} //println!("{:?}", packet); }, }) .unwrap(); diff --git a/ublox/src/ubx_packets/packets.rs b/ublox/src/ubx_packets/packets.rs index 3fdb36f..bcf7b27 100644 --- a/ublox/src/ubx_packets/packets.rs +++ b/ublox/src/ubx_packets/packets.rs @@ -2869,6 +2869,89 @@ impl fmt::Debug for CfgEsfAlgFlags { } } +/// Get/set wheel-tick configuration +/// Only available for ADR products +#[ubx_packet_recv_send] +#[ubx( + class = 0x06, + id = 0x82, + fixed_payload_len = 32, + flags = "default_for_builder" +)] +struct CfgEsfWt { + version: u8, + + #[ubx(map_type = CfgEsfWtFlags1)] + flags1: u8, + + #[ubx(map_type = CfgEsfWtFlags2)] + flags2: u8, + reserved1: u8, + + /// Wheel tick scaling factor + #[ubx(map_type = f64, scale = 1e-6)] + wt_factor: u32, + + /// Wheel tick quantization + #[ubx(map_type = f64, scale = 1e-6)] + wt_quant_error: u32, + + /// Wheel tick counter maximum value + wt_count_max: u32, + + /// Wheel tick latency due to e.g. CAN bus + wt_latency: u16, + + /// Nominal wheel tick data frequency + wt_frequency: u8, + + #[ubx(map_type = CfgEsfWtFlags3)] + flags3: u8, + + /// Speed sensor dead band + speed_dead_band: u16, + + reserved2: [u8; 10], +} + +#[ubx_extend_bitflags] +#[ubx(from, into_raw, rest_reserved)] +bitflags! { + #[derive(Default, Debug)] + pub struct CfgEsfWtFlags1 : u8 { + /// Use combined rear wheel-ticks + const COMBINED_TICKS = 0x01; + /// Low-speed COG filter enabled flag + const USE_WHEEL_TICK_SPEED = 0x10; + /// Direction pin polarity + const DIR_PIN_POLARITY = 0x20; + /// Use wheel tick pin for speed measurement + const USE_WT_PIN = 0x40; + } +} + +#[ubx_extend_bitflags] +#[ubx(from, into_raw, rest_reserved)] +bitflags! { + #[derive(Default, Debug)] + pub struct CfgEsfWtFlags2 : u8 { + const AUTO_WT_COUNT_MAX_OFF = 0x01; + const AUTO_DIR_PIN_POL_OFF = 0x02; + const AUTO_SOFTWARE_WT_OFF = 0x04; + const AUTO_USE_WT_SPEED_OFF = 0x08; + } +} + +#[ubx_extend_bitflags] +#[ubx(from, into_raw, rest_reserved)] +bitflags! { + #[derive(Default, Debug)] + pub struct CfgEsfWtFlags3 : u8 { + /// Count both rising and falling edges of wheel-tick + const CNT_BOTH_EDGES = 0x01; + } +} + #[ubx_extend] #[ubx(from, rest_reserved)] #[repr(u8)] @@ -4526,6 +4609,7 @@ define_recv_packets!( CfgTmode3, CfgTp5, CfgEsfAlg, + CfgEsfWt, EsfAlg, EsfIns, EsfMeas,