Skip to main content

Host

Struct Host 

Source
pub struct Host<A: Adapter> { /* private fields */ }
Expand description

A running coordinator host. Clones share it.

Implementations§

Source§

impl<A: Adapter> Host<A>

Source

pub async fn ota_check(&self, ieee: Ieee) -> Result<OtaOffer, HostError>

Ask a device which firmware it runs and whether the image directory has a newer one. The device is told to query (Image Notify) and answered “no image”; sleepy devices answer when they next wake.

Source

pub async fn ota_update(&self, ieee: Ieee) -> Result<OtaOffer, HostError>

Start upgrading a device from the image directory. Returns once the device took the offer; HostEvent::OtaProgress and HostEvent::OtaFinished follow.

Source§

impl<A: Adapter> Host<A>

Source

pub async fn start( adapter: A, adapter_events: UnboundedReceiver<AdapterEvent>, mode: StartMode, config: HostConfig, ) -> Result<(Host<A>, UnboundedReceiver<HostEvent>), HostError>

Start the network on adapter and run the host. Events arrive on the returned receiver until the adapter fails.

Source

pub fn network(&self) -> NetworkInfo

The network.

Source

pub fn adapter_info(&self) -> AdapterInfo

The NCP.

Source

pub fn adapter(&self) -> &A

The adapter, for NCP-specific calls.

Source

pub fn devices(&self) -> Vec<Device>

Every device.

Source

pub fn device(&self, ieee: Ieee) -> Option<Device>

One device.

Source

pub fn device_by_nwk(&self, nwk: NodeId) -> Option<Device>

The device with a network address.

Source

pub fn set_name( &self, ieee: Ieee, name: Option<String>, ) -> Result<(), HostError>

Give a device a name.

Source

pub async fn zcl_raw( &self, ieee: Ieee, request: RawZcl, ) -> Result<Option<Vec<u8>>, HostError>

Send a ZCL frame given as bytes, for a caller that builds frames itself (a device library). The frame’s transaction sequence number is overwritten with the host’s own. With response, waits for the device’s reply with that sequence number and returns it exactly as received; otherwise waits for APS delivery and returns None.

Source

pub async fn zdo_raw( &self, ieee: Ieee, cluster: u16, payload: Vec<u8>, response: bool, timeout: Option<Duration>, ) -> Result<Option<Vec<u8>>, HostError>

Send a ZDO request given as bytes (transaction sequence number first, then the request). The sequence number is overwritten with the host’s own. With response, returns the response payload exactly as received (sequence number first); otherwise waits for APS delivery and returns None.

Source

pub async fn zdo_request( &self, nwk: NodeId, body: Body, ) -> Result<Message, HostError>

Send a ZDO request to nwk and wait for its response.

Source

pub async fn zdo_request_retry( &self, nwk: NodeId, body: Body, ) -> Result<Message, HostError>

Host::zdo_request with the configured retries.

Source

pub async fn zcl_request( &self, ieee: Ieee, endpoint: u8, cluster: u16, frame: Frame, ) -> Result<Frame, HostError>

Send a ZCL frame to a device’s endpoint and wait for the reply with the same sequence number. The frame’s sequence number is assigned here.

Source

pub async fn read_attributes( &self, ieee: Ieee, endpoint: u8, cluster: u16, attributes: &[u16], ) -> Result<Vec<ReadRecord>, HostError>

Read attributes. Returns one record per attribute the device answered.

Source

pub async fn write_attributes( &self, ieee: Ieee, endpoint: u8, cluster: u16, values: Vec<(u16, Value)>, ) -> Result<Vec<(u8, Option<u16>)>, HostError>

Write attributes. Returns (status, attribute) records; one success record means every write succeeded.

Source

pub async fn configure_reporting( &self, ieee: Ieee, endpoint: u8, cluster: u16, configs: Vec<ReportingConfig>, ) -> Result<Vec<ReportingStatus>, HostError>

Configure attribute reporting.

Source

pub async fn command( &self, ieee: Ieee, endpoint: u8, cluster: u16, name: &str, values: &[Value], ) -> Result<Frame, HostError>

Send a cluster command by name, with field values in order (trailing optional fields may be left out). Returns the device’s reply: its default response or the command’s own response.

Source

pub async fn bind_to_host( &self, ieee: Ieee, endpoint: u8, cluster: u16, ) -> Result<(), HostError>

Bind a device’s cluster to the host’s endpoint, so its reports come here.

Source

pub async fn permit_join( &self, seconds: u8, via: Option<Ieee>, ) -> Result<(), HostError>

Open the network for joining for seconds (at most 254; 0 closes it), everywhere or only through one router. Opening through a router leaves the coordinator’s own radio closed.

Source

pub async fn add_install_code( &self, ieee: Ieee, code_with_crc: &[u8], ) -> Result<(), HostError>

Accept a device’s install code (with its CRC). The derived key is given to the NCP now and whenever joining opens, until the device joins. Install codes are kept in memory only.

Source

pub async fn set_install_codes( &self, entries: &[(Ieee, Vec<u8>)], ) -> Result<usize, HostError>

Replace every install code the host holds with entries (IEEE address, install code with its CRC). All are checked before any is taken. Returns how many there are now.

Source

pub async fn active_scan(&self) -> Result<Vec<Beacon>, HostError>

Other networks heard on every channel (an active scan).

Source

pub async fn leave(&self) -> Result<(), HostError>

Leave the network and erase it from the coordinator, then forget every device. The host stops; start a new one to form again.

Source

pub async fn remove(&self, ieee: Ieee, force: bool) -> Result<(), HostError>

Ask a device to leave and forget it. With force, it is forgotten even if it does not answer (a dead or sleepy device).

Source

pub fn topology(&self) -> Vec<(Option<Ieee>, Option<Ieee>, Link)>

Current links, with addresses resolved to IEEE where known.

Source

pub async fn scan_neighbors( &self, ieee: Ieee, ) -> Result<Vec<Neighbor>, HostError>

Read a router’s (or the coordinator’s) whole neighbor table. At most once a minute per device.

Source

pub async fn change_channel( &self, channel: u8, ) -> Result<NetworkInfo, HostError>

Move the network to channel (11 to 26): broadcast a network update with the next update id and wait until the coordinator runs on the new channel. Devices follow the broadcast; sleepy ones that miss it find the network again when they next rejoin.

Source

pub async fn energy_scan(&self) -> Result<Vec<(u8, i8)>, HostError>

Measure every channel’s energy (channel, max RSSI in dBm).

Source

pub async fn backup(&self) -> Result<Backup, HostError>

Take a backup now, and write it if a backup path is configured.

Source

pub async fn shutdown(&self) -> Result<(), HostError>

Stop the host: write the device store, end its tasks and release the adapter (and with it the port) once every clone is dropped.

Source

pub async fn flush(&self) -> Result<(), HostError>

Write the device store now.

Source

pub fn reinterview(&self, ieee: Ieee) -> Result<(), HostError>

Interview a device again from the start (after a firmware update, or to reconfigure reporting).

Trait Implementations§

Source§

impl<A: Adapter> Clone for Host<A>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Adapter> Debug for Host<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> !RefUnwindSafe for Host<A>

§

impl<A> !UnwindSafe for Host<A>

§

impl<A> Freeze for Host<A>

§

impl<A> Send for Host<A>

§

impl<A> Sync for Host<A>

§

impl<A> Unpin for Host<A>

§

impl<A> UnsafeUnpin for Host<A>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more