Skip to main content

vuquest_3320/
command.rs

1//! Serial commands for configuring the BCS device.
2
3use core::fmt;
4
5use alloc::string::String;
6
7pub mod image_snap;
8mod manual_trigger;
9mod mobile_phone;
10mod pdf;
11mod qr;
12mod query;
13mod serial_trigger;
14mod software_rev;
15mod symbologies;
16mod trigger;
17
18pub use image_snap::*;
19pub use manual_trigger::*;
20pub use mobile_phone::*;
21pub use pdf::*;
22pub use qr::*;
23pub use query::*;
24pub use serial_trigger::*;
25pub use software_rev::*;
26pub use symbologies::*;
27pub use trigger::*;
28
29/// Represents Honeywell BCS serial commands.
30#[derive(Clone, Copy, Debug, Eq, PartialEq)]
31pub enum SerialCommand {
32    AllSymbologies(AllSymbologies),
33    ImageSnap(ImageSnap),
34    ManualTriggerMode(ManualTriggerMode),
35    MobilePhoneReadMode(MobilePhoneReadMode),
36    PDF417(PDF417),
37    QRCode(QRCode),
38    SoftwareRevision(SoftwareRevision),
39    Trigger(Trigger),
40}
41
42impl SerialCommand {
43    /// Creates a new [SerialCommand].
44    pub const fn new() -> Self {
45        Self::AllSymbologies(AllSymbologies::new())
46    }
47
48    /// Gets the ASCII-encoded [SerialCommand].
49    pub fn command(&self) -> String {
50        match self {
51            Self::AllSymbologies(cmd) => cmd.command().into(),
52            Self::ImageSnap(cmd) => cmd.command(),
53            Self::ManualTriggerMode(cmd) => cmd.command().into(),
54            Self::MobilePhoneReadMode(cmd) => cmd.command().into(),
55            Self::PDF417(cmd) => cmd.command().into(),
56            Self::QRCode(cmd) => cmd.command().into(),
57            Self::SoftwareRevision(cmd) => cmd.command().into(),
58            Self::Trigger(cmd) => cmd.command().into(),
59        }
60    }
61}
62
63impl Default for SerialCommand {
64    fn default() -> Self {
65        Self::new()
66    }
67}
68
69/// Represents a Honeywell BCS serial command.
70#[derive(Clone, Copy, Debug, Eq, PartialEq)]
71pub struct Command {
72    serial: SerialCommand,
73    query: Option<QueryCommand>,
74}
75
76impl Command {
77    /// Creates a new [Command].
78    pub const fn new() -> Self {
79        Self {
80            serial: SerialCommand::new(),
81            query: None,
82        }
83    }
84}
85
86impl Default for Command {
87    fn default() -> Self {
88        Self::new()
89    }
90}
91
92impl fmt::Display for Command {
93    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94        let cmd = self.serial.command();
95        let query = self
96            .query
97            .map(|q| String::from(q.command()))
98            .unwrap_or_default();
99
100        write!(f, "{cmd}{query}.")
101    }
102}