Skip to content

Commit

Permalink
Fix the example
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Apr 30, 2024
1 parent ca59b1c commit fb0f4a8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 62 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
28 changes: 15 additions & 13 deletions examples/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
48 changes: 29 additions & 19 deletions src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<descriptor::DescriptorCluster<'a>>,
HandlerCompat<cluster_basic_information::BasicInfoCluster<'a>>,
HandlerCompat<general_commissioning::GenCommCluster<'a>>,
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<admin_commissioning::AdminCommCluster<'a>>,
HandlerCompat<noc::NocCluster<'a>>,
HandlerCompat<access_control::AccessControlCluster<'a>>,
HandlerCompat<general_diagnostics::GenDiagCluster>,
HandlerCompat<diag::WifiNwDiagCluster>,
HandlerCompat<group_key_management::GrpKeyMgmtCluster>
);

const CLUSTERS: [Cluster<'static>; 10] = [
Expand Down Expand Up @@ -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,
Expand All @@ -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))
}
}
28 changes: 12 additions & 16 deletions src/wifi/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
}
}

async fn read(
pub fn read(
&self,
attr: &AttrDetails<'_>,
encoder: AttrDataEncoder<'_, '_, '_>,
Expand Down Expand Up @@ -111,7 +111,7 @@ where
}
}

async fn invoke(
pub async fn invoke(
&self,
exchange: &Exchange<'_>,
cmd: &CmdDetails<'_>,
Expand All @@ -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");
Expand All @@ -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)");
Expand All @@ -155,7 +151,7 @@ where
Ok(())
}

async fn scan_networks(
fn scan_networks(
&self,
_exchange: &Exchange<'_>,
_req: &ScanNetworksRequest<'_>,
Expand All @@ -168,7 +164,7 @@ where
Ok(())
}

async fn add_network(
fn add_network(
&self,
exchange: &Exchange<'_>,
req: &AddWifiNetworkRequest<'_>,
Expand Down Expand Up @@ -244,7 +240,7 @@ where
})
}

async fn remove_network(
fn remove_network(
&self,
exchange: &Exchange<'_>,
req: &RemoveNetworkRequest<'_>,
Expand Down Expand Up @@ -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<'_>,
Expand Down Expand Up @@ -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>(
Expand Down
1 change: 0 additions & 1 deletion src/wifi/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,4 @@ impl Handler for WifiNwDiagCluster {
}
}

// TODO: Might be removed once the `on` member is externalized
impl NonBlockingHandler for WifiNwDiagCluster {}

0 comments on commit fb0f4a8

Please sign in to comment.