pub struct Odk<P: SerialPort, B: SignBus> { /* private fields */ }
Expand description
Connects to a real ODK over the specified serial port and uses it to drive a SignBus
.
Typically this will be used to drive a VirtualSignBus
in order to study the bus traffic
or inspect the pages of pixel data sent by the ODK.
§Examples
use flipdot_core::PageFlipStyle;
use flipdot_serial::SerialSignBus;
use flipdot_testing::{Address, Odk, VirtualSign, VirtualSignBus};
// Populate bus with signs from addresses 2 to 126
// (which seems to be the possible range for actual signs).
let signs = (2..127).map(Address).map(|addr| VirtualSign::new(addr, PageFlipStyle::Manual));
let bus = VirtualSignBus::new(signs);
// Hook up ODK to virtual bus.
let port = serial::open("/dev/ttyUSB0")?;
let mut odk = Odk::try_new(port, bus)?;
loop {
// ODK communications are forwarded to/from the virtual bus.
odk.process_message()?;
}
Implementations§
Source§impl<P: SerialPort, B: SignBus> Odk<P, B>
impl<P: SerialPort, B: SignBus> Odk<P, B>
Sourcepub fn try_new(port: P, bus: B) -> Result<Self, Error>
pub fn try_new(port: P, bus: B) -> Result<Self, Error>
Create a new Odk
that connects the specified serial port and bus.
§Errors
Returns the underlying serial_core::Error
if the serial port cannot be configured.
§Examples
let bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3), PageFlipStyle::Manual)]);
let port = serial::open("COM3")?;
let odk = Odk::try_new(port, bus)?;
Note: You would typically use the env_logger
crate and run with
RUST_LOG=debug
to watch the bus messages go by.
Sourcepub fn process_message(&mut self) -> Result<(), OdkError>
pub fn process_message(&mut self) -> Result<(), OdkError>
Reads the next frame from the ODK over the serial port, forwards it to the attached bus, and sends the response, if any, back to the ODK.
§Errors
Returns:
OdkError::Communication
if there was an error reading or writing the data.OdkError::Bus
if the bus failed to process the message.
§Examples
let bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3), PageFlipStyle::Manual)]);
let port = serial::open("/dev/ttyUSB0")?;
let mut odk = Odk::try_new(port, bus)?;
loop {
odk.process_message()?;
}
Trait Implementations§
impl<P: Eq + SerialPort, B: Eq + SignBus> Eq for Odk<P, B>
impl<P: SerialPort, B: SignBus> StructuralPartialEq for Odk<P, B>
Auto Trait Implementations§
impl<P, B> Freeze for Odk<P, B>
impl<P, B> RefUnwindSafe for Odk<P, B>where
P: RefUnwindSafe,
B: RefUnwindSafe,
impl<P, B> Send for Odk<P, B>
impl<P, B> Sync for Odk<P, B>
impl<P, B> Unpin for Odk<P, B>
impl<P, B> UnwindSafe for Odk<P, B>where
P: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more