Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#102, #103 #107

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/onoff_light/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unrelated, no?

.spawn(run)
.unwrap();

Expand Down Expand Up @@ -74,6 +74,7 @@ fn run() -> Result<(), Error> {
device_name: "OnOff Light",
product_name: "Light123",
vendor_name: "Vendor PQR",
unique_id: "aabbccdd",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per my analysis, this actually isn't required. We can choose to make this an Option and interpret None as "" and it will both work and be consistent with the main matter repo behaviour.

};

let (ipv4_addr, ipv6_addr, interface) = initialize_network()?;
Expand Down
9 changes: 9 additions & 0 deletions rs-matter/src/data_model/cluster_basic_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub enum Attributes {
SwVer(AttrType<u32>) = 9,
SwVerString(AttrUtfType) = 0xa,
SerialNo(AttrUtfType) = 0x0f,
UniqueId(AttrUtfType) = 0x12,
}

attribute_enum!(Attributes);
Expand All @@ -56,6 +57,7 @@ pub enum AttributesDiscriminants {
SwVer = 9,
SwVerString = 0xa,
SerialNo = 0x0f,
UniqueId = 0x12,
}

#[derive(Default)]
Expand All @@ -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 {
Expand Down Expand Up @@ -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: &[],
};
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions rs-matter/src/data_model/objects/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer clearer language like "Unsuccessful read status: " and "Unsuccessful write status: " -- otherwise it's easy to misinterpret as general info! level logging.


resp.to_tlv(tw, TagType::Anonymous)?;
}

Ok(true)
Expand All @@ -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)?;
}

Expand Down
1 change: 0 additions & 1 deletion rs-matter/src/transport/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ impl<'a> Matter<'a> {
};

if send {
dest_tx.log("Sending packet");
self.notify_changed();

return Ok(true);
Expand Down
2 changes: 2 additions & 0 deletions rs-matter/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions rs-matter/tests/common/im_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
45 changes: 29 additions & 16 deletions rs-matter/tests/data_model/long_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ use crate::{
},
};

fn wildcard_read_resp(part: u8) -> Vec<AttrResp<'static>> {
fn wildcard_read_resp(part: u8, subscription: bool) -> Vec<AttrResp<'static>> {
// 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!(
Expand Down Expand Up @@ -123,6 +123,12 @@ fn wildcard_read_resp(part: u8) -> Vec<AttrResp<'static>> {
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!(
Expand Down Expand Up @@ -201,21 +207,15 @@ fn wildcard_read_resp(part: u8) -> Vec<AttrResp<'static>> {
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!(
Expand Down Expand Up @@ -336,10 +336,23 @@ fn wildcard_read_resp(part: u8) -> Vec<AttrResp<'static>> {
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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down