bnr_xfs/status/
safe_door.rs1use std::fmt;
2
3use super::HardwareStatus;
4
5pub const SD_OPEN: u32 = 6194;
6pub const SD_LOCKED: u32 = 6196;
7pub const SD_UNKNOWN: u32 = 6197;
8
9#[repr(u32)]
11#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
12pub enum SafeDoorStatus {
13 Open = SD_OPEN,
15 Locked = SD_LOCKED,
17 #[default]
19 Unknown = SD_UNKNOWN,
20}
21
22impl SafeDoorStatus {
23 pub const fn new() -> Self {
25 Self::Unknown
26 }
27
28 pub const fn create(val: u32) -> Self {
30 match val {
31 SD_OPEN => Self::Open,
32 SD_LOCKED => Self::Locked,
33 SD_UNKNOWN => Self::Unknown,
34 _ => Self::Unknown,
35 }
36 }
37}
38
39impl From<SafeDoorStatus> for HardwareStatus {
40 fn from(val: SafeDoorStatus) -> Self {
41 match val {
42 SafeDoorStatus::Locked | SafeDoorStatus::Open => Self::Notification,
43 SafeDoorStatus::Unknown => Self::Warning,
44 }
45 }
46}
47
48impl From<SafeDoorStatus> for &'static str {
49 fn from(val: SafeDoorStatus) -> Self {
50 match val {
51 SafeDoorStatus::Open => "open",
52 SafeDoorStatus::Locked => "locked",
53 SafeDoorStatus::Unknown => "unknown",
54 }
55 }
56}
57
58impl From<&SafeDoorStatus> for &'static str {
59 fn from(val: &SafeDoorStatus) -> Self {
60 (*val).into()
61 }
62}
63
64impl fmt::Display for SafeDoorStatus {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 write!(f, r#""{}""#, <&str>::from(self))
67 }
68}
69
70impl_xfs_enum!(SafeDoorStatus, "safeDoorStatus");