mavlink_core/connection/direct_serial/
config.rs1use core::fmt::Display;
2
3#[derive(Debug, Clone)]
14pub struct SerialConfig {
15 pub(crate) port_name: String,
16 pub(crate) baud_rate: u32,
17 read_buffer_capacity: usize,
18}
19
20impl SerialConfig {
21 pub fn new(port_name: String, baud_rate: u32) -> Self {
23 let default_capacity = (baud_rate / 100).clamp(1024, 1024 * 8) as usize;
25
26 Self {
27 port_name,
28 baud_rate,
29 read_buffer_capacity: default_capacity,
30 }
31 }
32
33 pub fn with_read_buffer_capacity(mut self, capacity: usize) -> Self {
35 self.read_buffer_capacity = capacity;
36 self
37 }
38
39 pub fn buffer_capacity(&self) -> usize {
41 self.read_buffer_capacity
42 }
43}
44
45impl Display for SerialConfig {
46 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47 write!(f, "serial:{}:{}", self.port_name, self.baud_rate)
48 }
49}