#![deny(missing_docs)]
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_hex;
#[cfg(test)]
#[macro_use]
extern crate serde_json;
#[cfg(not(test))]
extern crate serde_json;
extern crate indexmap;
extern crate ommui_file_loading;
extern crate ommui_string_patterns;
extern crate serde;
extern crate uuid;
extern crate xio_base_datatypes;
use ommui_string_patterns::{freetextstring, idstring};
use std::collections::BTreeMap;
use uuid::Uuid;
use xio_base_datatypes as base;
mod hexnumber;
pub mod filesystem;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct DeviceDescription {
pub ftdi: FtdiDescription,
pub xio: Option<XioDescription>,
pub system: SystemDescription,
pub summary: SummaryDescription,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct FtdiDescription {
pub id: String,
pub vendor: String,
pub product: String,
pub uuid: Uuid,
pub recognized: bool,
pub programmed: bool,
pub board: String,
pub device: String,
pub symlink: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct XioDescription {
pub id: String,
pub vendor: String,
pub product: String,
pub uuid: Uuid,
pub recognized: bool,
pub programmed: bool,
pub board: String,
pub device: String,
pub symlink: String,
pub version: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SystemDescription {
pub version: String,
pub firmware: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SummaryDescription {
pub ready: bool,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct HardwareBoardDescription {
#[serde(rename = "_caption", with = "freetextstring")]
pub caption: String,
pub description: GenericDescription,
pub capabilities: BTreeMap<String, Capability>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GenericDescription {
#[serde(with = "freetextstring")]
pub vendor: String,
#[serde(with = "freetextstring")]
pub model: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Capability {
pub builtin: bool,
#[serde(with = "idstring")]
pub module: String,
#[serde(with = "hexnumber")]
pub id: u16,
}
#[cfg(test)]
mod capability_tests {
extern crate serde_json;
use super::Capability;
#[test]
fn deserialize_hex() {
let json =
json!({ "builtin": true, "module": "xyz", "id": "0x1234"});
let cap: Capability =
serde_json::from_str(&json.to_string()).unwrap();
assert_eq!(
cap,
Capability {
builtin: true,
module: "xyz".to_string(),
id: 0x1234,
}
);
assert_eq!(serde_json::to_value(cap).unwrap(), json);
}
#[test]
fn deserialize_hex_zero() {
let json =
json!({ "builtin": true, "module": "xyz", "id": "0x0000"});
let cap: Capability =
serde_json::from_str(&json.to_string()).unwrap();
assert_eq!(
cap,
Capability {
builtin: true,
module: "xyz".to_string(),
id: 0,
}
);
assert_eq!(serde_json::to_value(cap).unwrap(), json);
}
#[test]
fn deserialize() {
let json = json!({ "builtin": true, "module": "xyz", "id": 1234});
let cap: Capability =
serde_json::from_str(&json.to_string()).unwrap();
assert_eq!(
cap,
Capability {
builtin: true,
module: "xyz".to_string(),
id: 1234,
}
);
let json_hex =
json!({ "builtin": true, "module": "xyz", "id": "0x04d2"});
assert_eq!(serde_json::to_value(cap).unwrap(), json_hex);
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Module {
#[serde(rename = "_caption", with = "freetextstring")]
pub caption: String,
pub description: GenericDescription,
pub channels: Vec<Channel>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Channel {
#[serde(with = "idstring")]
pub id: String,
#[serde(rename = "_caption", with = "freetextstring")]
pub caption: String,
#[serde(rename = "type")]
pub channel_type: base::DataType,
pub permission: base::ChannelPermission,
}