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
use cmds::{CommandClass, Message};
use num::FromPrimitive;
use error::{Error, ErrorKind};
use driver::GenericType;
#[derive(Debug, Clone)]
pub struct NodeInfo;
impl NodeInfo {
/// Generate the message for the basic Command Class with
/// the function to get a value.
pub fn get(node_id: u8) -> Message {
Message::new(node_id, CommandClass::NODE_INFO, 0x02, vec!())
}
/// Read a the Node_Information message and parse it to the type and command
/// class types.
pub fn report<M>(msg: M) -> Result<(Vec<GenericType>, Vec<CommandClass>), Error>
where M: Into<Vec<u8>> {
// get the message
let msg = msg.into();
let mut types = vec!();
let mut cmds = vec!();
// extractthe types
for i in 2..6 {
// get the type fro the vector
let m = msg.get(i as usize).ok_or(Error::new(ErrorKind::UnknownZWave, "Message is to short"))?;
let m = m.clone();
// when the device is unkown continue
if m == GenericType::Unknown as u8 {
continue;
}
// try to convert the type
match GenericType::from_u8(m) {
// When the type is known push it to the vec
Some(t) => {
types.push(t);
},
// When the type is unknown, just continue
None => {
continue;
}
}
}
// extract the command classes
for i in 6..msg.len() {
// get the command for the vector
let m = msg.get(i as usize).ok_or(Error::new(ErrorKind::UnknownZWave, "Message is to short"))?;
let m = m.clone();
// try to convert the command
let cmd = CommandClass::from_u8(m.clone()).unwrap_or(CommandClass::NO_OPERATION);
// when the device is unkown continue
if cmd == CommandClass::NO_OPERATION {
continue;
}
// When the command is known push it to the vec
cmds.push(cmd);
}
// return the result
Ok((types, cmds))
}
}