1#![deny(missing_docs)]
2
3#[macro_use]
6extern crate serde_derive;
7
8#[macro_use]
9extern crate serde_hex;
10
11#[cfg(test)]
12#[macro_use]
13extern crate serde_json;
14
15#[cfg(not(test))]
16extern crate serde_json;
17
18extern crate indexmap;
19extern crate ommui_file_loading;
20extern crate ommui_string_patterns;
21extern crate serde;
22extern crate uuid;
23extern crate xio_base_datatypes;
24
25use ommui_string_patterns::{freetextstring, idstring};
26use std::collections::BTreeMap;
27use uuid::Uuid;
28use xio_base_datatypes as base;
29
30mod hexnumber;
31
32pub mod filesystem;
34
35#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
37#[serde(rename_all = "camelCase", deny_unknown_fields)]
38pub struct DeviceDescription {
39 pub ftdi: FtdiDescription,
41
42 pub xio: Option<XioDescription>,
44
45 pub system: SystemDescription,
47
48 pub summary: SummaryDescription,
50}
51
52#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
54#[serde(rename_all = "camelCase", deny_unknown_fields)]
55pub struct FtdiDescription {
56 pub id: String,
58
59 pub vendor: String,
61
62 pub product: String,
64
65 pub uuid: Uuid,
67
68 pub recognized: bool,
70
71 pub programmed: bool,
73
74 pub board: String,
76
77 pub device: String,
79
80 pub symlink: String,
82}
83
84#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
86#[serde(rename_all = "camelCase", deny_unknown_fields)]
87pub struct XioDescription {
88 pub id: String,
90
91 pub vendor: String,
93
94 pub product: String,
96
97 pub uuid: Uuid,
99
100 pub recognized: bool,
102
103 pub programmed: bool,
105
106 pub board: String,
108
109 pub device: String,
111
112 pub symlink: String,
114
115 pub version: String,
117}
118
119#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
121#[serde(rename_all = "camelCase", deny_unknown_fields)]
122pub struct SystemDescription {
123 pub version: String,
125
126 pub firmware: String,
128}
129
130#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
132#[serde(rename_all = "camelCase", deny_unknown_fields)]
133pub struct SummaryDescription {
134 pub ready: bool,
136}
137
138#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
140#[serde(rename_all = "camelCase", deny_unknown_fields)]
141pub struct HardwareBoardDescription {
142 #[serde(rename = "_caption", with = "freetextstring")]
144 pub caption: String,
145
146 pub description: GenericDescription,
148
149 pub capabilities: BTreeMap<String, Capability>,
151}
152
153#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
155#[serde(rename_all = "camelCase", deny_unknown_fields)]
156pub struct GenericDescription {
157 #[serde(with = "freetextstring")]
159 pub vendor: String,
160
161 #[serde(with = "freetextstring")]
163 pub model: String,
164}
165
166#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
168#[serde(rename_all = "camelCase", deny_unknown_fields)]
169pub struct Capability {
170 pub builtin: bool,
172
173 #[serde(with = "idstring")]
178 pub module: String,
179
180 #[serde(with = "hexnumber")]
182 pub id: u16,
183}
184
185#[cfg(test)]
186mod capability_tests {
187 extern crate serde_json;
188 use super::Capability;
189
190 #[test]
191 fn deserialize_hex() {
192 let json =
193 json!({ "builtin": true, "module": "xyz", "id": "0x1234"});
194 let cap: Capability =
195 serde_json::from_str(&json.to_string()).unwrap();
196 assert_eq!(
197 cap,
198 Capability {
199 builtin: true,
200 module: "xyz".to_string(),
201 id: 0x1234,
202 }
203 );
204 assert_eq!(serde_json::to_value(cap).unwrap(), json);
205 }
206
207 #[test]
208 fn deserialize_hex_zero() {
209 let json =
210 json!({ "builtin": true, "module": "xyz", "id": "0x0000"});
211 let cap: Capability =
212 serde_json::from_str(&json.to_string()).unwrap();
213 assert_eq!(
214 cap,
215 Capability {
216 builtin: true,
217 module: "xyz".to_string(),
218 id: 0,
219 }
220 );
221 assert_eq!(serde_json::to_value(cap).unwrap(), json);
222 }
223
224 #[test]
225 fn deserialize() {
226 let json = json!({ "builtin": true, "module": "xyz", "id": 1234});
227 let cap: Capability =
228 serde_json::from_str(&json.to_string()).unwrap();
229 assert_eq!(
230 cap,
231 Capability {
232 builtin: true,
233 module: "xyz".to_string(),
234 id: 1234,
235 }
236 );
237 let json_hex =
238 json!({ "builtin": true, "module": "xyz", "id": "0x04d2"});
239 assert_eq!(serde_json::to_value(cap).unwrap(), json_hex);
240 }
241}
242
243#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
251#[serde(rename_all = "camelCase", deny_unknown_fields)]
252pub struct Module {
253 #[serde(rename = "_caption", with = "freetextstring")]
255 pub caption: String,
256
257 pub description: GenericDescription,
259
260 pub channels: Vec<Channel>,
262}
263
264#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
266#[serde(rename_all = "camelCase", deny_unknown_fields)]
267pub struct Channel {
268 #[serde(with = "idstring")]
272 pub id: String,
273
274 #[serde(rename = "_caption", with = "freetextstring")]
276 pub caption: String,
277
278 #[serde(rename = "type")]
280 pub channel_type: base::DataType,
281
282 pub permission: base::ChannelPermission,
284}