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

feat: async serial #284

Merged
merged 2 commits into from
Nov 28, 2024
Merged

feat: async serial #284

merged 2 commits into from
Nov 28, 2024

Conversation

roby2014
Copy link
Contributor

Tried following the other connection wrappers structures.
Needs testing (i'll test soon).

@roby2014
Copy link
Contributor Author

Did a simple test with serial:/dev/ttyACM1:115200:

// ...
        let mut connection =
            mavlink::connect_async::<mavlink::ardupilotmega::MavMessage>("serial:/dev/ttyACM1:115200").await?;
        connection.set_protocol_version(self.mavlink_version);
// ...
            select! {
                res = connection.recv() => {
                    match res {
                        Ok((header, msg)) => {
                            trace!(?header, ?msg, "received message from connection");
                            //...
                        }
                        Err(e) => {
                            error!("failed to read: {e}");
                        }
                    }
                }
                res = channel.recv() => {
                    // ...
                }
            }

and I'm able to get data:

received message from connection header=MavHeader { system_id: 1, component_id: 1, sequence: 133 } msg=ATTITUDE(ATTITUDE_DATA { time_boot_ms: 389342, roll: 0.0, pitch: 0.0, yaw: 0.0, rollspeed: 0.0, pitchspeed: 0.0, yawspeed: 0.0 })

received message from connection header=MavHeader { system_id: 1, component_id: 1, sequence: 134 } msg=VFR_HUD(VFR_HUD_DATA { airspeed: 0.0, groundspeed: 0.0, alt: 0.0, climb: 0.0, heading: 0, throttle: 0 })

@peterkrull
Copy link

I would also like to have async serial be upstreamed so there is consistency between sync/async. Though looking at your code, is it not problem that the port is locked behind a single mutex, i.e. no reader and writer half? If I were to wrap the AsyncSerialConnection in an Arc and create a reader and writer thread, would the reader not be able to lock out the writer indefinitely if there are no incoming messages?

@patrickelectric patrickelectric merged commit 90d2ad4 into mavlink:master Nov 28, 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

Successfully merging this pull request may close these issues.

4 participants