Skip to main content

matter_kit/clusters/generated/
camera_av_settings_user_level_management.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Camera AV Settings User Level Management — cluster 0x0552.
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//! Camera AV Settings User Level Management (cluster `0x0552`, revision 1).
10//!
11//! 17 identifiers, 5 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 = 0x0552;
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 = "AVSUM";
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    /// Digital PTZ support
42    ///
43    /// Code `DPTZ`, bit 0.
44    pub const DIGITAL_PTZ: u32 = 1 << 0;
45    /// Mechanical Pan support
46    ///
47    /// Code `MPAN`, bit 1.
48    pub const MECHANICAL_PAN: u32 = 1 << 1;
49    /// Mechanical Tilt support
50    ///
51    /// Code `MTILT`, bit 2.
52    pub const MECHANICAL_TILT: u32 = 1 << 2;
53    /// Mechanical Zoom support
54    ///
55    /// Code `MZOOM`, bit 3.
56    pub const MECHANICAL_ZOOM: u32 = 1 << 3;
57    /// Mechanical saved presets support
58    ///
59    /// Code `MPRESETS`, bit 4.
60    pub const MECHANICAL_PRESETS: u32 = 1 << 4;
61}
62
63/// Every feature bit, with its conformance.
64pub const FEATURES: &[Feature] = &[
65    Feature {
66        bit: 0,
67        code: "DPTZ",
68        name: "DigitalPTZ",
69        conform: Conform::OPTIONAL,
70    },
71    Feature {
72        bit: 1,
73        code: "MPAN",
74        name: "MechanicalPan",
75        conform: Conform::OPTIONAL,
76    },
77    Feature {
78        bit: 2,
79        code: "MTILT",
80        name: "MechanicalTilt",
81        conform: Conform::OPTIONAL,
82    },
83    Feature {
84        bit: 3,
85        code: "MZOOM",
86        name: "MechanicalZoom",
87        conform: Conform::OPTIONAL,
88    },
89    Feature {
90        bit: 4,
91        code: "MPRESETS",
92        name: "MechanicalPresets",
93        conform: Conform {
94            clauses: &[Clause {
95                verdict: Conformance::Optional,
96                when: Condition::Any(&[
97                    Condition::Feature(1),
98                    Condition::Feature(2),
99                    Condition::Feature(3),
100                ]),
101            }],
102        },
103    },
104];
105
106/// The attribute ids.
107pub mod attribute {
108    use crate::im::AttributeId;
109
110    /// `MPTZPosition`.
111    pub const MPTZ_POSITION: AttributeId = 0x00;
112    /// `MaxPresets`.
113    pub const MAX_PRESETS: AttributeId = 0x01;
114    /// `MPTZPresets`.
115    pub const MPTZ_PRESETS: AttributeId = 0x02;
116    /// `DPTZStreams`.
117    pub const DPTZ_STREAMS: AttributeId = 0x03;
118    /// `ZoomMax`.
119    pub const ZOOM_MAX: AttributeId = 0x04;
120    /// `TiltMin`.
121    pub const TILT_MIN: AttributeId = 0x05;
122    /// `TiltMax`.
123    pub const TILT_MAX: AttributeId = 0x06;
124    /// `PanMin`.
125    pub const PAN_MIN: AttributeId = 0x07;
126    /// `PanMax`.
127    pub const PAN_MAX: AttributeId = 0x08;
128    /// `MovementState`.
129    pub const MOVEMENT_STATE: AttributeId = 0x09;
130}
131
132/// The command ids.
133pub mod command {
134    use crate::im::CommandId;
135
136    /// `MPTZSetPosition`.
137    pub const MPTZ_SET_POSITION: CommandId = 0x00;
138    /// `MPTZRelativeMove`.
139    pub const MPTZ_RELATIVE_MOVE: CommandId = 0x01;
140    /// `MPTZMoveToPreset`.
141    pub const MPTZ_MOVE_TO_PRESET: CommandId = 0x02;
142    /// `MPTZSavePreset`.
143    pub const MPTZ_SAVE_PRESET: CommandId = 0x03;
144    /// `MPTZRemovePreset`.
145    pub const MPTZ_REMOVE_PRESET: CommandId = 0x04;
146    /// `DPTZSetViewport`.
147    pub const DPTZ_SET_VIEWPORT: CommandId = 0x05;
148    /// `DPTZRelativeMove`.
149    pub const DPTZ_RELATIVE_MOVE: CommandId = 0x06;
150}
151
152/// `PhysicalMovementEnum`.
153#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
154#[repr(u8)]
155pub enum PhysicalMovementEnum {
156    /// The camera is idle.
157    Idle = 0,
158    /// The camera is moving to a new value of Pan, Tilt, and/or Zoom.
159    Moving = 1,
160}
161
162impl PhysicalMovementEnum {
163    /// Reads a wire value, or `None` for one this revision does not define.
164    #[must_use]
165    pub const fn from_value(value: u8) -> Option<Self> {
166        match value {
167            0 => Some(Self::Idle),
168            1 => Some(Self::Moving),
169            _ => None,
170        }
171    }
172
173    /// Its wire value.
174    #[must_use]
175    pub const fn value(self) -> u8 {
176        self as u8
177    }
178}
179
180impl ToTlv for PhysicalMovementEnum {
181    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
182        self.value().to_tlv(w, tag)
183    }
184}
185
186impl<'a> FromTlv<'a> for PhysicalMovementEnum {
187    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
188        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
189        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
190    }
191}
192
193/// `DPTZStruct`.
194#[derive(Debug, Clone, Copy, PartialEq)]
195pub struct DPTZStruct {
196    /// `VideoStreamID`, field 0.
197    pub video_stream_id: u16,
198    /// `Viewport`, field 1.
199    pub viewport: crate::clusters::generated::globals::ViewportStruct,
200}
201
202impl ToTlv for DPTZStruct {
203    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
204        w.start_structure(tag)?;
205        self.video_stream_id.to_tlv(w, Tag::Context(0))?;
206        self.viewport.to_tlv(w, Tag::Context(1))?;
207        w.end_container()
208    }
209}
210
211impl<'a> FromTlv<'a> for DPTZStruct {
212    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
213        if element.value.container() != Some(ContainerKind::Structure) {
214            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
215        }
216        let mut video_stream_id = None;
217        let mut viewport = None;
218        loop {
219            let Some(field) = reader.next_element()? else {
220                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
221            };
222            if field.value == Value::EndOfContainer {
223                break;
224            }
225            match field.tag.context() {
226                Some(0) => video_stream_id = Some(<u16>::from_tlv(reader, &field)?),
227                Some(1) => {
228                    viewport = Some(
229                        <crate::clusters::generated::globals::ViewportStruct>::from_tlv(
230                            reader, &field,
231                        )?,
232                    )
233                }
234                // A field this revision does not define. §7.19.2: a receiver
235                // ignores what it does not know rather than refusing the whole
236                // structure, which is what lets a newer peer talk to an older one.
237                _ => reader.skip_value(&field)?,
238            }
239        }
240        Ok(Self {
241            video_stream_id: video_stream_id
242                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
243            viewport: viewport.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
244        })
245    }
246}
247
248/// `MPTZPresetStruct`.
249#[derive(Debug, Clone, Copy, PartialEq)]
250pub struct MPTZPresetStruct<'a> {
251    /// `PresetID`, field 0.
252    pub preset_id: u8,
253    /// `Name`, field 1.
254    pub name: &'a str,
255    /// `Settings`, field 2.
256    pub settings: MPTZStruct,
257}
258
259impl<'a> ToTlv for MPTZPresetStruct<'a> {
260    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
261        w.start_structure(tag)?;
262        self.preset_id.to_tlv(w, Tag::Context(0))?;
263        self.name.to_tlv(w, Tag::Context(1))?;
264        self.settings.to_tlv(w, Tag::Context(2))?;
265        w.end_container()
266    }
267}
268
269impl<'a> FromTlv<'a> for MPTZPresetStruct<'a> {
270    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
271        if element.value.container() != Some(ContainerKind::Structure) {
272            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
273        }
274        let mut preset_id = None;
275        let mut name = None;
276        let mut settings = None;
277        loop {
278            let Some(field) = reader.next_element()? else {
279                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
280            };
281            if field.value == Value::EndOfContainer {
282                break;
283            }
284            match field.tag.context() {
285                Some(0) => preset_id = Some(<u8>::from_tlv(reader, &field)?),
286                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
287                Some(2) => settings = Some(<MPTZStruct>::from_tlv(reader, &field)?),
288                // A field this revision does not define. §7.19.2: a receiver
289                // ignores what it does not know rather than refusing the whole
290                // structure, which is what lets a newer peer talk to an older one.
291                _ => reader.skip_value(&field)?,
292            }
293        }
294        Ok(Self {
295            preset_id: preset_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
296            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
297            settings: settings.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
298        })
299    }
300}
301
302/// `MPTZStruct`.
303#[derive(Debug, Clone, Copy, PartialEq)]
304pub struct MPTZStruct {
305    /// `Pan`, field 0.
306    pub pan: Option<i16>,
307    /// `Tilt`, field 1.
308    pub tilt: Option<i16>,
309    /// `Zoom`, field 2.
310    pub zoom: Option<u8>,
311}
312
313impl ToTlv for MPTZStruct {
314    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
315        w.start_structure(tag)?;
316        if let Some(value) = &self.pan {
317            value.to_tlv(w, Tag::Context(0))?;
318        }
319        if let Some(value) = &self.tilt {
320            value.to_tlv(w, Tag::Context(1))?;
321        }
322        if let Some(value) = &self.zoom {
323            value.to_tlv(w, Tag::Context(2))?;
324        }
325        w.end_container()
326    }
327}
328
329impl<'a> FromTlv<'a> for MPTZStruct {
330    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
331        if element.value.container() != Some(ContainerKind::Structure) {
332            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
333        }
334        let mut pan = None;
335        let mut tilt = None;
336        let mut zoom = None;
337        loop {
338            let Some(field) = reader.next_element()? else {
339                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
340            };
341            if field.value == Value::EndOfContainer {
342                break;
343            }
344            match field.tag.context() {
345                Some(0) => pan = Some(<i16>::from_tlv(reader, &field)?),
346                Some(1) => tilt = Some(<i16>::from_tlv(reader, &field)?),
347                Some(2) => zoom = Some(<u8>::from_tlv(reader, &field)?),
348                // A field this revision does not define. §7.19.2: a receiver
349                // ignores what it does not know rather than refusing the whole
350                // structure, which is what lets a newer peer talk to an older one.
351                _ => reader.skip_value(&field)?,
352            }
353        }
354        Ok(Self { pan, tilt, zoom })
355    }
356}
357
358/// The fields of `MPTZSetPosition` (command `0x00`).
359#[derive(Debug, Clone, Copy, PartialEq)]
360pub struct MPTZSetPositionFields {
361    /// `Pan`, field 0.
362    pub pan: Option<i16>,
363    /// `Tilt`, field 1.
364    pub tilt: Option<i16>,
365    /// `Zoom`, field 2.
366    pub zoom: Option<u8>,
367}
368
369impl ToTlv for MPTZSetPositionFields {
370    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
371        w.start_structure(tag)?;
372        if let Some(value) = &self.pan {
373            value.to_tlv(w, Tag::Context(0))?;
374        }
375        if let Some(value) = &self.tilt {
376            value.to_tlv(w, Tag::Context(1))?;
377        }
378        if let Some(value) = &self.zoom {
379            value.to_tlv(w, Tag::Context(2))?;
380        }
381        w.end_container()
382    }
383}
384
385impl<'a> FromTlv<'a> for MPTZSetPositionFields {
386    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
387        if element.value.container() != Some(ContainerKind::Structure) {
388            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
389        }
390        let mut pan = None;
391        let mut tilt = None;
392        let mut zoom = None;
393        loop {
394            let Some(field) = reader.next_element()? else {
395                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
396            };
397            if field.value == Value::EndOfContainer {
398                break;
399            }
400            match field.tag.context() {
401                Some(0) => pan = Some(<i16>::from_tlv(reader, &field)?),
402                Some(1) => tilt = Some(<i16>::from_tlv(reader, &field)?),
403                Some(2) => zoom = Some(<u8>::from_tlv(reader, &field)?),
404                // A field this revision does not define. §7.19.2: a receiver
405                // ignores what it does not know rather than refusing the whole
406                // structure, which is what lets a newer peer talk to an older one.
407                _ => reader.skip_value(&field)?,
408            }
409        }
410        Ok(Self { pan, tilt, zoom })
411    }
412}
413
414/// The fields of `MPTZRelativeMove` (command `0x01`).
415#[derive(Debug, Clone, Copy, PartialEq)]
416pub struct MPTZRelativeMoveFields {
417    /// `PanDelta`, field 0.
418    pub pan_delta: Option<i16>,
419    /// `TiltDelta`, field 1.
420    pub tilt_delta: Option<i16>,
421    /// `ZoomDelta`, field 2.
422    pub zoom_delta: Option<i8>,
423}
424
425impl ToTlv for MPTZRelativeMoveFields {
426    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
427        w.start_structure(tag)?;
428        if let Some(value) = &self.pan_delta {
429            value.to_tlv(w, Tag::Context(0))?;
430        }
431        if let Some(value) = &self.tilt_delta {
432            value.to_tlv(w, Tag::Context(1))?;
433        }
434        if let Some(value) = &self.zoom_delta {
435            value.to_tlv(w, Tag::Context(2))?;
436        }
437        w.end_container()
438    }
439}
440
441impl<'a> FromTlv<'a> for MPTZRelativeMoveFields {
442    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
443        if element.value.container() != Some(ContainerKind::Structure) {
444            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
445        }
446        let mut pan_delta = None;
447        let mut tilt_delta = None;
448        let mut zoom_delta = None;
449        loop {
450            let Some(field) = reader.next_element()? else {
451                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
452            };
453            if field.value == Value::EndOfContainer {
454                break;
455            }
456            match field.tag.context() {
457                Some(0) => pan_delta = Some(<i16>::from_tlv(reader, &field)?),
458                Some(1) => tilt_delta = Some(<i16>::from_tlv(reader, &field)?),
459                Some(2) => zoom_delta = Some(<i8>::from_tlv(reader, &field)?),
460                // A field this revision does not define. §7.19.2: a receiver
461                // ignores what it does not know rather than refusing the whole
462                // structure, which is what lets a newer peer talk to an older one.
463                _ => reader.skip_value(&field)?,
464            }
465        }
466        Ok(Self {
467            pan_delta,
468            tilt_delta,
469            zoom_delta,
470        })
471    }
472}
473
474/// The fields of `MPTZMoveToPreset` (command `0x02`).
475#[derive(Debug, Clone, Copy, PartialEq)]
476pub struct MPTZMoveToPresetFields {
477    /// `PresetID`, field 0.
478    pub preset_id: u8,
479}
480
481impl ToTlv for MPTZMoveToPresetFields {
482    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
483        w.start_structure(tag)?;
484        self.preset_id.to_tlv(w, Tag::Context(0))?;
485        w.end_container()
486    }
487}
488
489impl<'a> FromTlv<'a> for MPTZMoveToPresetFields {
490    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
491        if element.value.container() != Some(ContainerKind::Structure) {
492            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
493        }
494        let mut preset_id = None;
495        loop {
496            let Some(field) = reader.next_element()? else {
497                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
498            };
499            if field.value == Value::EndOfContainer {
500                break;
501            }
502            match field.tag.context() {
503                Some(0) => preset_id = Some(<u8>::from_tlv(reader, &field)?),
504                // A field this revision does not define. §7.19.2: a receiver
505                // ignores what it does not know rather than refusing the whole
506                // structure, which is what lets a newer peer talk to an older one.
507                _ => reader.skip_value(&field)?,
508            }
509        }
510        Ok(Self {
511            preset_id: preset_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
512        })
513    }
514}
515
516/// The fields of `MPTZSavePreset` (command `0x03`).
517#[derive(Debug, Clone, Copy, PartialEq)]
518pub struct MPTZSavePresetFields<'a> {
519    /// `PresetID`, field 0.
520    pub preset_id: Option<u8>,
521    /// `Name`, field 1.
522    pub name: &'a str,
523}
524
525impl<'a> ToTlv for MPTZSavePresetFields<'a> {
526    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
527        w.start_structure(tag)?;
528        if let Some(value) = &self.preset_id {
529            value.to_tlv(w, Tag::Context(0))?;
530        }
531        self.name.to_tlv(w, Tag::Context(1))?;
532        w.end_container()
533    }
534}
535
536impl<'a> FromTlv<'a> for MPTZSavePresetFields<'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 preset_id = None;
542        let mut name = None;
543        loop {
544            let Some(field) = reader.next_element()? else {
545                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
546            };
547            if field.value == Value::EndOfContainer {
548                break;
549            }
550            match field.tag.context() {
551                Some(0) => preset_id = Some(<u8>::from_tlv(reader, &field)?),
552                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
553                // A field this revision does not define. §7.19.2: a receiver
554                // ignores what it does not know rather than refusing the whole
555                // structure, which is what lets a newer peer talk to an older one.
556                _ => reader.skip_value(&field)?,
557            }
558        }
559        Ok(Self {
560            preset_id,
561            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
562        })
563    }
564}
565
566/// The fields of `MPTZRemovePreset` (command `0x04`).
567#[derive(Debug, Clone, Copy, PartialEq)]
568pub struct MPTZRemovePresetFields {
569    /// `PresetID`, field 0.
570    pub preset_id: u8,
571}
572
573impl ToTlv for MPTZRemovePresetFields {
574    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
575        w.start_structure(tag)?;
576        self.preset_id.to_tlv(w, Tag::Context(0))?;
577        w.end_container()
578    }
579}
580
581impl<'a> FromTlv<'a> for MPTZRemovePresetFields {
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 preset_id = None;
587        loop {
588            let Some(field) = reader.next_element()? else {
589                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
590            };
591            if field.value == Value::EndOfContainer {
592                break;
593            }
594            match field.tag.context() {
595                Some(0) => preset_id = Some(<u8>::from_tlv(reader, &field)?),
596                // A field this revision does not define. §7.19.2: a receiver
597                // ignores what it does not know rather than refusing the whole
598                // structure, which is what lets a newer peer talk to an older one.
599                _ => reader.skip_value(&field)?,
600            }
601        }
602        Ok(Self {
603            preset_id: preset_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
604        })
605    }
606}
607
608/// The fields of `DPTZSetViewport` (command `0x05`).
609#[derive(Debug, Clone, Copy, PartialEq)]
610pub struct DPTZSetViewportFields {
611    /// `VideoStreamID`, field 0.
612    pub video_stream_id: u16,
613    /// `Viewport`, field 1.
614    pub viewport: crate::clusters::generated::globals::ViewportStruct,
615}
616
617impl ToTlv for DPTZSetViewportFields {
618    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
619        w.start_structure(tag)?;
620        self.video_stream_id.to_tlv(w, Tag::Context(0))?;
621        self.viewport.to_tlv(w, Tag::Context(1))?;
622        w.end_container()
623    }
624}
625
626impl<'a> FromTlv<'a> for DPTZSetViewportFields {
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 video_stream_id = None;
632        let mut viewport = None;
633        loop {
634            let Some(field) = reader.next_element()? else {
635                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
636            };
637            if field.value == Value::EndOfContainer {
638                break;
639            }
640            match field.tag.context() {
641                Some(0) => video_stream_id = Some(<u16>::from_tlv(reader, &field)?),
642                Some(1) => {
643                    viewport = Some(
644                        <crate::clusters::generated::globals::ViewportStruct>::from_tlv(
645                            reader, &field,
646                        )?,
647                    )
648                }
649                // A field this revision does not define. §7.19.2: a receiver
650                // ignores what it does not know rather than refusing the whole
651                // structure, which is what lets a newer peer talk to an older one.
652                _ => reader.skip_value(&field)?,
653            }
654        }
655        Ok(Self {
656            video_stream_id: video_stream_id
657                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
658            viewport: viewport.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
659        })
660    }
661}
662
663/// The fields of `DPTZRelativeMove` (command `0x06`).
664#[derive(Debug, Clone, Copy, PartialEq)]
665pub struct DPTZRelativeMoveFields {
666    /// `VideoStreamID`, field 0.
667    pub video_stream_id: u16,
668    /// `DeltaX`, field 1.
669    pub delta_x: Option<i16>,
670    /// `DeltaY`, field 2.
671    pub delta_y: Option<i16>,
672    /// `ZoomDelta`, field 3.
673    pub zoom_delta: Option<i8>,
674}
675
676impl ToTlv for DPTZRelativeMoveFields {
677    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
678        w.start_structure(tag)?;
679        self.video_stream_id.to_tlv(w, Tag::Context(0))?;
680        if let Some(value) = &self.delta_x {
681            value.to_tlv(w, Tag::Context(1))?;
682        }
683        if let Some(value) = &self.delta_y {
684            value.to_tlv(w, Tag::Context(2))?;
685        }
686        if let Some(value) = &self.zoom_delta {
687            value.to_tlv(w, Tag::Context(3))?;
688        }
689        w.end_container()
690    }
691}
692
693impl<'a> FromTlv<'a> for DPTZRelativeMoveFields {
694    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
695        if element.value.container() != Some(ContainerKind::Structure) {
696            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
697        }
698        let mut video_stream_id = None;
699        let mut delta_x = None;
700        let mut delta_y = None;
701        let mut zoom_delta = None;
702        loop {
703            let Some(field) = reader.next_element()? else {
704                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
705            };
706            if field.value == Value::EndOfContainer {
707                break;
708            }
709            match field.tag.context() {
710                Some(0) => video_stream_id = Some(<u16>::from_tlv(reader, &field)?),
711                Some(1) => delta_x = Some(<i16>::from_tlv(reader, &field)?),
712                Some(2) => delta_y = Some(<i16>::from_tlv(reader, &field)?),
713                Some(3) => zoom_delta = Some(<i8>::from_tlv(reader, &field)?),
714                // A field this revision does not define. §7.19.2: a receiver
715                // ignores what it does not know rather than refusing the whole
716                // structure, which is what lets a newer peer talk to an older one.
717                _ => reader.skip_value(&field)?,
718            }
719        }
720        Ok(Self {
721            video_stream_id: video_stream_id
722                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
723            delta_x,
724            delta_y,
725            zoom_delta,
726        })
727    }
728}
729
730/// Every attribute the specification defines, with its conformance.
731pub const ATTRIBUTES: &[Attribute] = &[
732    Attribute {
733        id: 0x0000,
734        name: "MPTZPosition",
735        kind: "MPTZStruct",
736        access: Access::read_only(Privilege::View),
737        qualities: AttributeQualities::NON_VOLATILE,
738        reporting: Reporting::OnChange,
739        conform: Conform {
740            clauses: &[Clause {
741                verdict: Conformance::Mandatory,
742                when: Condition::Any(&[
743                    Condition::Feature(1),
744                    Condition::Feature(2),
745                    Condition::Feature(3),
746                ]),
747            }],
748        },
749    },
750    Attribute {
751        id: 0x0001,
752        name: "MaxPresets",
753        kind: "uint8",
754        access: Access::read_only(Privilege::View),
755        qualities: AttributeQualities::FIXED,
756        reporting: Reporting::OnChange,
757        conform: Conform {
758            clauses: &[Clause {
759                verdict: Conformance::Mandatory,
760                when: Condition::Feature(4),
761            }],
762        },
763    },
764    Attribute {
765        id: 0x0002,
766        name: "MPTZPresets",
767        kind: "list[MPTZPresetStruct]",
768        access: Access::read_only(Privilege::View),
769        qualities: AttributeQualities::NON_VOLATILE,
770        reporting: Reporting::OnChange,
771        conform: Conform {
772            clauses: &[Clause {
773                verdict: Conformance::Mandatory,
774                when: Condition::Feature(4),
775            }],
776        },
777    },
778    Attribute {
779        id: 0x0003,
780        name: "DPTZStreams",
781        kind: "list[DPTZStruct]",
782        access: Access::read_only(Privilege::View),
783        qualities: AttributeQualities::NON_VOLATILE,
784        reporting: Reporting::OnChange,
785        conform: Conform {
786            clauses: &[Clause {
787                verdict: Conformance::Mandatory,
788                when: Condition::Feature(0),
789            }],
790        },
791    },
792    Attribute {
793        id: 0x0004,
794        name: "ZoomMax",
795        kind: "uint8",
796        access: Access::read_only(Privilege::View),
797        qualities: AttributeQualities::empty(),
798        reporting: Reporting::OnChange,
799        conform: Conform {
800            clauses: &[Clause {
801                verdict: Conformance::Mandatory,
802                when: Condition::Feature(3),
803            }],
804        },
805    },
806    Attribute {
807        id: 0x0005,
808        name: "TiltMin",
809        kind: "int16",
810        access: Access::read_only(Privilege::View),
811        qualities: AttributeQualities::empty(),
812        reporting: Reporting::OnChange,
813        conform: Conform {
814            clauses: &[Clause {
815                verdict: Conformance::Mandatory,
816                when: Condition::Feature(2),
817            }],
818        },
819    },
820    Attribute {
821        id: 0x0006,
822        name: "TiltMax",
823        kind: "int16",
824        access: Access::read_only(Privilege::View),
825        qualities: AttributeQualities::empty(),
826        reporting: Reporting::OnChange,
827        conform: Conform {
828            clauses: &[Clause {
829                verdict: Conformance::Mandatory,
830                when: Condition::Feature(2),
831            }],
832        },
833    },
834    Attribute {
835        id: 0x0007,
836        name: "PanMin",
837        kind: "int16",
838        access: Access::read_only(Privilege::View),
839        qualities: AttributeQualities::empty(),
840        reporting: Reporting::OnChange,
841        conform: Conform {
842            clauses: &[Clause {
843                verdict: Conformance::Mandatory,
844                when: Condition::Feature(1),
845            }],
846        },
847    },
848    Attribute {
849        id: 0x0008,
850        name: "PanMax",
851        kind: "int16",
852        access: Access::read_only(Privilege::View),
853        qualities: AttributeQualities::empty(),
854        reporting: Reporting::OnChange,
855        conform: Conform {
856            clauses: &[Clause {
857                verdict: Conformance::Mandatory,
858                when: Condition::Feature(1),
859            }],
860        },
861    },
862    Attribute {
863        id: 0x0009,
864        name: "MovementState",
865        kind: "PhysicalMovementEnum",
866        access: Access::read_only(Privilege::View),
867        qualities: AttributeQualities::empty(),
868        reporting: Reporting::OnChange,
869        conform: Conform {
870            clauses: &[Clause {
871                verdict: Conformance::Mandatory,
872                when: Condition::Any(&[
873                    Condition::Feature(1),
874                    Condition::Feature(2),
875                    Condition::Feature(3),
876                ]),
877            }],
878        },
879    },
880];
881
882/// Every command, with its conformance.
883pub const COMMANDS: &[Command] = &[
884    Command {
885        id: 0x00,
886        name: "MPTZSetPosition",
887        to_server: true,
888        response: None,
889        access: Access::invoke(Privilege::Operate),
890        conform: Conform {
891            clauses: &[Clause {
892                verdict: Conformance::Mandatory,
893                when: Condition::Any(&[
894                    Condition::Feature(1),
895                    Condition::Feature(2),
896                    Condition::Feature(3),
897                ]),
898            }],
899        },
900    },
901    Command {
902        id: 0x01,
903        name: "MPTZRelativeMove",
904        to_server: true,
905        response: None,
906        access: Access::invoke(Privilege::Operate),
907        conform: Conform {
908            clauses: &[Clause {
909                verdict: Conformance::Mandatory,
910                when: Condition::Any(&[
911                    Condition::Feature(1),
912                    Condition::Feature(2),
913                    Condition::Feature(3),
914                ]),
915            }],
916        },
917    },
918    Command {
919        id: 0x02,
920        name: "MPTZMoveToPreset",
921        to_server: true,
922        response: None,
923        access: Access::invoke(Privilege::Operate),
924        conform: Conform {
925            clauses: &[Clause {
926                verdict: Conformance::Mandatory,
927                when: Condition::Feature(4),
928            }],
929        },
930    },
931    Command {
932        id: 0x03,
933        name: "MPTZSavePreset",
934        to_server: true,
935        response: None,
936        access: Access::invoke(Privilege::Operate),
937        conform: Conform {
938            clauses: &[Clause {
939                verdict: Conformance::Mandatory,
940                when: Condition::Feature(4),
941            }],
942        },
943    },
944    Command {
945        id: 0x04,
946        name: "MPTZRemovePreset",
947        to_server: true,
948        response: None,
949        access: Access::invoke(Privilege::Operate),
950        conform: Conform {
951            clauses: &[Clause {
952                verdict: Conformance::Mandatory,
953                when: Condition::Feature(4),
954            }],
955        },
956    },
957    Command {
958        id: 0x05,
959        name: "DPTZSetViewport",
960        to_server: true,
961        response: None,
962        access: Access::invoke(Privilege::Operate),
963        conform: Conform {
964            clauses: &[Clause {
965                verdict: Conformance::Mandatory,
966                when: Condition::Feature(0),
967            }],
968        },
969    },
970    Command {
971        id: 0x06,
972        name: "DPTZRelativeMove",
973        to_server: true,
974        response: None,
975        access: Access::invoke(Privilege::Operate),
976        conform: Conform {
977            clauses: &[Clause {
978                verdict: Conformance::Optional,
979                when: Condition::Feature(0),
980            }],
981        },
982    },
983];
984
985/// Every event, with its conformance.
986pub const EVENTS: &[Event] = &[];
987
988/// The whole cluster, as the specification defines it.
989pub const CLUSTER: Cluster = Cluster {
990    id: ID,
991    name: "Camera AV Settings User Level Management",
992    revision: REVISION,
993    pics: "AVSUM",
994    derived_from: None,
995    features: FEATURES,
996    attributes: ATTRIBUTES,
997    commands: COMMANDS,
998    events: EVENTS,
999};