From fb0f4a8bf42a625509d70401b8330e86d2fb25b6 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Tue, 30 Apr 2024 10:11:05 +0000 Subject: [PATCH] Fix the example --- README.md | 28 ++++++++++++++------------- examples/light.rs | 28 ++++++++++++++------------- src/stack.rs | 48 ++++++++++++++++++++++++++++------------------- src/wifi/comm.rs | 28 ++++++++++++--------------- src/wifi/diag.rs | 1 - 5 files changed, 71 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index c790914..8f916c6 100644 --- a/README.md +++ b/README.md @@ -65,19 +65,21 @@ fn main() -> Result<(), Error> { // Chain our endpoint clusters with the // (root) Endpoint 0 system clusters in the final handler - let handler = HandlerCompat( - stack - .root_handler() - // Our on-off cluster, on Endpoint 1 - .chain(LIGHT_ENDPOINT_ID, cluster_on_off::ID, &on_off) - // Each Endpoint needs a Descriptor cluster too - // Just use the one that `rs-matter` provides out of the box - .chain( - LIGHT_ENDPOINT_ID, - descriptor::ID, - descriptor::DescriptorCluster::new(*stack.matter().borrow()), - ), - ); + let handler = stack + .root_handler() + // Our on-off cluster, on Endpoint 1 + .chain( + LIGHT_ENDPOINT_ID, + cluster_on_off::ID, + HandlerCompat(&on_off), + ) + // Each Endpoint needs a Descriptor cluster too + // Just use the one that `rs-matter` provides out of the box + .chain( + LIGHT_ENDPOINT_ID, + descriptor::ID, + HandlerCompat(descriptor::DescriptorCluster::new(*stack.matter().borrow())), + ); // Run the Matter stack with our handler // Using `pin!` is completely optional, but saves some memory due to `rustc` diff --git a/examples/light.rs b/examples/light.rs index 600577f..71d754c 100644 --- a/examples/light.rs +++ b/examples/light.rs @@ -44,19 +44,21 @@ fn main() -> Result<(), Error> { // Chain our endpoint clusters with the // (root) Endpoint 0 system clusters in the final handler - let handler = HandlerCompat( - stack - .root_handler() - // Our on-off cluster, on Endpoint 1 - .chain(LIGHT_ENDPOINT_ID, cluster_on_off::ID, &on_off) - // Each Endpoint needs a Descriptor cluster too - // Just use the one that `rs-matter` provides out of the box - .chain( - LIGHT_ENDPOINT_ID, - descriptor::ID, - descriptor::DescriptorCluster::new(*stack.matter().borrow()), - ), - ); + let handler = stack + .root_handler() + // Our on-off cluster, on Endpoint 1 + .chain( + LIGHT_ENDPOINT_ID, + cluster_on_off::ID, + HandlerCompat(&on_off), + ) + // Each Endpoint needs a Descriptor cluster too + // Just use the one that `rs-matter` provides out of the box + .chain( + LIGHT_ENDPOINT_ID, + descriptor::ID, + HandlerCompat(descriptor::DescriptorCluster::new(*stack.matter().borrow())), + ); // Run the Matter stack with our handler // Using `pin!` is completely optional, but saves some memory due to `rustc` diff --git a/src/stack.rs b/src/stack.rs index f7557f6..08ccb5f 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -306,7 +306,7 @@ mod wifible { self, BasicInfoCluster, BasicInfoConfig, }; use rs_matter::data_model::objects::{ - AsyncHandler, AsyncMetadata, Cluster, EmptyHandler, Endpoint, + AsyncHandler, AsyncMetadata, Cluster, EmptyHandler, Endpoint, HandlerCompat, }; use rs_matter::data_model::sdm::admin_commissioning::AdminCommCluster; use rs_matter::data_model::sdm::dev_att::DevAttDataFetcher; @@ -477,16 +477,16 @@ mod wifible { } pub type RootEndpointHandler<'a> = handler_chain_type!( - descriptor::DescriptorCluster<'static>, - cluster_basic_information::BasicInfoCluster<'a>, - general_commissioning::GenCommCluster<'a>, + HandlerCompat>, + HandlerCompat>, + HandlerCompat>, comm::WifiNwCommCluster<'a, 3, NoopRawMutex>, - admin_commissioning::AdminCommCluster<'a>, - noc::NocCluster<'a>, - access_control::AccessControlCluster<'a>, - general_diagnostics::GenDiagCluster, - diag::WifiNwDiagCluster, - group_key_management::GrpKeyMgmtCluster + HandlerCompat>, + HandlerCompat>, + HandlerCompat>, + HandlerCompat, + HandlerCompat, + HandlerCompat ); const CLUSTERS: [Cluster<'static>; 10] = [ @@ -552,28 +552,34 @@ mod wifible { .chain( endpoint_id, group_key_management::ID, - GrpKeyMgmtCluster::new(rand), + HandlerCompat(GrpKeyMgmtCluster::new(rand)), + ) + .chain( + endpoint_id, + diag::ID, + HandlerCompat(WifiNwDiagCluster::new(rand)), ) - .chain(endpoint_id, diag::ID, WifiNwDiagCluster::new(rand)) .chain( endpoint_id, general_diagnostics::ID, - GenDiagCluster::new(rand), + HandlerCompat(GenDiagCluster::new(rand)), ) .chain( endpoint_id, access_control::ID, - AccessControlCluster::new(acl, rand), + HandlerCompat(AccessControlCluster::new(acl, rand)), ) .chain( endpoint_id, noc::ID, - NocCluster::new(dev_att, fabric, acl, failsafe, mdns, epoch, rand), + HandlerCompat(NocCluster::new( + dev_att, fabric, acl, failsafe, mdns, epoch, rand, + )), ) .chain( endpoint_id, admin_commissioning::ID, - AdminCommCluster::new(pase, mdns, rand), + HandlerCompat(AdminCommCluster::new(pase, mdns, rand)), ) .chain( endpoint_id, @@ -583,13 +589,17 @@ mod wifible { .chain( endpoint_id, general_commissioning::ID, - GenCommCluster::new(failsafe, rand), + HandlerCompat(GenCommCluster::new(failsafe, rand)), ) .chain( endpoint_id, cluster_basic_information::ID, - BasicInfoCluster::new(basic_info, rand), + HandlerCompat(BasicInfoCluster::new(basic_info, rand)), + ) + .chain( + endpoint_id, + descriptor::ID, + HandlerCompat(DescriptorCluster::new(rand)), ) - .chain(endpoint_id, descriptor::ID, DescriptorCluster::new(rand)) } } diff --git a/src/wifi/comm.rs b/src/wifi/comm.rs index ab51986..bbe8420 100644 --- a/src/wifi/comm.rs +++ b/src/wifi/comm.rs @@ -39,7 +39,7 @@ where } } - async fn read( + pub fn read( &self, attr: &AttrDetails<'_>, encoder: AttrDataEncoder<'_, '_, '_>, @@ -111,7 +111,7 @@ where } } - async fn invoke( + pub async fn invoke( &self, exchange: &Exchange<'_>, cmd: &CmdDetails<'_>, @@ -121,18 +121,15 @@ where match cmd.cmd_id.try_into()? { Commands::ScanNetworks => { info!("ScanNetworks"); - self.scan_networks(exchange, &ScanNetworksRequest::from_tlv(data)?, encoder) - .await?; + self.scan_networks(exchange, &ScanNetworksRequest::from_tlv(data)?, encoder)?; } Commands::AddOrUpdateWifiNetwork => { info!("AddOrUpdateWifiNetwork"); - self.add_network(exchange, &AddWifiNetworkRequest::from_tlv(data)?, encoder) - .await?; + self.add_network(exchange, &AddWifiNetworkRequest::from_tlv(data)?, encoder)?; } Commands::RemoveNetwork => { info!("RemoveNetwork"); - self.remove_network(exchange, &RemoveNetworkRequest::from_tlv(data)?, encoder) - .await?; + self.remove_network(exchange, &RemoveNetworkRequest::from_tlv(data)?, encoder)?; } Commands::ConnectNetwork => { info!("ConnectNetwork"); @@ -141,8 +138,7 @@ where } Commands::ReorderNetwork => { info!("ReorderNetwork"); - self.reorder_network(exchange, &ReorderNetworkRequest::from_tlv(data)?, encoder) - .await?; + self.reorder_network(exchange, &ReorderNetworkRequest::from_tlv(data)?, encoder)?; } other => { error!("{other:?} (not supported)"); @@ -155,7 +151,7 @@ where Ok(()) } - async fn scan_networks( + fn scan_networks( &self, _exchange: &Exchange<'_>, _req: &ScanNetworksRequest<'_>, @@ -168,7 +164,7 @@ where Ok(()) } - async fn add_network( + fn add_network( &self, exchange: &Exchange<'_>, req: &AddWifiNetworkRequest<'_>, @@ -244,7 +240,7 @@ where }) } - async fn remove_network( + fn remove_network( &self, exchange: &Exchange<'_>, req: &RemoveNetworkRequest<'_>, @@ -312,11 +308,11 @@ where self.networks.network_connect_requested.notify(); - // Block forever waitinng for the firware to restart + // Block forever waiting for the firware to restart core::future::pending().await } - async fn reorder_network( + fn reorder_network( &self, exchange: &Exchange<'_>, req: &ReorderNetworkRequest<'_>, @@ -386,7 +382,7 @@ where attr: &'m AttrDetails<'_>, encoder: AttrDataEncoder<'m, '_, '_>, ) -> Result<(), Error> { - WifiNwCommCluster::read(self, attr, encoder).await + WifiNwCommCluster::read(self, attr, encoder) } async fn invoke<'m>( diff --git a/src/wifi/diag.rs b/src/wifi/diag.rs index 8634911..480e0e5 100644 --- a/src/wifi/diag.rs +++ b/src/wifi/diag.rs @@ -195,5 +195,4 @@ impl Handler for WifiNwDiagCluster { } } -// TODO: Might be removed once the `on` member is externalized impl NonBlockingHandler for WifiNwDiagCluster {}