Skip to content

Commit

Permalink
disable_payout: add the DisablePayout messages
Browse files Browse the repository at this point in the history
Adds the `DisablePayoutCommand` and `DisablePayoutResponse` messages, as
well as the `MessageVariant::DisablePayoutResponse` variant.
  • Loading branch information
ssp-rs committed Aug 23, 2023
1 parent d465284 commit 7630d5b
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 16 deletions.
8 changes: 2 additions & 6 deletions src/disable/command.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use crate::{
impl_command_display, impl_command_ops, impl_default, impl_message_from_buf, impl_message_ops,
len::DISABLE_COMMAND, CommandOps, MessageOps, MessageType,
};
use crate::{len::DISABLE_COMMAND, CommandOps, MessageOps, MessageType};

/// Disable - Command (0x09)
///
/// This single byte command disables the unit. This means the unit will enter its disabled state
/// and not execute any further commands or perform any other actions. A poll to the unit
/// while in this state will report disabled (0xE8)
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct DisableCommand {
buf: [u8; DISABLE_COMMAND],
}
Expand All @@ -28,7 +25,6 @@ impl DisableCommand {
}
}

impl_default!(DisableCommand);
impl_command_display!(DisableCommand);
impl_message_from_buf!(DisableCommand);
impl_message_ops!(DisableCommand);
Expand Down
8 changes: 2 additions & 6 deletions src/disable/response.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use crate::{
impl_default, impl_message_from_buf, impl_message_ops, impl_response_display,
impl_response_ops, len::DISABLE_RESPONSE, message::MessageOps, MessageType,
};
use crate::{len::DISABLE_RESPONSE, message::MessageOps, MessageType};

/// Disable - Response (0x09)
///
/// Represents a response to an [DisableCommand](crate::DisableCommand) message.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct DisableResponse {
buf: [u8; DISABLE_RESPONSE],
}
Expand All @@ -25,7 +22,6 @@ impl DisableResponse {
}
}

impl_default!(DisableResponse);
impl_message_from_buf!(DisableResponse);
impl_message_ops!(DisableResponse, MessageType::Disable);
impl_response_ops!(DisableResponse);
Expand Down
7 changes: 7 additions & 0 deletions src/disable_payout.rs
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::*;
29 changes: 29 additions & 0 deletions src/disable_payout/command.rs
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);
28 changes: 28 additions & 0 deletions src/disable_payout/response.rs
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);
4 changes: 4 additions & 0 deletions src/len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ pub const PAYOUT_BLOCK: usize = 9;
pub const ENABLE_PAYOUT_COMMAND: usize = 7;
/// EnablePayout Response full message length.
pub const ENABLE_PAYOUT_RESPONSE: usize = 6;
/// DisablePayout Command full message length.
pub const DISABLE_PAYOUT_COMMAND: usize = 6;
/// DisablePayout Response full message length.
pub const DISABLE_PAYOUT_RESPONSE: usize = 6;
/// Encrypted Command full message length.
///
/// Because encrypted messages have variable lengths, set the static length to maximum
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod configure_bezel;
pub mod crc;
pub mod dataset_version;
pub mod disable;
pub mod disable_payout;
pub mod display_off;
pub mod display_on;
pub mod empty;
Expand Down Expand Up @@ -82,6 +83,7 @@ pub use channels::*;
pub use configure_bezel::*;
pub use dataset_version::*;
pub use disable::*;
pub use disable_payout::*;
pub use display_off::*;
pub use display_on::*;
pub use empty::*;
Expand Down
17 changes: 13 additions & 4 deletions src/message/variant.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
std::fmt, ChannelValueDataResponse, ConfigureBezelResponse, DatasetVersionResponse,
DisableResponse, DisplayOffResponse, DisplayOnResponse, EmptyResponse, EnablePayoutResponse,
EnableResponse, EncryptionResetResponse, Error, EventAckResponse, GetBarcodeDataResponse,
GetBarcodeInhibitResponse, GetBarcodeReaderConfigurationResponse, HoldResponse,
HostProtocolVersionResponse, LastRejectCodeResponse, MessageType, PollResponse,
DisablePayoutResponse, DisableResponse, DisplayOffResponse, DisplayOnResponse, EmptyResponse,
EnablePayoutResponse, EnableResponse, EncryptionResetResponse, Error, EventAckResponse,
GetBarcodeDataResponse, GetBarcodeInhibitResponse, GetBarcodeReaderConfigurationResponse,
HoldResponse, HostProtocolVersionResponse, LastRejectCodeResponse, MessageType, PollResponse,
PollWithAckResponse, RejectResponse, RequestKeyExchangeResponse, ResponseOps, Result,
SerialNumberResponse, SetBarcodeInhibitResponse, SetBarcodeReaderConfigurationResponse,
SetEncryptionKeyResponse, SetGeneratorResponse, SetInhibitsResponse, SetModulusResponse,
Expand All @@ -24,6 +24,7 @@ pub enum MessageVariant {
ConfigureBezelResponse(ConfigureBezelResponse),
DatasetVersionResponse(DatasetVersionResponse),
DisableResponse(DisableResponse),
DisablePayoutResponse(DisablePayoutResponse),
DisplayOffResponse(DisplayOffResponse),
DisplayOnResponse(DisplayOnResponse),
EmptyResponse(EmptyResponse),
Expand Down Expand Up @@ -68,6 +69,7 @@ impl MessageVariant {
Self::DatasetVersionResponse(DatasetVersionResponse::new())
}
MessageType::Disable => Self::DisableResponse(DisableResponse::new()),
MessageType::DisablePayout => Self::DisablePayoutResponse(DisablePayoutResponse::new()),
MessageType::DisplayOff => Self::DisplayOffResponse(DisplayOffResponse::new()),
MessageType::DisplayOn => Self::DisplayOnResponse(DisplayOnResponse::new()),
MessageType::Empty => Self::EmptyResponse(EmptyResponse::new()),
Expand Down Expand Up @@ -132,6 +134,7 @@ impl MessageVariant {
Self::ConfigureBezelResponse(msg) => msg,
Self::DatasetVersionResponse(msg) => msg,
Self::DisableResponse(msg) => msg,
Self::DisablePayoutResponse(msg) => msg,
Self::DisplayOffResponse(msg) => msg,
Self::DisplayOnResponse(msg) => msg,
Self::EmptyResponse(msg) => msg,
Expand Down Expand Up @@ -171,6 +174,7 @@ impl MessageVariant {
Self::ConfigureBezelResponse(msg) => msg,
Self::DatasetVersionResponse(msg) => msg,
Self::DisableResponse(msg) => msg,
Self::DisablePayoutResponse(msg) => msg,
Self::DisplayOffResponse(msg) => msg,
Self::DisplayOnResponse(msg) => msg,
Self::EmptyResponse(msg) => msg,
Expand Down Expand Up @@ -223,6 +227,9 @@ impl MessageVariant {
DatasetVersionResponse::try_from(buf)?,
)),
MessageType::Disable => Ok(Self::DisableResponse(DisableResponse::try_from(buf)?)),
MessageType::DisablePayout => Ok(Self::DisablePayoutResponse(
DisablePayoutResponse::try_from(buf)?,
)),
MessageType::DisplayOff => {
Ok(Self::DisplayOffResponse(DisplayOffResponse::try_from(buf)?))
}
Expand Down Expand Up @@ -305,6 +312,7 @@ inner_enum!(MessageVariant, ChannelValueDataResponse);
inner_enum!(MessageVariant, ConfigureBezelResponse);
inner_enum!(MessageVariant, DatasetVersionResponse);
inner_enum!(MessageVariant, DisableResponse);
inner_enum!(MessageVariant, DisablePayoutResponse);
inner_enum!(MessageVariant, DisplayOffResponse);
inner_enum!(MessageVariant, DisplayOnResponse);
inner_enum!(MessageVariant, EmptyResponse);
Expand Down Expand Up @@ -342,6 +350,7 @@ impl fmt::Display for MessageVariant {
Self::ConfigureBezelResponse(msg) => write!(f, "ConfigureBezelResponse({msg})"),
Self::DatasetVersionResponse(msg) => write!(f, "DatasetVersionResponse({msg})"),
Self::DisableResponse(msg) => write!(f, "DisableResponse({msg})"),
Self::DisablePayoutResponse(msg) => write!(f, "DisablePayoutResponse({msg})"),
Self::DisplayOffResponse(msg) => write!(f, "DisplayOffResponse({msg})"),
Self::DisplayOnResponse(msg) => write!(f, "DisplayOnResponse({msg})"),
Self::EmptyResponse(msg) => write!(f, "EmptyResponse({msg})"),
Expand Down
15 changes: 15 additions & 0 deletions src/message/variant/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ fn test_variant_enable_payout_destructure() -> Result<()> {
Ok(())
}

#[test]
fn test_variant_disable_payout_destructure() -> Result<()> {
let mut exp_msg = DisablePayoutResponse::new();
exp_msg.calculate_checksum();

let exp_msg_type = exp_msg.message_type();
let var = MessageVariant::from_buf(exp_msg.buf(), exp_msg_type)?;

assert!(var.is_disable_payout_response());
assert_eq!(var.as_disable_payout_response()?, &exp_msg);
assert_eq!(var.into_disable_payout_response()?, exp_msg);

Ok(())
}

#[test]
fn test_variant_event_ack_destructure() -> Result<()> {
let mut exp_msg = EventAckResponse::new();
Expand Down

0 comments on commit 7630d5b

Please sign in to comment.