From ce188c2c9fac3b2dc5b1fbd435345064028b656a Mon Sep 17 00:00:00 2001 From: Ygor Souza Date: Wed, 15 May 2024 19:43:49 +0200 Subject: [PATCH] Add Mark and Space variants to Parity enum Closes #167 --- CHANGELOG.md | 1 + src/lib.rs | 8 ++++++++ src/posix/termios.rs | 14 ++++++++++++++ src/windows/com.rs | 2 ++ src/windows/dcb.rs | 2 ++ 5 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdc8e453..1e345edd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ project adheres to [Semantic Versioning](https://semver.org/). ### Added * Added conversions between `DataBits`, `StopBits` types and their numeric representations * Added `FromStr` implementation for `FlowControl` +* Added `Mark` and `Space` variants to `Parity` enum ### Changed ### Fixed * Fixes a bug where `available_ports()` returned disabled devices on Windows. diff --git a/src/lib.rs b/src/lib.rs index 200374e8..09caa473 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,6 +204,12 @@ pub enum Parity { /// Parity bit sets even number of 1 bits. Even, + + /// Parity bit is set to 1. + Mark, + + /// Parity bit is set to 0. + Space, } impl fmt::Display for Parity { @@ -212,6 +218,8 @@ impl fmt::Display for Parity { Parity::None => write!(f, "None"), Parity::Odd => write!(f, "Odd"), Parity::Even => write!(f, "Even"), + Parity::Mark => write!(f, "Mark"), + Parity::Space => write!(f, "Space"), } } } diff --git a/src/posix/termios.rs b/src/posix/termios.rs index f53af807..f790d6f7 100644 --- a/src/posix/termios.rs +++ b/src/posix/termios.rs @@ -163,6 +163,20 @@ pub(crate) fn set_parity(termios: &mut Termios, parity: Parity) { termios.c_iflag |= libc::INPCK; termios.c_iflag &= !libc::IGNPAR; } + Parity::Mark => { + termios.c_cflag |= libc::PARODD; + termios.c_cflag |= libc::PARENB; + termios.c_iflag |= libc::INPCK; + termios.c_iflag &= !libc::IGNPAR; + termios.c_iflag |= libc::CMSPAR; + } + Parity::Space => { + termios.c_cflag &= !libc::PARODD; + termios.c_cflag |= libc::PARENB; + termios.c_iflag |= libc::INPCK; + termios.c_iflag &= !libc::IGNPAR; + termios.c_iflag |= libc::CMSPAR; + } }; } diff --git a/src/windows/com.rs b/src/windows/com.rs index 5573ab77..990a9b05 100644 --- a/src/windows/com.rs +++ b/src/windows/com.rs @@ -314,6 +314,8 @@ impl SerialPort for COMPort { match dcb.Parity { ODDPARITY => Ok(Parity::Odd), EVENPARITY => Ok(Parity::Even), + MARKPARITY => Ok(Parity::Mark), + SPACEPARITY => Ok(Parity::Space), NOPARITY => Ok(Parity::None), _ => Err(Error::new( ErrorKind::Unknown, diff --git a/src/windows/dcb.rs b/src/windows/dcb.rs index d0207fd6..66f0221d 100644 --- a/src/windows/dcb.rs +++ b/src/windows/dcb.rs @@ -81,6 +81,8 @@ pub(crate) fn set_parity(dcb: &mut DCB, parity: Parity) { Parity::None => NOPARITY, Parity::Odd => ODDPARITY, Parity::Even => EVENPARITY, + Parity::Mark => MARKPARITY, + Parity::Space => SPACEPARITY, }; dcb.set_fParity(if parity == Parity::None { FALSE } else { TRUE } as DWORD);