Skip to main content

Controller

Struct Controller 

Source
pub struct Controller { /* private fields */ }
Expand description

A handle to a running controller. Clones share it.

Implementations§

Source§

impl Controller

Source

pub async fn start<P: Port>( port: P, cfg: HostConfig, ) -> Result<(Controller, Events), Error>

Initializes the controller on port, loads the store, starts the dispatcher and resumes interviews. Events arrive on the returned channel; read it, or events are dropped when it fills.

Source

pub fn info(&self) -> ControllerInfo

The controller’s own information.

Source

pub fn serial(&self) -> &SerialApi

The serial link, for functions this crate does not wrap.

Source

pub fn dsk(&self) -> Dsk

The controller’s S2 DSK (its key pair’s first 16 bytes).

Source

pub fn node(&self, node: NodeId) -> Option<NodeRecord>

A node’s record.

Source

pub fn nodes(&self) -> Vec<NodeRecord>

Every node’s record.

Source

pub fn status(&self, node: NodeId) -> NodeStatus

A node’s runtime status.

Source

pub fn set_name( &self, node: NodeId, name: Option<String>, location: Option<String>, ) -> Result<(), Error>

Sets a node’s name and location (persisted).

Source

pub fn store_error(&self) -> Option<String>

The last store write error, if the last write failed.

Source

pub fn close(&self) -> Result<(), Error>

Stops the controller: writes the store, closes the serial port and ends the event stream. Every clone stops with it; start a new Controller to use the stick again (after a restore or a region change, or to hand the port to something else).

Source

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

Writes the store now (e.g. before shutting down).

Source

pub async fn send( &self, node: NodeId, endpoint: u8, cmd: &Command, ) -> Result<(), Error>

Sends a command to a node’s endpoint. For a sleeping node this waits until the node wakes up.

Source

pub async fn send_supervised( &self, node: NodeId, endpoint: u8, cmd: &Command, ) -> Result<u8, Error>

Sends a command with Supervision and returns the node’s status (0xFF success, 0x01 working; failure and no support are errors).

Source

pub async fn request( &self, node: NodeId, endpoint: u8, cmd: Command, expect: impl Fn(&Command) -> bool + Send + Sync + 'static, ) -> Result<Command, Error>

Sends a command and waits for the reply expect accepts.

Source

pub async fn set_value( &self, id: &ValueId, value: &ValueKind, ) -> Result<(), Error>

Sets a value (switches, levels) and refreshes it.

Source

pub async fn configure( &self, node: NodeId, config: &DeviceConfig, settings: &[(String, i64)], ) -> Result<(), Error>

Applies configuration settings keyed as in the node’s device file ("3", "41[0xf00]"): partial parameters are read, merged and written as one value; each written parameter is read back so its value is reported.

Source

pub async fn factory_reset(&self) -> Result<(), Error>

Resets the controller to factory defaults: a new home id, no nodes. This Controller must be dropped and a new one started afterwards.

Source

pub async fn set_region(&self, region: RfRegion) -> Result<(), Error>

Sets the controller’s RF region and restarts it (the region takes effect after a restart). This Controller must be dropped and a new one started afterwards.

Source

pub async fn configure_raw( &self, node: NodeId, settings: &[(String, i64)], ) -> Result<(), Error>

Applies configuration settings by key ("3", "41[0xf00]") without a device file: each parameter is read first for its size and current value, partial values are merged into it, and it is read back after.

Source

pub async fn ping(&self, node: NodeId) -> bool

Pings a node (No Operation); true if it acknowledged.

Source

pub fn queued(&self, node: NodeId) -> usize

Requests waiting for a sleeping node to wake up.

Source

pub fn last_route(&self, node: NodeId) -> Option<(Vec<NodeId>, Option<i8>)>

The repeaters (nearest the controller first) and ACK RSSI of the last frame that reached a node.

Source

pub async fn refresh_neighbors( &self, node: NodeId, ) -> Result<Vec<NodeId>, Error>

Reads a node’s neighbor table from the controller (no radio traffic). Long Range nodes talk to the controller directly and have none.

Source

pub fn topology(&self) -> Topology

The topology: neighbor tables and the last route to each node.

Source§

impl Controller

Source

pub async fn update_firmware( &self, node: NodeId, image: &[u8], target: u8, ) -> Result<FirmwareUpdateResult, Error>

Updates a node’s firmware target (0 is the main firmware) with image. Emits Event::FirmwareUpdateProgress as fragments go out.

Source§

impl Controller

Source

pub async fn replace_failed_node( &self, node: NodeId, opts: InclusionOptions, ) -> Result<InclusionResult, Error>

Replaces a failed node: the controller gives its node id to the next node that joins (press its button), which then gets security and an interview as a new node would. The node must be one the controller considers failed.

Source

pub fn grant_security_classes(&self, classes: Vec<SecurityClass>) -> bool

Source

pub fn validate_dsk(&self, pin: Option<u16>) -> bool

Answers Event::ValidateDsk with the PIN, or None to abort.

Source

pub fn stop_inclusion(&self) -> bool

Stops a running inclusion or exclusion.

Source

pub async fn include( &self, opts: InclusionOptions, ) -> Result<InclusionResult, Error>

Includes a node: turns on inclusion mode, waits for a node, runs the key exchange, and starts its interview.

Source

pub async fn exclude( &self, timeout: Option<Duration>, ) -> Result<Option<NodeId>, Error>

Excludes a node: turns on exclusion mode and waits for one. Returns the node id it had in this network, if any.

Source

pub async fn remove_failed_node(&self, node: NodeId) -> Result<(), Error>

Removes a node the controller considers failed (it stopped answering).

Source

pub async fn provision(&self, entry: Entry) -> Result<(), Error>

Adds or replaces a provisioning list entry (from a scanned QR code).

Source

pub async fn unprovision(&self, dsk: &Dsk) -> Option<Entry>

Removes a provisioning list entry.

Source

pub fn provisioning_list(&self) -> Vec<Entry>

The provisioning list.

Source§

impl Controller

Source

pub fn spawn_interview(&self, node: NodeId)

Starts (or resumes) a node’s interview in the background, unless one is running.

Source

pub fn reinterview(&self, node: NodeId) -> Result<(), Error>

Re-runs a node’s interview from the start.

Source

pub fn security_classes(&self, node: NodeId) -> Vec<SecurityClass>

The classes a node was granted, for callers that need them.

Source§

impl Controller

Source

pub async fn backup_nvm(&self) -> Result<Vec<u8>, Error>

Reads the controller’s NVM image. Uses the extended or the 16-bit NVM operations on 700 and 800 series sticks and the external NVM functions on the 500 series. Normal operation pauses while it runs.

Source§

impl Controller

Source

pub async fn restore_nvm(&self, image: &[u8]) -> Result<(), Error>

Writes a backup image back to the controller and restarts it.

A backup from another series (700 or 800) or SDK is converted first (crate::nvm3::convert); one whose protocol format is newer than the controller reads is refused. The controller restarts afterwards, so this Controller must be dropped and a new one started.

Trait Implementations§

Source§

impl Clone for Controller

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 Debug for Controller

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
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.

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