Skip to content

Commit c1f62b0

Browse files
authored
Extensions to Basic Information Cluster; AttrId is now u32; report more global elements (Was: Chip tool tests) (#232)
* WIP - run chip-tool tests with rs-matter - TestBasicInformation * WIP - run chip-tool tests with rs-matter - TestAttributesById * WIP - run chip-tool tests with rs-matter - TestBasicInformation * Fix tests; clippy * Address code review comment
1 parent 8b4c396 commit c1f62b0

35 files changed

Lines changed: 827 additions & 351 deletions

chip-tool-tests.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
CHIP_HOME="../connectedhomeip"
3+
RS_MATTER=`pwd`
4+
RS_MATTER_DATA="/tmp/rs-matter"
5+
6+
rm -rf ${RS_MATTER_DATA}
7+
cd ${CHIP_HOME}
8+
#${CHIP_HOME}/scripts/run_in_build_env.sh "${CHIP_HOME}/scripts/tests/run_test_suite.py --log-level warn --target TestAccessControlCluster --runner chip_tool_python --chip-tool ${CHIP_HOME}/out/host/chip-tool run --iterations 1 --test-timeout-seconds 120 --all-clusters-app ${RS_MATTER}/target/debug/examples/onoff_light --lock-app ${RS_MATTER}/target/debug/examples/onoff_light"
9+
#${CHIP_HOME}/scripts/run_in_build_env.sh "${CHIP_HOME}/scripts/tests/run_test_suite.py --log-level warn --target TestBasicInformation --runner chip_tool_python --chip-tool ${CHIP_HOME}/out/host/chip-tool run --iterations 1 --test-timeout-seconds 120 --all-clusters-app ${RS_MATTER}/target/debug/examples/onoff_light --lock-app ${RS_MATTER}/target/debug/examples/onoff_light"
10+
${CHIP_HOME}/scripts/run_in_build_env.sh "${CHIP_HOME}/scripts/tests/run_test_suite.py --log-level warn --target TestAttributesById --runner chip_tool_python --chip-tool ${CHIP_HOME}/out/host/chip-tool run --iterations 1 --test-timeout-seconds 120 --all-clusters-app ${RS_MATTER}/target/debug/examples/onoff_light --lock-app ${RS_MATTER}/target/debug/examples/onoff_light"
11+
cd ${RS_MATTER}

examples/onoff_light/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static DEV_DET: BasicInfoConfig = BasicInfoConfig {
5252
vid: 0xFFF1,
5353
pid: 0x8001,
5454
hw_ver: 2,
55+
hw_ver_str: "2",
5556
sw_ver: 1,
5657
sw_ver_str: "1",
5758
serial_no: "aabbccdd",
@@ -98,6 +99,16 @@ fn run() -> Result<(), Error> {
9899
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
99100
);
100101

102+
// NOTE: chip-tool tests need the log to go to `stdout` instead
103+
// env_logger::builder()
104+
// .format(|buf, record| {
105+
// use std::io::Write;
106+
// writeln!(buf, "{}: {}", record.level(), record.args())
107+
// })
108+
// .target(env_logger::Target::Stdout)
109+
// .filter_level(::log::LevelFilter::Info)
110+
// .init();
111+
101112
info!(
102113
"Matter memory: Matter (BSS)={}B, IM Buffers (BSS)={}B, Subscriptions (BSS)={}B",
103114
core::mem::size_of::<Matter>(),
@@ -281,7 +292,6 @@ async fn run_mdns(matter: &Matter<'_>) -> Result<(), Error> {
281292
.filter_map(|ia| {
282293
ia.address
283294
.and_then(|addr| addr.as_sockaddr_in6().map(SockaddrIn6::ip))
284-
.filter(|ip| ip.octets()[..2] == [0xfe, 0x80])
285295
.map(|ipv6| (ia.interface_name, ipv6))
286296
})
287297
.filter_map(|(iname, ipv6)| {

examples/onoff_light_bt/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ fn run() -> Result<(), Error> {
104104
vid: 0xFFF1,
105105
pid: 0x8000,
106106
hw_ver: 2,
107+
hw_ver_str: "2",
107108
sw_ver: 1,
108109
sw_ver_str: "1",
109110
serial_no: "aabbccdd",

rs-matter/src/core.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
1919

2020
use crate::data_model::{
21-
cluster_basic_information::BasicInfoConfig,
21+
cluster_basic_information::{BasicInfoConfig, BasicInfoSettings},
2222
sdm::{dev_att::DevAttDataFetcher, failsafe::FailSafe},
2323
};
2424
use crate::error::*;
@@ -54,6 +54,7 @@ pub struct Matter<'a> {
5454
pub fabric_mgr: RefCell<FabricMgr>, // Public for tests
5555
pub(crate) pase_mgr: RefCell<PaseMgr>,
5656
pub(crate) failsafe: RefCell<FailSafe>,
57+
pub(crate) basic_info_settings: RefCell<BasicInfoSettings>,
5758
pub transport_mgr: TransportMgr<'a>, // Public for tests
5859
persist_notification: Notification<NoopRawMutex>,
5960
epoch: Epoch,
@@ -122,6 +123,7 @@ impl<'a> Matter<'a> {
122123
pase_mgr: RefCell::new(PaseMgr::new(epoch, rand)),
123124
failsafe: RefCell::new(FailSafe::new(epoch, rand)),
124125
transport_mgr: TransportMgr::new(mdns, dev_det, port, epoch, rand),
126+
basic_info_settings: RefCell::new(BasicInfoSettings::new()),
125127
persist_notification: Notification::new(),
126128
epoch,
127129
rand,
@@ -189,6 +191,7 @@ impl<'a> Matter<'a> {
189191
pase_mgr <- RefCell::init(PaseMgr::init(epoch, rand)),
190192
failsafe: RefCell::new(FailSafe::new(epoch, rand)),
191193
transport_mgr <- TransportMgr::init(mdns, dev_det, port, epoch, rand),
194+
basic_info_settings <- RefCell::init(BasicInfoSettings::init()),
192195
persist_notification: Notification::new(),
193196
epoch,
194197
rand,
@@ -274,6 +277,18 @@ impl<'a> Matter<'a> {
274277
self.fabric_mgr.borrow().is_changed()
275278
}
276279

280+
pub fn load_basic_info(&self, data: &[u8]) -> Result<(), Error> {
281+
self.basic_info_settings.borrow_mut().load(data)
282+
}
283+
284+
pub fn store_basic_info<'b>(&self, buf: &'b mut [u8]) -> Result<Option<&'b [u8]>, Error> {
285+
self.basic_info_settings.borrow_mut().store(buf)
286+
}
287+
288+
pub fn basic_info_changed(&self) -> bool {
289+
self.basic_info_settings.borrow().changed
290+
}
291+
277292
/// Return `true` if there is at least one commissioned fabric
278293
//
279294
// TODO:
@@ -346,6 +361,8 @@ impl<'a> Matter<'a> {
346361
S: NetworkSend,
347362
R: NetworkReceive,
348363
{
364+
// TODO: Figure out why chip-tool-tests expect the device to still be in commissioning mode
365+
// post device reboot, even if it was already commissioned
349366
if !self.is_commissioned() {
350367
self.enable_basic_commissioning(discovery_capabilities, 0 /*TODO*/)
351368
.await?;
@@ -390,24 +407,24 @@ impl<'a> Matter<'a> {
390407
.await
391408
}
392409

393-
/// Notify that the ACLs or Fabrics _might_ have changed
394-
/// This method is supposed to be called after processing SC and IM messages that might affect the ACLs or Fabrics.
410+
/// Notify that the ACLs, Fabrics or Basic Info _might_ have changed
411+
/// This method is supposed to be called after processing SC and IM messages that might affect the ACLs, Fabrics or Basic Info.
395412
///
396413
/// The default IM and SC handlers (`DataModel` and `SecureChannel`) do call this method after processing the messages.
397414
///
398415
/// TODO: Fix the method name as it is not clear enough. Potentially revamp the whole persistence notification logic
399-
pub fn notify_fabrics_maybe_changed(&self) {
400-
if self.fabrics_changed() {
416+
pub fn notify_persist(&self) {
417+
if self.fabrics_changed() || self.basic_info_changed() {
401418
self.persist_notification.notify();
402419
}
403420
}
404421

405-
/// A hook for user persistence code to wait for potential changes in ACLs and/or Fabrics.
406-
/// Once this future resolves, user code is supposed to inspect ACLs and Fabrics for changes, and
422+
/// A hook for user persistence code to wait for potential changes in ACLs, Fabrics or basic info.
423+
/// Once this future resolves, user code is supposed to inspect ACLs, Fabrics and basic info for changes, and
407424
/// if there are changes, persist them.
408425
///
409426
/// TODO: Fix the method name as it is not clear enough. Potentially revamp the whole persistence notification logic
410-
pub async fn wait_fabrics_changed(&self) {
427+
pub async fn wait_persist(&self) {
411428
self.persist_notification.wait().await
412429
}
413430
}

0 commit comments

Comments
 (0)