matter-kit 0.3.0

Matter (CSA smart-home standard) protocol implementation in Rust: no_std, no-alloc, executor-agnostic
Documentation
// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
//
// Ethernet Network Diagnostics — cluster 0x0037.
//
// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
// carries the CSA's own copyright notice and is not redistributable.

//! Ethernet Network Diagnostics (cluster `0x0037`, revision 1).
//!
//! 10 identifiers, 2 feature bits, and the specification's own conformance for
//! every element. `CLUSTER` is the whole table.

#![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,
};

/// The cluster id.
pub const ID: ClusterId = 0x0037;

/// The highest revision the specification's history defines — what `ClusterRevision`
/// must report (Core §7.13.1).
pub const REVISION: u16 = 1;

/// The PICS code, which a certification declaration names the cluster by.
pub const PICS: &str = "DGETH";

/// The `FeatureMap` bits (Core §7.13.2).
///
/// A feature has conformance of its own: a device may not claim one the
/// specification forbids it alongside another.
pub mod feature {
    /// Node makes available the counts for the number of received and transmitted packets on the ethernet interface.
    ///
    /// Code `PKTCNT`, bit 0.
    pub const PACKET_COUNTS: u32 = 1 << 0;
    /// Node makes available the counts for the number of errors that have occurred during the reception and transmission of packets on the ethernet interface.
    ///
    /// Code `ERRCNT`, bit 1.
    pub const ERROR_COUNTS: u32 = 1 << 1;
}

/// Every feature bit, with its conformance.
pub const FEATURES: &[Feature] = &[
    Feature {
        bit: 0,
        code: "PKTCNT",
        name: "PacketCounts",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 1,
        code: "ERRCNT",
        name: "ErrorCounts",
        conform: Conform::OPTIONAL,
    },
];

/// The attribute ids.
pub mod attribute {
    use crate::im::AttributeId;

    /// `PHYRate`.
    pub const PHY_RATE: AttributeId = 0x00;
    /// `FullDuplex`.
    pub const FULL_DUPLEX: AttributeId = 0x01;
    /// `PacketRxCount`.
    pub const PACKET_RX_COUNT: AttributeId = 0x02;
    /// `PacketTxCount`.
    pub const PACKET_TX_COUNT: AttributeId = 0x03;
    /// `TxErrCount`.
    pub const TX_ERR_COUNT: AttributeId = 0x04;
    /// `CollisionCount`.
    pub const COLLISION_COUNT: AttributeId = 0x05;
    /// `OverrunCount`.
    pub const OVERRUN_COUNT: AttributeId = 0x06;
    /// `CarrierDetect`.
    pub const CARRIER_DETECT: AttributeId = 0x07;
    /// `TimeSinceReset`.
    pub const TIME_SINCE_RESET: AttributeId = 0x08;
}

/// The command ids.
pub mod command {
    use crate::im::CommandId;

    /// `ResetCounts`.
    pub const RESET_COUNTS: CommandId = 0x00;
}

/// `PHYRateEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum PHYRateEnum {
    /// PHY rate is 10Mbps
    Rate10M = 0,
    /// PHY rate is 100Mbps
    Rate100M = 1,
    /// PHY rate is 1Gbps
    Rate1G = 2,
    /// PHY rate is 2.5Gbps
    Rate25G = 3,
    /// PHY rate is 5Gbps
    Rate5G = 4,
    /// PHY rate is 10Gbps
    Rate10G = 5,
    /// PHY rate is 40Gbps
    Rate40G = 6,
    /// PHY rate is 100Gbps
    Rate100G = 7,
    /// PHY rate is 200Gbps
    Rate200G = 8,
    /// PHY rate is 400Gbps
    Rate400G = 9,
}

impl PHYRateEnum {
    /// Reads a wire value, or `None` for one this revision does not define.
    #[must_use]
    pub const fn from_value(value: u8) -> Option<Self> {
        match value {
            0 => Some(Self::Rate10M),
            1 => Some(Self::Rate100M),
            2 => Some(Self::Rate1G),
            3 => Some(Self::Rate25G),
            4 => Some(Self::Rate5G),
            5 => Some(Self::Rate10G),
            6 => Some(Self::Rate40G),
            7 => Some(Self::Rate100G),
            8 => Some(Self::Rate200G),
            9 => Some(Self::Rate400G),
            _ => None,
        }
    }

    /// Its wire value.
    #[must_use]
    pub const fn value(self) -> u8 {
        self as u8
    }
}

impl ToTlv for PHYRateEnum {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        self.value().to_tlv(w, tag)
    }
}

impl<'a> FromTlv<'a> for PHYRateEnum {
    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))
    }
}

/// Every attribute the specification defines, with its conformance.
pub const ATTRIBUTES: &[Attribute] = &[
    Attribute {
        id: 0x0000,
        name: "PHYRate",
        kind: "PHYRateEnum",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE,
        reporting: Reporting::OnChange,
        conform: Conform::OPTIONAL,
    },
    Attribute {
        id: 0x0001,
        name: "FullDuplex",
        kind: "bool",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE,
        reporting: Reporting::OnChange,
        conform: Conform::OPTIONAL,
    },
    Attribute {
        id: 0x0002,
        name: "PacketRxCount",
        kind: "uint64",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::ChangesOmitted,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(0),
            }],
        },
    },
    Attribute {
        id: 0x0003,
        name: "PacketTxCount",
        kind: "uint64",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::ChangesOmitted,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(0),
            }],
        },
    },
    Attribute {
        id: 0x0004,
        name: "TxErrCount",
        kind: "uint64",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::ChangesOmitted,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(1),
            }],
        },
    },
    Attribute {
        id: 0x0005,
        name: "CollisionCount",
        kind: "uint64",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::ChangesOmitted,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(1),
            }],
        },
    },
    Attribute {
        id: 0x0006,
        name: "OverrunCount",
        kind: "uint64",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::ChangesOmitted,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(1),
            }],
        },
    },
    Attribute {
        id: 0x0007,
        name: "CarrierDetect",
        kind: "bool",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE,
        reporting: Reporting::ChangesOmitted,
        conform: Conform::OPTIONAL,
    },
    Attribute {
        id: 0x0008,
        name: "TimeSinceReset",
        kind: "uint64",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::ChangesOmitted,
        conform: Conform::OPTIONAL,
    },
];

/// Every command, with its conformance.
pub const COMMANDS: &[Command] = &[Command {
    id: 0x00,
    name: "ResetCounts",
    to_server: true,
    response: None,
    access: Access::invoke(Privilege::Manage),
    conform: Conform {
        clauses: &[Clause {
            verdict: Conformance::Mandatory,
            when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
        }],
    },
}];

/// Every event, with its conformance.
pub const EVENTS: &[Event] = &[];

/// The whole cluster, as the specification defines it.
pub const CLUSTER: Cluster = Cluster {
    id: ID,
    name: "Ethernet Network Diagnostics",
    revision: REVISION,
    pics: "DGETH",
    derived_from: None,
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};