From 7d0a4540bfda552199c8c0d5bd4e4f3d3ab87901 Mon Sep 17 00:00:00 2001 From: Omelia Iliffe Date: Fri, 8 Mar 2024 16:53:35 +1300 Subject: [PATCH] added rs485 checks to set_on_file and get_from_file --- src/sys/unix/mod.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sys/unix/mod.rs b/src/sys/unix/mod.rs index 0adfdcb..cb95031 100644 --- a/src/sys/unix/mod.rs +++ b/src/sys/unix/mod.rs @@ -54,6 +54,7 @@ cfg_if! { #[derive(Clone)] pub struct Settings { pub termios: RawTermios, + pub rs485: Option, } impl Settings { @@ -61,15 +62,22 @@ cfg_if! { unsafe { let mut termios = std::mem::zeroed(); check(libc::ioctl(file.as_raw_fd(), libc::TCGETS2 as _, &mut termios))?; - Ok(Settings { termios }) + if let Ok(rs485) = rs485::SerialRs485::from_fd(file.as_raw_fd()) { + Ok(Settings { termios, rs485: Some(rs485)}) + } else { + Ok(Settings { termios, rs485: None} + } } } fn set_on_file(&self, file: &mut std::fs::File) -> std::io::Result<()> { unsafe { check(libc::ioctl(file.as_raw_fd(), libc::TCSETSW2 as _, &self.termios))?; - Ok(()) } + if let Some(rs485) = self.rs485 { + rs485.set_on_fd(file.as_raw_fd())?; + } + Ok(()) } } } else { @@ -405,6 +413,12 @@ impl Settings { rs485.set_enabled(true); self.rs485 = Some(rs485); } + pub fn get_rs485(&self) -> Option { + self.rs485 + } + pub fn set_rs485(&mut self, rs485: rs485::SerialRs485) { + self.rs485 = Some(rs485); + } pub fn set_raw(&mut self) { unsafe { libc::cfmakeraw(&mut self.termios as *mut _ as *mut libc::termios);