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>
impl<T> Ncp<T>
Sourcepub const fn new(
transport: T,
aps_options: Options,
event_handler_proxy: Sender<Message>,
endpoints: Box<[Clusters]>,
) -> Self
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.
Sourcepub fn source_endpoint(
&self,
profile_id: u16,
cluster_id: u16,
) -> Result<u8, Error>
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§impl<T> Ncp<T>where
T: Messaging,
impl<T> Ncp<T>where
T: Messaging,
Sourcepub async fn unicast(
&mut self,
short_id: u16,
profile_id: u16,
cluster_id: u16,
destination_endpoint: u8,
payload: impl AsRef<[u8]>,
) -> Result<StackResponse, Error>
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.
Sourcepub 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>
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.
Sourcepub 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>
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,
impl<T> Ncp<T>where
T: Networking,
Sourcepub async fn scan_networks(
&mut self,
channel_mask: u32,
duration: u8,
) -> Result<Vec<NetworkFound>, Error>
pub async fn scan_networks( &mut self, channel_mask: u32, duration: u8, ) -> Result<Vec<NetworkFound>, Error>
Sourcepub async fn scan_channels(
&mut self,
channel_mask: u32,
duration: u8,
) -> Result<Vec<EnergyScanResult>, Error>
pub async fn scan_channels( &mut self, channel_mask: u32, duration: u8, ) -> Result<Vec<EnergyScanResult>, Error>
Source§impl Ncp<Uart>
impl Ncp<Uart>
Sourcepub fn ashv2<T>(serial_port: T, startup: Startup) -> (Builder<Uart>, Futures<T>)where
T: SerialPort + Sync + 'static,
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.