matter_kit/clusters/generated/
software_diagnostics.rs1#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23 ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26pub const ID: ClusterId = 0x0034;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "DGSW";
35
36pub mod feature {
41 pub const WATERMARKS: u32 = 1 << 0;
45}
46
47pub const FEATURES: &[Feature] = &[Feature {
49 bit: 0,
50 code: "WTRMRK",
51 name: "Watermarks",
52 conform: Conform::OPTIONAL,
53}];
54
55pub mod attribute {
57 use crate::im::AttributeId;
58
59 pub const THREAD_METRICS: AttributeId = 0x00;
61 pub const CURRENT_HEAP_FREE: AttributeId = 0x01;
63 pub const CURRENT_HEAP_USED: AttributeId = 0x02;
65 pub const CURRENT_HEAP_HIGH_WATERMARK: AttributeId = 0x03;
67}
68
69pub mod command {
71 use crate::im::CommandId;
72
73 pub const RESET_WATERMARKS: CommandId = 0x00;
75}
76
77pub mod event {
79 use crate::im::EventId;
80
81 pub const SOFTWARE_FAULT: EventId = 0x00;
83}
84
85#[derive(Debug, Clone, Copy, PartialEq)]
87pub struct ThreadMetricsStruct<'a> {
88 pub id: u64,
90 pub name: Option<&'a str>,
92 pub stack_free_current: Option<u32>,
94 pub stack_free_minimum: Option<u32>,
96 pub stack_size: Option<u32>,
98}
99
100impl<'a> ToTlv for ThreadMetricsStruct<'a> {
101 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
102 w.start_structure(tag)?;
103 self.id.to_tlv(w, Tag::Context(0))?;
104 if let Some(value) = &self.name {
105 value.to_tlv(w, Tag::Context(1))?;
106 }
107 if let Some(value) = &self.stack_free_current {
108 value.to_tlv(w, Tag::Context(2))?;
109 }
110 if let Some(value) = &self.stack_free_minimum {
111 value.to_tlv(w, Tag::Context(3))?;
112 }
113 if let Some(value) = &self.stack_size {
114 value.to_tlv(w, Tag::Context(4))?;
115 }
116 w.end_container()
117 }
118}
119
120impl<'a> FromTlv<'a> for ThreadMetricsStruct<'a> {
121 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
122 if element.value.container() != Some(ContainerKind::Structure) {
123 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
124 }
125 let mut id = None;
126 let mut name = None;
127 let mut stack_free_current = None;
128 let mut stack_free_minimum = None;
129 let mut stack_size = None;
130 loop {
131 let Some(field) = reader.next_element()? else {
132 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
133 };
134 if field.value == Value::EndOfContainer {
135 break;
136 }
137 match field.tag.context() {
138 Some(0) => id = Some(<u64>::from_tlv(reader, &field)?),
139 Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
140 Some(2) => stack_free_current = Some(<u32>::from_tlv(reader, &field)?),
141 Some(3) => stack_free_minimum = Some(<u32>::from_tlv(reader, &field)?),
142 Some(4) => stack_size = Some(<u32>::from_tlv(reader, &field)?),
143 _ => reader.skip_value(&field)?,
147 }
148 }
149 Ok(Self {
150 id: id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
151 name,
152 stack_free_current,
153 stack_free_minimum,
154 stack_size,
155 })
156 }
157}
158
159pub const ATTRIBUTES: &[Attribute] = &[
161 Attribute {
162 id: 0x0000,
163 name: "ThreadMetrics",
164 kind: "list[ThreadMetricsStruct]",
165 access: Access::read_only(Privilege::View),
166 qualities: AttributeQualities::empty(),
167 reporting: Reporting::ChangesOmitted,
168 conform: Conform::OPTIONAL,
169 },
170 Attribute {
171 id: 0x0001,
172 name: "CurrentHeapFree",
173 kind: "uint64",
174 access: Access::read_only(Privilege::View),
175 qualities: AttributeQualities::empty(),
176 reporting: Reporting::ChangesOmitted,
177 conform: Conform::OPTIONAL,
178 },
179 Attribute {
180 id: 0x0002,
181 name: "CurrentHeapUsed",
182 kind: "uint64",
183 access: Access::read_only(Privilege::View),
184 qualities: AttributeQualities::empty(),
185 reporting: Reporting::ChangesOmitted,
186 conform: Conform::OPTIONAL,
187 },
188 Attribute {
189 id: 0x0003,
190 name: "CurrentHeapHighWatermark",
191 kind: "uint64",
192 access: Access::read_only(Privilege::View),
193 qualities: AttributeQualities::empty(),
194 reporting: Reporting::ChangesOmitted,
195 conform: Conform {
196 clauses: &[Clause {
197 verdict: Conformance::Mandatory,
198 when: Condition::Feature(0),
199 }],
200 },
201 },
202];
203
204pub const COMMANDS: &[Command] = &[Command {
206 id: 0x00,
207 name: "ResetWatermarks",
208 to_server: true,
209 response: None,
210 access: Access::invoke(Privilege::Manage),
211 conform: Conform {
212 clauses: &[Clause {
213 verdict: Conformance::Mandatory,
214 when: Condition::Feature(0),
215 }],
216 },
217}];
218
219pub const EVENTS: &[Event] = &[Event {
221 id: 0x00,
222 name: "SoftwareFault",
223 priority: EventPriority::Info,
224 access: Access::read_only(Privilege::View),
225 conform: Conform::OPTIONAL,
226}];
227
228pub const CLUSTER: Cluster = Cluster {
230 id: ID,
231 name: "Software Diagnostics",
232 revision: REVISION,
233 pics: "DGSW",
234 derived_from: None,
235 features: FEATURES,
236 attributes: ATTRIBUTES,
237 commands: COMMANDS,
238 events: EVENTS,
239};