Skip to main content

Ncp

Struct Ncp 

Source
pub struct Ncp<T> { /* private fields */ }
Expand description

Host-side helper for an EZSP Network Co-Processor.

Ncp<T> owns a communicator. Its methods provide higher-level operations that need callback correlation or local host state, such as scans, outgoing APS message confirmation, and automatic source endpoint selection from the configured endpoint cluster lists. The apis-saltans startup path supplies an Arc<tokio::sync::Mutex<T>> shared with the callback event handler.

Implementations§

Source§

impl<T> Ncp<T>

Source

pub const fn new( transport: T, aps_options: Options, event_handler_proxy: Sender<Message>, endpoints: Box<[Clusters]>, ) -> Self

Creates a new Ncp with the given transport, event handler, and endpoints.

endpoints must contain the local endpoint cluster metadata in endpoint order. Outgoing APS helpers use this list to select the source endpoint for a cluster.

Source

pub fn source_endpoint( &self, profile_id: u16, cluster_id: u16, ) -> Result<u8, Error>

Returns the first local endpoint that lists the given cluster as an output cluster.

Endpoints are stored in the same order they were supplied to the builder. The returned endpoint number is one-based, matching the EZSP endpoint numbering used for outgoing APS frames.

§Errors

Returns Error::NoMatchingSourceEndpoint when no configured local endpoint advertises cluster_id as an output cluster.

Source

pub async fn terminate(self) -> Result<(), SendError<Message>>

Sends a termination request to the background event handler.

§Errors

Returns SendError if the termination request cannot be sent to the message handler.

Source§

impl<T> Ncp<T>
where T: Messaging,

Source

pub async fn unicast( &mut self, short_id: u16, profile_id: u16, cluster_id: u16, destination_endpoint: u8, payload: impl AsRef<[u8]>, ) -> Result<StackResponse, Error>

Starts a unicast APS send and returns its deferred StackResponse.

Payloads larger than the EZSP maximum APS payload length are fragmented for unicast delivery. The stack-assigned APS sequence from the first fragment is reused for follow-up fragments, matching EZSP host fragmentation behavior. Responses for all non-final fragments are awaited before this method returns the response for the final fragment. Await the returned StackResponse to confirm that final response.

§Errors

Returns an Error if no matching source endpoint exists, payload fragmentation would exceed 255 fragments, registering a message tag or sending an EZSP command fails, or a non-final fragment’s stack response reports failure. Errors reported by the returned StackResponse occur when that value is awaited.

Source

pub async fn multicast( &mut self, group_id: u16, options: MulticastOptions, profile_id: u16, cluster_id: u16, destination_endpoint: u8, payload: impl AsRef<[u8]>, ) -> Result<(StackResponse, u8), Error>

Starts a multicast APS send.

Returns the deferred StackResponse and the APS sequence assigned by the NCP. Await the response to confirm the matching messageSent callback.

§Errors

Returns an Error if no matching source endpoint exists, the payload is larger than the EZSP maximum APS payload length, registering the message tag fails, or sending the EZSP command fails. Errors reported by the returned StackResponse occur when that value is awaited.

Source

pub async fn broadcast( &mut self, short_id: u16, radius: u8, profile_id: u16, cluster_id: u16, destination_endpoint: u8, payload: impl AsRef<[u8]>, ) -> Result<StackResponse, Error>

Starts a broadcast APS send and returns its deferred StackResponse.

Await the returned response to confirm the matching messageSent callback.

§Errors

Returns an Error if no matching source endpoint exists, the payload is larger than the EZSP maximum APS payload length, registering the message tag fails, or sending the EZSP command fails. Errors reported by the returned StackResponse occur when that value is awaited.

Source§

impl<T> Ncp<T>
where T: Networking,

Source

pub async fn scan_networks( &mut self, channel_mask: u32, duration: u8, ) -> Result<Vec<NetworkFound>, Error>

Starts an active network scan and returns all networkFound callback results.

§Errors

Returns an Error if registering the scan, sending startScan, or receiving the scan result fails.

Source

pub async fn scan_channels( &mut self, channel_mask: u32, duration: u8, ) -> Result<Vec<EnergyScanResult>, Error>

Starts an energy scan and returns all energyScanResult callback results.

§Errors

Returns an Error if registering the scan, sending startScan, or receiving the scan result fails.

Source§

impl Ncp<Uart>

Source

pub fn ashv2<T>(serial_port: T, startup: Startup) -> (Builder<Uart>, Futures<T>)
where T: SerialPort + Sync + 'static,

Creates a new Builder backed by an ASHv2 UART transport.

The serial port must implement SerialPort, which is re-exported by the UART module from the ASHv2 transport crate. The returned Futures value must be spawned or otherwise polled by the caller for the UART transport to make progress. Use crate::Startup::Resume to restore a persisted network or crate::Startup::Initialize to form a new one.

Trait Implementations§

Source§

impl<T: Debug> Debug for Ncp<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Driver for Ncp<T>

Source§

async fn get_endpoints(&self) -> Result<BTreeMap<Application, Clusters>, Error>

Return the local endpoint cluster sets registered with the NCP. Read more
Source§

async fn get_pan_id(&mut self) -> Result<u16, Error>

Get the PAN ID of the network. Read more
Source§

async fn get_ieee_address(&mut self) -> Result<IeeeAddress, Error>

Get the IEEE address of the coordinator. Read more
Source§

async fn scan_networks( &mut self, channel_mask: u32, duration: u8, ) -> Result<Vec<FoundNetwork>, Error>

Scan for available networks. Read more
Source§

async fn scan_channels( &mut self, channel_mask: u32, duration: u8, ) -> Result<Vec<ScannedChannel>, Error>

Scan channels for activity. Read more
Source§

async fn allow_joins(&mut self, duration: Duration) -> Result<Duration, Error>

Allow devices to join the network for the specified duration. Read more
Source§

async fn route_request(&mut self, radius: u8) -> Result<(), Error>

Send a route request. Read more
Source§

async fn short_id_to_ieee_address( &mut self, short_id: u16, ) -> Result<IeeeAddress, Error>

Get the IEEE address of the device with the specified short ID. Read more
Source§

async fn ieee_address_to_short_id( &mut self, ieee_address: IeeeAddress, ) -> Result<u16, Error>

Get the short ID of the device with the specified IEEE address. Read more
Source§

async fn transmit( &mut self, destination: Destination, datagram: Datagram, ) -> Result<HwResponse, Error>

Transmit an application datagram to the specified destination. Read more
Source§

fn run( self, channel_size: usize, ) -> (Sender<Message>, impl Future<Output = Self> + Send)
where Self: Sized + SealedDriver + 'static,

Spawn the actor in a tokio task. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Ncp<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Ncp<T>
where T: RefUnwindSafe,

§

impl<T> Send for Ncp<T>
where T: Send,

§

impl<T> Sync for Ncp<T>
where T: Sync,

§

impl<T> Unpin for Ncp<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Ncp<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Ncp<T>
where T: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

impl<T, U> TryFromLeStream<T> for U
where T: FromLeStream, U: TryFrom<T>,

Source§

fn try_from_le_stream<I>( bytes: I, ) -> Result<U, Option<<U as TryFrom<T>>::Error>>
where I: Iterator<Item = u8>,

Try to parse an object from another type that can be parsed from a stream of bytes with little endianness. Read more
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.