Struct echonet::Controller
source · pub struct Controller { /* private fields */ }Expand description
Controller represents an ECHONET-Lite controller node to communicate other ECHONET-Lite nodes.
Examples
use std::{thread, time};
use echonet::{Controller, Property};
use echonet::protocol::{ESV, Message};
let mut ctrl = Controller::new();
ctrl.start();
ctrl.search();
thread::sleep(time::Duration::from_secs(2));
for (i, node) in ctrl.nodes().iter().enumerate() {
println!("[{}] {}", i, node.addr());
for (j, obj) in node.objects().iter().enumerate() {
println!("[{}] {:06X}", j, obj.code());
for obj_prop in obj.properties() {
if !obj_prop.is_read_required() {
continue;
}
print!("[{:02X}] {}:", obj_prop.code(), obj_prop.name());
let mut msg = Message::new();
msg.set_esv(ESV::ReadRequest);
msg.set_deoj(obj.code());
let mut prop = Property::new();
prop.set_code(obj_prop.code());
let rx = ctrl.post_message(&node, &mut msg);
match rx.recv_timeout(time::Duration::from_secs(1)) {
Ok(msg) => {
if 0 < msg.opc() {
println!("{}", hex::encode(msg.property(0).data()));
}
}
Err(_e) => {
println!("{}", "<timeout>");
}
};
}
}
}
ctrl.stop();Implementations§
source§impl Controller
impl Controller
sourcepub fn new() -> Controller
pub fn new() -> Controller
Create a new controller.
sourcepub fn new_with_node(node: Arc<Mutex<Node>>) -> Controller
pub fn new_with_node(node: Arc<Mutex<Node>>) -> Controller
Create a new controller with the node to which it belongs.
pub fn add_observer(&mut self, observer: ObserverObject) -> bool
sourcepub fn nodes(&mut self) -> Vec<RemoteNode>
pub fn nodes(&mut self) -> Vec<RemoteNode>
Returns all searched remote nodes.
sourcepub fn search_object(&mut self, obj_code: ObjectCode) -> bool
pub fn search_object(&mut self, obj_code: ObjectCode) -> bool
Searches only the specified object nodes on the local network.
sourcepub fn send_message(&self, remote_node: &RemoteNode, msg: &mut Message) -> bool
pub fn send_message(&self, remote_node: &RemoteNode, msg: &mut Message) -> bool
Sends the specified message to the specified remote node. The function automatically updates the SEOJ (Source ECHONET-Lite object) and TID (Transaction ID) in the specified message, so you do not need to set the message fields.
sourcepub fn post_message(
&self,
remote_node: &RemoteNode,
msg: &mut Message
) -> Receiver<Message>
pub fn post_message( &self, remote_node: &RemoteNode, msg: &mut Message ) -> Receiver<Message>
Posts the specified message to the remote node and waits for the response using the messaging channel. TThe function automatically updates the SEOJ (Source ECHONET-Lite object) and TID (Transaction ID) in the specified message, so you do not need to set the message fields.