From 22d0454a191b3270e13b48e7572b637c89749798 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Thu, 27 Jun 2024 14:17:07 +0000 Subject: [PATCH] Adjust after cluster duplicate state removal --- examples/onoff_light_bt/src/comm.rs | 15 ++++++++----- examples/onoff_light_bt/src/main.rs | 21 +++++++++---------- .../src/transport/network/btp/gatt/bluer.rs | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/examples/onoff_light_bt/src/comm.rs b/examples/onoff_light_bt/src/comm.rs index 7f5cf739..6052b485 100644 --- a/examples/onoff_light_bt/src/comm.rs +++ b/examples/onoff_light_bt/src/comm.rs @@ -33,7 +33,6 @@ use rs_matter::interaction_model::messages::ib::Status; use rs_matter::tlv::{FromTLV, OctetStr, TLVElement}; use rs_matter::transport::exchange::Exchange; use rs_matter::utils::notification::Notification; -use rs_matter::utils::rand::Rand; /// A _fake_ cluster implementing the Matter Network Commissioning Cluster /// for managing WiFi networks. @@ -46,9 +45,9 @@ pub struct WifiNwCommCluster<'a> { impl<'a> WifiNwCommCluster<'a> { /// Create a new instance. - pub fn new(rand: Rand, nw_setup_complete: &'a Notification) -> Self { + pub const fn new(data_ver: Dataver, nw_setup_complete: &'a Notification) -> Self { Self { - data_ver: Dataver::new(rand), + data_ver, nw_setup_complete, } } @@ -56,6 +55,7 @@ impl<'a> WifiNwCommCluster<'a> { /// Read an attribute. pub fn read( &self, + _exchange: &Exchange, attr: &AttrDetails<'_>, encoder: AttrDataEncoder<'_, '_, '_>, ) -> Result<(), Error> { @@ -241,8 +241,13 @@ impl<'a> WifiNwCommCluster<'a> { } impl<'a> Handler for WifiNwCommCluster<'a> { - fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> { - WifiNwCommCluster::read(self, attr, encoder) + fn read( + &self, + exchange: &Exchange, + attr: &AttrDetails, + encoder: AttrDataEncoder, + ) -> Result<(), Error> { + WifiNwCommCluster::read(self, exchange, attr, encoder) } fn invoke( diff --git a/examples/onoff_light_bt/src/main.rs b/examples/onoff_light_bt/src/main.rs index 71128a74..4d6725ab 100644 --- a/examples/onoff_light_bt/src/main.rs +++ b/examples/onoff_light_bt/src/main.rs @@ -31,8 +31,6 @@ //! that can manage Wifi networks on the device by using the device-specific APIs. //! (For (embedded) Linux, this could be done using `nmcli` or `wpa_supplicant`.) -use core::borrow::Borrow; -use core::cell::RefCell; use core::pin::pin; use std::net::UdpSocket; @@ -57,7 +55,6 @@ use rs_matter::data_model::sdm::wifi_nw_diagnostics::{ use rs_matter::data_model::subscriptions::Subscriptions; use rs_matter::data_model::system_model::descriptor; use rs_matter::error::Error; -use rs_matter::fabric::FabricMgr; use rs_matter::mdns::MdnsService; use rs_matter::pairing::DiscoveryCapabilities; use rs_matter::persist::Psm; @@ -132,7 +129,7 @@ fn run() -> Result<(), Error> { let dev_comm = CommissioningData { // TODO: Hard-coded for now - verifier: VerifierData::new_with_pw(123456, *matter.borrow()), + verifier: VerifierData::new_with_pw(123456, matter.rand()), discriminator: 250, }; @@ -148,7 +145,7 @@ fn run() -> Result<(), Error> { let mut mdns = pin!(run_mdns(&matter)); - let on_off = cluster_on_off::OnOffCluster::new(*matter.borrow()); + let on_off = cluster_on_off::OnOffCluster::new(Dataver::new_rand(matter.rand())); let subscriptions = Subscriptions::<3>::new(); @@ -188,8 +185,7 @@ fn run() -> Result<(), Error> { let mut psm = Psm::new(&matter, std::env::temp_dir().join("rs-matter"))?; let mut persist = pin!(psm.run()); - let fabrics: &RefCell = matter.borrow(); - if fabrics.borrow().is_empty() { + if !matter.is_commissioned() { // Not commissioned yet, start commissioning first let btp = Btp::new_builtin(&BTP_CONTEXT); @@ -264,11 +260,13 @@ fn dm_handler<'a>( NODE, root_endpoint::handler( 0, - matter, - HandlerCompat(WifiNwCommCluster::new(*matter.borrow(), &wifi_complete)), + HandlerCompat(WifiNwCommCluster::new( + Dataver::new_rand(matter.rand()), + &wifi_complete, + )), wifi_nw_diagnostics::ID, HandlerCompat(WifiNwDiagCluster::new( - *matter.borrow(), + Dataver::new_rand(matter.rand()), WifiNwDiagData { bssid: [0; 6], security_type: WiFiSecurity::Wpa2Personal, @@ -278,11 +276,12 @@ fn dm_handler<'a>( }, )), false, + matter.rand(), ) .chain( 1, descriptor::ID, - descriptor::DescriptorCluster::new(*matter.borrow()), + descriptor::DescriptorCluster::new(Dataver::new_rand(matter.rand())), ) .chain(1, cluster_on_off::ID, on_off), ) diff --git a/rs-matter/src/transport/network/btp/gatt/bluer.rs b/rs-matter/src/transport/network/btp/gatt/bluer.rs index fe34356e..ffac0740 100644 --- a/rs-matter/src/transport/network/btp/gatt/bluer.rs +++ b/rs-matter/src/transport/network/btp/gatt/bluer.rs @@ -101,7 +101,7 @@ impl BluerGattPeripheral { let session = bluer::Session::new().await?; // Register a "NoInputNoOutput" agent that will accept all incoming requests. - session.register_agent(Agent::default()).await?; + let _handle = session.register_agent(Agent::default()).await?; let adapter = if let Some(adapter_name) = self.0.adapter_name.as_ref() { session.adapter(adapter_name)?