use crate::{
impl_extended_ops, impl_message_ops, impl_omnibus_extended_command,
len::QUERY_EXTENDED_NOTE_SPECIFICATION, std::fmt, ExtendedCommand, ExtendedCommandOps,
ExtendedNoteReporting, MessageOps, MessageType, OmnibusCommandOps,
};
pub mod index {
pub const NOTE_INDEX: usize = 7;
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct QueryExtendedNoteSpecification {
buf: [u8; QUERY_EXTENDED_NOTE_SPECIFICATION],
}
impl QueryExtendedNoteSpecification {
pub fn new() -> Self {
let mut message = Self {
buf: [0u8; QUERY_EXTENDED_NOTE_SPECIFICATION],
};
message.init();
message.set_message_type(MessageType::Extended);
message.set_extended_command(ExtendedCommand::ExtendedNoteSpecification);
message.set_extended_note(ExtendedNoteReporting::Set);
message
}
pub fn note_index(&self) -> usize {
self.buf[index::NOTE_INDEX] as usize
}
pub fn set_note_index(&mut self, index: usize) {
self.buf[index::NOTE_INDEX] = index as u8;
}
}
impl_message_ops!(QueryExtendedNoteSpecification);
impl_extended_ops!(QueryExtendedNoteSpecification);
impl_omnibus_extended_command!(QueryExtendedNoteSpecification);
impl fmt::Display for QueryExtendedNoteSpecification {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{{")?;
write!(f, r#""acknak": {}, "#, self.acknak())?;
write!(f, r#""device_type": {}, "#, self.device_type())?;
write!(f, r#""message_type": {}, "#, self.message_type())?;
write!(f, r#""extended_command": {}, "#, self.extended_command())?;
write!(f, r#""denomination": {}, "#, self.denomination())?;
write!(f, r#""operational_mode": {}, "#, self.operational_mode())?;
write!(f, r#""configuration": {}, "#, self.configuration())?;
write!(f, r#""note_index": {}"#, self.note_index())?;
write!(f, "}}")
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Result;
#[test]
#[rustfmt::skip]
fn test_query_extended_note_specification_from_bytes() -> Result<()> {
let msg_bytes = [
0x02, 0x0a, 0x70, 0x02,
0x00, 0x00, 0x00,
0x01,
0x03, 0x79,
];
let mut msg = QueryExtendedNoteSpecification::new();
msg.from_buf(msg_bytes.as_ref())?;
assert_eq!(msg.message_type(), MessageType::Extended);
assert_eq!(msg.extended_command(), ExtendedCommand::ExtendedNoteSpecification);
assert_eq!(msg.note_index(), 1);
Ok(())
}
}