Commit 365dc3cd authored by Karol Harasim's avatar Karol Harasim

Add support for Mark & Space parity modes.

parent 4aed7262
Pipeline #132451570 failed with stages
in 2 minutes and 2 seconds
......@@ -221,6 +221,8 @@ fn test_single_port(port: &mut dyn serialport::SerialPort, loopback: bool) {
println!("Testing parity...");
parity_check!(port, Parity::Odd);
parity_check!(port, Parity::Even);
parity_check!(port, Parity::Mark);
parity_check!(port, Parity::Space);
parity_check!(port, Parity::None);
// Test setting stop bits
......
......@@ -174,6 +174,12 @@ pub enum Parity {
/// Parity bit sets even number of 1 bits.
Even,
/// Parity bit always set to 1.
Mark,
/// Parity bit always set to 0.
Space,
}
/// Number of stop bits.
......
......@@ -667,7 +667,13 @@ impl SerialPort for TTYPort {
fn parity(&self) -> Result<Parity> {
let termios = self.get_termios()?;
if termios.c_cflag & libc::PARENB == libc::PARENB {
if termios.c_cflag & libc::PARODD == libc::PARODD {
if termios.c_cflag & libc::CMSPAR == libc::CMSPAR {
if termios.c_cflag & libc::PARODD == libc::PARODD {
Ok(Parity::Mark)
} else {
Ok(Parity::Space)
}
} else if termios.c_cflag & libc::PARODD == libc::PARODD {
Ok(Parity::Odd)
} else {
Ok(Parity::Even)
......@@ -841,6 +847,17 @@ impl SerialPort for TTYPort {
termios.c_iflag |= libc::INPCK;
termios.c_iflag &= !libc::IGNPAR;
}
Parity::Mark => {
termios.c_cflag |= libc::PARENB | libc::CMSPAR | libc::PARODD;
termios.c_iflag &= !libc::INPCK;
termios.c_iflag |= libc::IGNPAR;
}
Parity::Space => {
termios.c_cflag |= libc::PARENB | libc::CMSPAR;
termios.c_cflag &= !libc::PARODD;
termios.c_iflag &= !libc::INPCK;
termios.c_iflag |= libc::IGNPAR;
}
};
self.set_termios(&termios)
}
......
......@@ -305,6 +305,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,
......@@ -372,6 +374,8 @@ impl SerialPort for COMPort {
Parity::None => NOPARITY as u8,
Parity::Odd => ODDPARITY as u8,
Parity::Even => EVENPARITY as u8,
Parity::Mark => MARKPARITY as u8,
Parity::Space => SPACEPARITY as u8,
};
self.set_dcb(&dcb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment