Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Connection Trait #256

Closed
pv42 opened this issue Aug 22, 2024 · 3 comments
Closed

Async Connection Trait #256

pv42 opened this issue Aug 22, 2024 · 3 comments

Comments

@pv42
Copy link
Contributor

pv42 commented Aug 22, 2024

With #255 support for tokio-based async was merged, adding async versions of write_versioned_msg and read_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 to MavConnection<M: Message>:

#[async_trait]
pub trait AsyncMavConnection<M: Message> {
    async fn recv(..) -> ..
    async fn send(..) -> ..
    fn set_protocol_version(..)
    fn get_protocol_version(..) -> ..
    async fn send_frame(..) -> ..
    async fn recv_frame(..) -> .. 
    async fn send_default(..) -> ..
}

And then implementing it for the tcp, udp, file and potentially serial (unsure if/how tokio support that) connections and providing a public function to open async 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.

@joaoantoniocardoso
Copy link
Contributor

joaoantoniocardoso commented Aug 22, 2024

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).

@BWStearns
Copy link

I was literally looking to see if this existed last night! +100!

@joaoantoniocardoso
Copy link
Contributor

@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.

@pv42 pv42 mentioned this issue Aug 29, 2024
@pv42 pv42 closed this as completed Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants