mavlink / rust-mavlink

MAVLink library for Rust.
https://mavlink.github.io/rust-mavlink/mavlink/
Apache License 2.0
158 stars 79 forks source link

(Bug) Deser function in MavFrame/MavHeader not working properly #205

Closed IhsenBouallegue closed 1 year ago

IhsenBouallegue commented 1 year ago

While using rust mavlink to serialize MavFrames and send them over a LoRa link, I noticed some weird inconsistencies. I noticed a weird problem. Not sure if I am the only one having it. Here are my findings, if you can point me I will be happy to fix it and open a PR.

image All the values inside the MavMessage are wrong. But not random! so it's not a problem with the LoRa link. I also printed the buffers out and confirmed that they are identical. The problem happens when deserialising. I noticed something peculiar 20 is 0000000000010100 while 5120 is 0001010000000000 1792 is 0000011100000000 while 0000000000000111 It is consistent. At first, I suspected it has something to do with big/little endian. But maybe the bits don't quite align for that? Not sure what it can be, because I can't find the code responsible for serializing and deserializing the message anywhere in the repo. Is it being imported from somewhere? I would appreciate any hint 😃

patrickelectric commented 1 year ago

Merged and available on latest release: https://github.com/mavlink/rust-mavlink/releases/tag/0.12.1

IhsenBouallegue commented 1 year ago

hey @patrickelectric thank you for releasing this fast. But this issue, while related to PR https://github.com/mavlink/rust-mavlink/pull/204, is not the same. That PR fixes another related problem (I didn't bother creating an issue for it, because it was straightforward). As far as I understood, the problem with the parsing of the MavMessage (discussed here) was not fixed yet. So this issue remains open. Let me know if I missed something.

patrickelectric commented 1 year ago

Hi @IhsenBouallegue, sorry for closing the issue early.

It's a weird problem, to be sure, what kind of hardware is sending this messages ? is it x86 ? is it ARM ? It's probably not an issue with the LoRa link, but it's the first time that I'm seeing such problem.

patrickelectric commented 1 year ago

And how the companion part is running ? Is it using rust-mavlink as well ?

IhsenBouallegue commented 1 year ago

@patrickelectric I threw together a reproduction repo (no lora, just ser and then deser, and still getting the same output) https://github.com/IhsenBouallegue/mavlink-rust-test This also means it has nothing to do with the hardware. But here is what I tried it on:

patrickelectric commented 1 year ago

Thanks for creating your repository @IhsenBouallegue.

It should be fixed by #206 now, I just used in your repository and it indeed solves the problem.

I'll add your example as a test.

IhsenBouallegue commented 1 year ago

Hey @patrickelectric, most welcome! Glad to see it fixed. Would you be so kind and do a quick hotfix release, so I can use it in my full repo?

patrickelectric commented 1 year ago

Hey @patrickelectric, most welcome! Glad to see it fixed. Would you be so kind and do a quick hotfix release, so I can use it in my full repo?

Soon after merging a second test, I'll update you.

patrickelectric commented 1 year ago

@IhsenBouallegue tag done, should be available soon.

IhsenBouallegue commented 1 year ago

@patrickelectric Yup it works! Can't thank you enough :D You literally saved my thesis 😆 You, my friend, will be going into the acknowledgements 🏆

patrickelectric commented 1 year ago

@patrickelectric Yup it works! Can't thank you enough :D You literally saved my thesis 😆 You, my friend, will be going into the acknowledgements 🏆

wow, Thank you :laughing: