ezsp 7.3.1

Ember ZNet Serial Protocol
Documentation
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
use core::future::Future;

use crate::ember::multi_phy::{nwk, radio};
use crate::ember::{
    Eui64, MAX_END_DEVICE_CHILDREN, NodeId, PerDeviceDutyCycle, beacon, child, concentrator,
    duty_cycle, neighbor, network, node, route,
};
use crate::error::Error;
use crate::ezsp::network::{InitBitmask, scan};
use crate::frame::parameters::networking::{
    child_id, clear_stored_beacons, energy_scan_request, find_and_rejoin_network,
    find_unused_pan_id, form_network, get_child_data, get_current_duty_cycle,
    get_duty_cycle_limits, get_duty_cycle_state, get_first_beacon, get_logical_channel,
    get_neighbor, get_neighbor_frame_counter, get_network_parameters, get_next_beacon,
    get_num_stored_beacons, get_parent_child_parameters, get_radio_channel, get_radio_parameters,
    get_route_table_entry, get_routing_shortcut_threshold, get_source_route_table_entry,
    get_source_route_table_filled_size, get_source_route_table_total_size, id, join_network,
    join_network_directly, leave_network, multi_phy_set_radio_channel, multi_phy_set_radio_power,
    multi_phy_start, multi_phy_stop, neighbor_count, network_init, network_state, permit_joining,
    send_link_power_delta_request, set_broken_route_error_code, set_child_data, set_concentrator,
    set_duty_cycle_limits_in_stack, set_logical_and_radio_channel, set_manufacturer_code,
    set_neighbor_frame_counter, set_power_descriptor, set_radio_channel,
    set_radio_ieee802154_cca_mode, set_radio_power, set_routing_shortcut_threshold, start_scan,
    stop_scan,
};
use crate::transport::Transport;

/// The `Networking` trait provides an interface for the networking features.
pub trait Networking {
    /// Convert a child index to a node ID.
    fn child_id(
        &mut self,
        child_index: u8,
    ) -> impl Future<Output = Result<Option<NodeId>, Error>> + Send;

    /// Clears all cached beacons that have been collected from a scan.
    fn clear_stored_beacons(&mut self) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sends a ZDO energy scan request.
    ///
    /// This request may only be sent by the current network manager and must be unicast, not broadcast.
    fn energy_scan_request(
        &mut self,
        target: NodeId,
        scan_channels: u32,
        scan_duration: u8,
        scan_count: u16,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// The application may call this function when contact with the network has been lost.
    ///
    /// The most common usage case is when an end device can no longer communicate with its parent
    /// and wishes to find a new one. Another case is when a device has missed a Network Key update
    /// and no longer has the current Network Key.
    ///
    /// The stack will call `ezspStackStatusHandler` to indicate that the network is down,
    /// then try to re-establish contact with the network by performing an active scan,
    /// choosing a network with matching extended pan id, and sending a Zigbee network rejoin request.
    /// A second call to the `ezspStackStatusHandler` callback indicates either the success or the
    /// failure of the attempt. The process takes approximately 150 milliseconds per channel to complete.
    ///
    /// This call replaces the emberMobileNodeHasMoved API from `EmberZNet` 2.x,
    /// which used MAC association and consequently took half a second longer to complete.
    fn find_and_rejoin_network(
        &mut self,
        have_current_network_key: bool,
        channel_mask: u32,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// This function starts a series of scans which will return an available panId.
    fn find_unused_pan_id(
        &mut self,
        channel_mask: u32,
        duration: u8,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Forms a new network by becoming the coordinator.
    fn form_network(
        &mut self,
        parameters: network::Parameters,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Returns information about a child of the local node.
    fn get_child_data(
        &mut self,
        index: u8,
    ) -> impl Future<Output = Result<child::Data, Error>> + Send;

    /// Returns the duty cycle of the stack's connected children that are being monitored, up to `max_devices`.
    ///
    /// It indicates the amount of overall duty cycle they have consumed (up to the suspend limit).
    /// The first entry is always the local stack's nodeId, and thus the total aggregate duty cycle
    /// for the device. The passed pointer arrayOfDeviceDutyCycles MUST have space for `max_devices`.
    fn get_current_duty_cycle(
        &mut self,
        max_devices: u8,
    ) -> impl Future<
        Output = Result<heapless::Vec<PerDeviceDutyCycle, MAX_END_DEVICE_CHILDREN>, Error>,
    > + Send;

    /// Obtains the current duty cycle limits that were previously set by a call to
    /// [`set_duty_cycle_limits_in_stack()`](Self::set_duty_cycle_limits_in_stack),
    /// or the defaults set by the stack if no set call was made.
    fn get_duty_cycle_limits(
        &mut self,
    ) -> impl Future<Output = Result<duty_cycle::Limits, Error>> + Send;

    /// Obtains the current duty cycle state.
    fn get_duty_cycle_state(
        &mut self,
    ) -> impl Future<Output = Result<duty_cycle::State, Error>> + Send;

    /// Returns the first beacon in the cache.
    ///
    /// Beacons are stored in cache after issuing an active scan.
    fn get_first_beacon(&mut self) -> impl Future<Output = Result<beacon::Iterator, Error>> + Send;

    /// Get the logical channel from the ZLL stack.
    fn get_logical_channel(&mut self) -> impl Future<Output = Result<u8, Error>> + Send;

    /// Returns the neighbor table entry at the given index.
    ///
    /// The number of active neighbors can be obtained using the
    /// [`neighbor_count()`](Self::neighbor_count) command.
    fn get_neighbor(
        &mut self,
        index: u8,
    ) -> impl Future<Output = Result<neighbor::TableEntry, Error>> + Send;

    /// Return counter status depending on whether the frame counter of the node is found in the
    /// neighbor or child table.
    ///
    /// This function gets the last received frame counter as found in the Network Auxiliary header
    /// for the specified neighbor or child
    fn get_neighbor_frame_counter(
        &mut self,
        eui64: Eui64,
    ) -> impl Future<Output = Result<u32, Error>> + Send;

    /// Returns the current network parameters.
    fn get_network_parameters(
        &mut self,
    ) -> impl Future<Output = Result<(node::Type, network::Parameters), Error>> + Send;

    /// Returns the next beacon in the cache.
    ///
    /// Beacons are stored in cache after issuing an active scan.
    fn get_next_beacon(&mut self) -> impl Future<Output = Result<beacon::Data, Error>> + Send;

    /// Returns the number of cached beacons that have been collected from a scan.
    fn get_num_stored_beacons(&mut self) -> impl Future<Output = Result<u8, Error>> + Send;

    /// Returns information about the children of the local node and the parent of the local node.
    fn get_parent_child_parameters(
        &mut self,
    ) -> impl Future<Output = Result<get_parent_child_parameters::Response, Error>> + Send;

    /// Gets the channel in use for sending and receiving messages.
    fn get_radio_channel(&mut self) -> impl Future<Output = Result<u8, Error>> + Send;

    /// Returns the current radio parameters based on phy index.
    fn get_radio_parameters(
        &mut self,
        phy_index: u8,
    ) -> impl Future<Output = Result<radio::Parameters, Error>> + Send;

    /// Returns the route table entry at the given index.
    ///
    /// The route table size can be obtained using the
    /// [`get_configuration_value()`](crate::Configuration::get_configuration_value) command.
    fn get_route_table_entry(
        &mut self,
        index: u8,
    ) -> impl Future<Output = Result<route::TableEntry, Error>> + Send;

    /// Gets the routing shortcut threshold used to differentiate between directly using a neighbor
    /// vs. performing routing.
    fn get_routing_shortcut_threshold(&mut self) -> impl Future<Output = Result<u8, Error>> + Send;

    /// Returns information about a source route table entry.
    fn get_source_route_table_entry(
        &mut self,
        index: u8,
    ) -> impl Future<Output = Result<get_source_route_table_entry::Entry, Error>> + Send;

    /// Returns the number of filled entries in source route table.
    fn get_source_route_table_filled_size(
        &mut self,
    ) -> impl Future<Output = Result<u8, Error>> + Send;

    /// Returns the source route table total size.
    fn get_source_route_table_total_size(
        &mut self,
    ) -> impl Future<Output = Result<u8, Error>> + Send;

    /// Convert a node ID to a child index.
    fn id(&mut self, child_id: NodeId) -> impl Future<Output = Result<u8, Error>> + Send;

    /// Causes the stack to associate with the network using the specified network parameters.
    ///
    /// It can take several seconds for the stack to associate with the local network.
    /// Do not send messages until the stackStatusHandler callback informs you that the stack is up.
    fn join_network(
        &mut self,
        node_type: node::Type,
        parameters: network::Parameters,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Causes the stack to associate with the network using the specified network parameters in
    /// the beacon parameter.
    ///
    /// It can take several seconds for the stack to associate with the local network.
    /// Do not send messages until the stackStatusHandler callback informs you that the stack is up.
    /// Unlike [`Self::join_network`], this function does not issue an active scan before joining.
    /// Instead, it will cause the local node to issue a MAC Association Request directly to the
    /// specified target node. It is assumed that the beacon parameter is an artifact after issuing
    /// an active scan. (For more information, see emberGetBestBeacon and emberGetNextBeacon.)
    fn join_network_directly(
        &mut self,
        local_node_type: node::Type,
        beacon: beacon::Data,
        radio_tx_power: i8,
        clear_beacons_after_network_up: bool,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Causes the stack to leave the current network.
    ///
    /// This generates a stackStatusHandler callback to indicate that the network is down.
    /// The radio will not be used until after sending a formNetwork or joinNetwork command.
    fn leave_network(&mut self) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the channel for desired phy interface to use for sending and receiving messages.
    ///
    /// For a list of available radio pages and channels, see the technical specification for the
    /// RF communication module in your Developer Kit.
    ///
    /// Note: Care should be taken when using this API,
    /// as all devices on a network must use the same page and channel.
    fn multi_phy_set_radio_channel(
        &mut self,
        phy_index: u8,
        page: u8,
        channel: u8,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the radio output power for desired phy interface at which a node is operating.
    ///
    /// Ember radios have discrete power settings. For a list of available power settings,
    /// see the technical specification for the RF communication module in your Developer Kit.
    ///
    /// Note: Care should be taken when using this api on a running network,
    /// as it will directly impact the established link qualities neighboring
    /// nodes have with the node on which it is called.
    /// This can lead to disruption of existing routes and erratic network behavior.
    fn multi_phy_set_radio_power(
        &mut self,
        phy_index: u8,
        power: i8,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// This causes to initialize the desired radio interface other than native and form a new
    /// network by becoming the coordinator with same panId as native radio network.
    fn multi_phy_start(
        &mut self,
        phy_index: u8,
        page: u8,
        channel: u8,
        power: i8,
        bitmask: nwk::Config,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// This causes to bring down the radio interface other than native.
    fn multi_phy_stop(&mut self, phy_index: u8) -> impl Future<Output = Result<(), Error>> + Send;

    /// Returns the number of active entries in the neighbor table.
    fn neighbor_count(&mut self) -> impl Future<Output = Result<u8, Error>> + Send;

    /// Resume network operation after a reboot.
    ///
    /// The node retains its original type.
    /// This should be called on startup whether the node was previously part of a network.
    /// [`Status::NotJoined`](crate::ember::Status::NotJoined) is returned if the node is not part of a network.
    /// This command accepts options to control the network initialization.
    fn network_init(
        &mut self,
        bitmask: InitBitmask,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Returns a value indicating whether the node is joining, joined to, or leaving a network.
    fn network_state(&mut self) -> impl Future<Output = Result<network::Status, Error>> + Send;

    /// Tells the stack to allow other nodes to join the network with this node as their parent.
    ///
    /// Joining is initially disabled by default.
    fn permit_joining(
        &mut self,
        duration: network::Duration,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Send Link Power Delta Request from a child to its parent.
    fn send_link_power_delta_request(&mut self) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the error code that is sent back from a router with a broken route.
    fn set_broken_route_error_code(
        &mut self,
        error_code: u8,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets child data to the child table token.
    fn set_child_data(
        &mut self,
        index: u8,
        child_data: child::Data,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Enable/disable concentrator support.
    fn set_concentrator(
        &mut self,
        parameters: Option<concentrator::Parameters>,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Set the current duty cycle limits configuration.
    ///
    /// The Default limits set by stack if this call is not made.
    fn set_duty_cycle_limits_in_stack(
        &mut self,
        limits: duty_cycle::Limits,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// This call sets the radio channel in the stack and propagates the information to the hardware.
    fn set_logical_and_radio_channel(
        &mut self,
        radio_channel: u8,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the manufacturer code to the specified value.
    ///
    /// The manufacturer code is one of the fields of the node descriptor.
    fn set_manufacturer_code(
        &mut self,
        code: u16,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the frame counter for the neighbor or child.
    fn set_neighbor_frame_counter(
        &mut self,
        eui64: Eui64,
        frame_counter: u32,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the power descriptor to the specified value.
    ///
    /// The power descriptor is a dynamic value.
    /// Therefore, you should call this function whenever the value changes.
    fn set_power_descriptor(
        &mut self,
        power_descriptor: u16,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the channel to use for sending and receiving messages.
    ///
    /// For a list of available radio channels, see the technical specification for the RF
    /// communication module in your Developer Kit.
    ///
    /// Note: Care should be taken when using this API,
    /// as all devices on a network must use the same channel.
    fn set_radio_channel(&mut self, channel: u8) -> impl Future<Output = Result<(), Error>> + Send;

    /// Set the configured 802.15.4 CCA mode in the radio.
    fn set_radio_ieee802154_cca_mode(
        &mut self,
        cca_mode: u8,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the radio output power at which a node is operating.
    ///
    /// Ember radios have discrete power settings. For a list of available power settings,
    /// see the technical specification for the RF communication module in your Developer Kit.
    ///
    /// Note: Care should be taken when using this API on a running network,
    /// as it will directly impact the established link qualities neighboring nodes have with
    /// the node on which it is called.
    /// This can lead to disruption of existing routes and erratic network behavior.
    fn set_radio_power(&mut self, power: i8) -> impl Future<Output = Result<(), Error>> + Send;

    /// Sets the routing shortcut threshold to directly use a neighbor instead of performing routing.
    fn set_routing_shortcut_threshold(
        &mut self,
        cost_thresh: u8,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// This function will start a scan.
    fn start_scan(
        &mut self,
        scan_type: scan::Type,
        channel_mask: u32,
        duration: u8,
    ) -> impl Future<Output = Result<(), Error>> + Send;

    /// Terminates a scan in progress.
    fn stop_scan(&mut self) -> impl Future<Output = Result<(), Error>> + Send;
}

impl<T> Networking for T
where
    T: Transport,
{
    async fn child_id(&mut self, child_index: u8) -> Result<Option<NodeId>, Error> {
        self.communicate(child_id::Command::new(child_index))
            .await
            .map(|response| response.child_id())
    }

    async fn clear_stored_beacons(&mut self) -> Result<(), Error> {
        self.communicate(clear_stored_beacons::Command)
            .await
            .map(drop)
    }

    async fn energy_scan_request(
        &mut self,
        target: NodeId,
        scan_channels: u32,
        scan_duration: u8,
        scan_count: u16,
    ) -> Result<(), Error> {
        self.communicate(energy_scan_request::Command::new(
            target,
            scan_channels,
            scan_duration,
            scan_count,
        ))
        .await?
        .try_into()
    }

    async fn find_and_rejoin_network(
        &mut self,
        have_current_network_key: bool,
        channel_mask: u32,
    ) -> Result<(), Error> {
        self.communicate(find_and_rejoin_network::Command::new(
            have_current_network_key,
            channel_mask,
        ))
        .await?
        .try_into()
    }

    async fn find_unused_pan_id(&mut self, channel_mask: u32, duration: u8) -> Result<(), Error> {
        self.communicate(find_unused_pan_id::Command::new(channel_mask, duration))
            .await?
            .try_into()
    }

    async fn form_network(&mut self, parameters: network::Parameters) -> Result<(), Error> {
        self.communicate(form_network::Command::new(parameters))
            .await?
            .try_into()
    }

    async fn get_child_data(&mut self, index: u8) -> Result<child::Data, Error> {
        self.communicate(get_child_data::Command::new(index))
            .await?
            .try_into()
    }

    async fn get_current_duty_cycle(
        &mut self,
        max_devices: u8,
    ) -> Result<heapless::Vec<PerDeviceDutyCycle, MAX_END_DEVICE_CHILDREN>, Error> {
        self.communicate(get_current_duty_cycle::Command::new(max_devices))
            .await?
            .try_into()
    }

    async fn get_duty_cycle_limits(&mut self) -> Result<duty_cycle::Limits, Error> {
        self.communicate(get_duty_cycle_limits::Command)
            .await?
            .try_into()
    }

    async fn get_duty_cycle_state(&mut self) -> Result<duty_cycle::State, Error> {
        self.communicate(get_duty_cycle_state::Command)
            .await?
            .try_into()
    }

    async fn get_first_beacon(&mut self) -> Result<beacon::Iterator, Error> {
        self.communicate(get_first_beacon::Command)
            .await?
            .try_into()
    }

    async fn get_logical_channel(&mut self) -> Result<u8, Error> {
        self.communicate(get_logical_channel::Command)
            .await
            .map(|response| response.logical_channel())
    }

    async fn get_neighbor(&mut self, index: u8) -> Result<neighbor::TableEntry, Error> {
        self.communicate(get_neighbor::Command::new(index))
            .await?
            .try_into()
    }

    async fn get_neighbor_frame_counter(&mut self, eui64: Eui64) -> Result<u32, Error> {
        self.communicate(get_neighbor_frame_counter::Command::new(eui64))
            .await?
            .try_into()
    }

    async fn get_network_parameters(&mut self) -> Result<(node::Type, network::Parameters), Error> {
        self.communicate(get_network_parameters::Command)
            .await?
            .try_into()
    }

    async fn get_next_beacon(&mut self) -> Result<beacon::Data, Error> {
        self.communicate(get_next_beacon::Command).await?.try_into()
    }

    async fn get_num_stored_beacons(&mut self) -> Result<u8, Error> {
        self.communicate(get_num_stored_beacons::Command)
            .await
            .map(|response| response.num_beacons())
    }

    async fn get_parent_child_parameters(
        &mut self,
    ) -> Result<get_parent_child_parameters::Response, Error> {
        self.communicate(get_parent_child_parameters::Command).await
    }

    async fn get_radio_channel(&mut self) -> Result<u8, Error> {
        self.communicate(get_radio_channel::Command)
            .await
            .map(|response| response.channel())
    }

    async fn get_radio_parameters(&mut self, phy_index: u8) -> Result<radio::Parameters, Error> {
        self.communicate(get_radio_parameters::Command::new(phy_index))
            .await?
            .try_into()
    }

    async fn get_route_table_entry(&mut self, index: u8) -> Result<route::TableEntry, Error> {
        self.communicate(get_route_table_entry::Command::new(index))
            .await?
            .try_into()
    }

    async fn get_routing_shortcut_threshold(&mut self) -> Result<u8, Error> {
        self.communicate(get_routing_shortcut_threshold::Command)
            .await
            .map(|response| response.routing_shortcut_thresh())
    }

    async fn get_source_route_table_entry(
        &mut self,
        index: u8,
    ) -> Result<get_source_route_table_entry::Entry, Error> {
        self.communicate(get_source_route_table_entry::Command::new(index))
            .await?
            .try_into()
    }

    async fn get_source_route_table_filled_size(&mut self) -> Result<u8, Error> {
        self.communicate(get_source_route_table_filled_size::Command)
            .await
            .map(|response| response.source_route_table_filled_size())
    }

    async fn get_source_route_table_total_size(&mut self) -> Result<u8, Error> {
        self.communicate(get_source_route_table_total_size::Command)
            .await
            .map(|response| response.source_route_table_total_size())
    }

    async fn id(&mut self, child_id: NodeId) -> Result<u8, Error> {
        self.communicate(id::Command::new(child_id))
            .await
            .map(|response| response.child_index())
    }

    async fn join_network(
        &mut self,
        node_type: node::Type,
        parameters: network::Parameters,
    ) -> Result<(), Error> {
        self.communicate(join_network::Command::new(node_type, parameters))
            .await?
            .try_into()
    }

    async fn join_network_directly(
        &mut self,
        local_node_type: node::Type,
        beacon: beacon::Data,
        radio_tx_power: i8,
        clear_beacons_after_network_up: bool,
    ) -> Result<(), Error> {
        self.communicate(join_network_directly::Command::new(
            local_node_type,
            beacon,
            radio_tx_power,
            clear_beacons_after_network_up,
        ))
        .await?
        .try_into()
    }

    async fn leave_network(&mut self) -> Result<(), Error> {
        self.communicate(leave_network::Command).await?.try_into()
    }

    async fn multi_phy_set_radio_channel(
        &mut self,
        phy_index: u8,
        page: u8,
        channel: u8,
    ) -> Result<(), Error> {
        self.communicate(multi_phy_set_radio_channel::Command::new(
            phy_index, page, channel,
        ))
        .await?
        .try_into()
    }

    async fn multi_phy_set_radio_power(&mut self, phy_index: u8, power: i8) -> Result<(), Error> {
        self.communicate(multi_phy_set_radio_power::Command::new(phy_index, power))
            .await?
            .try_into()
    }

    async fn multi_phy_start(
        &mut self,
        phy_index: u8,
        page: u8,
        channel: u8,
        power: i8,
        bitmask: nwk::Config,
    ) -> Result<(), Error> {
        self.communicate(multi_phy_start::Command::new(
            phy_index, page, channel, power, bitmask,
        ))
        .await?
        .try_into()
    }

    async fn multi_phy_stop(&mut self, phy_index: u8) -> Result<(), Error> {
        self.communicate(multi_phy_stop::Command::new(phy_index))
            .await?
            .try_into()
    }

    async fn neighbor_count(&mut self) -> Result<u8, Error> {
        self.communicate(neighbor_count::Command)
            .await
            .map(|response| response.value())
    }

    async fn network_init(&mut self, bitmask: InitBitmask) -> Result<(), Error> {
        self.communicate(network_init::Command::new(bitmask))
            .await?
            .try_into()
    }

    async fn network_state(&mut self) -> Result<network::Status, Error> {
        self.communicate(network_state::Command).await?.try_into()
    }

    async fn permit_joining(&mut self, duration: network::Duration) -> Result<(), Error> {
        self.communicate(permit_joining::Command::new(duration))
            .await?
            .try_into()
    }

    async fn send_link_power_delta_request(&mut self) -> Result<(), Error> {
        self.communicate(send_link_power_delta_request::Command)
            .await?
            .try_into()
    }

    async fn set_broken_route_error_code(&mut self, error_code: u8) -> Result<(), Error> {
        self.communicate(set_broken_route_error_code::Command::new(error_code))
            .await?
            .try_into()
    }

    async fn set_child_data(&mut self, index: u8, child_data: child::Data) -> Result<(), Error> {
        self.communicate(set_child_data::Command::new(index, child_data))
            .await?
            .try_into()
    }

    async fn set_concentrator(
        &mut self,
        parameters: Option<concentrator::Parameters>,
    ) -> Result<(), Error> {
        self.communicate(set_concentrator::Command::from(parameters))
            .await?
            .try_into()
    }

    async fn set_duty_cycle_limits_in_stack(
        &mut self,
        limits: duty_cycle::Limits,
    ) -> Result<(), Error> {
        self.communicate(set_duty_cycle_limits_in_stack::Command::from(limits))
            .await?
            .try_into()
    }

    async fn set_logical_and_radio_channel(&mut self, radio_channel: u8) -> Result<(), Error> {
        self.communicate(set_logical_and_radio_channel::Command::new(radio_channel))
            .await?
            .try_into()
    }

    async fn set_manufacturer_code(&mut self, code: u16) -> Result<(), Error> {
        self.communicate(set_manufacturer_code::Command::new(code))
            .await
            .map(drop)
    }

    async fn set_neighbor_frame_counter(
        &mut self,
        eui64: Eui64,
        frame_counter: u32,
    ) -> Result<(), Error> {
        self.communicate(set_neighbor_frame_counter::Command::new(
            eui64,
            frame_counter,
        ))
        .await?
        .try_into()
    }

    async fn set_power_descriptor(&mut self, power_descriptor: u16) -> Result<(), Error> {
        self.communicate(set_power_descriptor::Command::new(power_descriptor))
            .await
            .map(drop)
    }

    async fn set_radio_channel(&mut self, channel: u8) -> Result<(), Error> {
        self.communicate(set_radio_channel::Command::new(channel))
            .await?
            .try_into()
    }

    async fn set_radio_ieee802154_cca_mode(&mut self, cca_mode: u8) -> Result<(), Error> {
        self.communicate(set_radio_ieee802154_cca_mode::Command::new(cca_mode))
            .await?
            .try_into()
    }

    async fn set_radio_power(&mut self, power: i8) -> Result<(), Error> {
        self.communicate(set_radio_power::Command::new(power))
            .await?
            .try_into()
    }

    async fn set_routing_shortcut_threshold(&mut self, cost_thresh: u8) -> Result<(), Error> {
        self.communicate(set_routing_shortcut_threshold::Command::new(cost_thresh))
            .await?
            .try_into()
    }

    async fn start_scan(
        &mut self,
        scan_type: scan::Type,
        channel_mask: u32,
        duration: u8,
    ) -> Result<(), Error> {
        self.communicate(start_scan::Command::new(scan_type, channel_mask, duration))
            .await?
            .try_into()
    }

    async fn stop_scan(&mut self) -> Result<(), Error> {
        self.communicate(stop_scan::Command).await?.try_into()
    }
}