mavlink_core/connection/direct_serial/
config.rs1use core::fmt::Display;
2use core::time::Duration;
3
4#[derive(Debug, Clone)]
15pub struct SerialConfig {
16 pub(crate) port_name: String,
17 pub(crate) baud_rate: u32,
18 pub(crate) timeout: Option<Duration>,
19 read_buffer_capacity: usize,
20}
21
22impl SerialConfig {
23 pub fn new(port_name: String, baud_rate: u32) -> Self {
25 let default_capacity = (baud_rate / 100).clamp(1024, 1024 * 8) as usize;
27
28 Self {
29 port_name,
30 baud_rate,
31 timeout: None,
32 read_buffer_capacity: default_capacity,
33 }
34 }
35
36 pub fn timeout(mut self, timeout: Duration) -> Self {
44 self.timeout = Some(timeout);
45 self
46 }
47
48 pub fn with_read_buffer_capacity(mut self, capacity: usize) -> Self {
50 self.read_buffer_capacity = capacity;
51 self
52 }
53
54 pub fn buffer_capacity(&self) -> usize {
56 self.read_buffer_capacity
57 }
58}
59
60impl Display for SerialConfig {
61 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62 write!(f, "serial:{}:{}", self.port_name, self.baud_rate)
63 }
64}