#![allow(unused_imports)]
use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};
pub const ID: ClusterId = 0x0150;
pub const REVISION: u16 = 2;
pub const PICS: &str = "SEAR";
pub mod feature {
pub const SELECT_WHILE_RUNNING: u32 = 1 << 0;
pub const PROGRESS_REPORTING: u32 = 1 << 1;
pub const MAPS: u32 = 1 << 2;
}
pub const FEATURES: &[Feature] = &[
Feature {
bit: 0,
code: "SELRUN",
name: "SelectWhileRunning",
conform: Conform::OPTIONAL,
},
Feature {
bit: 1,
code: "PROG",
name: "ProgressReporting",
conform: Conform::OPTIONAL,
},
Feature {
bit: 2,
code: "MAPS",
name: "Maps",
conform: Conform::OPTIONAL,
},
];
pub mod attribute {
use crate::im::AttributeId;
pub const SUPPORTED_AREAS: AttributeId = 0x00;
pub const SUPPORTED_MAPS: AttributeId = 0x01;
pub const SELECTED_AREAS: AttributeId = 0x02;
pub const CURRENT_AREA: AttributeId = 0x03;
pub const ESTIMATED_END_TIME: AttributeId = 0x04;
pub const PROGRESS: AttributeId = 0x05;
}
pub mod command {
use crate::im::CommandId;
pub const SELECT_AREAS: CommandId = 0x00;
pub const SELECT_AREAS_RESPONSE: CommandId = 0x01;
pub const SKIP_AREA: CommandId = 0x02;
pub const SKIP_AREA_RESPONSE: CommandId = 0x03;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum OperationalStatusEnum {
Pending = 0,
Operating = 1,
Skipped = 2,
Completed = 3,
}
impl OperationalStatusEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Pending),
1 => Some(Self::Operating),
2 => Some(Self::Skipped),
3 => Some(Self::Completed),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for OperationalStatusEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for OperationalStatusEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum SelectAreasStatus {
Success = 0,
UnsupportedArea = 1,
InvalidInMode = 2,
InvalidSet = 3,
}
impl SelectAreasStatus {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Success),
1 => Some(Self::UnsupportedArea),
2 => Some(Self::InvalidInMode),
3 => Some(Self::InvalidSet),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for SelectAreasStatus {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for SelectAreasStatus {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum SkipAreaStatus {
Success = 0,
InvalidAreaList = 1,
InvalidInMode = 2,
InvalidSkippedArea = 3,
}
impl SkipAreaStatus {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Success),
1 => Some(Self::InvalidAreaList),
2 => Some(Self::InvalidInMode),
3 => Some(Self::InvalidSkippedArea),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for SkipAreaStatus {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for SkipAreaStatus {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AreaInfoStruct<'a> {
pub location_info: Nullable<crate::clusters::generated::globals::LocationDescriptorStruct<'a>>,
pub landmark_info: Nullable<LandmarkInfoStruct>,
}
impl<'a> ToTlv for AreaInfoStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.location_info.to_tlv(w, Tag::Context(0))?;
self.landmark_info.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AreaInfoStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut location_info = None;
let mut landmark_info = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => {
location_info = Some(<Nullable<
crate::clusters::generated::globals::LocationDescriptorStruct<'a>,
>>::from_tlv(reader, &field)?)
}
Some(1) => {
landmark_info = Some(<Nullable<LandmarkInfoStruct>>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
location_info: location_info.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
landmark_info: landmark_info.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AreaStruct<'a> {
pub area_id: u32,
pub map_id: Nullable<u32>,
pub area_info: AreaInfoStruct<'a>,
}
impl<'a> ToTlv for AreaStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.area_id.to_tlv(w, Tag::Context(0))?;
self.map_id.to_tlv(w, Tag::Context(1))?;
self.area_info.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for AreaStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut area_id = None;
let mut map_id = None;
let mut area_info = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => area_id = Some(<u32>::from_tlv(reader, &field)?),
Some(1) => map_id = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
Some(2) => area_info = Some(<AreaInfoStruct<'a>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
area_id: area_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
map_id: map_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
area_info: area_info.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LandmarkInfoStruct {
pub landmark_tag: u8,
pub relative_position_tag: Nullable<u8>,
}
impl ToTlv for LandmarkInfoStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.landmark_tag.to_tlv(w, Tag::Context(0))?;
self.relative_position_tag.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for LandmarkInfoStruct {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut landmark_tag = None;
let mut relative_position_tag = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => landmark_tag = Some(<u8>::from_tlv(reader, &field)?),
Some(1) => relative_position_tag = Some(<Nullable<u8>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
landmark_tag: landmark_tag.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
relative_position_tag: relative_position_tag
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MapStruct<'a> {
pub map_id: u32,
pub name: &'a str,
}
impl<'a> ToTlv for MapStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.map_id.to_tlv(w, Tag::Context(0))?;
self.name.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for MapStruct<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut map_id = None;
let mut name = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => map_id = Some(<u32>::from_tlv(reader, &field)?),
Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
map_id: map_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ProgressStruct {
pub area_id: u32,
pub status: OperationalStatusEnum,
pub total_operational_time: Option<Nullable<u32>>,
pub estimated_time: Option<Nullable<u32>>,
}
impl ToTlv for ProgressStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.area_id.to_tlv(w, Tag::Context(0))?;
self.status.to_tlv(w, Tag::Context(1))?;
if let Some(value) = &self.total_operational_time {
value.to_tlv(w, Tag::Context(2))?;
}
if let Some(value) = &self.estimated_time {
value.to_tlv(w, Tag::Context(3))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for ProgressStruct {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut area_id = None;
let mut status = None;
let mut total_operational_time = None;
let mut estimated_time = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => area_id = Some(<u32>::from_tlv(reader, &field)?),
Some(1) => status = Some(<OperationalStatusEnum>::from_tlv(reader, &field)?),
Some(2) => {
total_operational_time = Some(<Nullable<u32>>::from_tlv(reader, &field)?)
}
Some(3) => estimated_time = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
area_id: area_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
total_operational_time,
estimated_time,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SelectAreasFields<'a> {
pub new_areas: TlvList<'a, u32>,
}
impl<'a> ToTlv for SelectAreasFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.new_areas.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SelectAreasFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut new_areas = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => new_areas = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
new_areas: new_areas.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SelectAreasResponseFields<'a> {
pub status: SelectAreasStatus,
pub status_text: &'a str,
}
impl<'a> ToTlv for SelectAreasResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.status.to_tlv(w, Tag::Context(0))?;
self.status_text.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SelectAreasResponseFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut status = None;
let mut status_text = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => status = Some(<SelectAreasStatus>::from_tlv(reader, &field)?),
Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SkipAreaFields {
pub skipped_area: u32,
}
impl ToTlv for SkipAreaFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.skipped_area.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SkipAreaFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut skipped_area = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => skipped_area = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
skipped_area: skipped_area.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SkipAreaResponseFields<'a> {
pub status: SkipAreaStatus,
pub status_text: &'a str,
}
impl<'a> ToTlv for SkipAreaResponseFields<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.status.to_tlv(w, Tag::Context(0))?;
self.status_text.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SkipAreaResponseFields<'a> {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut status = None;
let mut status_text = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => status = Some(<SkipAreaStatus>::from_tlv(reader, &field)?),
Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "SupportedAreas",
kind: "list[AreaStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "SupportedMaps",
kind: "list[MapStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(2),
}],
},
},
Attribute {
id: 0x0002,
name: "SelectedAreas",
kind: "list[uint32]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0003,
name: "CurrentArea",
kind: "uint32",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform::DESCRIBED,
},
Attribute {
id: 0x0004,
name: "EstimatedEndTime",
kind: "epoch-s",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::Quieter,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Optional,
when: Condition::Attribute(0x0003),
}],
},
},
Attribute {
id: 0x0005,
name: "Progress",
kind: "list[ProgressStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Feature(1),
}],
},
},
];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "SelectAreas",
to_server: true,
response: Some(0x01),
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "SelectAreasResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x02,
name: "SkipArea",
to_server: true,
response: Some(0x03),
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Optional,
when: Condition::Any(&[Condition::Attribute(0x0003), Condition::Attribute(0x0005)]),
}],
},
},
Command {
id: 0x03,
name: "SkipAreaResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::Command(0x02),
}],
},
},
];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Service Area",
revision: REVISION,
pics: "SEAR",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};