Skip to main content

zwave_serial/
function.rs

1//! Serial API function ids.
2
3/// A Serial API function id.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
5pub struct FunctionId(pub u8);
6
7impl From<FunctionId> for u8 {
8    fn from(f: FunctionId) -> u8 {
9        f.0
10    }
11}
12
13macro_rules! functions {
14    ($($name:ident = $v:expr, $doc:literal;)*) => {
15        impl FunctionId {
16            $(#[doc = $doc] pub const $name: FunctionId = FunctionId($v);)*
17
18            /// The function's name, for logs.
19            pub fn name(self) -> &'static str {
20                match self.0 {
21                    $($v => stringify!($name),)*
22                    _ => "UNKNOWN",
23                }
24            }
25        }
26    };
27}
28
29functions! {
30    GET_INIT_DATA = 0x02, "Serial API init data: API version, capabilities, node list, chip.";
31    SET_APPLICATION_NODE_INFO = 0x03, "Sets the node information frame the controller sends.";
32    APPLICATION_COMMAND_HANDLER = 0x04, "A command class frame received from a node.";
33    GET_CONTROLLER_CAPABILITIES = 0x05, "Controller role flags (primary, SIS, SUC).";
34    SET_SERIAL_API_TIMEOUTS = 0x06, "Serial API ACK and byte timeouts.";
35    GET_SERIAL_API_CAPABILITIES = 0x07, "Firmware version, manufacturer, product and supported functions.";
36    SOFT_RESET = 0x08, "Restarts the controller firmware.";
37    GET_PROTOCOL_VERSION = 0x09, "Z-Wave protocol version.";
38    SERIAL_API_STARTED = 0x0a, "Sent by the controller after it starts.";
39    SERIAL_API_SETUP = 0x0b, "Serial API setup subcommands (TX status report, region, power).";
40    SEND_NODE_INFORMATION = 0x12, "Broadcasts or sends the controller's node information frame.";
41    SEND_DATA = 0x13, "Sends a command class frame to a node.";
42    SEND_DATA_MULTICAST = 0x14, "Sends a command class frame to several nodes.";
43    GET_CONTROLLER_VERSION = 0x15, "Library version string and library type.";
44    SEND_DATA_ABORT = 0x16, "Aborts the SendData in progress.";
45    GET_RANDOM = 0x1c, "Random bytes from the chip.";
46    GET_CONTROLLER_ID = 0x20, "Home id and own node id.";
47    GET_NVM_ID = 0x29, "External NVM manufacturer, type and size (500 series).";
48    EXT_NVM_READ_LONG_BUFFER = 0x2a, "Reads from the external NVM (500 series).";
49    NVM_OPERATIONS = 0x2e, "NVM backup and restore (700 and 800 series, 16-bit offsets).";
50    GET_BACKGROUND_RSSI = 0x3b, "Background noise per channel.";
51    EXTENDED_NVM_OPERATIONS = 0x3d, "NVM backup and restore (32-bit offsets).";
52    REMOVE_NODE_ID_FROM_NETWORK = 0x3f, "Removes a specific node id (exclusion).";
53    GET_NODE_PROTOCOL_INFO = 0x41, "Listening, routing, security and device class of a node.";
54    SET_DEFAULT = 0x42, "Resets the controller to factory defaults (new home id).";
55    ASSIGN_RETURN_ROUTE = 0x46, "Assigns a return route from a node to another.";
56    DELETE_RETURN_ROUTE = 0x47, "Deletes a node's return routes.";
57    REQUEST_NODE_NEIGHBOR_UPDATE = 0x48, "Asks a node to rediscover its neighbors.";
58    APPLICATION_UPDATE = 0x49, "Node information and SmartStart events.";
59    ADD_NODE_TO_NETWORK = 0x4a, "Inclusion.";
60    REMOVE_NODE_FROM_NETWORK = 0x4b, "Exclusion.";
61    ASSIGN_SUC_RETURN_ROUTE = 0x51, "Assigns a return route to the SUC.";
62    SET_SUC_NODE_ID = 0x54, "Makes a node the SUC/SIS.";
63    GET_SUC_NODE_ID = 0x56, "The SUC's node id.";
64    REQUEST_NODE_INFO = 0x60, "Asks a node for its node information frame.";
65    REMOVE_FAILED_NODE = 0x61, "Removes a node that no longer responds.";
66    IS_FAILED_NODE = 0x62, "Whether the controller considers a node failed.";
67    REPLACE_FAILED_NODE = 0x63, "Includes a new node in a failed node's id.";
68    GET_ROUTING_INFO = 0x80, "A node's neighbor table.";
69    GET_PRIORITY_ROUTE = 0x92, "A node's priority route.";
70    SET_PRIORITY_ROUTE = 0x93, "Sets a node's priority route.";
71    BRIDGE_APPLICATION_COMMAND_HANDLER = 0xa8, "A command class frame received, bridge format.";
72    SEND_DATA_BRIDGE = 0xa9, "SendData from a virtual node.";
73    GET_LONG_RANGE_NODES = 0xda, "Long Range node list.";
74    GET_LONG_RANGE_CHANNEL = 0xdb, "Long Range channel.";
75    SET_LONG_RANGE_CHANNEL = 0xdc, "Sets the Long Range channel.";
76}
77
78impl std::fmt::Display for FunctionId {
79    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80        write!(f, "{}({:#04x})", self.name(), self.0)
81    }
82}