DeviceHandle

Struct DeviceHandle 

Source
pub struct DeviceHandle { /* private fields */ }
Expand description

Handle for communicating with a SSP-enabled device over serial.

let _handle = ssp_server::DeviceHandle::new("/dev/ttyUSB0").unwrap();

Implementations§

Source§

impl DeviceHandle

Source

pub fn new(serial_path: &str) -> Result<Self>

Creates a new DeviceHandle with a serial connection over the supplied serial device.

Source

pub fn start_background_polling( &self, stop_polling: Arc<AtomicBool>, ) -> Result<()>

Starts background polling routine to regularly send [PollCommand] messages to the device.

Args

  • stop_polling: used to control when the polling routine should stop sending polling messages.

If background polling has already started, the function just returns.

Example:

let stop_polling = Arc::new(AtomicBool::new(false));

let handle = ssp_server::DeviceHandle::new("/dev/ttyUSB0")?;

handle.start_background_polling(Arc::clone(&stop_polling))?;
Source

pub fn start_background_polling_with_queue( &self, stop_polling: Arc<AtomicBool>, poll_mode: PollMode, ) -> Result<PushEventReceiver>

Starts background polling routine to regularly send [PollCommand] messages to the device, with an additional event queue for sending push events from the device to the host.

Args

  • stop_polling: used to control when the polling routine should stop sending polling messages.

If background polling has already started, the function just returns.

Returns an event queue receiver that the caller can use to receive device-sent events.

Example:

let stop_polling = Arc::new(AtomicBool::new(false));
let poll_mode = ssp_server::PollMode::Interactive;

let handle = ssp_server::DeviceHandle::new("/dev/ttyUSB0")?;

let rx = handle.start_background_polling_with_queue(
    Arc::clone(&stop_polling),
    poll_mode,
)?;

// Pop events from the queue
loop {
    while let Ok(event) = rx.pop_event() {
        log::debug!("Received an event: {event}");
        // do stuff in response to the event...
    }
}
Source

pub fn on_message(&mut self, stream: &mut UnixStream) -> Result<Method>

Available on crate feature jsonrpc only.
Source

pub fn on_disable(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for Disable events.

Exposed to help with creating a custom message handler.

Source

pub fn on_disable_payout( &self, stream: &mut UnixStream, _event: &Event, ) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for Disable events.

Exposed to help with creating a custom message handler.

Source

pub fn on_enable(&self, stream: &mut UnixStream, event: &Event) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for Enable events.

Exposed to help with creating a custom message handler.

Source

pub fn on_enable_payout( &self, stream: &mut UnixStream, event: &Event, ) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for Enable events.

Exposed to help with creating a custom message handler.

Source

pub fn on_reject(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for Reject events.

Exposed to help with creating a custom message handler.

Source

pub fn on_stack(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for Stack events.

Exposed to help with creating a custom message handler.

Source

pub fn on_stacker_full( &self, _stream: &mut UnixStream, _event: &Event, ) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for StackerFull events.

Exposed to help with creating a custom message handler.

Source

pub fn on_status(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for Status events.

Exposed to help with creating a custom message handler.

Source

pub fn on_reset(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>

Available on crate feature jsonrpc only.

Message handler for Status events.

Exposed to help with creating a custom message handler.

Source

pub fn full_reset(&self) -> Result<()>

Performs the full reset protocol to restart a device.

Source

pub fn dispensing(&self) -> bool

Gets whether the device is currently dispensing notes.

Source

pub fn on_dispense(&self, stream: &mut UnixStream, event: &Event) -> Result<()>

Available on crate feature jsonrpc only.

Message handle for dispense request using a PayoutDenominationList.

User is responsible for parsing a request into a valid list.

Exposed to help with creating a custom message handler.

Source

pub fn serial_port(&self) -> Result<MutexGuard<'_, TTYPort>>

Acquires a lock on the serial port used for communication with the acceptor device.

Source

pub fn encryption_key(&self) -> Result<MutexGuard<'_, Option<AesKey>>>

Acquires a lock on the AES encryption key.

Source

pub fn new_generator_key(&mut self)

Creates a new GeneratorKey from system entropy.

Source

pub fn new_modulus_key(&mut self)

Creates a new ModulusKey from system entropy.

Source

pub fn new_random_key(&mut self)

Creates a new RandomKey from system entropy.

Source

pub fn reset_key(&mut self) -> Option<AesKey>

Resets the Encryption key to none, requires a new key negotiation before performing eSSP operations.

Source

pub fn negotiate_key(&mut self) -> Result<()>

Performs key negotiation to start a new eSSP session.

Uses currently set [GeneratorKey] and [ModulusKey].

Source

pub fn renegotiate_key(&mut self) -> Result<()>

Renegotiates the encryption key for a new eSSP session.

Source

pub fn stack(&self) -> Result<ChannelValue>

Sends a command to stack a bill in escrow.

Source

pub fn set_inhibits( &self, enable_list: EnableBitfieldList, ) -> Result<SetInhibitsResponse>

Send a SetInhibitsCommand message to the device.

No response is returned.

The caller should wait a reasonable amount of time for the device to come back online before sending additional messages.

Source

pub fn reset(&self) -> Result<()>

Send a ResetCommand message to the device.

No response is returned.

The caller should wait a reasonable amount of time for the device to come back online before sending additional messages.

Source

pub fn poll(&self) -> Result<PollResponse>

Send a PollCommand message to the device.

Source

pub fn poll_with_ack(&self) -> Result<PollWithAckResponse>

Send a PollWithAckCommand message to the device.

Source

pub fn event_ack(&self) -> Result<EventAckResponse>

Send a EventAckCommand message to the device.

Source

pub fn reject(&self) -> Result<RejectResponse>

Send a RejectCommand message to the device.

Source

pub fn sync(&self) -> Result<SyncResponse>

Send a SyncCommand message to the device.

Source

pub fn enable_device( &self, protocol_version: ProtocolVersion, ) -> Result<EnableResponse>

Starts the device by performing the full initialization sequence.

Source

pub fn enable(&self) -> Result<EnableResponse>

Send a EnableCommand message to the device.

Source

pub fn enable_payout(&self) -> Result<EnablePayoutResponse>

Send a EnablePayoutCommand message to the device.

Source

pub fn disable(&self) -> Result<DisableResponse>

Send a DisableCommand message to the device.

Source

pub fn disable_payout(&self) -> Result<DisablePayoutResponse>

Send a DisablePayoutCommand message to the device.

Source

pub fn display_off(&self) -> Result<DisplayOffResponse>

Send a DisplayOffCommand message to the device.

Source

pub fn display_on(&self) -> Result<DisplayOnResponse>

Send a DisplayOnCommand message to the device.

Source

pub fn empty(&self) -> Result<EmptyResponse>

Send an EmptyCommand message to the device.

Source

pub fn smart_empty(&self) -> Result<SmartEmptyResponse>

Send an SmartEmptyCommand message to the device.

Source

pub fn host_protocol_version( &self, protocol_version: ProtocolVersion, ) -> Result<HostProtocolVersionResponse>

Send an HostProtocolVersionCommand message to the device.

Source

pub fn serial_number(&self) -> Result<SerialNumberResponse>

Send a SerialNumberCommand message to the device.

Source

pub fn set_generator(&self) -> Result<SetGeneratorResponse>

Send a SetGeneratorCommand message to the device.

If the response is an Err(_), or the response status is not RsponseStatus::Ok, the caller should call new_generator_key, and try again.

Source

pub fn set_modulus(&mut self) -> Result<SetModulusResponse>

Send a SetModulusCommand message to the device.

If the response is an Err(_), or the response status is not RsponseStatus::Ok, the caller should call new_modulus_key, and try again.

Source

pub fn request_key_exchange(&mut self) -> Result<RequestKeyExchangeResponse>

Send a RequestKeyExchangeCommand message to the device.

If the response is an Err(_), or the response status is not RsponseStatus::Ok, the caller should call new_random_key, and try again.

Source

pub fn set_encryption_key(&mut self) -> Result<SetEncryptionKeyResponse>

Send a SetEncryptionKeyCommand message to the device.

If the response is an Err(_), or the response status is not RsponseStatus::Ok, the caller should call new_modulus_key, and try again.

Source

pub fn encryption_reset(&mut self) -> Result<EncryptionResetResponse>

Send a EncryptionResetCommand message to the device.

Source

pub fn setup_request(&self) -> Result<SetupRequestResponse>

Send a SetupRequestCommand message to the device.

Source

pub fn unit_data(&self) -> Result<UnitDataResponse>

Send a UnitDataCommand message to the device.

Source

pub fn dataset_version(&self) -> Result<DatasetVersionResponse>

Source

pub fn dataset_version_inner( serial_port: &mut TTYPort, key: Option<&AesKey>, ) -> Result<DatasetVersionResponse>

Source

pub fn channel_value_data(&self) -> Result<ChannelValueDataResponse>

Send a ChannelValueDataCommand message to the device.

Source

pub fn last_reject_code(&self) -> Result<LastRejectCodeResponse>

Send a LastRejectCodeCommand message to the device.

Source

pub fn hold(&self) -> Result<HoldResponse>

Send a HoldCommand message to the device.

Source

pub fn get_barcode_reader_configuration( &self, ) -> Result<GetBarcodeReaderConfigurationResponse>

Send a GetBarcodeReaderConfigurationCommand message to the device.

Source

pub fn has_barcode_reader(&self) -> Result<bool>

Gets whether the device has barcode readers present.

Source

pub fn set_barcode_reader_configuration( &self, config: BarcodeConfiguration, ) -> Result<SetBarcodeReaderConfigurationResponse>

Send a SetBarcodeReaderConfigurationCommand message to the device.

Source

pub fn get_barcode_inhibit(&self) -> Result<GetBarcodeInhibitResponse>

Send a GetBarcodeInhibitCommand message to the device.

Source

pub fn set_barcode_inhibit( &self, inhibit: BarcodeCurrencyInhibit, ) -> Result<SetBarcodeInhibitResponse>

Send a SetBarcodeInhibitCommand message to the device.

Source

pub fn get_barcode_data(&self) -> Result<GetBarcodeDataResponse>

Send a GetBarcodeDataCommand message to the device.

Source

pub fn configure_bezel( &self, rgb: RGB, storage: BezelConfigStorage, ) -> Result<ConfigureBezelResponse>

Send a ConfigureBezelCommand message to the device.

Source

pub fn payout_by_denomination( &self, list: &PayoutDenominationList, ) -> Result<()>

Dispenses notes from the device by sending a [PayoutByDenominationCommand] message.

NOTE: this command requires encryption mode.

Parameters:

  • list: list of [PayoutDenomination] requests

Returns:

  • Ok(())
  • Err(Error) if an error occured

Auto Trait Implementations§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V