Skip to content

Commit

Permalink
Adjust after cluster duplicate state removal
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Jun 27, 2024
1 parent dc35fde commit 22d0454
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
15 changes: 10 additions & 5 deletions examples/onoff_light_bt/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -46,16 +45,17 @@ pub struct WifiNwCommCluster<'a> {

impl<'a> WifiNwCommCluster<'a> {
/// Create a new instance.
pub fn new(rand: Rand, nw_setup_complete: &'a Notification<NoopRawMutex>) -> Self {
pub const fn new(data_ver: Dataver, nw_setup_complete: &'a Notification<NoopRawMutex>) -> Self {
Self {
data_ver: Dataver::new(rand),
data_ver,
nw_setup_complete,
}
}

/// Read an attribute.
pub fn read(
&self,
_exchange: &Exchange,
attr: &AttrDetails<'_>,
encoder: AttrDataEncoder<'_, '_, '_>,
) -> Result<(), Error> {
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 10 additions & 11 deletions examples/onoff_light_bt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
};

Expand All @@ -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();

Expand Down Expand Up @@ -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<FabricMgr> = matter.borrow();
if fabrics.borrow().is_empty() {
if !matter.is_commissioned() {
// Not commissioned yet, start commissioning first

let btp = Btp::new_builtin(&BTP_CONTEXT);
Expand Down Expand Up @@ -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,
Expand All @@ -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),
)
Expand Down
2 changes: 1 addition & 1 deletion rs-matter/src/transport/network/btp/gatt/bluer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down

0 comments on commit 22d0454

Please sign in to comment.