bnr_xfs/cash_unit/threshold/
status.rs

1use std::fmt;
2
3use crate::impl_xfs_enum;
4
5const THRESHOLD_STAT_OK: u32 = 0;
6const THRESHOLD_STAT_FULL: u32 = 1;
7const THRESHOLD_STAT_HIGH: u32 = 2;
8const THRESHOLD_STAT_LOW: u32 = 4;
9const THRESHOLD_STAT_EMPTY: u32 = 8;
10const THRESHOLD_STAT_UNKNOWN: u32 = 16;
11const THRESHOLD_STAT_NOT_SUPPORTED: u32 = 32;
12
13/// Filling status of a cash unit.
14///
15/// How the threshold status of a cash unit is determined, depends of the threshold mode :
16///
17/// @par SensorMode (default value):
18/// ThresholdStatus changes are determined by the sensors of the BNR (physical filling status).
19///
20/// - `CountMode`: The management of these values depends of the physical cash unit type
21///  - Cashbox, Recycler and Bundler: Based on the Threshold levels, but if the physical limit of filling is reached before the threshold Full, then the ThresholdStatus is forced to Full anyway.
22///  - Loader: Based on the Threshold levels, but if there is a lack of bills before the threshold Empty, the ThresholdStatus is forced to Empty anyway.
23///
24/// **see** [Threshold], [ThresholdMode], [PhysicalCashUnit].
25#[repr(u32)]
26#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
27pub enum ThresholdStatus {
28    /// The cash unit is neither empty nor full.
29    #[default]
30    Ok = THRESHOLD_STAT_OK,
31    /// The cash unit is full. In CountMode, the cash unit count is higher or equal to its full threshold level.
32    Full = THRESHOLD_STAT_FULL,
33    /// The cash unit is alomst full. In CountMode, the cash unit count is higher than its high threshold level.
34    High = THRESHOLD_STAT_HIGH,
35    /// The cash unit is almost empty. In CountMode, the cash unit count is lower than its low threshold level.
36    Low = THRESHOLD_STAT_LOW,
37    /// The cash unit is empty. In CountMode, the cash unit count is lower or equal to its empty threshold level.
38    Empty = THRESHOLD_STAT_EMPTY,
39    /// Threshold state cannot be determined.
40    Unknown = THRESHOLD_STAT_UNKNOWN,
41    /// Threshold state is not supported.
42    NotSupported = THRESHOLD_STAT_NOT_SUPPORTED,
43}
44
45impl ThresholdStatus {
46    /// Creates a new [ThresholdStatus].
47    pub const fn new() -> Self {
48        Self::Ok
49    }
50
51    /// Creates a new [ThresholdStatus] from the provided parameter.
52    pub const fn create(val: u32) -> Self {
53        match val {
54            THRESHOLD_STAT_OK => Self::Ok,
55            THRESHOLD_STAT_FULL => Self::Full,
56            THRESHOLD_STAT_HIGH => Self::High,
57            THRESHOLD_STAT_LOW => Self::Low,
58            THRESHOLD_STAT_EMPTY => Self::Empty,
59            THRESHOLD_STAT_UNKNOWN => Self::Unknown,
60            THRESHOLD_STAT_NOT_SUPPORTED => Self::NotSupported,
61            _ => Self::Unknown,
62        }
63    }
64}
65
66impl From<&ThresholdStatus> for &'static str {
67    fn from(val: &ThresholdStatus) -> Self {
68        match val {
69            ThresholdStatus::Ok => "OK",
70            ThresholdStatus::Full => "full",
71            ThresholdStatus::High => "high",
72            ThresholdStatus::Low => "low",
73            ThresholdStatus::Empty => "empty",
74            ThresholdStatus::Unknown => "unknown",
75            ThresholdStatus::NotSupported => "not supported",
76        }
77    }
78}
79
80impl From<ThresholdStatus> for &'static str {
81    fn from(val: ThresholdStatus) -> Self {
82        (&val).into()
83    }
84}
85
86impl fmt::Display for ThresholdStatus {
87    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88        write!(f, r#""{}""#, <&str>::from(self))
89    }
90}
91
92impl_xfs_enum!(ThresholdStatus, "thresholdStatus");