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
impl DeviceHandle
Sourcepub fn new(serial_path: &str) -> Result<Self>
pub fn new(serial_path: &str) -> Result<Self>
Creates a new DeviceHandle with a serial connection over the supplied serial device.
Sourcepub fn start_background_polling(
&self,
stop_polling: Arc<AtomicBool>,
) -> Result<()>
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))?;Sourcepub fn start_background_polling_with_queue(
&self,
stop_polling: Arc<AtomicBool>,
poll_mode: PollMode,
) -> Result<PushEventReceiver>
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...
}
}pub fn on_message(&mut self, stream: &mut UnixStream) -> Result<Method>
jsonrpc only.Sourcepub fn on_disable(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_disable(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
jsonrpc only.Message handler for Disable events.
Exposed to help with creating a custom message handler.
Sourcepub fn on_disable_payout(
&self,
stream: &mut UnixStream,
_event: &Event,
) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_disable_payout( &self, stream: &mut UnixStream, _event: &Event, ) -> Result<()>
jsonrpc only.Message handler for Disable events.
Exposed to help with creating a custom message handler.
Sourcepub fn on_enable(&self, stream: &mut UnixStream, event: &Event) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_enable(&self, stream: &mut UnixStream, event: &Event) -> Result<()>
jsonrpc only.Message handler for Enable events.
Exposed to help with creating a custom message handler.
Sourcepub fn on_enable_payout(
&self,
stream: &mut UnixStream,
event: &Event,
) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_enable_payout( &self, stream: &mut UnixStream, event: &Event, ) -> Result<()>
jsonrpc only.Message handler for Enable events.
Exposed to help with creating a custom message handler.
Sourcepub fn on_reject(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_reject(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
jsonrpc only.Message handler for Reject events.
Exposed to help with creating a custom message handler.
Sourcepub fn on_stack(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_stack(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
jsonrpc only.Message handler for Stack events.
Exposed to help with creating a custom message handler.
Sourcepub fn on_stacker_full(
&self,
_stream: &mut UnixStream,
_event: &Event,
) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_stacker_full( &self, _stream: &mut UnixStream, _event: &Event, ) -> Result<()>
jsonrpc only.Message handler for StackerFull events.
Exposed to help with creating a custom message handler.
Sourcepub fn on_status(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_status(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
jsonrpc only.Message handler for Status events.
Exposed to help with creating a custom message handler.
Sourcepub fn on_reset(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_reset(&self, stream: &mut UnixStream, _event: &Event) -> Result<()>
jsonrpc only.Message handler for Status events.
Exposed to help with creating a custom message handler.
Sourcepub fn full_reset(&self) -> Result<()>
pub fn full_reset(&self) -> Result<()>
Performs the full reset protocol to restart a device.
Sourcepub fn dispensing(&self) -> bool
pub fn dispensing(&self) -> bool
Gets whether the device is currently dispensing notes.
Sourcepub fn on_dispense(&self, stream: &mut UnixStream, event: &Event) -> Result<()>
Available on crate feature jsonrpc only.
pub fn on_dispense(&self, stream: &mut UnixStream, event: &Event) -> Result<()>
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.
Sourcepub fn serial_port(&self) -> Result<MutexGuard<'_, TTYPort>>
pub fn serial_port(&self) -> Result<MutexGuard<'_, TTYPort>>
Acquires a lock on the serial port used for communication with the acceptor device.
Sourcepub fn encryption_key(&self) -> Result<MutexGuard<'_, Option<AesKey>>>
pub fn encryption_key(&self) -> Result<MutexGuard<'_, Option<AesKey>>>
Acquires a lock on the AES encryption key.
Sourcepub fn new_generator_key(&mut self)
pub fn new_generator_key(&mut self)
Creates a new GeneratorKey from system entropy.
Sourcepub fn new_modulus_key(&mut self)
pub fn new_modulus_key(&mut self)
Creates a new ModulusKey from system entropy.
Sourcepub fn new_random_key(&mut self)
pub fn new_random_key(&mut self)
Creates a new RandomKey from system entropy.
Sourcepub fn reset_key(&mut self) -> Option<AesKey>
pub fn reset_key(&mut self) -> Option<AesKey>
Resets the Encryption key to none, requires a new key negotiation before performing eSSP operations.
Sourcepub fn negotiate_key(&mut self) -> Result<()>
pub fn negotiate_key(&mut self) -> Result<()>
Performs key negotiation to start a new eSSP session.
Uses currently set [GeneratorKey] and [ModulusKey].
Sourcepub fn renegotiate_key(&mut self) -> Result<()>
pub fn renegotiate_key(&mut self) -> Result<()>
Renegotiates the encryption key for a new eSSP session.
Sourcepub fn stack(&self) -> Result<ChannelValue>
pub fn stack(&self) -> Result<ChannelValue>
Sends a command to stack a bill in escrow.
Sourcepub fn set_inhibits(
&self,
enable_list: EnableBitfieldList,
) -> Result<SetInhibitsResponse>
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.
Sourcepub fn reset(&self) -> Result<()>
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.
Sourcepub fn poll(&self) -> Result<PollResponse>
pub fn poll(&self) -> Result<PollResponse>
Send a PollCommand message to the device.
Sourcepub fn poll_with_ack(&self) -> Result<PollWithAckResponse>
pub fn poll_with_ack(&self) -> Result<PollWithAckResponse>
Send a PollWithAckCommand message to the device.
Sourcepub fn event_ack(&self) -> Result<EventAckResponse>
pub fn event_ack(&self) -> Result<EventAckResponse>
Send a EventAckCommand message to the device.
Sourcepub fn reject(&self) -> Result<RejectResponse>
pub fn reject(&self) -> Result<RejectResponse>
Send a RejectCommand message to the device.
Sourcepub fn sync(&self) -> Result<SyncResponse>
pub fn sync(&self) -> Result<SyncResponse>
Send a SyncCommand message to the device.
Sourcepub fn enable_device(
&self,
protocol_version: ProtocolVersion,
) -> Result<EnableResponse>
pub fn enable_device( &self, protocol_version: ProtocolVersion, ) -> Result<EnableResponse>
Starts the device by performing the full initialization sequence.
Sourcepub fn enable(&self) -> Result<EnableResponse>
pub fn enable(&self) -> Result<EnableResponse>
Send a EnableCommand message to the device.
Sourcepub fn enable_payout(&self) -> Result<EnablePayoutResponse>
pub fn enable_payout(&self) -> Result<EnablePayoutResponse>
Send a EnablePayoutCommand message to the device.
Sourcepub fn disable(&self) -> Result<DisableResponse>
pub fn disable(&self) -> Result<DisableResponse>
Send a DisableCommand message to the device.
Sourcepub fn disable_payout(&self) -> Result<DisablePayoutResponse>
pub fn disable_payout(&self) -> Result<DisablePayoutResponse>
Send a DisablePayoutCommand message to the device.
Sourcepub fn display_off(&self) -> Result<DisplayOffResponse>
pub fn display_off(&self) -> Result<DisplayOffResponse>
Send a DisplayOffCommand message to the device.
Sourcepub fn display_on(&self) -> Result<DisplayOnResponse>
pub fn display_on(&self) -> Result<DisplayOnResponse>
Send a DisplayOnCommand message to the device.
Sourcepub fn empty(&self) -> Result<EmptyResponse>
pub fn empty(&self) -> Result<EmptyResponse>
Send an EmptyCommand message to the device.
Sourcepub fn smart_empty(&self) -> Result<SmartEmptyResponse>
pub fn smart_empty(&self) -> Result<SmartEmptyResponse>
Send an SmartEmptyCommand message to the device.
Sourcepub fn host_protocol_version(
&self,
protocol_version: ProtocolVersion,
) -> Result<HostProtocolVersionResponse>
pub fn host_protocol_version( &self, protocol_version: ProtocolVersion, ) -> Result<HostProtocolVersionResponse>
Send an HostProtocolVersionCommand message to the device.
Sourcepub fn serial_number(&self) -> Result<SerialNumberResponse>
pub fn serial_number(&self) -> Result<SerialNumberResponse>
Send a SerialNumberCommand message to the device.
Sourcepub fn set_generator(&self) -> Result<SetGeneratorResponse>
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.
Sourcepub fn set_modulus(&mut self) -> Result<SetModulusResponse>
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.
Sourcepub fn request_key_exchange(&mut self) -> Result<RequestKeyExchangeResponse>
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.
Sourcepub fn set_encryption_key(&mut self) -> Result<SetEncryptionKeyResponse>
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.
Sourcepub fn encryption_reset(&mut self) -> Result<EncryptionResetResponse>
pub fn encryption_reset(&mut self) -> Result<EncryptionResetResponse>
Send a EncryptionResetCommand message to the device.
Sourcepub fn setup_request(&self) -> Result<SetupRequestResponse>
pub fn setup_request(&self) -> Result<SetupRequestResponse>
Send a SetupRequestCommand message to the device.
Sourcepub fn unit_data(&self) -> Result<UnitDataResponse>
pub fn unit_data(&self) -> Result<UnitDataResponse>
Send a UnitDataCommand message to the device.
pub fn dataset_version(&self) -> Result<DatasetVersionResponse>
pub fn dataset_version_inner( serial_port: &mut TTYPort, key: Option<&AesKey>, ) -> Result<DatasetVersionResponse>
Sourcepub fn channel_value_data(&self) -> Result<ChannelValueDataResponse>
pub fn channel_value_data(&self) -> Result<ChannelValueDataResponse>
Send a ChannelValueDataCommand message to the device.
Sourcepub fn last_reject_code(&self) -> Result<LastRejectCodeResponse>
pub fn last_reject_code(&self) -> Result<LastRejectCodeResponse>
Send a LastRejectCodeCommand message to the device.
Sourcepub fn hold(&self) -> Result<HoldResponse>
pub fn hold(&self) -> Result<HoldResponse>
Send a HoldCommand message to the device.
Sourcepub fn get_barcode_reader_configuration(
&self,
) -> Result<GetBarcodeReaderConfigurationResponse>
pub fn get_barcode_reader_configuration( &self, ) -> Result<GetBarcodeReaderConfigurationResponse>
Send a GetBarcodeReaderConfigurationCommand message to the device.
Sourcepub fn has_barcode_reader(&self) -> Result<bool>
pub fn has_barcode_reader(&self) -> Result<bool>
Gets whether the device has barcode readers present.
Sourcepub fn set_barcode_reader_configuration(
&self,
config: BarcodeConfiguration,
) -> Result<SetBarcodeReaderConfigurationResponse>
pub fn set_barcode_reader_configuration( &self, config: BarcodeConfiguration, ) -> Result<SetBarcodeReaderConfigurationResponse>
Send a SetBarcodeReaderConfigurationCommand message to the device.
Sourcepub fn get_barcode_inhibit(&self) -> Result<GetBarcodeInhibitResponse>
pub fn get_barcode_inhibit(&self) -> Result<GetBarcodeInhibitResponse>
Send a GetBarcodeInhibitCommand message to the device.
Sourcepub fn set_barcode_inhibit(
&self,
inhibit: BarcodeCurrencyInhibit,
) -> Result<SetBarcodeInhibitResponse>
pub fn set_barcode_inhibit( &self, inhibit: BarcodeCurrencyInhibit, ) -> Result<SetBarcodeInhibitResponse>
Send a SetBarcodeInhibitCommand message to the device.
Sourcepub fn get_barcode_data(&self) -> Result<GetBarcodeDataResponse>
pub fn get_barcode_data(&self) -> Result<GetBarcodeDataResponse>
Send a GetBarcodeDataCommand message to the device.
Sourcepub fn configure_bezel(
&self,
rgb: RGB,
storage: BezelConfigStorage,
) -> Result<ConfigureBezelResponse>
pub fn configure_bezel( &self, rgb: RGB, storage: BezelConfigStorage, ) -> Result<ConfigureBezelResponse>
Send a ConfigureBezelCommand message to the device.
Sourcepub fn payout_by_denomination(
&self,
list: &PayoutDenominationList,
) -> Result<()>
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