use crate::std;
use std::fmt;
use crate::{
impl_aux_ops, impl_message_ops, impl_omnibus_command_ops, len::QUERY_VARIANT_NAME_COMMAND,
AuxCommand, AuxCommandOps, MessageOps, MessageType,
};
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct QueryVariantNameCommand {
buf: [u8; QUERY_VARIANT_NAME_COMMAND],
}
impl QueryVariantNameCommand {
pub fn new() -> Self {
let mut message = Self {
buf: [0u8; QUERY_VARIANT_NAME_COMMAND],
};
message.init();
message.set_message_type(MessageType::AuxCommand);
message.set_aux_command(AuxCommand::QueryVariantName);
message
}
}
impl_message_ops!(QueryVariantNameCommand);
impl_omnibus_command_ops!(QueryVariantNameCommand);
impl_aux_ops!(QueryVariantNameCommand);
impl fmt::Display for QueryVariantNameCommand {
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#""aux_command": {}"#, self.aux_command())?;
write!(f, "}}")
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Result;
#[test]
#[rustfmt::skip]
fn test_query_boot_part_number_command_from_buf() -> Result<()> {
let msg_bytes = [
0x02, 0x08, 0x60,
0x00, 0x00,
0x08,
0x03, 0x60,
];
let mut msg = QueryVariantNameCommand::new();
msg.from_buf(msg_bytes.as_ref())?;
assert_eq!(msg.message_type(), MessageType::AuxCommand);
assert_eq!(msg.aux_command(), AuxCommand::QueryVariantName);
Ok(())
}
}