diff --git a/src/controller.rs b/src/controller.rs index 42a8c020..6585280e 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -113,20 +113,23 @@ impl Controller { /// 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. pub fn send_message(&self, remote_node: &RemoteNode, msg: &mut Message) -> bool { - let ctrl = self.node.lock().unwrap(); - ctrl.send_message(remote_node, msg) + if self.node.try_lock().is_err() { + return false; + } + let node = self.node.lock().unwrap(); + node.send_message(remote_node, msg) } /// 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. pub fn post_message(&self, remote_node: &RemoteNode, msg: &mut Message) -> Receiver { - let ctrl = self.node.lock().unwrap(); - ctrl.post_message(remote_node, msg) + let node = self.node.lock().unwrap(); + node.post_message(remote_node, msg) } /// Starts the controller node to communicate with other ECHONET-Lite nodes on the local network. pub fn start(&mut self) -> bool { - let mut ctrl = self.node.lock().unwrap(); - if !ctrl.start() { + let mut node = self.node.lock().unwrap(); + if !node.start() { return false; } true @@ -134,8 +137,8 @@ impl Controller { /// Stops the controller node, and clears all searched remote nodes. pub fn stop(&mut self) -> bool { - let mut ctrl = self.node.lock().unwrap(); - ctrl.stop() + let mut node = self.node.lock().unwrap(); + node.stop() } }