matter_kit/clusters/generated/
target_navigator.rs1#![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
26pub const ID: ClusterId = 0x0505;
28
29pub const REVISION: u16 = 2;
32
33pub const PICS: &str = "TGTNAV";
35
36pub const FEATURES: &[Feature] = &[];
38
39pub mod attribute {
41 use crate::im::AttributeId;
42
43 pub const TARGET_LIST: AttributeId = 0x00;
45 pub const CURRENT_TARGET: AttributeId = 0x01;
47}
48
49pub mod command {
51 use crate::im::CommandId;
52
53 pub const NAVIGATE_TARGET: CommandId = 0x00;
55 pub const NAVIGATE_TARGET_RESPONSE: CommandId = 0x01;
57}
58
59pub mod event {
61 use crate::im::EventId;
62
63 pub const TARGET_UPDATED: EventId = 0x00;
65}
66
67#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
69#[repr(u8)]
70pub enum StatusEnum {
71 Success = 0,
73 TargetNotFound = 1,
75 NotAllowed = 2,
77}
78
79impl StatusEnum {
80 #[must_use]
82 pub const fn from_value(value: u8) -> Option<Self> {
83 match value {
84 0 => Some(Self::Success),
85 1 => Some(Self::TargetNotFound),
86 2 => Some(Self::NotAllowed),
87 _ => None,
88 }
89 }
90
91 #[must_use]
93 pub const fn value(self) -> u8 {
94 self as u8
95 }
96}
97
98impl ToTlv for StatusEnum {
99 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
100 self.value().to_tlv(w, tag)
101 }
102}
103
104impl<'a> FromTlv<'a> for StatusEnum {
105 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
106 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
107 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
108 }
109}
110
111#[derive(Debug, Clone, Copy, PartialEq)]
113pub struct TargetInfoStruct<'a> {
114 pub identifier: u8,
116 pub name: &'a str,
118}
119
120impl<'a> ToTlv for TargetInfoStruct<'a> {
121 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
122 w.start_structure(tag)?;
123 self.identifier.to_tlv(w, Tag::Context(0))?;
124 self.name.to_tlv(w, Tag::Context(1))?;
125 w.end_container()
126 }
127}
128
129impl<'a> FromTlv<'a> for TargetInfoStruct<'a> {
130 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
131 if element.value.container() != Some(ContainerKind::Structure) {
132 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
133 }
134 let mut identifier = None;
135 let mut name = None;
136 loop {
137 let Some(field) = reader.next_element()? else {
138 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
139 };
140 if field.value == Value::EndOfContainer {
141 break;
142 }
143 match field.tag.context() {
144 Some(0) => identifier = Some(<u8>::from_tlv(reader, &field)?),
145 Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
146 _ => reader.skip_value(&field)?,
150 }
151 }
152 Ok(Self {
153 identifier: identifier.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
154 name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
155 })
156 }
157}
158
159#[derive(Debug, Clone, Copy, PartialEq)]
161pub struct NavigateTargetFields<'a> {
162 pub target: u8,
164 pub data: Option<&'a str>,
166}
167
168impl<'a> ToTlv for NavigateTargetFields<'a> {
169 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
170 w.start_structure(tag)?;
171 self.target.to_tlv(w, Tag::Context(0))?;
172 if let Some(value) = &self.data {
173 value.to_tlv(w, Tag::Context(1))?;
174 }
175 w.end_container()
176 }
177}
178
179impl<'a> FromTlv<'a> for NavigateTargetFields<'a> {
180 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
181 if element.value.container() != Some(ContainerKind::Structure) {
182 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
183 }
184 let mut target = None;
185 let mut data = None;
186 loop {
187 let Some(field) = reader.next_element()? else {
188 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
189 };
190 if field.value == Value::EndOfContainer {
191 break;
192 }
193 match field.tag.context() {
194 Some(0) => target = Some(<u8>::from_tlv(reader, &field)?),
195 Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
196 _ => reader.skip_value(&field)?,
200 }
201 }
202 Ok(Self {
203 target: target.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
204 data,
205 })
206 }
207}
208
209#[derive(Debug, Clone, Copy, PartialEq)]
211pub struct NavigateTargetResponseFields<'a> {
212 pub status: StatusEnum,
214 pub data: Option<&'a str>,
216}
217
218impl<'a> ToTlv for NavigateTargetResponseFields<'a> {
219 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
220 w.start_structure(tag)?;
221 self.status.to_tlv(w, Tag::Context(0))?;
222 if let Some(value) = &self.data {
223 value.to_tlv(w, Tag::Context(1))?;
224 }
225 w.end_container()
226 }
227}
228
229impl<'a> FromTlv<'a> for NavigateTargetResponseFields<'a> {
230 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
231 if element.value.container() != Some(ContainerKind::Structure) {
232 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
233 }
234 let mut status = None;
235 let mut data = None;
236 loop {
237 let Some(field) = reader.next_element()? else {
238 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
239 };
240 if field.value == Value::EndOfContainer {
241 break;
242 }
243 match field.tag.context() {
244 Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
245 Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
246 _ => reader.skip_value(&field)?,
250 }
251 }
252 Ok(Self {
253 status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
254 data,
255 })
256 }
257}
258
259pub const ATTRIBUTES: &[Attribute] = &[
261 Attribute {
262 id: 0x0000,
263 name: "TargetList",
264 kind: "list[TargetInfoStruct]",
265 access: Access::read_only(Privilege::View),
266 qualities: AttributeQualities::empty(),
267 reporting: Reporting::OnChange,
268 conform: Conform::MANDATORY,
269 },
270 Attribute {
271 id: 0x0001,
272 name: "CurrentTarget",
273 kind: "uint8",
274 access: Access::read_only(Privilege::View),
275 qualities: AttributeQualities::empty(),
276 reporting: Reporting::OnChange,
277 conform: Conform::OPTIONAL,
278 },
279];
280
281pub const COMMANDS: &[Command] = &[
283 Command {
284 id: 0x00,
285 name: "NavigateTarget",
286 to_server: true,
287 response: Some(0x01),
288 access: Access::invoke(Privilege::Operate),
289 conform: Conform::MANDATORY,
290 },
291 Command {
292 id: 0x01,
293 name: "NavigateTargetResponse",
294 to_server: false,
295 response: None,
296 access: Access::invoke(Privilege::Operate),
297 conform: Conform::MANDATORY,
298 },
299];
300
301pub const EVENTS: &[Event] = &[Event {
303 id: 0x00,
304 name: "TargetUpdated",
305 priority: EventPriority::Info,
306 access: Access::read_only(Privilege::View),
307 conform: Conform::OPTIONAL,
308}];
309
310pub const CLUSTER: Cluster = Cluster {
312 id: ID,
313 name: "Target Navigator",
314 revision: REVISION,
315 pics: "TGTNAV",
316 derived_from: None,
317 features: FEATURES,
318 attributes: ATTRIBUTES,
319 commands: COMMANDS,
320 events: EVENTS,
321};