Skip to main content

matter_kit/clusters/generated/
alarm_base.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Alarm Base — cluster 0xFFFF0001.
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//! Alarm Base (cluster `0xFFFF0001`, 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 = 0xFFFF0001;
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 = "ALARM";
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    /// Supports the ability to reset alarms
42    ///
43    /// Code `RESET`, bit 0.
44    pub const RESET: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "RESET",
51    name: "Reset",
52    conform: Conform::OPTIONAL,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `Mask`.
60    pub const MASK: AttributeId = 0x00;
61    /// `Latch`.
62    pub const LATCH: AttributeId = 0x01;
63    /// `State`.
64    pub const STATE: AttributeId = 0x02;
65    /// `Supported`.
66    pub const SUPPORTED: AttributeId = 0x03;
67}
68
69/// The command ids.
70pub mod command {
71    use crate::im::CommandId;
72
73    /// `Reset`.
74    pub const RESET: CommandId = 0x00;
75    /// `ModifyEnabledAlarms`.
76    pub const MODIFY_ENABLED_ALARMS: CommandId = 0x01;
77}
78
79/// The event ids.
80pub mod event {
81    use crate::im::EventId;
82
83    /// `Notify`.
84    pub const NOTIFY: EventId = 0x00;
85}
86
87bitflags::bitflags! {
88    /// `AlarmBitmap`.
89    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
90    pub struct AlarmBitmap: u8 {
91    }
92}
93
94impl ToTlv for AlarmBitmap {
95    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
96        self.bits().to_tlv(w, tag)
97    }
98}
99
100impl<'a> FromTlv<'a> for AlarmBitmap {
101    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
102        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
103        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
104    }
105}
106
107/// The fields of `Reset` (command `0x00`).
108#[derive(Debug, Clone, Copy, PartialEq)]
109pub struct ResetFields {
110    /// `Alarms`, field 0.
111    pub alarms: AlarmBitmap,
112}
113
114impl ToTlv for ResetFields {
115    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
116        w.start_structure(tag)?;
117        self.alarms.to_tlv(w, Tag::Context(0))?;
118        w.end_container()
119    }
120}
121
122impl<'a> FromTlv<'a> for ResetFields {
123    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
124        if element.value.container() != Some(ContainerKind::Structure) {
125            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
126        }
127        let mut alarms = None;
128        loop {
129            let Some(field) = reader.next_element()? else {
130                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
131            };
132            if field.value == Value::EndOfContainer {
133                break;
134            }
135            match field.tag.context() {
136                Some(0) => alarms = Some(<AlarmBitmap>::from_tlv(reader, &field)?),
137                // A field this revision does not define. §7.19.2: a receiver
138                // ignores what it does not know rather than refusing the whole
139                // structure, which is what lets a newer peer talk to an older one.
140                _ => reader.skip_value(&field)?,
141            }
142        }
143        Ok(Self {
144            alarms: alarms.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
145        })
146    }
147}
148
149/// The fields of `ModifyEnabledAlarms` (command `0x01`).
150#[derive(Debug, Clone, Copy, PartialEq)]
151pub struct ModifyEnabledAlarmsFields {
152    /// `Mask`, field 0.
153    pub mask: AlarmBitmap,
154}
155
156impl ToTlv for ModifyEnabledAlarmsFields {
157    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
158        w.start_structure(tag)?;
159        self.mask.to_tlv(w, Tag::Context(0))?;
160        w.end_container()
161    }
162}
163
164impl<'a> FromTlv<'a> for ModifyEnabledAlarmsFields {
165    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
166        if element.value.container() != Some(ContainerKind::Structure) {
167            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
168        }
169        let mut mask = None;
170        loop {
171            let Some(field) = reader.next_element()? else {
172                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
173            };
174            if field.value == Value::EndOfContainer {
175                break;
176            }
177            match field.tag.context() {
178                Some(0) => mask = Some(<AlarmBitmap>::from_tlv(reader, &field)?),
179                // A field this revision does not define. §7.19.2: a receiver
180                // ignores what it does not know rather than refusing the whole
181                // structure, which is what lets a newer peer talk to an older one.
182                _ => reader.skip_value(&field)?,
183            }
184        }
185        Ok(Self {
186            mask: mask.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
187        })
188    }
189}