Closed pv42 closed 2 months ago
Hi @pv42, nice idea, surely mavlink-camera-manager (and potentially mavlink2rest) would benefit from that!
To contextualize, I did implement these tokio-based async read/write because I've been experimenting with a new mavlink router written in rust (mavlink-server). This router can also be refactored to make use of that, but it already has an implementation (which might help us here?).
Feel free to use any of that code if useful, the mavlink-server repo still lacks a license file, but it's intended to be MIT (edit: MIT License file added).
I was literally looking to see if this existed last night! +100!
@pv42 just so you know, I'm reworking the tokio async reader around tokio-utils' codec, so we can ensure a frame would be received from the raw read functions, and using the same codec you can have a tokio's UdpStream.
With #255 support for
tokio
-basedasync
was merged, addingasync
versions ofwrite_versioned_msg
andread_v2_msg
which is very welcome (as it is something I was thinking of doing myself).I suggest adding an
async
version of the connection trait similar toMavConnection<M: Message>
:And then implementing it for the
tcp
,udp
,file
and potentiallyserial
(unsure if/howtokio
support that) connections and providing a public function to openasync
connections:pub async fn connect_async<M: Message>(address: &str) -> io::Result<Box<dyn AsyncMavConnection<M> + Sync + Send>>
If this is something that would fit and if @joaoantoniocardoso is not already working on it I would be happy to submit a PR.