ublox-rs / ublox

Rust crate to talk UBX protocol to u-blox GPS devices.
MIT License
54 stars 30 forks source link

u-blox M8 not working? (UbxUnknownPacketRef) #54

Closed brandonros closed 1 year ago

brandonros commented 1 year ago

Hardware: Geekstory USB GPS Module Antenna Supports GPS+GLONASS Beidou Built-in Flash for Arduino Pixhawk IPEX Compatible, Better Than VK-162 https://www.amazon.com/gp/product/B07ZR8R17Q/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

$ uname -a
Darwin MacBook-Air.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:21:34 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8112 arm64
$ cargo run -- --port /dev/cu.usbmodem11401
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/ublox_cli --port /dev/cu.usbmodem11401`
Opened u-blox device, waiting for solutions...
Unknown(UbxUnknownPacketRef { payload: [82, 79, 77, 32, 67, 79, 82, 69, 32, 51, 46, 48, 49, 32, 40, 49, 48, 55, 56, 56, 56, 41, 0, 0, 0, 0, 0, 0, 0, 0, 48, 48, 48, 56, 48, 48, 48, 48, 0, 0, 70, 87, 86, 69, 82, 61, 83, 80, 71, 32, 51, 46, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80, 82, 79, 84, 86, 69, 82, 61, 49, 56, 46, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71, 80, 83, 59, 71, 76, 79, 59, 71, 65, 76, 59, 66, 68, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 66, 65, 83, 59, 73, 77, 69, 83, 59, 81, 90, 83, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], class: 10, msg_id: 4 })

There's a support document on the Amazon product page https://m.media-amazon.com/images/I/91+EnzD0qpL.pdf that mentions u-block u-center (M9 and below)

Still trying to identify which u-blox product it is...?

Edit: found it u-blox M8 (ProductID = 0x01A8, VendorID = 0x1546)

brandonros commented 1 year ago

image

I would guess it isn't u-blox if it didn't show up this way on System Information.... is it... a knockoff? How can I find out exactly which chip it is?

brandonros commented 1 year ago

It sort of works with PyGPSClient which probably rules out the hardware being funky/non-complaint

image

I'll try to get serial TX/RX logs if that'll help us.

lkolbly commented 1 year ago

Thanks for the report! It definitely seems like this is a bug in the crate. In particular, a bug here: https://github.com/ublox-rs/ublox/blob/master/ublox/src/ubx_packets/packets.rs#L3032

That function is what decides whether the packet is "valid" or not. I'm able to reproduce the bug in a playground here, which points to the issue: the .any(|c| !is_cstr_valid(c)) will return true if any of the extensions aren't valid, so we need to actually do:

    fn is_valid(payload: &[u8]) -> bool {
        payload.len() % 30 == 0 && !payload.chunks(30).any(|c| !is_cstr_valid(c))
    }

I think?

lkolbly commented 1 year ago

I'm not sure how I never caught this. Maybe my hardware has a non-UTF8-decodable extension, and I never noticed (the original HW I developed this crate with was, in fact, somewhat less than genuine).

brandonros commented 1 year ago

thank you so much! @lkolbly do you need anything else from me to make a fix? would love to try again

lkolbly commented 1 year ago

@brandonros Can you try the lkolbly/mon-ver-fix branch?

Dushistov commented 1 year ago

There is also this PR https://github.com/ublox-rs/ublox/pull/47 , in particular it changes is_valid to:

fn is_valid(payload: &[u8]) -> bool {
        payload.len() % 30 == 0 && payload.chunks(30).all(|c| is_cstr_valid(c))
}
lkolbly commented 1 year ago

Oh yeah, that's a much better fix.

brandonros commented 1 year ago

Thanks for merging. Not sure if you want to trigger a full new tag bump + release. Thank you!

$ cargo run --bin ublox_cli -- --port /dev/cu.usbmodem1301
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/ublox_cli --port /dev/cu.usbmodem1301`
Opened u-blox device, waiting for solutions...
SW version: ROM CORE 3.01 (107888) HW version: 00080000
MonVer { software_version: "ROM CORE 3.01 (107888)", hardware_version: "00080000", extension: MonVerExtensionIter { data: [70, 87, 86, 69, 82, 61, 83, 80, 71, 32, 51, 46, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80, 82, 79, 84, 86, 69, 82, 61, 49, 56, 46, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 71, 80, 83, 59, 71, 76, 79, 59, 71, 65, 76, 59, 66, 68, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 66, 65, 83, 59, 73, 77, 69, 83, 59, 81, 90, 83, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], offset: 0 } }