1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Ember message types.
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use repr_discriminant::ReprDiscriminant;
use crate::ember::NodeId;
/// Ember incoming message type.
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, FromPrimitive)]
#[repr(u8)]
pub enum Incoming {
/// Unicast.
Unicast = 0x00,
/// Unicast reply.
UnicastReply = 0x01,
/// Multicast.
Multicast = 0x02,
/// Multicast sent by the local device.
MulticastLoopback = 0x03,
/// Broadcast.
Broadcast = 0x04,
/// Broadcast sent by the local device.
BroadcastLoopback = 0x05,
/// Many to one route request.
ManyToOneRouteRequest = 0x06,
}
impl From<Incoming> for u8 {
fn from(incoming: Incoming) -> Self {
incoming as Self
}
}
impl TryFrom<u8> for Incoming {
type Error = u8;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::from_u8(value).ok_or(value)
}
}
/// Ember outgoing message type for receiving `message_send::Handler`s.
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, FromPrimitive)]
#[repr(u8)]
pub enum Outgoing {
/// Unicast sent directly to an `EmberNodeId`.
Direct = 0x00,
/// Unicast sent using an entry in the address table.
ViaAddressTable = 0x01,
/// Unicast sent using an entry in the binding table.
ViaBinding = 0x02,
/// Multicast message.
///
/// This value is passed to `emberMessageSentHandler()` only.
/// It may not be passed to `emberSendUnicast()`.
Multicast = 0x03,
/// Broadcast message.
///
/// This value is passed to `emberMessageSentHandler()` only.
/// It may not be passed to `emberSendUnicast()`.
Broadcast = 0x04,
}
impl From<Outgoing> for u8 {
fn from(outgoing: Outgoing) -> Self {
outgoing as Self
}
}
impl TryFrom<u8> for Outgoing {
type Error = u8;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::from_u8(value).ok_or(value)
}
}
/// Ember outgoing message type for sending unicasts.
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, ReprDiscriminant)]
#[repr(u8)]
pub enum Destination {
/// Unicast sent directly to an `EmberNodeId`.
Direct(NodeId) = 0x00,
/// Unicast sent using an entry in the address table.
ViaAddressTable(u16) = 0x01,
/// Unicast sent using an entry in the binding table.
ViaBinding(u16) = 0x02,
}