1use std::convert::From;
30use std::fmt;
31
32#[derive(Debug, PartialEq, Eq, Copy, Clone)]
33#[repr(u8)]
34pub enum P50XReply {
35 Ok = 0x00,
36 BadCommand = 0x01,
37 BadParameter = 0x02,
38 PowerOff = 0x06,
39 NoLokCommandSpace = 0x08,
40 FullTurnoutCommandStack = 0x09,
41 NoData = 0x0A,
42 NoSlot = 0x0B,
43 BadLokParameter = 0x0C,
44 LokBusy = 0x0D,
45 BadTurnoutParameter = 0x0E,
46 BadSpecialOptionValue = 0x0F,
47 NoI2CCommandSpace = 0x10,
48 LowTurnoutCommandStackSpace = 0x40,
49 LokHalt = 0x41,
50 LokPowerOff = 0x42,
51 Busy = 0x80,
52 Unknown
53}
54
55impl From<u8> for P50XReply {
56 fn from(value: u8) -> P50XReply {
57 match value {
58 0x00 => P50XReply::Ok,
59 0x01 => P50XReply::BadCommand,
60 0x02 => P50XReply::BadParameter,
61 0x06 => P50XReply::PowerOff,
62 0x08 => P50XReply::NoLokCommandSpace,
63 0x09 => P50XReply::FullTurnoutCommandStack,
64 0x0A => P50XReply::NoData,
65 0x0B => P50XReply::NoSlot,
66 0x0C => P50XReply::BadLokParameter,
67 0x0D => P50XReply::LokBusy,
68 0x0E => P50XReply::BadTurnoutParameter,
69 0x0F => P50XReply::BadSpecialOptionValue,
70 0x10 => P50XReply::NoI2CCommandSpace,
71 0x40 => P50XReply::LowTurnoutCommandStackSpace,
72 0x41 => P50XReply::LokHalt,
73 0x42 => P50XReply::LokPowerOff,
74 0x80 => P50XReply::Busy,
75 _ => P50XReply::Unknown
76 }
77 }
78}
79
80impl fmt::Display for P50XReply {
81 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82 match *self {
83 P50XReply::Ok => write!(f, "Ok"),
84 P50XReply::BadCommand => write!(f, "Command not implemented"),
85 P50XReply::BadParameter => write!(f, "Bad parameter value"),
86 P50XReply::PowerOff => write!(f, "Power is off"),
87 P50XReply::NoLokCommandSpace => write!(f, "Locomotive command stack is full"),
88 P50XReply::FullTurnoutCommandStack => write!(f, "Turnout command stack is full"),
89 P50XReply::NoData => write!(f, "No locomotive data available"),
90 P50XReply::NoSlot => write!(f, "No slot available"),
91 P50XReply::BadLokParameter => write!(f, "Bad locomotive address"),
92 P50XReply::LokBusy => write!(f, "Locomotive already controlled by another device"),
93 P50XReply::BadTurnoutParameter => write!(f, "Bad turnout address"),
94 P50XReply::BadSpecialOptionValue => write!(f, "Bad special option value"),
95 P50XReply::NoI2CCommandSpace => write!(f, "I2C command stack is full"),
96 P50XReply::LowTurnoutCommandStackSpace => write!(f, "Tunrout command stack is nearly full"),
97 P50XReply::LokHalt => write!(f, "Command accepted but in halt mode"),
98 P50XReply::LokPowerOff => write!(f, "Command accepted but power is off"),
99 P50XReply::Busy => write!(f, "Device is busy"),
100 P50XReply::Unknown => write!(f, "Unknown error")
101 }
102 }
103}