Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions bloat-check/src/bin/bloat-check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ use rs_matter::dm::subscriptions::{Subscriptions, DEFAULT_MAX_SUBSCRIPTIONS};
use rs_matter::dm::{endpoints, IMBuffer};
use rs_matter::dm::{Async, DataModel, Dataver, EmptyHandler, Endpoint, EpClMatcher, Node};
use rs_matter::error::Error;
use rs_matter::pairing::qr::QrTextType;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::respond::DefaultResponder;
use rs_matter::sc::pake::MAX_COMM_WINDOW_TIMEOUT_SECS;
use rs_matter::tlv::Nullable;
use rs_matter::transport::network::btp::{
AdvData, Btp, BtpContext, GattPeripheral, GattPeripheralEvent,
Expand Down Expand Up @@ -404,14 +406,23 @@ fn main() -> ! {

info!("===================================================");

executor.run(|spawner| {
unwrap!(embassy_futures::block_on(
stack.matter.enable_basic_commissioning(
DiscoveryCapabilities::BLE,
TEST_DEV_COMM.discriminator
)
));
if !stack.matter.is_commissioned() {
// If the device is not commissioned yet, print the QR text and code to the console
// and enable basic commissioning

unwrap!(stack
.matter
.print_standard_qr_text(DiscoveryCapabilities::IP));
unwrap!(stack
.matter
.print_standard_qr_code(QrTextType::Unicode, DiscoveryCapabilities::IP));

unwrap!(stack
.matter
.open_basic_comm_window(MAX_COMM_WINDOW_TIMEOUT_SECS));
}

executor.run(|spawner| {
unwrap!(spawner.spawn(respond_task(responder)));
unwrap!(spawner.spawn(dm_task(dm)));
unwrap!(spawner.spawn(mdns_task(mdns)));
Expand Down
14 changes: 13 additions & 1 deletion examples/src/bin/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ use rs_matter::dm::{
EpClMatcher, Node, ReadContext,
};
use rs_matter::error::Error;
use rs_matter::pairing::qr::QrTextType;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::{Psm, NO_NETWORKS};
use rs_matter::respond::DefaultResponder;
use rs_matter::sc::pake::MAX_COMM_WINDOW_TIMEOUT_SECS;
use rs_matter::transport::MATTER_SOCKET_BIND_ADDR;
use rs_matter::utils::select::Coalesce;
use rs_matter::utils::storage::pooled::PooledBuffers;
Expand Down Expand Up @@ -108,14 +110,24 @@ fn main() -> Result<(), Error> {

// Run the Matter and mDNS transports
let mut mdns = pin!(mdns::run_mdns(&matter));
let mut transport = pin!(matter.run(&socket, &socket, DiscoveryCapabilities::IP));
let mut transport = pin!(matter.run(&socket, &socket));

// Create, load and run the persister
let mut psm: Psm<4096> = Psm::new();
let path = std::env::temp_dir().join("rs-matter");

psm.load(&path, &matter, NO_NETWORKS)?;

if !matter.is_commissioned() {
// If the device is not commissioned yet, print the QR text and code to the console
// and enable basic commissioning

matter.print_standard_qr_text(DiscoveryCapabilities::IP)?;
matter.print_standard_qr_code(QrTextType::Unicode, DiscoveryCapabilities::IP)?;

matter.open_basic_comm_window(MAX_COMM_WINDOW_TIMEOUT_SECS)?;
}

let mut persist = pin!(psm.run(&path, &matter, NO_NETWORKS));

// Combine all async tasks in a single one
Expand Down
41 changes: 23 additions & 18 deletions examples/src/bin/chip_tool_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use futures_lite::StreamExt;
use log::info;

use rs_matter::dm::clusters::basic_info::{
BasicInfoConfig, ColorEnum, ProductAppearance, ProductFinishEnum,
BasicInfoConfig, ColorEnum, PairingHintFlags, ProductAppearance, ProductFinishEnum,
};
use rs_matter::dm::clusters::desc::{self, ClusterHandler as _};
use rs_matter::dm::clusters::level_control::LevelControlHooks;
Expand All @@ -53,9 +53,11 @@ use rs_matter::dm::{
Node,
};
use rs_matter::error::Error;
use rs_matter::pairing::qr::QrTextType;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::{Psm, NO_NETWORKS};
use rs_matter::respond::DefaultResponder;
use rs_matter::sc::pake::MAX_COMM_WINDOW_TIMEOUT_SECS;
use rs_matter::transport::MATTER_SOCKET_BIND_ADDR;
use rs_matter::utils::cell::RefCell;
use rs_matter::utils::init::InitMaybeUninit;
Expand Down Expand Up @@ -171,26 +173,13 @@ fn main() -> Result<(), Error> {

info!(
"Transport memory: Transport fut (stack)={}B, mDNS fut (stack)={}B",
core::mem::size_of_val(&matter.run(&socket, &socket, DiscoveryCapabilities::IP)),
core::mem::size_of_val(&matter.run(&socket, &socket)),
core::mem::size_of_val(&mdns::run_mdns(matter))
);

// Run the Matter and mDNS transports
let mut mdns = pin!(mdns::run_mdns(matter));
let mut transport = pin!(async {
// Unconditionally enable basic commissioning because the `chip-tool` tests
// expect that - even if the device is already commissioned,
// as the code path always unconditionally scans for the QR code.
//
// TODO: Figure out why the test suite has this expectation and also whether
// to instead just always enable printing the QR code to the console at startup
// rather than to enable basic commissioning.
matter
.enable_basic_commissioning(DiscoveryCapabilities::IP, 0)
.await?;

matter.run_transport(&socket, &socket).await
});
let mut transport = pin!(matter.run_transport(&socket, &socket));

// Create, load and run the persister
let psm = PSM.uninit().init_with(Psm::init());
Expand All @@ -204,6 +193,19 @@ fn main() -> Result<(), Error> {

psm.load(&path, matter, NO_NETWORKS)?;

// We need to always print the QR text, because the test runner expects it to be printed
// even if the device is already commissioned
matter.print_standard_qr_text(DiscoveryCapabilities::IP)?;

if !matter.is_commissioned() {
// If the device is not commissioned yet, print the QR code to the console
// and enable basic commissioning

matter.print_standard_qr_code(QrTextType::Unicode, DiscoveryCapabilities::IP)?;

matter.open_basic_comm_window(MAX_COMM_WINDOW_TIMEOUT_SECS)?;
}

let mut persist = pin!(psm.run(&path, matter, NO_NETWORKS));

// Listen to SIGTERM because at the end of the test we'll receive it
Expand All @@ -225,13 +227,16 @@ fn main() -> Result<(), Error> {
futures_lite::future::block_on(all.coalesce())
}

/// Overriden so that we can set the product appearance to
/// what the `TestBasicInformation` tests expect.
/// Overriden so that:
/// - We can set the product appearance to what the `TestBasicInformation` tests expect;
/// - We can set the device type and pairing hint to what the `TestDiscovery` tests expect.
const BASIC_INFO: BasicInfoConfig<'static> = BasicInfoConfig {
product_appearance: ProductAppearance {
finish: ProductFinishEnum::Satin,
color: Some(ColorEnum::Purple),
},
device_type: Some(65535),
pairing_hint: PairingHintFlags::PRESS_RESET_BUTTON,
..TEST_DEV_DET
};

Expand Down
35 changes: 17 additions & 18 deletions examples/src/bin/dimmable_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ use rs_matter::dm::{
EpClMatcher, Node,
};
use rs_matter::error::{Error, ErrorCode};
use rs_matter::pairing::qr::QrTextType;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::{Psm, NO_NETWORKS};
use rs_matter::respond::DefaultResponder;
use rs_matter::sc::pake::MAX_COMM_WINDOW_TIMEOUT_SECS;
use rs_matter::tlv::Nullable;
use rs_matter::transport::MATTER_SOCKET_BIND_ADDR;
use rs_matter::utils::init::InitMaybeUninit;
Expand Down Expand Up @@ -186,29 +188,13 @@ fn run() -> Result<(), Error> {

info!(
"Transport memory: Transport fut (stack)={}B, mDNS fut (stack)={}B",
core::mem::size_of_val(&matter.run(&socket, &socket, DiscoveryCapabilities::IP)),
core::mem::size_of_val(&matter.run(&socket, &socket)),
core::mem::size_of_val(&mdns::run_mdns(matter))
);

// Run the Matter and mDNS transports
let mut mdns = pin!(mdns::run_mdns(matter));
#[cfg(not(feature = "chip-test"))]
let mut transport = pin!(matter.run(&socket, &socket, DiscoveryCapabilities::IP));
#[cfg(feature = "chip-test")]
let mut transport = pin!(async {
// Unconditionally enable basic commissioning because the `chip-tool` tests
// expect that - even if the device is already commissioned,
// as the code path always unconditionally scans for the QR code.
//
// TODO: Figure out why the test suite has this expectation and also whether
// to instead just always enable printing the QR code to the console at startup
// rather than to enable basic commissioning.
matter
.enable_basic_commissioning(DiscoveryCapabilities::IP, 0)
.await?;

matter.run_transport(&socket, &socket).await
});
let mut transport = pin!(matter.run(&socket, &socket));

// Create, load and run the persister
let psm = PSM.uninit().init_with(Psm::init());
Expand All @@ -226,6 +212,19 @@ fn run() -> Result<(), Error> {

psm.load(&path, matter, NO_NETWORKS)?;

// We need to always print the QR text, because the test runner expects it to be printed
// even if the device is already commissioned
matter.print_standard_qr_text(DiscoveryCapabilities::IP)?;

if !matter.is_commissioned() {
// If the device is not commissioned yet, print the QR code to the console
// and enable basic commissioning

matter.print_standard_qr_code(QrTextType::Unicode, DiscoveryCapabilities::IP)?;

matter.open_basic_comm_window(MAX_COMM_WINDOW_TIMEOUT_SECS)?;
}

let mut persist = pin!(psm.run(&path, matter, NO_NETWORKS));

// Listen to SIGTERM because at the end of the test we'll receive it
Expand Down
14 changes: 13 additions & 1 deletion examples/src/bin/media_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ use rs_matter::dm::{
EmptyHandler, Endpoint, EpClMatcher, InvokeContext, Node, ReadContext,
};
use rs_matter::error::{Error, ErrorCode};
use rs_matter::pairing::qr::QrTextType;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::{Psm, NO_NETWORKS};
use rs_matter::respond::DefaultResponder;
use rs_matter::sc::pake::MAX_COMM_WINDOW_TIMEOUT_SECS;
use rs_matter::tlv::{TLVBuilderParent, Utf8StrArrayBuilder, Utf8StrBuilder};
use rs_matter::transport::MATTER_SOCKET_BIND_ADDR;
use rs_matter::utils::select::Coalesce;
Expand Down Expand Up @@ -128,14 +130,24 @@ fn main() -> Result<(), Error> {

// Run the Matter and mDNS transports
let mut mdns = pin!(mdns::run_mdns(&matter));
let mut transport = pin!(matter.run(&socket, &socket, DiscoveryCapabilities::IP));
let mut transport = pin!(matter.run(&socket, &socket));

// Create, load and run the persister
let mut psm: Psm<4096> = Psm::new();
let path = std::env::temp_dir().join("rs-matter");

psm.load(&path, &matter, NO_NETWORKS)?;

if !matter.is_commissioned() {
// If the device is not commissioned yet, print the QR text and code to the console
// and enable basic commissioning

matter.print_standard_qr_text(DiscoveryCapabilities::IP)?;
matter.print_standard_qr_code(QrTextType::Unicode, DiscoveryCapabilities::IP)?;

matter.open_basic_comm_window(MAX_COMM_WINDOW_TIMEOUT_SECS)?;
}

let mut persist = pin!(psm.run(&path, &matter, NO_NETWORKS));

// Combine all async tasks in a single one
Expand Down
16 changes: 14 additions & 2 deletions examples/src/bin/onoff_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ use rs_matter::dm::{
Node,
};
use rs_matter::error::Error;
use rs_matter::pairing::qr::QrTextType;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::{Psm, NO_NETWORKS};
use rs_matter::respond::DefaultResponder;
use rs_matter::sc::pake::MAX_COMM_WINDOW_TIMEOUT_SECS;
use rs_matter::transport::MATTER_SOCKET_BIND_ADDR;
use rs_matter::utils::init::InitMaybeUninit;
use rs_matter::utils::select::Coalesce;
Expand Down Expand Up @@ -147,13 +149,13 @@ fn run() -> Result<(), Error> {

info!(
"Transport memory: Transport fut (stack)={}B, mDNS fut (stack)={}B",
core::mem::size_of_val(&matter.run(&socket, &socket, DiscoveryCapabilities::IP)),
core::mem::size_of_val(&matter.run(&socket, &socket)),
core::mem::size_of_val(&mdns::run_mdns(matter))
);

// Run the Matter and mDNS transports
let mut mdns = pin!(mdns::run_mdns(matter));
let mut transport = pin!(matter.run(&socket, &socket, DiscoveryCapabilities::IP));
let mut transport = pin!(matter.run(&socket, &socket));

// Create, load and run the persister
let psm = PSM.uninit().init_with(Psm::init());
Expand All @@ -167,6 +169,16 @@ fn run() -> Result<(), Error> {

psm.load(&path, matter, NO_NETWORKS)?;

if !matter.is_commissioned() {
// If the device is not commissioned yet, print the QR text and code to the console
// and enable basic commissioning

matter.print_standard_qr_text(DiscoveryCapabilities::IP)?;
matter.print_standard_qr_code(QrTextType::Unicode, DiscoveryCapabilities::IP)?;

matter.open_basic_comm_window(MAX_COMM_WINDOW_TIMEOUT_SECS)?;
}

let mut persist = pin!(psm.run(&path, matter, NO_NETWORKS));

// Combine all async tasks in a single one
Expand Down
12 changes: 11 additions & 1 deletion examples/src/bin/onoff_light_bt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ use rs_matter::dm::{
Node,
};
use rs_matter::error::Error;
use rs_matter::pairing::qr::QrTextType;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::Psm;
use rs_matter::respond::DefaultResponder;
use rs_matter::sc::pake::MAX_COMM_WINDOW_TIMEOUT_SECS;
use rs_matter::transport::network::btp::bluez::BluezGattPeripheral;
use rs_matter::transport::network::btp::{Btp, BtpContext};
use rs_matter::transport::network::wifi::nm::NetMgrCtl;
Expand Down Expand Up @@ -178,11 +180,19 @@ fn run<N: NetCtl + WifiDiag>(connection: &Connection, net_ctl: N) -> Result<(),
if !matter.is_commissioned() {
// Not commissioned yet, start commissioning first

// Print the QR text and code to the console
// and enable basic commissioning

matter.print_standard_qr_text(DiscoveryCapabilities::IP)?;
matter.print_standard_qr_code(QrTextType::Unicode, DiscoveryCapabilities::IP)?;

matter.open_basic_comm_window(MAX_COMM_WINDOW_TIMEOUT_SECS)?;

// The BTP transport impl
let btp = Btp::new(BluezGattPeripheral::new(None, connection), &BTP_CONTEXT);
let mut bluetooth = pin!(btp.run("MT", &TEST_DEV_DET, TEST_DEV_COMM.discriminator));

let mut transport = pin!(matter.run(&btp, &btp, DiscoveryCapabilities::BLE));
let mut transport = pin!(matter.run(&btp, &btp));
let mut wifi_prov_task = pin!(async {
NetCtlState::wait_prov_ready(&net_ctl_state, &btp).await;
Ok(())
Expand Down
14 changes: 13 additions & 1 deletion examples/src/bin/speaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ use rs_matter::dm::{
Node,
};
use rs_matter::error::Error;
use rs_matter::pairing::qr::QrTextType;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::{Psm, NO_NETWORKS};
use rs_matter::respond::DefaultResponder;
use rs_matter::sc::pake::MAX_COMM_WINDOW_TIMEOUT_SECS;
use rs_matter::tlv::Nullable;
use rs_matter::transport::MATTER_SOCKET_BIND_ADDR;
use rs_matter::utils::select::Coalesce;
Expand Down Expand Up @@ -121,14 +123,24 @@ fn main() -> Result<(), Error> {

// Run the Matter and mDNS transports
let mut mdns = pin!(mdns::run_mdns(&matter));
let mut transport = pin!(matter.run(&socket, &socket, DiscoveryCapabilities::IP));
let mut transport = pin!(matter.run(&socket, &socket));

// Create, load and run the persister
let mut psm: Psm<4096> = Psm::new();
let path = std::env::temp_dir().join("rs-matter");

psm.load(&path, &matter, NO_NETWORKS)?;

if !matter.is_commissioned() {
// If the device is not commissioned yet, print the QR text and code to the console
// and enable basic commissioning

matter.print_standard_qr_text(DiscoveryCapabilities::IP)?;
matter.print_standard_qr_code(QrTextType::Unicode, DiscoveryCapabilities::IP)?;

matter.open_basic_comm_window(MAX_COMM_WINDOW_TIMEOUT_SECS)?;
}

let mut persist = pin!(psm.run(&path, &matter, NO_NETWORKS));

// Combine all async tasks in a single one
Expand Down
2 changes: 1 addition & 1 deletion examples/src/common/mdns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async fn run_builtin_mdns(matter: &Matter<'_>) -> Result<(), Error> {
&socket,
&Host {
id: 0,
hostname: "rs-matter-demo",
hostname: "001122334455", //"rs-matter-demo",
ip: ipv4_addr,
ipv6: ipv6_addr,
},
Expand Down
Loading
Loading