Skip to main content

matter_kit/clusters/generated/
application_basic.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Application Basic — cluster 0x050D.
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//! Application Basic (cluster `0x050D`, revision 1).
10//!
11//! 8 identifiers, 0 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 = 0x050D;
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 = "APBSC";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `VendorName`.
44    pub const VENDOR_NAME: AttributeId = 0x00;
45    /// `VendorID`.
46    pub const VENDOR_ID: AttributeId = 0x01;
47    /// `ApplicationName`.
48    pub const APPLICATION_NAME: AttributeId = 0x02;
49    /// `ProductID`.
50    pub const PRODUCT_ID: AttributeId = 0x03;
51    /// `Application`.
52    pub const APPLICATION: AttributeId = 0x04;
53    /// `Status`.
54    pub const STATUS: AttributeId = 0x05;
55    /// `ApplicationVersion`.
56    pub const APPLICATION_VERSION: AttributeId = 0x06;
57    /// `AllowedVendorList`.
58    pub const ALLOWED_VENDOR_LIST: AttributeId = 0x07;
59}
60
61/// `ApplicationStatusEnum`.
62#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
63#[repr(u8)]
64pub enum ApplicationStatusEnum {
65    /// Application is not running.
66    Stopped = 0,
67    /// Application is running, is visible to the user, and is the active target for input.
68    ActiveVisibleFocus = 1,
69    /// Application is running but not visible to the user.
70    ActiveHidden = 2,
71    /// Application is running and visible, but is not the active target for input.
72    ActiveVisibleNotFocus = 3,
73}
74
75impl ApplicationStatusEnum {
76    /// Reads a wire value, or `None` for one this revision does not define.
77    #[must_use]
78    pub const fn from_value(value: u8) -> Option<Self> {
79        match value {
80            0 => Some(Self::Stopped),
81            1 => Some(Self::ActiveVisibleFocus),
82            2 => Some(Self::ActiveHidden),
83            3 => Some(Self::ActiveVisibleNotFocus),
84            _ => None,
85        }
86    }
87
88    /// Its wire value.
89    #[must_use]
90    pub const fn value(self) -> u8 {
91        self as u8
92    }
93}
94
95impl ToTlv for ApplicationStatusEnum {
96    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
97        self.value().to_tlv(w, tag)
98    }
99}
100
101impl<'a> FromTlv<'a> for ApplicationStatusEnum {
102    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
103        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
104        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
105    }
106}
107
108/// `ApplicationStruct`.
109#[derive(Debug, Clone, Copy, PartialEq)]
110pub struct ApplicationStruct<'a> {
111    /// `CatalogVendorID`, field 0.
112    pub catalog_vendor_id: u16,
113    /// `ApplicationID`, field 1.
114    pub application_id: &'a str,
115}
116
117impl<'a> ToTlv for ApplicationStruct<'a> {
118    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
119        w.start_structure(tag)?;
120        self.catalog_vendor_id.to_tlv(w, Tag::Context(0))?;
121        self.application_id.to_tlv(w, Tag::Context(1))?;
122        w.end_container()
123    }
124}
125
126impl<'a> FromTlv<'a> for ApplicationStruct<'a> {
127    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
128        if element.value.container() != Some(ContainerKind::Structure) {
129            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
130        }
131        let mut catalog_vendor_id = None;
132        let mut application_id = None;
133        loop {
134            let Some(field) = reader.next_element()? else {
135                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
136            };
137            if field.value == Value::EndOfContainer {
138                break;
139            }
140            match field.tag.context() {
141                Some(0) => catalog_vendor_id = Some(<u16>::from_tlv(reader, &field)?),
142                Some(1) => application_id = Some(<&'a str>::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            catalog_vendor_id: catalog_vendor_id
151                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
152            application_id: application_id
153                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
154        })
155    }
156}
157
158/// Every attribute the specification defines, with its conformance.
159pub const ATTRIBUTES: &[Attribute] = &[
160    Attribute {
161        id: 0x0000,
162        name: "VendorName",
163        kind: "string",
164        access: Access::read_only(Privilege::View),
165        qualities: AttributeQualities::FIXED,
166        reporting: Reporting::OnChange,
167        conform: Conform::OPTIONAL,
168    },
169    Attribute {
170        id: 0x0001,
171        name: "VendorID",
172        kind: "vendor-id",
173        access: Access::read_only(Privilege::View),
174        qualities: AttributeQualities::FIXED,
175        reporting: Reporting::OnChange,
176        conform: Conform::OPTIONAL,
177    },
178    Attribute {
179        id: 0x0002,
180        name: "ApplicationName",
181        kind: "string",
182        access: Access::read_only(Privilege::View),
183        qualities: AttributeQualities::FIXED,
184        reporting: Reporting::OnChange,
185        conform: Conform::MANDATORY,
186    },
187    Attribute {
188        id: 0x0003,
189        name: "ProductID",
190        kind: "uint16",
191        access: Access::read_only(Privilege::View),
192        qualities: AttributeQualities::FIXED,
193        reporting: Reporting::OnChange,
194        conform: Conform::OPTIONAL,
195    },
196    Attribute {
197        id: 0x0004,
198        name: "Application",
199        kind: "ApplicationStruct",
200        access: Access::read_only(Privilege::View),
201        qualities: AttributeQualities::FIXED,
202        reporting: Reporting::OnChange,
203        conform: Conform::MANDATORY,
204    },
205    Attribute {
206        id: 0x0005,
207        name: "Status",
208        kind: "ApplicationStatusEnum",
209        access: Access::read_only(Privilege::View),
210        qualities: AttributeQualities::empty(),
211        reporting: Reporting::OnChange,
212        conform: Conform::MANDATORY,
213    },
214    Attribute {
215        id: 0x0006,
216        name: "ApplicationVersion",
217        kind: "string",
218        access: Access::read_only(Privilege::View),
219        qualities: AttributeQualities::FIXED,
220        reporting: Reporting::OnChange,
221        conform: Conform::MANDATORY,
222    },
223    Attribute {
224        id: 0x0007,
225        name: "AllowedVendorList",
226        kind: "list[vendor-id]",
227        access: Access::read_only(Privilege::Administer),
228        qualities: AttributeQualities::FIXED,
229        reporting: Reporting::OnChange,
230        conform: Conform::MANDATORY,
231    },
232];
233
234/// Every command, with its conformance.
235pub const COMMANDS: &[Command] = &[];
236
237/// Every event, with its conformance.
238pub const EVENTS: &[Event] = &[];
239
240/// The whole cluster, as the specification defines it.
241pub const CLUSTER: Cluster = Cluster {
242    id: ID,
243    name: "Application Basic",
244    revision: REVISION,
245    pics: "APBSC",
246    derived_from: None,
247    features: FEATURES,
248    attributes: ATTRIBUTES,
249    commands: COMMANDS,
250    events: EVENTS,
251};