zigbee/zdo/
mod.rs

1use config::Config;
2
3pub mod config;
4use crate::aps::apsme::Apsme;
5
6/// provides an interface between the appication object, the device profile and
7/// the APS
8pub struct ZigbeeDevice {
9    config: Config,
10    apsme: Apsme,
11}
12
13/// zigbee network
14pub struct ZigBeeNetwork {}
15
16impl ZigbeeDevice {
17    /// creates a new instance
18    pub fn new() -> Self {
19        Self {
20            config: Config::default(),
21            apsme: Apsme::new(),
22        }
23    }
24
25    /// configures the device
26    pub fn configure(&self, _config: Config) {}
27
28    /// Indicates if the device is connected to a zigbee network
29    pub fn is_connected(&self) -> bool {
30        false // TODO: check connection state
31    }
32
33    /// scans for nearby reachable networks by sending a beacon request
34    pub fn scan_for_available_networks(&self) {
35        self.apsme.start_network_discovery();
36        // TODO: send beacon requests to actively scan for networks
37        // TODO: Beacon response (signal strenght - RSSI, network PAN ID, permit
38        // to join)
39    }
40
41    /// tries to connect to the first reachable network by sending a join
42    /// request
43    pub fn try_to_connect(&self) {
44        self.apsme.join_network();
45        // TODO: send Association request to choosen network coordinator or
46        // router TODO coordinator/router responds with an association
47        // confirmation
48    }
49
50    pub fn setup_security(&self) {
51        // TODO: exchange security keys (pre-configured trust center link keys)
52    }
53
54    pub fn send_keep_alive(&self) {}
55
56    pub fn send_data(&self, _input: &[u8]) {}
57
58    /// 2.1.3.1 - Device Discovery
59    /// is the process whereby a ZigBee device can discover other ZigBee
60    /// devices.
61    pub fn start_device_discovery(&self) {
62        match self.config.device_discovery_type {
63            config::DiscoveryType::IEEE => {
64                todo!()
65                // TODO: send IEEE address request as unicast to a particular
66                // device TODO: wait for incoming frames
67            }
68            config::DiscoveryType::NWK => {
69                todo!()
70                // TODO: send NWK address request as broadcast with the known
71                // IEEE address as data payload TODO: wait for
72                // incoming frames
73            }
74        }
75    }
76
77    /// 2.1.3.2 - Service Discovery
78    /// is the process whereby the capabilities of a given device are discovered
79    /// by other devices.
80    pub fn start_service_discovery(&self) {}
81}
82
83impl Default for ZigbeeDevice {
84    fn default() -> Self {
85        Self::new()
86    }
87}