Skip to main content

matter_kit/clusters/generated/
service_area.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Service Area — cluster 0x0150.
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//! Service Area (cluster `0x0150`, revision 2).
10//!
11//! 10 identifiers, 3 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 = 0x0150;
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 = "SEAR";
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    /// The device allows changing the selected areas while running
42    ///
43    /// Code `SELRUN`, bit 0.
44    pub const SELECT_WHILE_RUNNING: u32 = 1 << 0;
45    /// The device implements the progress reporting feature
46    ///
47    /// Code `PROG`, bit 1.
48    pub const PROGRESS_REPORTING: u32 = 1 << 1;
49    /// The device has map support
50    ///
51    /// Code `MAPS`, bit 2.
52    pub const MAPS: u32 = 1 << 2;
53}
54
55/// Every feature bit, with its conformance.
56pub const FEATURES: &[Feature] = &[
57    Feature {
58        bit: 0,
59        code: "SELRUN",
60        name: "SelectWhileRunning",
61        conform: Conform::OPTIONAL,
62    },
63    Feature {
64        bit: 1,
65        code: "PROG",
66        name: "ProgressReporting",
67        conform: Conform::OPTIONAL,
68    },
69    Feature {
70        bit: 2,
71        code: "MAPS",
72        name: "Maps",
73        conform: Conform::OPTIONAL,
74    },
75];
76
77/// The attribute ids.
78pub mod attribute {
79    use crate::im::AttributeId;
80
81    /// `SupportedAreas`.
82    pub const SUPPORTED_AREAS: AttributeId = 0x00;
83    /// `SupportedMaps`.
84    pub const SUPPORTED_MAPS: AttributeId = 0x01;
85    /// `SelectedAreas`.
86    pub const SELECTED_AREAS: AttributeId = 0x02;
87    /// `CurrentArea`.
88    pub const CURRENT_AREA: AttributeId = 0x03;
89    /// `EstimatedEndTime`.
90    pub const ESTIMATED_END_TIME: AttributeId = 0x04;
91    /// `Progress`.
92    pub const PROGRESS: AttributeId = 0x05;
93}
94
95/// The command ids.
96pub mod command {
97    use crate::im::CommandId;
98
99    /// `SelectAreas`.
100    pub const SELECT_AREAS: CommandId = 0x00;
101    /// `SelectAreasResponse`.
102    pub const SELECT_AREAS_RESPONSE: CommandId = 0x01;
103    /// `SkipArea`.
104    pub const SKIP_AREA: CommandId = 0x02;
105    /// `SkipAreaResponse`.
106    pub const SKIP_AREA_RESPONSE: CommandId = 0x03;
107}
108
109/// `OperationalStatusEnum`.
110#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
111#[repr(u8)]
112pub enum OperationalStatusEnum {
113    /// The device has not yet started operating at the given area, or has not finished operating at that area but it is not currently operating at the area
114    Pending = 0,
115    /// The device is currently operating at the given area
116    Operating = 1,
117    /// The device has skipped the given area, before or during operating at it, due to a SkipArea command, due an out of band command (e.g. from the vendor's application), due to a vendor specific reason, such as a time limit used by the device, or due the device ending operating unsuccessfully
118    Skipped = 2,
119    /// The device has completed operating at the given area
120    Completed = 3,
121}
122
123impl OperationalStatusEnum {
124    /// Reads a wire value, or `None` for one this revision does not define.
125    #[must_use]
126    pub const fn from_value(value: u8) -> Option<Self> {
127        match value {
128            0 => Some(Self::Pending),
129            1 => Some(Self::Operating),
130            2 => Some(Self::Skipped),
131            3 => Some(Self::Completed),
132            _ => None,
133        }
134    }
135
136    /// Its wire value.
137    #[must_use]
138    pub const fn value(self) -> u8 {
139        self as u8
140    }
141}
142
143impl ToTlv for OperationalStatusEnum {
144    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
145        self.value().to_tlv(w, tag)
146    }
147}
148
149impl<'a> FromTlv<'a> for OperationalStatusEnum {
150    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
151        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
152        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
153    }
154}
155
156/// `SelectAreasStatus`.
157#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
158#[repr(u8)]
159pub enum SelectAreasStatus {
160    /// Attempting to operate in the areas identified by the entries of the NewAreas field is allowed and possible. The SelectedAreas attribute is set to the value of the NewAreas field.
161    Success = 0,
162    /// The value of at least one of the entries of the NewAreas field doesn't match any entries in the SupportedAreas attribute.
163    UnsupportedArea = 1,
164    /// The received request cannot be handled due to the current mode of the device.
165    InvalidInMode = 2,
166    /// The set of values is invalid. For example, areas on different floors, that a robot knows it can't reach on its own.
167    InvalidSet = 3,
168}
169
170impl SelectAreasStatus {
171    /// Reads a wire value, or `None` for one this revision does not define.
172    #[must_use]
173    pub const fn from_value(value: u8) -> Option<Self> {
174        match value {
175            0 => Some(Self::Success),
176            1 => Some(Self::UnsupportedArea),
177            2 => Some(Self::InvalidInMode),
178            3 => Some(Self::InvalidSet),
179            _ => None,
180        }
181    }
182
183    /// Its wire value.
184    #[must_use]
185    pub const fn value(self) -> u8 {
186        self as u8
187    }
188}
189
190impl ToTlv for SelectAreasStatus {
191    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
192        self.value().to_tlv(w, tag)
193    }
194}
195
196impl<'a> FromTlv<'a> for SelectAreasStatus {
197    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
198        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
199        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
200    }
201}
202
203/// `SkipAreaStatus`.
204#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
205#[repr(u8)]
206pub enum SkipAreaStatus {
207    /// Skipping the area is allowed and possible, or the device was operating at the last available area and has stopped.
208    Success = 0,
209    /// The SelectedAreas attribute is empty.
210    InvalidAreaList = 1,
211    /// The received request cannot be handled due to the current mode of the device. For example, the CurrentArea attribute is null or the device is not operating.
212    InvalidInMode = 2,
213    /// The SkippedArea field doesn't match an entry in the SupportedAreas list.
214    InvalidSkippedArea = 3,
215}
216
217impl SkipAreaStatus {
218    /// Reads a wire value, or `None` for one this revision does not define.
219    #[must_use]
220    pub const fn from_value(value: u8) -> Option<Self> {
221        match value {
222            0 => Some(Self::Success),
223            1 => Some(Self::InvalidAreaList),
224            2 => Some(Self::InvalidInMode),
225            3 => Some(Self::InvalidSkippedArea),
226            _ => None,
227        }
228    }
229
230    /// Its wire value.
231    #[must_use]
232    pub const fn value(self) -> u8 {
233        self as u8
234    }
235}
236
237impl ToTlv for SkipAreaStatus {
238    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
239        self.value().to_tlv(w, tag)
240    }
241}
242
243impl<'a> FromTlv<'a> for SkipAreaStatus {
244    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
245        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
246        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
247    }
248}
249
250/// `AreaInfoStruct`.
251#[derive(Debug, Clone, Copy, PartialEq)]
252pub struct AreaInfoStruct<'a> {
253    /// `LocationInfo`, field 0.
254    pub location_info: Nullable<crate::clusters::generated::globals::LocationDescriptorStruct<'a>>,
255    /// `LandmarkInfo`, field 1.
256    pub landmark_info: Nullable<LandmarkInfoStruct>,
257}
258
259impl<'a> ToTlv for AreaInfoStruct<'a> {
260    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
261        w.start_structure(tag)?;
262        self.location_info.to_tlv(w, Tag::Context(0))?;
263        self.landmark_info.to_tlv(w, Tag::Context(1))?;
264        w.end_container()
265    }
266}
267
268impl<'a> FromTlv<'a> for AreaInfoStruct<'a> {
269    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
270        if element.value.container() != Some(ContainerKind::Structure) {
271            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
272        }
273        let mut location_info = None;
274        let mut landmark_info = None;
275        loop {
276            let Some(field) = reader.next_element()? else {
277                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
278            };
279            if field.value == Value::EndOfContainer {
280                break;
281            }
282            match field.tag.context() {
283                Some(0) => {
284                    location_info = Some(<Nullable<
285                        crate::clusters::generated::globals::LocationDescriptorStruct<'a>,
286                    >>::from_tlv(reader, &field)?)
287                }
288                Some(1) => {
289                    landmark_info = Some(<Nullable<LandmarkInfoStruct>>::from_tlv(reader, &field)?)
290                }
291                // A field this revision does not define. §7.19.2: a receiver
292                // ignores what it does not know rather than refusing the whole
293                // structure, which is what lets a newer peer talk to an older one.
294                _ => reader.skip_value(&field)?,
295            }
296        }
297        Ok(Self {
298            location_info: location_info.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
299            landmark_info: landmark_info.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
300        })
301    }
302}
303
304/// `AreaStruct`.
305#[derive(Debug, Clone, Copy, PartialEq)]
306pub struct AreaStruct<'a> {
307    /// `AreaID`, field 0.
308    pub area_id: u32,
309    /// `MapID`, field 1.
310    pub map_id: Nullable<u32>,
311    /// `AreaInfo`, field 2.
312    pub area_info: AreaInfoStruct<'a>,
313}
314
315impl<'a> ToTlv for AreaStruct<'a> {
316    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
317        w.start_structure(tag)?;
318        self.area_id.to_tlv(w, Tag::Context(0))?;
319        self.map_id.to_tlv(w, Tag::Context(1))?;
320        self.area_info.to_tlv(w, Tag::Context(2))?;
321        w.end_container()
322    }
323}
324
325impl<'a> FromTlv<'a> for AreaStruct<'a> {
326    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
327        if element.value.container() != Some(ContainerKind::Structure) {
328            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
329        }
330        let mut area_id = None;
331        let mut map_id = None;
332        let mut area_info = None;
333        loop {
334            let Some(field) = reader.next_element()? else {
335                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
336            };
337            if field.value == Value::EndOfContainer {
338                break;
339            }
340            match field.tag.context() {
341                Some(0) => area_id = Some(<u32>::from_tlv(reader, &field)?),
342                Some(1) => map_id = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
343                Some(2) => area_info = Some(<AreaInfoStruct<'a>>::from_tlv(reader, &field)?),
344                // A field this revision does not define. §7.19.2: a receiver
345                // ignores what it does not know rather than refusing the whole
346                // structure, which is what lets a newer peer talk to an older one.
347                _ => reader.skip_value(&field)?,
348            }
349        }
350        Ok(Self {
351            area_id: area_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
352            map_id: map_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
353            area_info: area_info.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
354        })
355    }
356}
357
358/// `LandmarkInfoStruct`.
359#[derive(Debug, Clone, Copy, PartialEq)]
360pub struct LandmarkInfoStruct {
361    /// `LandmarkTag`, field 0.
362    pub landmark_tag: u8,
363    /// `RelativePositionTag`, field 1.
364    pub relative_position_tag: Nullable<u8>,
365}
366
367impl ToTlv for LandmarkInfoStruct {
368    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
369        w.start_structure(tag)?;
370        self.landmark_tag.to_tlv(w, Tag::Context(0))?;
371        self.relative_position_tag.to_tlv(w, Tag::Context(1))?;
372        w.end_container()
373    }
374}
375
376impl<'a> FromTlv<'a> for LandmarkInfoStruct {
377    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
378        if element.value.container() != Some(ContainerKind::Structure) {
379            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
380        }
381        let mut landmark_tag = None;
382        let mut relative_position_tag = None;
383        loop {
384            let Some(field) = reader.next_element()? else {
385                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
386            };
387            if field.value == Value::EndOfContainer {
388                break;
389            }
390            match field.tag.context() {
391                Some(0) => landmark_tag = Some(<u8>::from_tlv(reader, &field)?),
392                Some(1) => relative_position_tag = Some(<Nullable<u8>>::from_tlv(reader, &field)?),
393                // A field this revision does not define. §7.19.2: a receiver
394                // ignores what it does not know rather than refusing the whole
395                // structure, which is what lets a newer peer talk to an older one.
396                _ => reader.skip_value(&field)?,
397            }
398        }
399        Ok(Self {
400            landmark_tag: landmark_tag.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
401            relative_position_tag: relative_position_tag
402                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
403        })
404    }
405}
406
407/// `MapStruct`.
408#[derive(Debug, Clone, Copy, PartialEq)]
409pub struct MapStruct<'a> {
410    /// `MapID`, field 0.
411    pub map_id: u32,
412    /// `Name`, field 1.
413    pub name: &'a str,
414}
415
416impl<'a> ToTlv for MapStruct<'a> {
417    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
418        w.start_structure(tag)?;
419        self.map_id.to_tlv(w, Tag::Context(0))?;
420        self.name.to_tlv(w, Tag::Context(1))?;
421        w.end_container()
422    }
423}
424
425impl<'a> FromTlv<'a> for MapStruct<'a> {
426    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
427        if element.value.container() != Some(ContainerKind::Structure) {
428            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
429        }
430        let mut map_id = None;
431        let mut name = None;
432        loop {
433            let Some(field) = reader.next_element()? else {
434                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
435            };
436            if field.value == Value::EndOfContainer {
437                break;
438            }
439            match field.tag.context() {
440                Some(0) => map_id = Some(<u32>::from_tlv(reader, &field)?),
441                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
442                // A field this revision does not define. §7.19.2: a receiver
443                // ignores what it does not know rather than refusing the whole
444                // structure, which is what lets a newer peer talk to an older one.
445                _ => reader.skip_value(&field)?,
446            }
447        }
448        Ok(Self {
449            map_id: map_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
450            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
451        })
452    }
453}
454
455/// `ProgressStruct`.
456#[derive(Debug, Clone, Copy, PartialEq)]
457pub struct ProgressStruct {
458    /// `AreaID`, field 0.
459    pub area_id: u32,
460    /// `Status`, field 1.
461    pub status: OperationalStatusEnum,
462    /// `TotalOperationalTime`, field 2.
463    pub total_operational_time: Option<Nullable<u32>>,
464    /// `EstimatedTime`, field 3.
465    pub estimated_time: Option<Nullable<u32>>,
466}
467
468impl ToTlv for ProgressStruct {
469    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
470        w.start_structure(tag)?;
471        self.area_id.to_tlv(w, Tag::Context(0))?;
472        self.status.to_tlv(w, Tag::Context(1))?;
473        if let Some(value) = &self.total_operational_time {
474            value.to_tlv(w, Tag::Context(2))?;
475        }
476        if let Some(value) = &self.estimated_time {
477            value.to_tlv(w, Tag::Context(3))?;
478        }
479        w.end_container()
480    }
481}
482
483impl<'a> FromTlv<'a> for ProgressStruct {
484    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
485        if element.value.container() != Some(ContainerKind::Structure) {
486            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
487        }
488        let mut area_id = None;
489        let mut status = None;
490        let mut total_operational_time = None;
491        let mut estimated_time = None;
492        loop {
493            let Some(field) = reader.next_element()? else {
494                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
495            };
496            if field.value == Value::EndOfContainer {
497                break;
498            }
499            match field.tag.context() {
500                Some(0) => area_id = Some(<u32>::from_tlv(reader, &field)?),
501                Some(1) => status = Some(<OperationalStatusEnum>::from_tlv(reader, &field)?),
502                Some(2) => {
503                    total_operational_time = Some(<Nullable<u32>>::from_tlv(reader, &field)?)
504                }
505                Some(3) => estimated_time = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
506                // A field this revision does not define. §7.19.2: a receiver
507                // ignores what it does not know rather than refusing the whole
508                // structure, which is what lets a newer peer talk to an older one.
509                _ => reader.skip_value(&field)?,
510            }
511        }
512        Ok(Self {
513            area_id: area_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
514            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
515            total_operational_time,
516            estimated_time,
517        })
518    }
519}
520
521/// The fields of `SelectAreas` (command `0x00`).
522#[derive(Debug, Clone, Copy, PartialEq)]
523pub struct SelectAreasFields<'a> {
524    /// `NewAreas`, field 0.
525    pub new_areas: TlvList<'a, u32>,
526}
527
528impl<'a> ToTlv for SelectAreasFields<'a> {
529    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
530        w.start_structure(tag)?;
531        self.new_areas.to_tlv(w, Tag::Context(0))?;
532        w.end_container()
533    }
534}
535
536impl<'a> FromTlv<'a> for SelectAreasFields<'a> {
537    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
538        if element.value.container() != Some(ContainerKind::Structure) {
539            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
540        }
541        let mut new_areas = None;
542        loop {
543            let Some(field) = reader.next_element()? else {
544                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
545            };
546            if field.value == Value::EndOfContainer {
547                break;
548            }
549            match field.tag.context() {
550                Some(0) => new_areas = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?),
551                // A field this revision does not define. §7.19.2: a receiver
552                // ignores what it does not know rather than refusing the whole
553                // structure, which is what lets a newer peer talk to an older one.
554                _ => reader.skip_value(&field)?,
555            }
556        }
557        Ok(Self {
558            new_areas: new_areas.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
559        })
560    }
561}
562
563/// The fields of `SelectAreasResponse` (command `0x01`).
564#[derive(Debug, Clone, Copy, PartialEq)]
565pub struct SelectAreasResponseFields<'a> {
566    /// `Status`, field 0.
567    pub status: SelectAreasStatus,
568    /// `StatusText`, field 1.
569    pub status_text: &'a str,
570}
571
572impl<'a> ToTlv for SelectAreasResponseFields<'a> {
573    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
574        w.start_structure(tag)?;
575        self.status.to_tlv(w, Tag::Context(0))?;
576        self.status_text.to_tlv(w, Tag::Context(1))?;
577        w.end_container()
578    }
579}
580
581impl<'a> FromTlv<'a> for SelectAreasResponseFields<'a> {
582    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
583        if element.value.container() != Some(ContainerKind::Structure) {
584            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
585        }
586        let mut status = None;
587        let mut status_text = None;
588        loop {
589            let Some(field) = reader.next_element()? else {
590                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
591            };
592            if field.value == Value::EndOfContainer {
593                break;
594            }
595            match field.tag.context() {
596                Some(0) => status = Some(<SelectAreasStatus>::from_tlv(reader, &field)?),
597                Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
598                // A field this revision does not define. §7.19.2: a receiver
599                // ignores what it does not know rather than refusing the whole
600                // structure, which is what lets a newer peer talk to an older one.
601                _ => reader.skip_value(&field)?,
602            }
603        }
604        Ok(Self {
605            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
606            status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
607        })
608    }
609}
610
611/// The fields of `SkipArea` (command `0x02`).
612#[derive(Debug, Clone, Copy, PartialEq)]
613pub struct SkipAreaFields {
614    /// `SkippedArea`, field 0.
615    pub skipped_area: u32,
616}
617
618impl ToTlv for SkipAreaFields {
619    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
620        w.start_structure(tag)?;
621        self.skipped_area.to_tlv(w, Tag::Context(0))?;
622        w.end_container()
623    }
624}
625
626impl<'a> FromTlv<'a> for SkipAreaFields {
627    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
628        if element.value.container() != Some(ContainerKind::Structure) {
629            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
630        }
631        let mut skipped_area = None;
632        loop {
633            let Some(field) = reader.next_element()? else {
634                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
635            };
636            if field.value == Value::EndOfContainer {
637                break;
638            }
639            match field.tag.context() {
640                Some(0) => skipped_area = Some(<u32>::from_tlv(reader, &field)?),
641                // A field this revision does not define. §7.19.2: a receiver
642                // ignores what it does not know rather than refusing the whole
643                // structure, which is what lets a newer peer talk to an older one.
644                _ => reader.skip_value(&field)?,
645            }
646        }
647        Ok(Self {
648            skipped_area: skipped_area.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
649        })
650    }
651}
652
653/// The fields of `SkipAreaResponse` (command `0x03`).
654#[derive(Debug, Clone, Copy, PartialEq)]
655pub struct SkipAreaResponseFields<'a> {
656    /// `Status`, field 0.
657    pub status: SkipAreaStatus,
658    /// `StatusText`, field 1.
659    pub status_text: &'a str,
660}
661
662impl<'a> ToTlv for SkipAreaResponseFields<'a> {
663    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
664        w.start_structure(tag)?;
665        self.status.to_tlv(w, Tag::Context(0))?;
666        self.status_text.to_tlv(w, Tag::Context(1))?;
667        w.end_container()
668    }
669}
670
671impl<'a> FromTlv<'a> for SkipAreaResponseFields<'a> {
672    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
673        if element.value.container() != Some(ContainerKind::Structure) {
674            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
675        }
676        let mut status = None;
677        let mut status_text = None;
678        loop {
679            let Some(field) = reader.next_element()? else {
680                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
681            };
682            if field.value == Value::EndOfContainer {
683                break;
684            }
685            match field.tag.context() {
686                Some(0) => status = Some(<SkipAreaStatus>::from_tlv(reader, &field)?),
687                Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
688                // A field this revision does not define. §7.19.2: a receiver
689                // ignores what it does not know rather than refusing the whole
690                // structure, which is what lets a newer peer talk to an older one.
691                _ => reader.skip_value(&field)?,
692            }
693        }
694        Ok(Self {
695            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
696            status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
697        })
698    }
699}
700
701/// Every attribute the specification defines, with its conformance.
702pub const ATTRIBUTES: &[Attribute] = &[
703    Attribute {
704        id: 0x0000,
705        name: "SupportedAreas",
706        kind: "list[AreaStruct]",
707        access: Access::read_only(Privilege::View),
708        qualities: AttributeQualities::empty(),
709        reporting: Reporting::OnChange,
710        conform: Conform::MANDATORY,
711    },
712    Attribute {
713        id: 0x0001,
714        name: "SupportedMaps",
715        kind: "list[MapStruct]",
716        access: Access::read_only(Privilege::View),
717        qualities: AttributeQualities::empty(),
718        reporting: Reporting::OnChange,
719        conform: Conform {
720            clauses: &[Clause {
721                verdict: Conformance::Mandatory,
722                when: Condition::Feature(2),
723            }],
724        },
725    },
726    Attribute {
727        id: 0x0002,
728        name: "SelectedAreas",
729        kind: "list[uint32]",
730        access: Access::read_only(Privilege::View),
731        qualities: AttributeQualities::empty(),
732        reporting: Reporting::OnChange,
733        conform: Conform::MANDATORY,
734    },
735    Attribute {
736        id: 0x0003,
737        name: "CurrentArea",
738        kind: "uint32",
739        access: Access::read_only(Privilege::View),
740        qualities: AttributeQualities::NULLABLE,
741        reporting: Reporting::OnChange,
742        conform: Conform::DESCRIBED,
743    },
744    Attribute {
745        id: 0x0004,
746        name: "EstimatedEndTime",
747        kind: "epoch-s",
748        access: Access::read_only(Privilege::View),
749        qualities: AttributeQualities::NULLABLE,
750        reporting: Reporting::Quieter,
751        conform: Conform {
752            clauses: &[Clause {
753                verdict: Conformance::Optional,
754                when: Condition::Attribute(0x0003),
755            }],
756        },
757    },
758    Attribute {
759        id: 0x0005,
760        name: "Progress",
761        kind: "list[ProgressStruct]",
762        access: Access::read_only(Privilege::View),
763        qualities: AttributeQualities::empty(),
764        reporting: Reporting::OnChange,
765        conform: Conform {
766            clauses: &[Clause {
767                verdict: Conformance::Mandatory,
768                when: Condition::Feature(1),
769            }],
770        },
771    },
772];
773
774/// Every command, with its conformance.
775pub const COMMANDS: &[Command] = &[
776    Command {
777        id: 0x00,
778        name: "SelectAreas",
779        to_server: true,
780        response: Some(0x01),
781        access: Access::invoke(Privilege::Operate),
782        conform: Conform::MANDATORY,
783    },
784    Command {
785        id: 0x01,
786        name: "SelectAreasResponse",
787        to_server: false,
788        response: None,
789        access: Access::invoke(Privilege::Operate),
790        conform: Conform::MANDATORY,
791    },
792    Command {
793        id: 0x02,
794        name: "SkipArea",
795        to_server: true,
796        response: Some(0x03),
797        access: Access::invoke(Privilege::Operate),
798        conform: Conform {
799            clauses: &[Clause {
800                verdict: Conformance::Optional,
801                when: Condition::Any(&[Condition::Attribute(0x0003), Condition::Attribute(0x0005)]),
802            }],
803        },
804    },
805    Command {
806        id: 0x03,
807        name: "SkipAreaResponse",
808        to_server: false,
809        response: None,
810        access: Access::invoke(Privilege::Operate),
811        conform: Conform {
812            clauses: &[Clause {
813                verdict: Conformance::Mandatory,
814                when: Condition::Command(0x02),
815            }],
816        },
817    },
818];
819
820/// Every event, with its conformance.
821pub const EVENTS: &[Event] = &[];
822
823/// The whole cluster, as the specification defines it.
824pub const CLUSTER: Cluster = Cluster {
825    id: ID,
826    name: "Service Area",
827    revision: REVISION,
828    pics: "SEAR",
829    derived_from: None,
830    features: FEATURES,
831    attributes: ATTRIBUTES,
832    commands: COMMANDS,
833    events: EVENTS,
834};