bnr_xfs/capabilities/self_test_mode.rs
1use std::fmt;
2
3use crate::impl_xfs_enum;
4
5const SELF_TEST_AUTO: u32 = 0;
6const SELF_TEST_DEVICE: u32 = 1;
7
8/// Defines how the BNR perform the self tests.
9///
10/// Integration recommendations:
11///
12/// If the device mode [Device](SelfTestMode::Device) is used, the Host should send a [self_test](crate::maintenance::self_test) command at every time that internal tests and movements of the BNR can be allowed.
13///
14/// It is recommended to send [self_test](crate::maintenance::self_test), after a [present](crate::cash::present) command to allow the BNR to refloat the recyclers.
15#[repr(u32)]
16#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
17pub enum SelfTestMode {
18 /// This is the default and recommended mode. In this mode, the BNR does self tests automatically.
19 /// After [reset](crate::init::reset) or [present](crate::cash::present), the BNR refloats the Recyclers from the Loader, when necessary.
20 #[default]
21 Auto = SELF_TEST_AUTO,
22 /// In this mode, the BNR doesn’t do anything automatically, but waits for a [self_test](crate::maintenance::self_test) command to do all self test actions.
23 Device = SELF_TEST_DEVICE,
24}
25
26impl SelfTestMode {
27 /// Creates a new [SelfTestMode].
28 pub const fn new() -> Self {
29 Self::Auto
30 }
31
32 /// Creates a new [SelfTestMode] from the provided parameter.
33 pub const fn create(val: u32) -> Self {
34 match val {
35 SELF_TEST_AUTO => Self::Auto,
36 SELF_TEST_DEVICE => Self::Device,
37 _ => Self::Auto,
38 }
39 }
40}
41
42impl From<&SelfTestMode> for &'static str {
43 fn from(val: &SelfTestMode) -> Self {
44 match val {
45 SelfTestMode::Auto => "auto",
46 SelfTestMode::Device => "device",
47 }
48 }
49}
50
51impl From<SelfTestMode> for &'static str {
52 fn from(val: SelfTestMode) -> Self {
53 (&val).into()
54 }
55}
56
57impl fmt::Display for SelfTestMode {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 write!(f, r#""{}""#, <&str>::from(self))
60 }
61}
62
63impl_xfs_enum!(SelfTestMode, "selfTestMode");