Skip to main content

matter_kit/clusters/generated/
rvc_run_mode.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// RVC Run Mode — cluster 0x0054.
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//! RVC Run Mode (cluster `0x0054`, revision 4).
10//!
11//! 6 identifiers, 2 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 = 0x0054;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 4;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "RVCRUNM";
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    /// Cluster supports changing run modes from non-Idle states
46    ///
47    /// Code `DIRECTMODECH`, bit 20.
48    pub const DIRECT_MODE_CHANGE: u32 = 1 << 20;
49}
50
51/// Every feature bit, with its conformance.
52pub const FEATURES: &[Feature] = &[
53    Feature {
54        bit: 0,
55        code: "DEPONOFF",
56        name: "OnOff",
57        conform: Conform::DISALLOWED,
58    },
59    Feature {
60        bit: 20,
61        code: "DIRECTMODECH",
62        name: "DirectModeChange",
63        conform: Conform::OPTIONAL,
64    },
65];
66
67/// The attribute ids.
68pub mod attribute {
69    use crate::im::AttributeId;
70
71    /// `SupportedModes`.
72    pub const SUPPORTED_MODES: AttributeId = 0x00;
73    /// `CurrentMode`.
74    pub const CURRENT_MODE: AttributeId = 0x01;
75    /// `StartUpMode`.
76    pub const START_UP_MODE: AttributeId = 0x02;
77    /// `OnMode`.
78    pub const ON_MODE: AttributeId = 0x03;
79}
80
81/// The command ids.
82pub mod command {
83    use crate::im::CommandId;
84
85    /// `ChangeToMode`.
86    pub const CHANGE_TO_MODE: CommandId = 0x00;
87    /// `ChangeToModeResponse`.
88    pub const CHANGE_TO_MODE_RESPONSE: CommandId = 0x01;
89}
90
91/// `ModeTag`.
92#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
93#[repr(u16)]
94pub enum ModeTag {
95    /// `Auto`.
96    Auto = 0,
97    /// `Quick`.
98    Quick = 1,
99    /// `Quiet`.
100    Quiet = 2,
101    /// `LowNoise`.
102    LowNoise = 3,
103    /// `LowEnergy`.
104    LowEnergy = 4,
105    /// `Vacation`.
106    Vacation = 5,
107    /// `Min`.
108    Min = 6,
109    /// `Max`.
110    Max = 7,
111    /// `Night`.
112    Night = 8,
113    /// `Day`.
114    Day = 9,
115    /// `Idle`.
116    Idle = 16384,
117    /// `Cleaning`.
118    Cleaning = 16385,
119    /// `Mapping`.
120    Mapping = 16386,
121}
122
123impl ModeTag {
124    /// Reads a wire value, or `None` for one this revision does not define.
125    #[must_use]
126    pub const fn from_value(value: u16) -> Option<Self> {
127        match value {
128            0 => Some(Self::Auto),
129            1 => Some(Self::Quick),
130            2 => Some(Self::Quiet),
131            3 => Some(Self::LowNoise),
132            4 => Some(Self::LowEnergy),
133            5 => Some(Self::Vacation),
134            6 => Some(Self::Min),
135            7 => Some(Self::Max),
136            8 => Some(Self::Night),
137            9 => Some(Self::Day),
138            16384 => Some(Self::Idle),
139            16385 => Some(Self::Cleaning),
140            16386 => Some(Self::Mapping),
141            _ => None,
142        }
143    }
144
145    /// Its wire value.
146    #[must_use]
147    pub const fn value(self) -> u16 {
148        self as u16
149    }
150}
151
152impl ToTlv for ModeTag {
153    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
154        self.value().to_tlv(w, tag)
155    }
156}
157
158impl<'a> FromTlv<'a> for ModeTag {
159    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
160        let value = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
161        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
162    }
163}
164
165/// `StatusCodeEnum`.
166#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
167#[repr(u8)]
168pub enum StatusCodeEnum {
169    /// `Stuck`.
170    Stuck = 65,
171    /// `DustBinMissing`.
172    DustBinMissing = 66,
173    /// `DustBinFull`.
174    DustBinFull = 67,
175    /// `WaterTankEmpty`.
176    WaterTankEmpty = 68,
177    /// `WaterTankMissing`.
178    WaterTankMissing = 69,
179    /// `WaterTankLidOpen`.
180    WaterTankLidOpen = 70,
181    /// `MopCleaningPadMissing`.
182    MopCleaningPadMissing = 71,
183    /// `BatteryLow`.
184    BatteryLow = 72,
185}
186
187impl StatusCodeEnum {
188    /// Reads a wire value, or `None` for one this revision does not define.
189    #[must_use]
190    pub const fn from_value(value: u8) -> Option<Self> {
191        match value {
192            65 => Some(Self::Stuck),
193            66 => Some(Self::DustBinMissing),
194            67 => Some(Self::DustBinFull),
195            68 => Some(Self::WaterTankEmpty),
196            69 => Some(Self::WaterTankMissing),
197            70 => Some(Self::WaterTankLidOpen),
198            71 => Some(Self::MopCleaningPadMissing),
199            72 => Some(Self::BatteryLow),
200            _ => None,
201        }
202    }
203
204    /// Its wire value.
205    #[must_use]
206    pub const fn value(self) -> u8 {
207        self as u8
208    }
209}
210
211impl ToTlv for StatusCodeEnum {
212    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
213        self.value().to_tlv(w, tag)
214    }
215}
216
217impl<'a> FromTlv<'a> for StatusCodeEnum {
218    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
219        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
220        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
221    }
222}
223
224/// `ModeOptionStruct`.
225#[derive(Debug, Clone, Copy, PartialEq)]
226pub struct ModeOptionStruct<'a> {
227    /// `Label`, field 0.
228    pub label: &'a str,
229    /// `Mode`, field 1.
230    pub mode: u8,
231    /// `ModeTags`, field 2.
232    pub mode_tags: TlvList<'a, ModeTagStruct>,
233}
234
235impl<'a> ToTlv for ModeOptionStruct<'a> {
236    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
237        w.start_structure(tag)?;
238        self.label.to_tlv(w, Tag::Context(0))?;
239        self.mode.to_tlv(w, Tag::Context(1))?;
240        self.mode_tags.to_tlv(w, Tag::Context(2))?;
241        w.end_container()
242    }
243}
244
245impl<'a> FromTlv<'a> for ModeOptionStruct<'a> {
246    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
247        if element.value.container() != Some(ContainerKind::Structure) {
248            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
249        }
250        let mut label = None;
251        let mut mode = None;
252        let mut mode_tags = None;
253        loop {
254            let Some(field) = reader.next_element()? else {
255                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
256            };
257            if field.value == Value::EndOfContainer {
258                break;
259            }
260            match field.tag.context() {
261                Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
262                Some(1) => mode = Some(<u8>::from_tlv(reader, &field)?),
263                Some(2) => {
264                    mode_tags = Some(<TlvList<'a, ModeTagStruct>>::from_tlv(reader, &field)?)
265                }
266                // A field this revision does not define. §7.19.2: a receiver
267                // ignores what it does not know rather than refusing the whole
268                // structure, which is what lets a newer peer talk to an older one.
269                _ => reader.skip_value(&field)?,
270            }
271        }
272        Ok(Self {
273            label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
274            mode: mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
275            mode_tags: mode_tags.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
276        })
277    }
278}
279
280/// `ModeTagStruct`.
281#[derive(Debug, Clone, Copy, PartialEq)]
282pub struct ModeTagStruct {
283    /// `MfgCode`, field 0.
284    pub mfg_code: Option<crate::msg::VendorId>,
285    /// `Value`, field 1.
286    pub value: u16,
287}
288
289impl ToTlv for ModeTagStruct {
290    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
291        w.start_structure(tag)?;
292        if let Some(value) = &self.mfg_code {
293            value.to_tlv(w, Tag::Context(0))?;
294        }
295        self.value.to_tlv(w, Tag::Context(1))?;
296        w.end_container()
297    }
298}
299
300impl<'a> FromTlv<'a> for ModeTagStruct {
301    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
302        if element.value.container() != Some(ContainerKind::Structure) {
303            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
304        }
305        let mut mfg_code = None;
306        let mut value = None;
307        loop {
308            let Some(field) = reader.next_element()? else {
309                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
310            };
311            if field.value == Value::EndOfContainer {
312                break;
313            }
314            match field.tag.context() {
315                Some(0) => mfg_code = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
316                Some(1) => value = Some(<u16>::from_tlv(reader, &field)?),
317                // A field this revision does not define. §7.19.2: a receiver
318                // ignores what it does not know rather than refusing the whole
319                // structure, which is what lets a newer peer talk to an older one.
320                _ => reader.skip_value(&field)?,
321            }
322        }
323        Ok(Self {
324            mfg_code,
325            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
326        })
327    }
328}
329
330/// The fields of `ChangeToMode` (command `0x00`).
331#[derive(Debug, Clone, Copy, PartialEq)]
332pub struct ChangeToModeFields {
333    /// `NewMode`, field 0.
334    pub new_mode: u8,
335}
336
337impl ToTlv for ChangeToModeFields {
338    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
339        w.start_structure(tag)?;
340        self.new_mode.to_tlv(w, Tag::Context(0))?;
341        w.end_container()
342    }
343}
344
345impl<'a> FromTlv<'a> for ChangeToModeFields {
346    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
347        if element.value.container() != Some(ContainerKind::Structure) {
348            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
349        }
350        let mut new_mode = None;
351        loop {
352            let Some(field) = reader.next_element()? else {
353                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
354            };
355            if field.value == Value::EndOfContainer {
356                break;
357            }
358            match field.tag.context() {
359                Some(0) => new_mode = Some(<u8>::from_tlv(reader, &field)?),
360                // A field this revision does not define. §7.19.2: a receiver
361                // ignores what it does not know rather than refusing the whole
362                // structure, which is what lets a newer peer talk to an older one.
363                _ => reader.skip_value(&field)?,
364            }
365        }
366        Ok(Self {
367            new_mode: new_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
368        })
369    }
370}
371
372/// The fields of `ChangeToModeResponse` (command `0x01`).
373#[derive(Debug, Clone, Copy, PartialEq)]
374pub struct ChangeToModeResponseFields<'a> {
375    /// `Status`, field 0.
376    pub status: u8,
377    /// `StatusText`, field 1.
378    pub status_text: &'a str,
379}
380
381impl<'a> ToTlv for ChangeToModeResponseFields<'a> {
382    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
383        w.start_structure(tag)?;
384        self.status.to_tlv(w, Tag::Context(0))?;
385        self.status_text.to_tlv(w, Tag::Context(1))?;
386        w.end_container()
387    }
388}
389
390impl<'a> FromTlv<'a> for ChangeToModeResponseFields<'a> {
391    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
392        if element.value.container() != Some(ContainerKind::Structure) {
393            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
394        }
395        let mut status = None;
396        let mut status_text = None;
397        loop {
398            let Some(field) = reader.next_element()? else {
399                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
400            };
401            if field.value == Value::EndOfContainer {
402                break;
403            }
404            match field.tag.context() {
405                Some(0) => status = Some(<u8>::from_tlv(reader, &field)?),
406                Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
407                // A field this revision does not define. §7.19.2: a receiver
408                // ignores what it does not know rather than refusing the whole
409                // structure, which is what lets a newer peer talk to an older one.
410                _ => reader.skip_value(&field)?,
411            }
412        }
413        Ok(Self {
414            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
415            status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
416        })
417    }
418}
419
420/// Every attribute the specification defines, with its conformance.
421pub const ATTRIBUTES: &[Attribute] = &[
422    Attribute {
423        id: 0x0000,
424        name: "SupportedModes",
425        kind: "list[ModeOptionStruct]",
426        access: Access::read_only(Privilege::View),
427        qualities: AttributeQualities::empty(),
428        reporting: Reporting::OnChange,
429        conform: Conform::MANDATORY,
430    },
431    Attribute {
432        id: 0x0001,
433        name: "CurrentMode",
434        kind: "uint8",
435        access: Access::read_only(Privilege::View),
436        qualities: AttributeQualities::empty(),
437        reporting: Reporting::OnChange,
438        conform: Conform::MANDATORY,
439    },
440    Attribute {
441        id: 0x0002,
442        name: "StartUpMode",
443        kind: "uint8",
444        access: Access::read_only(Privilege::View),
445        qualities: AttributeQualities::empty(),
446        reporting: Reporting::OnChange,
447        conform: Conform::DISALLOWED,
448    },
449    Attribute {
450        id: 0x0003,
451        name: "OnMode",
452        kind: "uint8",
453        access: Access::read_only(Privilege::View),
454        qualities: AttributeQualities::empty(),
455        reporting: Reporting::OnChange,
456        conform: Conform::DISALLOWED,
457    },
458];
459
460/// Every command, with its conformance.
461pub const COMMANDS: &[Command] = &[
462    Command {
463        id: 0x00,
464        name: "ChangeToMode",
465        to_server: true,
466        response: Some(0x01),
467        access: Access::invoke(Privilege::Operate),
468        conform: Conform::MANDATORY,
469    },
470    Command {
471        id: 0x01,
472        name: "ChangeToModeResponse",
473        to_server: false,
474        response: None,
475        access: Access::invoke(Privilege::Operate),
476        conform: Conform::MANDATORY,
477    },
478];
479
480/// Every event, with its conformance.
481pub const EVENTS: &[Event] = &[];
482
483/// The whole cluster, as the specification defines it.
484pub const CLUSTER: Cluster = Cluster {
485    id: ID,
486    name: "RVC Run Mode",
487    revision: REVISION,
488    pics: "RVCRUNM",
489    derived_from: Some("Mode Base"),
490    features: FEATURES,
491    attributes: ATTRIBUTES,
492    commands: COMMANDS,
493    events: EVENTS,
494};