Skip to main content

matter_kit/clusters/generated/
mode_select.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Mode Select — cluster 0x0050.
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//! Mode Select (cluster `0x0050`, revision 2).
10//!
11//! 7 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 = 0x0050;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 2;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "MOD";
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    /// Dependency with the OnOff cluster
42    ///
43    /// Code `DEPONOFF`, bit 0.
44    pub const ON_OFF: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "DEPONOFF",
51    name: "OnOff",
52    conform: Conform::OPTIONAL,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `Description`.
60    pub const DESCRIPTION: AttributeId = 0x00;
61    /// `StandardNamespace`.
62    pub const STANDARD_NAMESPACE: AttributeId = 0x01;
63    /// `SupportedModes`.
64    pub const SUPPORTED_MODES: AttributeId = 0x02;
65    /// `CurrentMode`.
66    pub const CURRENT_MODE: AttributeId = 0x03;
67    /// `StartUpMode`.
68    pub const START_UP_MODE: AttributeId = 0x04;
69    /// `OnMode`.
70    pub const ON_MODE: AttributeId = 0x05;
71}
72
73/// The command ids.
74pub mod command {
75    use crate::im::CommandId;
76
77    /// `ChangeToMode`.
78    pub const CHANGE_TO_MODE: CommandId = 0x00;
79}
80
81/// `ModeOptionStruct`.
82#[derive(Debug, Clone, Copy, PartialEq)]
83pub struct ModeOptionStruct<'a> {
84    /// `Label`, field 0.
85    pub label: &'a str,
86    /// `Mode`, field 1.
87    pub mode: u8,
88    /// `SemanticTags`, field 2.
89    pub semantic_tags: TlvList<'a, SemanticTagStruct>,
90}
91
92impl<'a> ToTlv for ModeOptionStruct<'a> {
93    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
94        w.start_structure(tag)?;
95        self.label.to_tlv(w, Tag::Context(0))?;
96        self.mode.to_tlv(w, Tag::Context(1))?;
97        self.semantic_tags.to_tlv(w, Tag::Context(2))?;
98        w.end_container()
99    }
100}
101
102impl<'a> FromTlv<'a> for ModeOptionStruct<'a> {
103    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
104        if element.value.container() != Some(ContainerKind::Structure) {
105            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
106        }
107        let mut label = None;
108        let mut mode = None;
109        let mut semantic_tags = None;
110        loop {
111            let Some(field) = reader.next_element()? else {
112                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
113            };
114            if field.value == Value::EndOfContainer {
115                break;
116            }
117            match field.tag.context() {
118                Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
119                Some(1) => mode = Some(<u8>::from_tlv(reader, &field)?),
120                Some(2) => {
121                    semantic_tags =
122                        Some(<TlvList<'a, SemanticTagStruct>>::from_tlv(reader, &field)?)
123                }
124                // A field this revision does not define. §7.19.2: a receiver
125                // ignores what it does not know rather than refusing the whole
126                // structure, which is what lets a newer peer talk to an older one.
127                _ => reader.skip_value(&field)?,
128            }
129        }
130        Ok(Self {
131            label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
132            mode: mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
133            semantic_tags: semantic_tags.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
134        })
135    }
136}
137
138/// `SemanticTagStruct`.
139#[derive(Debug, Clone, Copy, PartialEq)]
140pub struct SemanticTagStruct {
141    /// `MfgCode`, field 0.
142    pub mfg_code: crate::msg::VendorId,
143    /// `Value`, field 1.
144    pub value: u16,
145}
146
147impl ToTlv for SemanticTagStruct {
148    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
149        w.start_structure(tag)?;
150        self.mfg_code.to_tlv(w, Tag::Context(0))?;
151        self.value.to_tlv(w, Tag::Context(1))?;
152        w.end_container()
153    }
154}
155
156impl<'a> FromTlv<'a> for SemanticTagStruct {
157    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
158        if element.value.container() != Some(ContainerKind::Structure) {
159            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
160        }
161        let mut mfg_code = None;
162        let mut value = None;
163        loop {
164            let Some(field) = reader.next_element()? else {
165                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
166            };
167            if field.value == Value::EndOfContainer {
168                break;
169            }
170            match field.tag.context() {
171                Some(0) => mfg_code = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
172                Some(1) => value = Some(<u16>::from_tlv(reader, &field)?),
173                // A field this revision does not define. §7.19.2: a receiver
174                // ignores what it does not know rather than refusing the whole
175                // structure, which is what lets a newer peer talk to an older one.
176                _ => reader.skip_value(&field)?,
177            }
178        }
179        Ok(Self {
180            mfg_code: mfg_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
181            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
182        })
183    }
184}
185
186/// The fields of `ChangeToMode` (command `0x00`).
187#[derive(Debug, Clone, Copy, PartialEq)]
188pub struct ChangeToModeFields {
189    /// `NewMode`, field 0.
190    pub new_mode: u8,
191}
192
193impl ToTlv for ChangeToModeFields {
194    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
195        w.start_structure(tag)?;
196        self.new_mode.to_tlv(w, Tag::Context(0))?;
197        w.end_container()
198    }
199}
200
201impl<'a> FromTlv<'a> for ChangeToModeFields {
202    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
203        if element.value.container() != Some(ContainerKind::Structure) {
204            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
205        }
206        let mut new_mode = None;
207        loop {
208            let Some(field) = reader.next_element()? else {
209                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
210            };
211            if field.value == Value::EndOfContainer {
212                break;
213            }
214            match field.tag.context() {
215                Some(0) => new_mode = Some(<u8>::from_tlv(reader, &field)?),
216                // A field this revision does not define. §7.19.2: a receiver
217                // ignores what it does not know rather than refusing the whole
218                // structure, which is what lets a newer peer talk to an older one.
219                _ => reader.skip_value(&field)?,
220            }
221        }
222        Ok(Self {
223            new_mode: new_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
224        })
225    }
226}
227
228/// Every attribute the specification defines, with its conformance.
229pub const ATTRIBUTES: &[Attribute] = &[
230    Attribute {
231        id: 0x0000,
232        name: "Description",
233        kind: "string",
234        access: Access::read_only(Privilege::View),
235        qualities: AttributeQualities::FIXED,
236        reporting: Reporting::OnChange,
237        conform: Conform::MANDATORY,
238    },
239    Attribute {
240        id: 0x0001,
241        name: "StandardNamespace",
242        kind: "enum16",
243        access: Access::read_only(Privilege::View),
244        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::FIXED),
245        reporting: Reporting::OnChange,
246        conform: Conform::MANDATORY,
247    },
248    Attribute {
249        id: 0x0002,
250        name: "SupportedModes",
251        kind: "list[ModeOptionStruct]",
252        access: Access::read_only(Privilege::View),
253        qualities: AttributeQualities::FIXED,
254        reporting: Reporting::OnChange,
255        conform: Conform::MANDATORY,
256    },
257    Attribute {
258        id: 0x0003,
259        name: "CurrentMode",
260        kind: "uint8",
261        access: Access::read_only(Privilege::View),
262        qualities: AttributeQualities::NON_VOLATILE,
263        reporting: Reporting::OnChange,
264        conform: Conform::MANDATORY,
265    },
266    Attribute {
267        id: 0x0004,
268        name: "StartUpMode",
269        kind: "uint8",
270        access: Access::read_write_with(Privilege::View, Privilege::Operate),
271        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
272        reporting: Reporting::OnChange,
273        conform: Conform::OPTIONAL,
274    },
275    Attribute {
276        id: 0x0005,
277        name: "OnMode",
278        kind: "uint8",
279        access: Access::read_write_with(Privilege::View, Privilege::Operate),
280        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
281        reporting: Reporting::OnChange,
282        conform: Conform {
283            clauses: &[Clause {
284                verdict: Conformance::Mandatory,
285                when: Condition::Feature(0),
286            }],
287        },
288    },
289];
290
291/// Every command, with its conformance.
292pub const COMMANDS: &[Command] = &[Command {
293    id: 0x00,
294    name: "ChangeToMode",
295    to_server: true,
296    response: None,
297    access: Access::invoke(Privilege::Operate),
298    conform: Conform::MANDATORY,
299}];
300
301/// Every event, with its conformance.
302pub const EVENTS: &[Event] = &[];
303
304/// The whole cluster, as the specification defines it.
305pub const CLUSTER: Cluster = Cluster {
306    id: ID,
307    name: "Mode Select",
308    revision: REVISION,
309    pics: "MOD",
310    derived_from: None,
311    features: FEATURES,
312    attributes: ATTRIBUTES,
313    commands: COMMANDS,
314    events: EVENTS,
315};