Skip to content

Commit

Permalink
added rs485 checks to set_on_file and get_from_file
Browse files Browse the repository at this point in the history
  • Loading branch information
omelia-iliffe committed Mar 8, 2024
1 parent 0af3ca4 commit 7d0a454
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,30 @@ cfg_if! {
#[derive(Clone)]
pub struct Settings {
pub termios: RawTermios,
pub rs485: Option<rs485::SerialRs485>,
}

impl Settings {
fn get_from_file(file: &std::fs::File) -> std::io::Result<Self> {
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 {
Expand Down Expand Up @@ -405,6 +413,12 @@ impl Settings {
rs485.set_enabled(true);
self.rs485 = Some(rs485);
}
pub fn get_rs485(&self) -> Option<rs485::SerialRs485> {
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);
Expand Down

0 comments on commit 7d0a454

Please sign in to comment.