rzw/cmds/
basic.rs

1use cmds::{CommandClass, Message};
2use error::{Error, ErrorKind};
3
4
5#[derive(Debug, Clone)]
6pub struct Basic;
7
8impl Basic {
9    /// Generate the message for the basic Command Class with
10    /// the function to set a value.
11    pub fn set(node_id: u8, value: u8) -> Message {
12        Message::new(node_id, CommandClass::BASIC, 0x01, vec!(value))
13    }
14
15    /// Generate the message for the basic Command Class with
16    /// the function to get a value.
17    pub fn get(node_id: u8) -> Message {
18        Message::new(node_id, CommandClass::BASIC, 0x02, vec!())
19    }
20
21    /// Returns the basic node value
22    pub fn report<M>(msg: M) -> Result<u8, Error>
23    where M: Into<Vec<u8>> {
24        // get the message
25        let msg = msg.into();
26
27        // the message need to be exact 6 digits long
28        if msg.len() != 6 {
29            return Err(Error::new(ErrorKind::UnknownZWave, "Message is to short"));
30        }
31
32        // check the CommandClass and command
33        if msg[3] != CommandClass::BASIC as u8 || msg[4] != 0x03 {
34            return Err(Error::new(ErrorKind::UnknownZWave, "Answer contained wrong command class"));
35        }
36
37        // return the value
38        Ok(msg[5])
39    }
40}