use crate::{
impl_extended_ops, impl_message_ops, impl_omnibus_extended_command,
len::SET_ESCROW_TIMEOUT_COMMAND, ExtendedCommand, ExtendedCommandOps, MessageOps, MessageType,
};
pub mod index {
pub const NOTES: usize = 7;
pub const BARCODES: usize = 8;
}
const TIMEOUT_MASK: u8 = 0x7f;
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct SetEscrowTimeoutCommand {
buf: [u8; SET_ESCROW_TIMEOUT_COMMAND],
}
impl SetEscrowTimeoutCommand {
pub fn new() -> Self {
let mut message = Self {
buf: [0u8; SET_ESCROW_TIMEOUT_COMMAND],
};
message.init();
message.set_message_type(MessageType::Extended);
message.set_extended_command(ExtendedCommand::SetEscrowTimeout);
message
}
pub fn notes_timeout(&self) -> u8 {
self.buf[index::NOTES] & TIMEOUT_MASK
}
pub fn set_notes_timeout(&mut self, secs: u8) {
self.buf[index::NOTES] = secs & TIMEOUT_MASK;
}
pub fn set_barcodes_timeout(&mut self, secs: u8) {
self.buf[index::BARCODES] = secs & TIMEOUT_MASK;
}
pub fn barcodes_timeout(&self) -> u8 {
self.buf[index::BARCODES] & TIMEOUT_MASK
}
}
impl_message_ops!(SetEscrowTimeoutCommand);
impl_extended_ops!(SetEscrowTimeoutCommand);
impl_omnibus_extended_command!(SetEscrowTimeoutCommand);
#[cfg(test)]
mod tests {
use super::*;
use crate::Result;
#[test]
#[rustfmt::skip]
fn test_set_escrow_timeout_command_from_bytes() -> Result<()> {
let msg_bytes = [
0x02, 0x0b, 0x70, 0x04,
0x00, 0x00, 0x00,
0x01,
0x02,
0x03, 0x7c,
];
let mut msg = SetEscrowTimeoutCommand::new();
msg.from_buf(msg_bytes.as_ref())?;
assert_eq!(msg.message_type(), MessageType::Extended);
assert_eq!(msg.extended_command(), ExtendedCommand::SetEscrowTimeout);
assert_eq!(msg.notes_timeout(), 1);
assert_eq!(msg.barcodes_timeout(), 2);
Ok(())
}
}