Comments (8)
@tstellanova ping
Also please consider implementing the new async/await feature, as it is even nicer than non blocking recv()
from rust-mavlink.
@wucke13 feel free to submit a pull request
from rust-mavlink.
I have looked into this a bit more. AFAIK, there are two ways of accomplishing this:
- ugly: spawning a new thread, blocking
recv()
in that thread, push to MPSC, use MPSCtry_recv()
to get async behavior. That's what I'm currently doing as a hot fix. - correct: Adding state to
read_versioned_msg()
. Detect if buffer is not big enough to parse the message, and returnstd::io::ErrorKindWouldBlock
in that case. Preserve the so far consumed bytes, as they might be part of a valid message. That way it becomes trivial to implement the actualtry_recv()
. One could orient at tokio's codec trait, for the implementation.
The correct way of doing this involves re-implementing parts of the MAVLink parser. Any chances that you will look into this? Can you confirm my understanding of the possible solutions, or is there a neat way that I'm missing out on?
from rust-mavlink.
from rust-mavlink.
Hi @wucke13 !
I thought about this library as "bare minimum" - i.e. it only provides struct definitions and a couple of convenience functions (socket and serial read for example). What you are mentioning would benefit from using rust futures for example.
That being sad, feel free to submit a PR with your solution, just make sure it is properly feature gated with #[cfg(feature = "...")]
(we want the library to be usable even in no-std
environments)
@tstellanova I got kind of stuck typechecking enums and implementing a set of sensible quickcheck tests, then I ran out of time. So it is kind of half finished at the moment:-/
from rust-mavlink.
I would oppose to using futures for this. From recent experiment I took away that futures are only beneficial when one build complex dependencies on them. For a simple "give it to me, if and only if its ready" they are not a good fit. I would therefore still prefer the try_recv
style interface.
Also, I think try_recv
should be considered part of bare minimum. I mean, even the Arduino serial interface offers a an aswer to "How much can I receive". So IMHO even in an absolute bare minimum setup, there should be an non blocking way of asking for new messages.
I'm still not convinced that my understanding is sufficient to make a PR for this, we will see 😄
from rust-mavlink.
Just to update this issue, I'm working to add such feature, probably a PR should be ready in a couple of days, the ideas is to implement something like try_recv
as @wucke13 commented, and maybe in the future having something closer to mpsc
.
from rust-mavlink.
@patrickelectric That is very good news! However, please note: Since I wrote my comment, futures came a long way! Especially with smol
the futures thing became much more accessible, at least to me. I think the correct way of doing making the mavlink crate future proof is this:
- Offering
recv()
for legacy compatibilitie, and because it is sufficient sometimes - Offering
try_recv()
for simple async-ish stuff. This is important especially for no_std, as it may not be so simple to spawn a real async executor there. - Offering
async recv()
. This is the most useful way of interacting with a message stub, IMO.
Internally, recv()
could just await the aysn recv
for the sake of simplicity. I don't see any reason so far, why this wouldn't work. That way mavlink.rs can offer a rich and modern API without too much code duplication or other sacrifices.
What do you think about this?
from rust-mavlink.
Related Issues (20)
- Project is not truncating trailing zeros for payload HOT 4
- Routing issue: somehow packets get dropped communicating with ground station HOT 9
- Missing fields in some ardupilotmega structs HOT 2
- Unable to access raw_bytes pub fn for MAVLinkV2MessageRaw HOT 3
- (Question) SerialConnection mutex locks read and write methods HOT 1
- udp sending long commands through send is unsuccessful, but can succeed through send_default
- Allow access to the internal buffers of raw messages HOT 2
- (Bug) Deser function in MavFrame/MavHeader not working properly HOT 11
- Return error if crc validation fails over continuing processing for new messages
- All enum entries and message ids use isize, some should use usize HOT 2
- 0.12.2 does not compile HOT 2
- Panics on [tcpin, tcpout, udpout, udpin, udpbcast]: `failed to lookup address information: Temporary failure in name resolution`
- Incorrect message frame detection HOT 3
- MAVLink XML change to allow exponentiation operator in bitmask flag HOT 2
- 0.13.0 not published on crates.io HOT 6
- Broken `no_std` from recent commits HOT 3
- Error reported in udpin LAN IP code: 10049, kind: AddrNotAvailable HOT 1
- README: broken example links HOT 1
- Incremental build broken (mavlink always regenerated/recompiled) HOT 3
- Read implementation for UdpRead needs buffering
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-mavlink.