1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use super::*;
use byteorder::LittleEndian;
mod log;
mod unlog;
mod unlog_all;
pub use self::log::*;
pub use self::unlog::*;
pub use self::unlog_all::*;
pub trait Message {
fn serialize(&self) -> Vec<u8>;
}
#[derive(Clone, Debug, PartialEq)]
pub struct Response {
pub resp_id: ResponseID,
pub resp_string: String,
}
impl Response {
pub fn new(msg: Vec<u8>) -> Option<Self> {
match le_u32(&msg) {
Ok(conv) => {
let mut resp: Response = Response {
resp_id: conv.1.into(),
resp_string: "".to_owned(),
};
resp.resp_string.push_str(&String::from_utf8_lossy(&conv.0));
Some(resp)
}
_ => None,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum ResponseID {
Ok = 1,
LogInvalid = 2,
OutOfResources = 3,
PacketNotVerified = 4,
CommandFailed = 5,
InvalidID = 6,
InvalidField = 7,
InvalidChecksum = 8,
MissingField = 9,
ArrayOverflow = 10,
ErrorField = 11,
InvalidTrigger = 14,
AuthcodeOverflow = 15,
InvalidDate = 16,
InvalidAuthcode = 17,
NoModel = 18,
InvalidModel = 19,
InvalidChannel = 20,
InvalidRate = 21,
NoMask = 22,
LockedChannels = 23,
InvalidTime = 24,
InvalidPort = 25,
InvalidMessage = 26,
InvalidPRN = 27,
PRNNotLocked = 28,
PRNLockoutOverflow = 29,
PRNAlreadyLocked = 30,
Timeout = 31,
UnknownPort = 33,
BadHex = 34,
InvalidBaud = 35,
ModelInvalidMessage = 36,
RequiresFailMode = 40,
InvalidOffset = 41,
MessageOverflow = 78,
PreciseTimeAlreadyKnown = 84,
Unknown,
}
impl From<u32> for ResponseID {
fn from(t: u32) -> ResponseID {
match t {
1 => ResponseID::Ok,
2 => ResponseID::LogInvalid,
3 => ResponseID::OutOfResources,
4 => ResponseID::PacketNotVerified,
5 => ResponseID::CommandFailed,
6 => ResponseID::InvalidID,
7 => ResponseID::InvalidField,
8 => ResponseID::InvalidChecksum,
9 => ResponseID::MissingField,
10 => ResponseID::ArrayOverflow,
11 => ResponseID::ErrorField,
14 => ResponseID::InvalidTrigger,
15 => ResponseID::AuthcodeOverflow,
16 => ResponseID::InvalidDate,
17 => ResponseID::InvalidAuthcode,
18 => ResponseID::NoModel,
19 => ResponseID::InvalidModel,
20 => ResponseID::InvalidChannel,
21 => ResponseID::InvalidRate,
22 => ResponseID::NoMask,
23 => ResponseID::LockedChannels,
24 => ResponseID::InvalidTime,
25 => ResponseID::InvalidPort,
26 => ResponseID::InvalidMessage,
27 => ResponseID::InvalidPRN,
28 => ResponseID::PRNNotLocked,
29 => ResponseID::PRNLockoutOverflow,
30 => ResponseID::PRNAlreadyLocked,
31 => ResponseID::Timeout,
33 => ResponseID::UnknownPort,
34 => ResponseID::BadHex,
35 => ResponseID::InvalidBaud,
36 => ResponseID::ModelInvalidMessage,
40 => ResponseID::RequiresFailMode,
41 => ResponseID::InvalidOffset,
78 => ResponseID::MessageOverflow,
84 => ResponseID::PreciseTimeAlreadyKnown,
_ => ResponseID::Unknown,
}
}
}