Skip to main content

ezsp/ember/
node.rs

1//! Ember node type.
2
3use core::fmt::Display;
4
5use num_derive::FromPrimitive;
6
7/// Ember node type.
8#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Ord, PartialOrd, FromPrimitive)]
9#[repr(u8)]
10pub enum Type {
11    /// Device is not joined.
12    UnknownDevice = 0x00,
13    /// Will relay messages and can act as a parent to other nodes.
14    Coordinator = 0x01,
15    /// Will relay messages and can act as a parent to other nodes.
16    Router = 0x02,
17    /// Communicates only with its parent and will not relay messages.
18    EndDevice = 0x03,
19    /// An end device whose radio can be turned off to save power.
20    ///
21    /// The application must poll to receive messages.
22    SleepyEndDevice = 0x04,
23}
24
25impl Display for Type {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        match self {
28            Self::UnknownDevice => write!(f, "Unknown Device"),
29            Self::Coordinator => write!(f, "Coordinator"),
30            Self::Router => write!(f, "Router"),
31            Self::EndDevice => write!(f, "End Device"),
32            Self::SleepyEndDevice => write!(f, "Sleepy End Device"),
33        }
34    }
35}
36
37impl From<Type> for u8 {
38    fn from(typ: Type) -> Self {
39        typ as Self
40    }
41}