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

source

pub fn new() -> Controller

Create a new controller.

source

pub fn new_with_node(node: Arc<Mutex<Node>>) -> Controller

Create a new controller with the node to which it belongs.

source

pub fn add_observer(&mut self, observer: ObserverObject) -> bool

source

pub fn nodes(&mut self) -> Vec<RemoteNode>

Returns all searched remote nodes.

source

pub fn search_object(&mut self, obj_code: ObjectCode) -> bool

Searches only the specified object nodes on the local network.

source

pub fn search(&mut self) -> bool

Searches all ECHONET-Lite nodes on the local network.

source

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.

source

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.

source

pub fn start(&mut self) -> bool

Starts the controller node to communicate with other ECHONET-Lite nodes on the local network.

source

pub fn stop(&mut self) -> bool

Stops the controller node, and clears all searched remote nodes.

Trait Implementations§

source§

impl Drop for Controller

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V