From 3c1f05c52301f2f28780e2518636b630d8fa3b7d Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Mon, 2 Oct 2023 11:00:07 +0000 Subject: [PATCH 1/2] #102, #103 --- examples/onoff_light/src/main.rs | 3 ++- rs-matter/src/data_model/cluster_basic_information.rs | 9 +++++++++ rs-matter/src/data_model/objects/encoder.rs | 8 ++++++-- rs-matter/src/transport/core.rs | 1 - rs-matter/src/transport/session.rs | 2 ++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/onoff_light/src/main.rs b/examples/onoff_light/src/main.rs index ad72cbd7..11fc6c6e 100644 --- a/examples/onoff_light/src/main.rs +++ b/examples/onoff_light/src/main.rs @@ -39,7 +39,7 @@ mod dev_att; #[cfg(feature = "std")] fn main() -> Result<(), Error> { let thread = std::thread::Builder::new() - .stack_size(160 * 1024) + .stack_size(180 * 1024) .spawn(run) .unwrap(); @@ -74,6 +74,7 @@ fn run() -> Result<(), Error> { device_name: "OnOff Light", product_name: "Light123", vendor_name: "Vendor PQR", + unique_id: "aabbccdd", }; let (ipv4_addr, ipv6_addr, interface) = initialize_network()?; diff --git a/rs-matter/src/data_model/cluster_basic_information.rs b/rs-matter/src/data_model/cluster_basic_information.rs index ee6279f7..b9e061dc 100644 --- a/rs-matter/src/data_model/cluster_basic_information.rs +++ b/rs-matter/src/data_model/cluster_basic_information.rs @@ -41,6 +41,7 @@ pub enum Attributes { SwVer(AttrType) = 9, SwVerString(AttrUtfType) = 0xa, SerialNo(AttrUtfType) = 0x0f, + UniqueId(AttrUtfType) = 0x12, } attribute_enum!(Attributes); @@ -56,6 +57,7 @@ pub enum AttributesDiscriminants { SwVer = 9, SwVerString = 0xa, SerialNo = 0x0f, + UniqueId = 0x12, } #[derive(Default)] @@ -70,6 +72,7 @@ pub struct BasicInfoConfig<'a> { pub device_name: &'a str, pub vendor_name: &'a str, pub product_name: &'a str, + pub unique_id: &'a str, } pub const CLUSTER: Cluster<'static> = Cluster { @@ -128,6 +131,11 @@ pub const CLUSTER: Cluster<'static> = Cluster { Access::RV, Quality::FIXED, ), + Attribute::new( + AttributesDiscriminants::UniqueId as u16, + Access::RV, + Quality::FIXED, + ), ], commands: &[], }; @@ -166,6 +174,7 @@ impl<'a> BasicInfoCluster<'a> { Attributes::SwVer(codec) => codec.encode(writer, self.cfg.sw_ver), Attributes::SwVerString(codec) => codec.encode(writer, self.cfg.sw_ver_str), Attributes::SerialNo(codec) => codec.encode(writer, self.cfg.serial_no), + Attributes::UniqueId(codec) => codec.encode(writer, self.cfg.unique_id), } } } else { diff --git a/rs-matter/src/data_model/objects/encoder.rs b/rs-matter/src/data_model/objects/encoder.rs index e24c1a00..d2d4878b 100644 --- a/rs-matter/src/data_model/objects/encoder.rs +++ b/rs-matter/src/data_model/objects/encoder.rs @@ -30,7 +30,7 @@ use crate::{ interaction_model::messages::ib::{AttrDataTag, AttrRespTag}, tlv::{FromTLV, TLVElement, TLVWriter, TagType, ToTLV}, }; -use log::error; +use log::{error, warn}; use super::{AttrDetails, CmdDetails, DataModelHandler}; @@ -149,7 +149,10 @@ impl<'a, 'b, 'c> AttrDataEncoder<'a, 'b, 'c> { }; if let Some(status) = status { - AttrResp::Status(status).to_tlv(tw, TagType::Anonymous)?; + let resp = AttrResp::Status(status); + warn!("Read status: {:?}", resp); + + resp.to_tlv(tw, TagType::Anonymous)?; } Ok(true) @@ -172,6 +175,7 @@ impl<'a, 'b, 'c> AttrDataEncoder<'a, 'b, 'c> { }; if let Some(status) = status { + warn!("Write status: {:?}", status); status.to_tlv(tw, TagType::Anonymous)?; } diff --git a/rs-matter/src/transport/core.rs b/rs-matter/src/transport/core.rs index dccf5cb7..d60724f7 100644 --- a/rs-matter/src/transport/core.rs +++ b/rs-matter/src/transport/core.rs @@ -694,7 +694,6 @@ impl<'a> Matter<'a> { }; if send { - dest_tx.log("Sending packet"); self.notify_changed(); return Ok(true); diff --git a/rs-matter/src/transport/session.rs b/rs-matter/src/transport/session.rs index b25631f6..f0e43245 100644 --- a/rs-matter/src/transport/session.rs +++ b/rs-matter/src/transport/session.rs @@ -263,6 +263,8 @@ impl Session { pub(crate) fn send(&mut self, epoch: Epoch, tx: &mut Packet) -> Result<(), Error> { self.last_use = epoch(); + tx.log("About to send packet"); + tx.proto_encode( self.peer_addr, self.peer_nodeid, From fbc90fc00a6ccaf2afdb54b2309fc699182e63b9 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Mon, 2 Oct 2023 11:26:07 +0000 Subject: [PATCH 2/2] Fix tests --- rs-matter/tests/common/im_engine.rs | 1 + rs-matter/tests/data_model/long_reads.rs | 45 +++++++++++++++--------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/rs-matter/tests/common/im_engine.rs b/rs-matter/tests/common/im_engine.rs index 02e7847c..9c758063 100644 --- a/rs-matter/tests/common/im_engine.rs +++ b/rs-matter/tests/common/im_engine.rs @@ -72,6 +72,7 @@ const BASIC_INFO: BasicInfoConfig<'static> = BasicInfoConfig { device_name: "Test Device", product_name: "TestProd", vendor_name: "TestVendor", + unique_id: "aabbccdd", }; struct DummyDevAtt; diff --git a/rs-matter/tests/data_model/long_reads.rs b/rs-matter/tests/data_model/long_reads.rs index 333801c4..9fc85f4e 100644 --- a/rs-matter/tests/data_model/long_reads.rs +++ b/rs-matter/tests/data_model/long_reads.rs @@ -46,10 +46,10 @@ use crate::{ }, }; -fn wildcard_read_resp(part: u8) -> Vec> { +fn wildcard_read_resp(part: u8, subscription: bool) -> Vec> { // For brevity, we only check the AttrPath, not the actual 'data' let dont_care = ElementType::U8(0); - let part1 = vec![ + let mut part1 = vec![ attr_data!(0, 29, GlobalElements::FeatureMap, dont_care.clone()), attr_data!(0, 29, GlobalElements::AttributeList, dont_care.clone()), attr_data!( @@ -123,6 +123,12 @@ fn wildcard_read_resp(part: u8) -> Vec> { basic_info::AttributesDiscriminants::SerialNo, dont_care.clone() ), + attr_data!( + 0, + 40, + basic_info::AttributesDiscriminants::UniqueId, + dont_care.clone() + ), attr_data!(0, 48, GlobalElements::FeatureMap, dont_care.clone()), attr_data!(0, 48, GlobalElements::AttributeList, dont_care.clone()), attr_data!( @@ -201,21 +207,15 @@ fn wildcard_read_resp(part: u8) -> Vec> { adm_comm::AttributesDiscriminants::WindowStatus, dont_care.clone() ), - attr_data!( - 0, - 60, - adm_comm::AttributesDiscriminants::AdminFabricIndex, - dont_care.clone() - ), + ]; + + let mut part2 = vec![ attr_data!( 0, 60, adm_comm::AttributesDiscriminants::AdminVendorId, dont_care.clone() ), - ]; - - let part2 = vec![ attr_data!(0, 62, GlobalElements::FeatureMap, dont_care.clone()), attr_data!(0, 62, GlobalElements::AttributeList, dont_care.clone()), attr_data!( @@ -336,10 +336,23 @@ fn wildcard_read_resp(part: u8) -> Vec> { 1, echo::ID, echo::AttributesDiscriminants::AttCustom, - dont_care + dont_care.clone() ), ]; + let attr_data = attr_data!( + 0, + 60, + adm_comm::AttributesDiscriminants::AdminFabricIndex, + dont_care + ); + + if subscription { + part2.insert(0, attr_data); + } else { + part1.push(attr_data); + } + if part == 1 { part1 } else { @@ -362,12 +375,12 @@ fn test_long_read_success() { let read_all = [AttrPath::new(&wc_path)]; let read_req = ReadReq::new(true).set_attr_requests(&read_all); - let expected_part1 = wildcard_read_resp(1); + let expected_part1 = wildcard_read_resp(1, false); let status_report = StatusResp { status: IMStatusCode::Success, }; - let expected_part2 = wildcard_read_resp(2); + let expected_part2 = wildcard_read_resp(2, false); im.process( &handler, @@ -411,12 +424,12 @@ fn test_long_read_subscription_success() { let read_all = [AttrPath::new(&wc_path)]; let subs_req = SubscribeReq::new(true, 1, 20).set_attr_requests(&read_all); - let expected_part1 = wildcard_read_resp(1); + let expected_part1 = wildcard_read_resp(1, true); let status_report = StatusResp { status: IMStatusCode::Success, }; - let expected_part2 = wildcard_read_resp(2); + let expected_part2 = wildcard_read_resp(2, true); im.process( &handler,