Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions mavlink-core/src/connection/direct_serial/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::fmt::Display;
use core::time::Duration;

/// MAVLink address for a serial connection
///
Expand All @@ -14,6 +15,7 @@ use core::fmt::Display;
pub struct SerialConfig {
pub(crate) port_name: String,
pub(crate) baud_rate: u32,
pub(crate) timeout: Option<Duration>,
read_buffer_capacity: usize,
}

Expand All @@ -26,10 +28,23 @@ impl SerialConfig {
Self {
port_name,
baud_rate,
timeout: None,
read_buffer_capacity: default_capacity,
}
}

/// Sets the serial port timeout.
///
/// When set, serial reads will return an error after the specified duration.
///
/// By default, this is 1 millisecond.
///
/// Only applies to sync connections and is a no-op for async ones.
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = Some(timeout);
self
}

/// Updates the read buffer capacity.
pub fn with_read_buffer_capacity(mut self, capacity: usize) -> Self {
self.read_buffer_capacity = capacity;
Expand Down
2 changes: 1 addition & 1 deletion mavlink-core/src/connection/direct_serial/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Connectable for SerialConfig {
.parity(Parity::None)
.stop_bits(StopBits::One)
.flow_control(FlowControl::None)
.timeout(Duration::from_millis(1))
.timeout(self.timeout.unwrap_or(Duration::from_millis(1)))
.open()?;

let write_port = read_port.try_clone()?;
Expand Down
Loading