Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Aug 25, 2024
1 parent a1c5252 commit dbff289
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
10 changes: 5 additions & 5 deletions mavlink-core/src/connection/direct_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub fn open(settings: &str) -> io::Result<SerialConnection> {
));
}

let baud_opt = settings_toks[1].parse::<usize>();
if baud_opt.is_err() {
let Ok(baud) = settings_toks[1]
.parse::<usize>()
.map(serial::core::BaudRate::from_speed)
else {
return Err(io::Error::new(
io::ErrorKind::AddrNotAvailable,
"Invalid baud rate",
));
}

let baud = serial::core::BaudRate::from_speed(baud_opt.unwrap());
};

let settings = serial::core::PortSettings {
baud_rate: baud,
Expand Down
14 changes: 4 additions & 10 deletions mavlink-core/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,8 @@ pub fn connect<M: Message>(address: &str) -> io::Result<Box<dyn MavConnection<M>
pub(crate) fn get_socket_addr<T: std::net::ToSocketAddrs>(
address: T,
) -> Result<std::net::SocketAddr, io::Error> {
let addr = match address.to_socket_addrs()?.next() {
Some(addr) => addr,
None => {
return Err(io::Error::new(
io::ErrorKind::Other,
"Host address lookup failed",
));
}
};
Ok(addr)
address.to_socket_addrs()?.next().ok_or(io::Error::new(
io::ErrorKind::Other,
"Host address lookup failed",
))
}
4 changes: 2 additions & 2 deletions mavlink-core/src/connection/udp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! UDP MAVLink connection
//!
use std::collections::VecDeque;

use crate::connection::MavConnection;
Expand All @@ -11,8 +13,6 @@ use std::sync::Mutex;

use super::get_socket_addr;

/// UDP MAVLink connection

pub fn select_protocol<M: Message>(
address: &str,
) -> io::Result<Box<dyn MavConnection<M> + Sync + Send>> {
Expand Down

0 comments on commit dbff289

Please sign in to comment.