Skip to main content

matter_kit/clusters/generated/
software_diagnostics.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Software Diagnostics — cluster 0x0034.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Software Diagnostics (cluster `0x0034`, revision 1).
10//!
11//! 6 identifiers, 1 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![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
26/// The cluster id.
27pub const ID: ClusterId = 0x0034;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "DGSW";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Node makes available the metrics for high watermark related to memory consumption.
42    ///
43    /// Code `WTRMRK`, bit 0.
44    pub const WATERMARKS: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "WTRMRK",
51    name: "Watermarks",
52    conform: Conform::OPTIONAL,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `ThreadMetrics`.
60    pub const THREAD_METRICS: AttributeId = 0x00;
61    /// `CurrentHeapFree`.
62    pub const CURRENT_HEAP_FREE: AttributeId = 0x01;
63    /// `CurrentHeapUsed`.
64    pub const CURRENT_HEAP_USED: AttributeId = 0x02;
65    /// `CurrentHeapHighWatermark`.
66    pub const CURRENT_HEAP_HIGH_WATERMARK: AttributeId = 0x03;
67}
68
69/// The command ids.
70pub mod command {
71    use crate::im::CommandId;
72
73    /// `ResetWatermarks`.
74    pub const RESET_WATERMARKS: CommandId = 0x00;
75}
76
77/// The event ids.
78pub mod event {
79    use crate::im::EventId;
80
81    /// `SoftwareFault`.
82    pub const SOFTWARE_FAULT: EventId = 0x00;
83}
84
85/// `ThreadMetricsStruct`.
86#[derive(Debug, Clone, Copy, PartialEq)]
87pub struct ThreadMetricsStruct<'a> {
88    /// `ID`, field 0.
89    pub id: u64,
90    /// `Name`, field 1.
91    pub name: Option<&'a str>,
92    /// `StackFreeCurrent`, field 2.
93    pub stack_free_current: Option<u32>,
94    /// `StackFreeMinimum`, field 3.
95    pub stack_free_minimum: Option<u32>,
96    /// `StackSize`, field 4.
97    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                // A field this revision does not define. §7.19.2: a receiver
144                // ignores what it does not know rather than refusing the whole
145                // structure, which is what lets a newer peer talk to an older one.
146                _ => 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
159/// Every attribute the specification defines, with its conformance.
160pub 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
204/// Every command, with its conformance.
205pub 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
219/// Every event, with its conformance.
220pub 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
228/// The whole cluster, as the specification defines it.
229pub 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};