pub mod ftdi;
pub mod ip_port;
pub mod ip_server_port;
pub mod null_port;
pub mod option_parse;
pub mod prologix;
pub mod serial_config;
pub mod usbtmc;
pub mod vxi11;
#[cfg(unix)]
pub mod serial_port;
#[cfg(windows)]
#[path = "serial_port_win32.rs"]
pub mod serial_port;
pub(crate) fn wait_millis(budget: std::time::Duration) -> u128 {
if budget.is_zero() {
0
} else {
budget.as_millis().max(1)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::port::PortDriver;
use std::time::Duration;
#[test]
fn no_ported_driver_grants_the_shutdown_rights_c_withholds() {
let mut granted: Vec<&str> = Vec::new();
let mut check = |what: &'static str, d: &dyn PortDriver| {
if d.base().flags.destructible {
granted.push(what);
}
};
let server =
ip_server_port::DrvAsynIPServerPort::new("SRV", "127.0.0.1:0 tcp").expect("server");
let child = server.make_subport(0).expect("subport 0");
check(
"ftdi",
&ftdi::DrvAsynFtdiPort::configure("FTDI", 0x0403, 0x6001, 9600, 1, 0, true, false, 0)
.expect("ftdi"),
);
check(
"ip_port",
&ip_port::DrvAsynIPPort::new("IP", "127.0.0.1:1234 TCP").expect("ip"),
);
check("ip_server_port (listener)", &server);
check("ip_server_port (child)", &child);
check("null_port", &null_port::NullOctetPort::new("NULLP"));
check(
"prologix",
&prologix::DrvAsynPrologixPort::new("GPIB", "127.0.0.1:1234", true).expect("prologix"),
);
check(
"serial_port",
&serial_port::DrvAsynSerialPort::new("SER", "/dev/null").expect("serial"),
);
check(
"usbtmc",
&usbtmc::DrvAsynUsbtmcPort::configure("TMC", 0x0957, 0x1755, "", 0, 1).expect("usbtmc"),
);
check(
"vxi11",
&vxi11::DrvVxi11Port::configure("VXI", "127.0.0.1", 0, "", "inst0", 0, true)
.expect("vxi11"),
);
assert!(
granted.is_empty(),
"these ports grant ASYN_DESTRUCTIBLE where their C original withholds it: {granted:?}"
);
}
#[test]
fn wait_millis_separates_an_expired_budget_from_a_sub_millisecond_one() {
assert_eq!(wait_millis(Duration::ZERO), 0);
assert_eq!(wait_millis(Duration::from_nanos(1)), 1);
assert_eq!(wait_millis(Duration::from_micros(500)), 1);
assert_eq!(wait_millis(Duration::from_millis(1)), 1);
assert_eq!(wait_millis(Duration::from_micros(1500)), 1);
assert_eq!(wait_millis(Duration::from_millis(250)), 250);
}
}