Struct ssp_server::device_handle::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
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...
}
}sourcepub fn serial_port(&self) -> Result<MutexGuard<'_, TTYPort>>
pub fn serial_port(&self) -> Result<MutexGuard<'_, TTYPort>>
Get 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 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 disable(&self) -> Result<DisableResponse>
pub fn disable(&self) -> Result<DisableResponse>
Send a DisableCommand 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.
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.