Skip to content

Commit 44e01a5

Browse files
committed
Configurable parts_list in descriptor
1 parent 8318536 commit 44e01a5

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

matter/src/data_model/root_endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use super::{
2727
};
2828

2929
pub type RootEndpointHandler<'a> = handler_chain_type!(
30-
DescriptorCluster,
30+
DescriptorCluster<'static>,
3131
BasicInfoCluster<'a>,
3232
GenCommCluster<'a>,
3333
NwCommCluster,

matter/src/data_model/system_model/descriptor.rs

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,63 @@ pub const CLUSTER: Cluster<'static> = Cluster {
5353
commands: &[],
5454
};
5555

56-
pub struct DescriptorCluster {
56+
struct StandardPartsMatcher;
57+
58+
impl PartsMatcher for StandardPartsMatcher {
59+
fn describe(&self, our_endpoint: EndptId, endpoint: EndptId) -> bool {
60+
our_endpoint == 0 && endpoint != our_endpoint
61+
}
62+
}
63+
64+
struct AggregatorPartsMatcher;
65+
66+
impl PartsMatcher for AggregatorPartsMatcher {
67+
fn describe(&self, our_endpoint: EndptId, endpoint: EndptId) -> bool {
68+
endpoint != our_endpoint && endpoint != 0
69+
}
70+
}
71+
72+
pub trait PartsMatcher {
73+
fn describe(&self, our_endpoint: EndptId, endpoint: EndptId) -> bool;
74+
}
75+
76+
impl<T> PartsMatcher for &T
77+
where
78+
T: PartsMatcher,
79+
{
80+
fn describe(&self, our_endpoint: EndptId, endpoint: EndptId) -> bool {
81+
(**self).describe(our_endpoint, endpoint)
82+
}
83+
}
84+
85+
impl<T> PartsMatcher for &mut T
86+
where
87+
T: PartsMatcher,
88+
{
89+
fn describe(&self, our_endpoint: EndptId, endpoint: EndptId) -> bool {
90+
(**self).describe(our_endpoint, endpoint)
91+
}
92+
}
93+
94+
pub struct DescriptorCluster<'a> {
95+
matcher: &'a dyn PartsMatcher,
5796
data_ver: Dataver,
5897
}
5998

60-
impl DescriptorCluster {
99+
impl DescriptorCluster<'static> {
61100
pub fn new(rand: Rand) -> Self {
101+
Self::new_matching(&StandardPartsMatcher, rand)
102+
}
103+
104+
pub fn new_aggregator(rand: Rand) -> Self {
105+
Self::new_matching(&AggregatorPartsMatcher, rand)
106+
}
107+
}
108+
109+
impl<'a> DescriptorCluster<'a> {
110+
pub fn new_matching(matcher: &'a dyn PartsMatcher, rand: Rand) -> DescriptorCluster<'a> {
62111
Self {
112+
matcher,
63113
data_ver: Dataver::new(rand),
64114
}
65115
}
@@ -159,12 +209,9 @@ impl DescriptorCluster {
159209
) -> Result<(), Error> {
160210
tw.start_array(tag)?;
161211

162-
if endpoint_id == 0 {
163-
// TODO: If endpoint is another than 0, need to figure out what to do
164-
for endpoint in node.endpoints {
165-
if endpoint.id != 0 {
166-
tw.u16(TagType::Anonymous, endpoint.id)?;
167-
}
212+
for endpoint in node.endpoints {
213+
if self.matcher.describe(endpoint_id, endpoint.id) {
214+
tw.u16(TagType::Anonymous, endpoint.id)?;
168215
}
169216
}
170217

@@ -184,15 +231,15 @@ impl DescriptorCluster {
184231
}
185232
}
186233

187-
impl Handler for DescriptorCluster {
234+
impl<'a> Handler for DescriptorCluster<'a> {
188235
fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> {
189236
DescriptorCluster::read(self, attr, encoder)
190237
}
191238
}
192239

193-
impl NonBlockingHandler for DescriptorCluster {}
240+
impl<'a> NonBlockingHandler for DescriptorCluster<'a> {}
194241

195-
impl ChangeNotifier<()> for DescriptorCluster {
242+
impl<'a> ChangeNotifier<()> for DescriptorCluster<'a> {
196243
fn consume_change(&mut self) -> Option<()> {
197244
self.data_ver.consume_change(())
198245
}

matter/tests/common/im_engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a> ImInput<'a> {
101101
}
102102
}
103103

104-
pub type DmHandler<'a> = handler_chain_type!(OnOffCluster, EchoCluster, DescriptorCluster, EchoCluster | RootEndpointHandler<'a>);
104+
pub type DmHandler<'a> = handler_chain_type!(OnOffCluster, EchoCluster, DescriptorCluster<'a>, EchoCluster | RootEndpointHandler<'a>);
105105

106106
pub fn matter(mdns: &mut dyn Mdns) -> Matter<'_> {
107107
#[cfg(feature = "std")]

0 commit comments

Comments
 (0)