Struct Odk

Source
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>

Source

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.

Source

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:

§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§

Source§

impl<P: Debug + SerialPort, B: Debug + SignBus> Debug for Odk<P, B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: Hash + SerialPort, B: Hash + SignBus> Hash for Odk<P, B>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<P: PartialEq + SerialPort, B: PartialEq + SignBus> PartialEq for Odk<P, B>

Source§

fn eq(&self, other: &Odk<P, B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Eq + SerialPort, B: Eq + SignBus> Eq for Odk<P, B>

Source§

impl<P: SerialPort, B: SignBus> StructuralPartialEq for Odk<P, B>

Auto Trait Implementations§

§

impl<P, B> Freeze for Odk<P, B>
where P: Freeze, B: Freeze,

§

impl<P, B> RefUnwindSafe for Odk<P, B>

§

impl<P, B> Send for Odk<P, B>
where P: Send, B: Send,

§

impl<P, B> Sync for Odk<P, B>
where P: Sync, B: Sync,

§

impl<P, B> Unpin for Odk<P, B>
where P: Unpin, B: Unpin,

§

impl<P, B> UnwindSafe for Odk<P, B>
where P: UnwindSafe, B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.