Skip to content

Commit

Permalink
Merge pull request #210 from ivmarkov/basic-comm-window
Browse files Browse the repository at this point in the history
Compatibility with C++ E2E tests continued: Implement the Open Basic Commissioning Window CMD
  • Loading branch information
kedars authored Sep 26, 2024
2 parents ec62ca9 + b0d6d04 commit 5b349c6
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 327 deletions.
46 changes: 17 additions & 29 deletions examples/onoff_light/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use embassy_time::{Duration, Timer};
use log::info;

use rs_matter::core::{CommissioningData, Matter};
use rs_matter::core::{BasicCommData, Matter, MATTER_PORT};
use rs_matter::data_model::cluster_basic_information::BasicInfoConfig;
use rs_matter::data_model::cluster_on_off;
use rs_matter::data_model::core::IMBuffer;
Expand All @@ -36,21 +36,21 @@ use rs_matter::data_model::subscriptions::Subscriptions;
use rs_matter::data_model::system_model::descriptor;
use rs_matter::error::Error;
use rs_matter::mdns::MdnsService;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::Psm;
use rs_matter::respond::DefaultResponder;
use rs_matter::secure_channel::spake2p::VerifierData;
use rs_matter::transport::core::MATTER_SOCKET_BIND_ADDR;
use rs_matter::utils::init::InitMaybeUninit;
use rs_matter::utils::select::Coalesce;
use rs_matter::utils::storage::pooled::PooledBuffers;
use rs_matter::MATTER_PORT;

use static_cell::StaticCell;

mod dev_att;

static DEV_DET: BasicInfoConfig = BasicInfoConfig {
vid: 0xFFF1,
pid: 0x8000,
pid: 0x8001,
hw_ver: 2,
sw_ver: 1,
sw_ver_str: "1",
Expand All @@ -60,6 +60,11 @@ static DEV_DET: BasicInfoConfig = BasicInfoConfig {
vendor_name: "Vendor PQR",
};

static DEV_COMM: BasicCommData = BasicCommData {
password: 20202021,
discriminator: 3840,
};

static DEV_ATT: dev_att::HardCodedDevAtt = dev_att::HardCodedDevAtt::new();

static MATTER: StaticCell<Matter> = StaticCell::new();
Expand Down Expand Up @@ -100,6 +105,7 @@ fn run() -> Result<(), Error> {

let matter = MATTER.uninit().init_with(Matter::init(
&DEV_DET,
DEV_COMM,
&DEV_ATT,
// NOTE:
// For `no_std` environments, provide your own epoch and rand functions here
Expand Down Expand Up @@ -159,35 +165,13 @@ fn run() -> Result<(), Error> {
// Run the Matter and mDNS transports
info!(
"Transport memory: Transport fut (stack)={}B, mDNS fut (stack)={}B",
core::mem::size_of_val(&matter.run(
&socket,
&socket,
Some((
CommissioningData {
// TODO: Hard-coded for now
verifier: VerifierData::new_with_pw(123456, matter.rand()),
discriminator: 250,
},
Default::default(),
)),
)),
core::mem::size_of_val(&matter.run(&socket, &socket, DiscoveryCapabilities::IP)),
core::mem::size_of_val(&run_mdns(&matter))
);

let mut mdns = pin!(run_mdns(&matter));

let mut transport = pin!(matter.run(
&socket,
&socket,
Some((
CommissioningData {
// TODO: Hard-coded for now
verifier: VerifierData::new_with_pw(123456, matter.rand()),
discriminator: 250,
},
Default::default(),
)),
));
let mut transport = pin!(matter.run(&socket, &socket, DiscoveryCapabilities::IP));

// NOTE:
// Replace with your own persister for e.g. `no_std` environments
Expand All @@ -199,7 +183,11 @@ fn run() -> Result<(), Error> {
core::mem::size_of_val(&psm.run(std::env::temp_dir().join("rs-matter"), &matter))
);

let mut persist = pin!(psm.run(std::env::temp_dir().join("rs-matter"), &matter));
let dir = std::env::temp_dir().join("rs-matter");

psm.load(&dir, &matter)?;

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

// Combine all async tasks in a single one
let all = select4(
Expand Down
31 changes: 17 additions & 14 deletions examples/onoff_light_bt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use embassy_time::{Duration, Timer};
use log::{info, warn};

use rs_matter::core::{CommissioningData, Matter};
use rs_matter::core::{BasicCommData, Matter};
use rs_matter::data_model::cluster_basic_information::BasicInfoConfig;
use rs_matter::data_model::cluster_on_off;
use rs_matter::data_model::core::IMBuffer;
Expand All @@ -59,7 +59,6 @@ use rs_matter::mdns::MdnsService;
use rs_matter::pairing::DiscoveryCapabilities;
use rs_matter::persist::Psm;
use rs_matter::respond::DefaultResponder;
use rs_matter::secure_channel::spake2p::VerifierData;
use rs_matter::transport::core::MATTER_SOCKET_BIND_ADDR;
use rs_matter::transport::network::btp::{Btp, BtpContext};
use rs_matter::utils::select::Coalesce;
Expand Down Expand Up @@ -113,10 +112,16 @@ fn run() -> Result<(), Error> {
vendor_name: "Vendor PQR",
};

let dev_comm = BasicCommData {
password: 20202021,
discriminator: 3840,
};

let dev_att = dev_att::HardCodedDevAtt::new();

let matter = Matter::new(
&dev_det,
dev_comm,
&dev_att,
// NOTE:
// For `no_std` environments, provide your own epoch and rand functions here
Expand All @@ -126,14 +131,6 @@ fn run() -> Result<(), Error> {
MATTER_PORT,
);

let dev_comm = CommissioningData {
// TODO: Hard-coded for now
verifier: VerifierData::new_with_pw(123456, matter.rand()),
discriminator: 250,
};

let discovery_caps = DiscoveryCapabilities::new(false, true, false);

matter.initialize_transport_buffers()?;

info!("Matter initialized");
Expand Down Expand Up @@ -181,16 +178,22 @@ fn run() -> Result<(), Error> {

// NOTE:
// Replace with your own persister for e.g. `no_std` environments

let mut psm: Psm<4096> = Psm::new();
let mut persist = pin!(psm.run(std::env::temp_dir().join("rs-matter"), &matter));

let dir = std::env::temp_dir().join("rs-matter");

psm.load(&dir, &matter)?;

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

if !matter.is_commissioned() {
// Not commissioned yet, start commissioning first

let btp = Btp::new_builtin(&BTP_CONTEXT);
let mut bluetooth = pin!(btp.run("MT", &dev_det, &dev_comm));
let mut bluetooth = pin!(btp.run("MT", &dev_det, dev_comm.discriminator));

let mut transport = pin!(matter.run(&btp, &btp, Some((dev_comm, discovery_caps))));
let mut transport = pin!(matter.run(&btp, &btp, DiscoveryCapabilities::BLE));

let mut wifi_complete_task = pin!(async {
wifi_complete.wait().await;
Expand Down Expand Up @@ -223,7 +226,7 @@ fn run() -> Result<(), Error> {
let udp = async_io::Async::<UdpSocket>::bind(MATTER_SOCKET_BIND_ADDR)?;

// Run the Matter transport
let mut transport = pin!(matter.run(&udp, &udp, None));
let mut transport = pin!(matter.run_transport(&udp, &udp));

// Combine all async tasks in a single one
let all = select4(
Expand Down
Loading

0 comments on commit 5b349c6

Please sign in to comment.