-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from ssp-rs/feature/enable_payout
Feature/enable payout
- Loading branch information
Showing
18 changed files
with
943 additions
and
977 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Message types for disabling a payout device. | ||
|
||
mod command; | ||
mod response; | ||
|
||
pub use command::*; | ||
pub use response::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{len::DISABLE_PAYOUT_COMMAND, CommandOps, MessageOps, MessageType}; | ||
|
||
/// DisablePayout - Command (0x5B) | ||
/// | ||
/// All accepted notes will be routed to the stacker and payout commands will not be accepted. | ||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, Default, PartialEq)] | ||
pub struct DisablePayoutCommand { | ||
buf: [u8; DISABLE_PAYOUT_COMMAND], | ||
} | ||
|
||
impl DisablePayoutCommand { | ||
/// Creates a new [DisablePayoutCommand] message. | ||
pub fn new() -> Self { | ||
let mut msg = Self { | ||
buf: [0u8; DISABLE_PAYOUT_COMMAND], | ||
}; | ||
|
||
msg.init(); | ||
msg.set_command(MessageType::DisablePayout); | ||
|
||
msg | ||
} | ||
} | ||
|
||
impl_command_display!(DisablePayoutCommand); | ||
impl_message_from_buf!(DisablePayoutCommand); | ||
impl_message_ops!(DisablePayoutCommand); | ||
impl_command_ops!(DisablePayoutCommand); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::{len::DISABLE_PAYOUT_RESPONSE, message::MessageOps, MessageType}; | ||
|
||
/// DisablePayout - Response (0x09) | ||
/// | ||
/// Represents a response to an [DisablePayoutCommand](crate::DisablePayoutCommand) message. | ||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, Default, PartialEq)] | ||
pub struct DisablePayoutResponse { | ||
buf: [u8; DISABLE_PAYOUT_RESPONSE], | ||
} | ||
|
||
impl DisablePayoutResponse { | ||
/// Creates a new [DisablePayoutResponse] message. | ||
pub fn new() -> Self { | ||
let mut msg = Self { | ||
buf: [0u8; DISABLE_PAYOUT_RESPONSE], | ||
}; | ||
|
||
msg.init(); | ||
|
||
msg | ||
} | ||
} | ||
|
||
impl_message_from_buf!(DisablePayoutResponse); | ||
impl_message_ops!(DisablePayoutResponse, MessageType::DisablePayout); | ||
impl_response_ops!(DisablePayoutResponse); | ||
impl_response_display!(DisablePayoutResponse); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Messages for enabling devices equipped with a `Smart Payout` module. | ||
|
||
mod command; | ||
mod response; | ||
|
||
pub use command::*; | ||
pub use response::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use crate::{len, std::fmt, CommandOps, MessageOps, MessageType}; | ||
|
||
mod index { | ||
pub const PAYOUT_OPTION: usize = 4; | ||
} | ||
|
||
mod bitmask { | ||
pub const OPTION: u8 = 0b11; | ||
} | ||
|
||
bitfield! { | ||
/// Option byte for the [EnablePayoutCommand](crate::EnablePayoutCommand) message. | ||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, Default, PartialEq)] | ||
pub struct EnablePayoutOption(u8); | ||
u8; | ||
/// Option bitfield zero, has different meaning based on device type. | ||
/// | ||
/// - `nv11`: `GIVE_VALUE_ON_STORED` - set to enable the value of the note stored to be given | ||
/// with the `Note Stored` event. | ||
/// - `smart payout`: `REQUIRE_FULL_STARTUP` - if set, the `Smart Payout` will return busy | ||
/// until it has fully completed the startup procedure. | ||
pub field_0, set_field_0: 0; | ||
/// Option bitfield one, has different meaning based on device type. | ||
/// | ||
/// - `nv11`: `NO_HOLD_NOTE_ON_PAYOUT` - set to enable the function of fully rejecting the | ||
/// dispensed banknote rather then holding it in the bezel. | ||
/// - `smart payout`: `OPTIMISE_FOR_PAYIN_SPEED` - if set, the `Smart Payout` will always move | ||
/// towards an empty slot when idle to try and ensure the shortest pay in speed possible. | ||
pub field_1, set_field_1: 1; | ||
} | ||
|
||
impl From<u8> for EnablePayoutOption { | ||
fn from(val: u8) -> Self { | ||
Self(val & bitmask::OPTION) | ||
} | ||
} | ||
|
||
impl From<&EnablePayoutOption> for u8 { | ||
fn from(val: &EnablePayoutOption) -> Self { | ||
val.0 | ||
} | ||
} | ||
|
||
impl From<EnablePayoutOption> for u8 { | ||
fn from(val: EnablePayoutOption) -> Self { | ||
(&val).into() | ||
} | ||
} | ||
|
||
impl fmt::Display for EnablePayoutOption { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let f0 = self.field_0(); | ||
let f1 = self.field_1(); | ||
|
||
write!(f, r#"{{"field_0": {f0}, "field_1": {f1}}}"#) | ||
} | ||
} | ||
|
||
/// EnablePayout - Command (0x5C) | ||
/// | ||
/// A command to enable the attached payout device for storing/paying out notes. | ||
/// | ||
/// A successful enable will return OK. | ||
/// | ||
/// If there is a problem the reply will be generic response `COMMAND_CANNOT_BE_PROCESSED`, followed by an error code. | ||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct EnablePayoutCommand { | ||
buf: [u8; len::ENABLE_PAYOUT_COMMAND], | ||
} | ||
|
||
impl EnablePayoutCommand { | ||
/// Creates a new [EnablePayoutCommand] message. | ||
pub fn new() -> Self { | ||
let mut msg = Self { | ||
buf: [0u8; len::ENABLE_PAYOUT_COMMAND], | ||
}; | ||
|
||
msg.init(); | ||
msg.set_command(MessageType::EnablePayout); | ||
|
||
msg | ||
} | ||
|
||
/// Gets the [EnablePayoutOption]. | ||
pub fn option(&self) -> EnablePayoutOption { | ||
self.buf[index::PAYOUT_OPTION].into() | ||
} | ||
|
||
/// Sets the [EnablePayoutOption]. | ||
pub fn set_option(&mut self, option: EnablePayoutOption) { | ||
self.buf[index::PAYOUT_OPTION] = option.into(); | ||
} | ||
|
||
/// Builder function that sets the [EnablePayoutOption]. | ||
pub fn with_option(mut self, option: EnablePayoutOption) -> Self { | ||
self.set_option(option); | ||
self | ||
} | ||
} | ||
|
||
impl_default!(EnablePayoutCommand); | ||
impl_message_from_buf!(EnablePayoutCommand); | ||
impl_message_ops!(EnablePayoutCommand); | ||
impl_command_ops!(EnablePayoutCommand); | ||
|
||
impl fmt::Display for EnablePayoutCommand { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{{")?; | ||
write!(f, r#""stx": "0x{:02x}", "#, self.stx())?; | ||
write!(f, r#""sequence_id": {}, "#, self.sequence_id())?; | ||
write!(f, r#""len": "0x{:02x}", "#, self.data_len())?; | ||
write!(f, r#""command": {}, "#, self.command())?; | ||
write!(f, r#""option": {}, "#, self.option())?; | ||
write!(f, r#""checksum": "0x{:04x}""#, self.checksum())?; | ||
write!(f, "}}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{len, MessageOps, MessageType}; | ||
|
||
/// EnablePayout - Response (0x5C) | ||
/// | ||
/// Represents a response to an [EnablePayoutCommand](crate::EnablePayoutCommand) message. | ||
#[repr(C)] | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct EnablePayoutResponse { | ||
buf: [u8; len::ENABLE_PAYOUT_RESPONSE], | ||
} | ||
|
||
impl EnablePayoutResponse { | ||
/// Creates a new [EnablePayoutResponse] message. | ||
pub fn new() -> Self { | ||
let mut msg = Self { | ||
buf: [0u8; len::ENABLE_PAYOUT_RESPONSE], | ||
}; | ||
|
||
msg.init(); | ||
|
||
msg | ||
} | ||
} | ||
|
||
impl_default!(EnablePayoutResponse); | ||
impl_message_from_buf!(EnablePayoutResponse); | ||
impl_message_ops!(EnablePayoutResponse, MessageType::EnablePayout); | ||
impl_response_ops!(EnablePayoutResponse); | ||
impl_response_display!(EnablePayoutResponse); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.