Skip to content

Commit ebc64ad

Browse files
authored
Merge pull request #16 from thvdveld/cargo-formatting
Break long comments into lines
2 parents 2b8dfd9 + 86c906c commit ebc64ad

27 files changed

+338
-189
lines changed

dot15d4/src/csma/constants.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,44 @@
33
// Constants from section 11.3, Table 11-1, PHY constants
44
/// The maximum PSDU size (in octets) the PHY shall be able to receive.
55
pub const MAX_PHY_PACKET_SIZE: u32 = 127;
6-
/// RX-to-TX or TX-to-RX turnaround time (in symbol periods), as defined in 10.2.2 and 10.2.3.
6+
/// RX-to-TX or TX-to-RX turnaround time (in symbol periods), as defined in
7+
/// 10.2.2 and 10.2.3.
78
pub const TURNAROUND_TIME: u32 = 12;
8-
// /// The delay between the start of the SFD and the LEIP, as described in 18.6.
9-
// const A_LEIP_DELAY_TIME: u32 = 0.815 ms
109
/// The time required to perform CCA detection in symbol periods.
1110
pub const CCA_TIME: u32 = 8;
1211

12+
// /// The delay between the start of the SFD and the LEIP, as described in
13+
// /// 18.6.
14+
// const A_LEIP_DELAY_TIME: u32 = 0.815 ms
15+
1316
// Constants of section 8.4.2, Table 8-93, MAC constants
14-
/// The number of symbols forming a superframe slot when the superframe order is equal to zero, as described in 6.2.1.
17+
/// The number of symbols forming a superframe slot when the superframe order is
18+
/// equal to zero, as described in 6.2.1.
1519
pub const BASE_SLOT_DURATION: u32 = 60;
16-
/// The number of symbols forming a superframe when the superframe order is equal to zero.
20+
/// The number of symbols forming a superframe when the superframe order is
21+
/// equal to zero.
1722
pub const BASE_SUPERFRAME_DURATION: u32 = BASE_SLOT_DURATION * NUM_SUPERFRAME_SLOTS;
18-
/// The number of superframes in which a GTS descriptor exists in the beacon frame of the PAN coordinator.
23+
/// The number of superframes in which a GTS descriptor exists in the beacon
24+
/// frame of the PAN coordinator.
1925
pub const GTS_DESC_PERSISTENCE_TIME: u32 = 4;
20-
/// The number of consecutive lost beacons that will cause the MAC sublayer of a receiving device to declare a loss of synchronization.
26+
/// The number of consecutive lost beacons that will cause the MAC sublayer of a
27+
/// receiving device to declare a loss of synchronization.
2128
pub const MAX_LOST_BEACONS: u32 = 4;
22-
/// The maximum size of an MPDU, in octets, that can be followed by a SIFS period.
29+
/// The maximum size of an MPDU, in octets, that can be followed by a SIFS
30+
/// period.
2331
pub const MAX_SIFS_FRAME_SIZE: u32 = 18;
24-
/// The minimum number of symbols forming the CAP. This ensures that MAC commands can still be transferred to devices when GTSs are being used.
32+
/// The minimum number of symbols forming the CAP. This ensures that MAC
33+
/// commands can still be transferred to devices when GTSs are being used.
2534
///
2635
/// An exception to this minimum shall be allowed for the accommodation of the
27-
/// temporary increase in the beacon frame length needed to perform GTS maintenance,
28-
/// as described in 7.3.1.5. Additional restrictions apply when PCA is enabled,
29-
/// as described in 6.2.5.4.
36+
/// temporary increase in the beacon frame length needed to perform GTS
37+
/// maintenance, as described in 7.3.1.5. Additional restrictions apply when PCA
38+
/// is enabled, as described in 6.2.5.4.
3039
pub const MIN_CAP_LENGTH: u32 = 440;
3140
/// The number of slots contained in any superframe.
3241
pub const NUM_SUPERFRAME_SLOTS: u32 = 440;
33-
/// The number of symbols forming the basic time period used by the CSMA-CA algorithm.
42+
/// The number of symbols forming the basic time period used by the CSMA-CA
43+
/// algorithm.
3444
pub const UNIT_BACKOFF_PERIOD: u32 = TURNAROUND_TIME + CCA_TIME;
3545
/// The number of symbols forming an RCCN superframe slot.
3646
pub const RCCN_BASE_SLOT_DURATION: u32 = 60;

dot15d4/src/csma/mod.rs

Lines changed: 91 additions & 45 deletions
Large diffs are not rendered by default.

dot15d4/src/csma/transmission.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ impl<'r, Rng: RngCore> CCABackoffStrategy<'r, Rng> {
9595
// delay periods = random(2^{BE} - 1) periods
9696
// Page 63 IEEE 802.15.4 2015 edition
9797
let max_backoff = (1u32 << *backoff_exponent) - 1;
98-
// The +1 in (max_backoff + 1) comes from the interpretation that the random() function
99-
// used in the specification includes max_backoff as a possible value. The possible
100-
// values periods now can take are: [0, max_backoff].
98+
// The +1 in (max_backoff + 1) comes from the interpretation that the random()
99+
// function used in the specification includes max_backoff as a
100+
// possible value. The possible values periods now can take are:
101+
// [0, max_backoff].
101102
let periods = rng.lock().await.next_u32() % (max_backoff + 1);
102103
let delay = MAC_UNIT_BACKOFF_DURATION * periods as usize;
103104
timer.delay_us(delay.as_us() as u32).await;

dot15d4/src/csma/user_configurable_constants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::time::Duration;
44

55
use super::constants::{SYMBOL_RATE_INV_US, UNIT_BACKOFF_PERIOD};
66

7-
// XXX These are just random numbers I picked by fair dice roll; what should they be?
7+
// XXX These are just random numbers I picked by fair dice roll; what should
8+
// they be?
89
pub const MAC_MIN_BE: u16 = 0;
910
pub const MAC_MAX_BE: u16 = 8;
1011
pub const MAC_MAX_CSMA_BACKOFFS: u16 = 16;

dot15d4/src/csma/utils.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use crate::sync::channel::Sender;
22
use crate::sync::mutex::{Mutex, MutexGuard};
33

4-
/// Acquire the lock on Mutex by repeatably calling the wants_lock channel to request access.
5-
/// The resulting guard will be made available through the out_guard and will first check if the guard is not already in our possession. If it is, spinning will be performed.
4+
/// Acquire the lock on Mutex by repeatably calling the wants_lock channel to
5+
/// request access. The resulting guard will be made available through the
6+
/// out_guard and will first check if the guard is not already in our
7+
/// possession. If it is, spinning will be performed.
68
pub async fn acquire_lock<'a, 'b, T>(
79
mutex: &'a Mutex<T>,
810
wants_lock: &Sender<'b, ()>,
@@ -12,16 +14,21 @@ pub async fn acquire_lock<'a, 'b, T>(
1214
Some(_) => (),
1315
None => {
1416
'inner: loop {
15-
// repeatably ask for the lock, as this might need a few tries to prevent deadlocks
17+
// repeatably ask for the lock, as this might need a few tries to prevent
18+
// deadlocks
1619
match mutex.try_lock() {
1720
Some(guard) => {
18-
// wants_to_transmit_signal.reset(); // reset signal, such that the receiving end may continue the next time it acquires the lock
21+
// wants_to_transmit_signal.reset();
22+
23+
// reset signal, such that the receiving end may continue the next time it
24+
// acquires the lock
1925
*out_guard = Some(guard);
2026
return;
2127
}
2228
None => {
23-
wants_lock.send_async(()).await; // Ask the receiving loop to let go of the radio
24-
// yield_now().await; // Give the receiving end time to react
29+
// Ask the receiving loop to let go of the radio
30+
wants_lock.send_async(()).await;
31+
// yield_now().await; // Give the receiving end time to react
2532
continue 'inner;
2633
}
2734
}

dot15d4/src/frame/addressing.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ impl<T: AsRef<[u8]>> AddressingFields<T> {
141141
///
142142
/// # Errors
143143
///
144-
/// This function will check the length of the buffer to ensure it is large enough to contain
145-
/// the addressing fields. If the buffer is too small, an error will be returned.
144+
/// This function will check the length of the buffer to ensure it is large
145+
/// enough to contain the addressing fields. If the buffer is too small,
146+
/// an error will be returned.
146147
pub fn new(buffer: T, fc: &FrameControl<T>) -> Result<Self> {
147148
let af = Self::new_unchecked(buffer);
148149

@@ -174,8 +175,8 @@ impl<T: AsRef<[u8]>> AddressingFields<T> {
174175
self.buffer.as_ref().len() >= expected_len
175176
}
176177

177-
/// Create a new [`AddressingFields`] reader/writer from a given buffer without checking the
178-
/// length.
178+
/// Create a new [`AddressingFields`] reader/writer from a given buffer
179+
/// without checking the length.
179180
pub fn new_unchecked(buffer: T) -> Self {
180181
Self { buffer }
181182
}

dot15d4/src/frame/frame_control.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ impl<T: AsRef<[u8]>> FrameControl<T> {
7474
Ok(fc)
7575
}
7676

77-
/// Returns `false` if the buffer is too short to contain the Frame Control field.
77+
/// Returns `false` if the buffer is too short to contain the Frame Control
78+
/// field.
7879
fn check_len(&self) -> bool {
7980
self.buffer.as_ref().len() >= 2
8081
}
8182

82-
/// Create a new [`FrameControl`] reader/writer from a given buffer without length checking.
83+
/// Create a new [`FrameControl`] reader/writer from a given buffer without
84+
/// length checking.
8385
pub fn new_unchecked(buffer: T) -> Self {
8486
Self { buffer }
8587
}

dot15d4/src/frame/ie/headers.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ pub struct HeaderInformationElement<T: AsRef<[u8]>> {
1111
}
1212

1313
impl<T: AsRef<[u8]>> HeaderInformationElement<T> {
14-
/// Create a new [`HeaderInformationElement`] reader/writer from a given buffer.
14+
/// Create a new [`HeaderInformationElement`] reader/writer from a given
15+
/// buffer.
1516
///
1617
/// # Errors
1718
///
@@ -26,12 +27,14 @@ impl<T: AsRef<[u8]>> HeaderInformationElement<T> {
2627
Ok(ie)
2728
}
2829

29-
/// Returns `false` if the buffer is too short to contain the Header Information Element.
30+
/// Returns `false` if the buffer is too short to contain the Header
31+
/// Information Element.
3032
fn check_len(&self) -> bool {
3133
self.data.as_ref().len() >= 2
3234
}
3335

34-
/// Create a new [`HeaderInformationElement`] reader/writer from a given buffer without length checking.
36+
/// Create a new [`HeaderInformationElement`] reader/writer from a given
37+
/// buffer without length checking.
3538
pub fn new_unchecked(data: T) -> Self {
3639
Self { data }
3740
}
@@ -305,7 +308,8 @@ pub struct RendezvousTime {
305308
wake_up_interval: u16,
306309
}
307310

308-
/// A reader/writer for the IEEE 802.15.4 Time Correction Header Information Element.
311+
/// A reader/writer for the IEEE 802.15.4 Time Correction Header Information
312+
/// Element.
309313
pub struct TimeCorrection<T: AsRef<[u8]>> {
310314
buffer: T,
311315
}
@@ -326,12 +330,14 @@ impl<T: AsRef<[u8]>> TimeCorrection<T> {
326330
Ok(ie)
327331
}
328332

329-
/// Returns `false` if the buffer is too short to contain the Time Correction field.
333+
/// Returns `false` if the buffer is too short to contain the Time
334+
/// Correction field.
330335
fn check_len(&self) -> bool {
331336
self.buffer.as_ref().len() >= 2
332337
}
333338

334-
/// Create a new [`TimeCorrection`] reader/writer from a given buffer without length checking.
339+
/// Create a new [`TimeCorrection`] reader/writer from a given buffer
340+
/// without length checking.
335341
pub fn new_unchecked(buffer: T) -> Self {
336342
Self { buffer }
337343
}
@@ -386,8 +392,8 @@ impl<T: AsRef<[u8]>> core::fmt::Display for TimeCorrection<T> {
386392

387393
#[frame]
388394
#[derive(Debug)]
389-
/// A reader/writer for the IEEE 802.15.4 Simplified Superframe Specification Header
390-
/// Information Element.
395+
/// A reader/writer for the IEEE 802.15.4 Simplified Superframe Specification
396+
/// Header Information Element.
391397
pub struct SimplifiedSuperframeSpecification {
392398
/// Returns the timestamp field value.
393399
timestamp: u16,
@@ -401,7 +407,8 @@ pub struct SimplifiedSuperframeSpecification {
401407

402408
#[frame]
403409
#[derive(Debug)]
404-
/// A reader/writer for the IEEE 802.15.4 Superframe Specification Header Information Element.
410+
/// A reader/writer for the IEEE 802.15.4 Superframe Specification Header
411+
/// Information Element.
405412
pub struct SuperframeSpecification {
406413
#[bits(4)]
407414
beacon_order: u8,
@@ -421,7 +428,8 @@ pub struct SuperframeSpecification {
421428

422429
#[frame]
423430
#[derive(Debug)]
424-
/// A reader/writer for the IEEE 802.15.4 CFP Specification Header Information Element.
431+
/// A reader/writer for the IEEE 802.15.4 CFP Specification Header Information
432+
/// Element.
425433
pub struct CfpSpecification {
426434
#[bits(3)]
427435
gts_count: u8,

dot15d4/src/frame/ie/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ impl<T: AsRef<[u8]>> InformationElements<T> {
2121
///
2222
/// # Errors
2323
///
24-
/// Returns an error if the buffer is too short to contain the information elements.
24+
/// Returns an error if the buffer is too short to contain the information
25+
/// elements.
2526
pub fn new(data: T) -> Result<Self> {
2627
let ie = Self::new_unchecked(data);
2728

@@ -32,7 +33,8 @@ impl<T: AsRef<[u8]>> InformationElements<T> {
3233
Ok(ie)
3334
}
3435

35-
/// Returns `false` if the buffer is too short to contain the information elements.
36+
/// Returns `false` if the buffer is too short to contain the information
37+
/// elements.
3638
fn check_len(&self) -> bool {
3739
let mut len = 0;
3840

@@ -51,7 +53,8 @@ impl<T: AsRef<[u8]>> InformationElements<T> {
5153
self.data.as_ref().len() >= len
5254
}
5355

54-
/// Create a new [`InformationElements`] reader from a given buffer without length checking.
56+
/// Create a new [`InformationElements`] reader from a given buffer without
57+
/// length checking.
5558
pub fn new_unchecked(data: T) -> Self {
5659
Self { data }
5760
}

dot15d4/src/frame/ie/nested.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ use bitflags::bitflags;
1717
/// | Length | Sub-ID | Type=1 | Content (0-2046 octets)...|
1818
/// +--------+--------+--------+---------------------------+
1919
/// ```
20-
///
2120
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
2221
pub struct NestedInformationElement<T: AsRef<[u8]>> {
2322
data: T,
2423
}
2524

2625
impl<T: AsRef<[u8]>> NestedInformationElement<T> {
27-
/// Create a new [`NestedInformationElement`] reader/writer from a given buffer.
26+
/// Create a new [`NestedInformationElement`] reader/writer from a given
27+
/// buffer.
2828
///
2929
/// # Errors
3030
///
31-
/// Returns an error if the buffer is too short to contain the nested information element.
31+
/// Returns an error if the buffer is too short to contain the nested
32+
/// information element.
3233
pub fn new(data: T) -> Result<Self> {
3334
let nested = Self::new_unchecked(data);
3435

@@ -39,7 +40,8 @@ impl<T: AsRef<[u8]>> NestedInformationElement<T> {
3940
Ok(nested)
4041
}
4142

42-
/// Returns `false` if the buffer is too short to contain the nested information element.
43+
/// Returns `false` if the buffer is too short to contain the nested
44+
/// information element.
4345
fn check_len(&self) -> bool {
4446
if self.data.as_ref().len() < 2 {
4547
return false;
@@ -50,7 +52,8 @@ impl<T: AsRef<[u8]>> NestedInformationElement<T> {
5052
self.data.as_ref().len() >= len + 2
5153
}
5254

53-
/// Create a new [`NestedInformationElement`] reader/writer from a given buffer without length checking.
55+
/// Create a new [`NestedInformationElement`] reader/writer from a given
56+
/// buffer without length checking.
5457
pub fn new_unchecked(data: T) -> Self {
5558
Self { data }
5659
}
@@ -537,27 +540,32 @@ impl<T: AsRef<[u8]>> core::fmt::Display for TschTimeslot<T> {
537540
#[derive(Debug)]
538541
pub struct TschTimeslotTimings {
539542
id: u8,
540-
/// Offset from the start of the time slot to the start of the CCA in microseconds.
543+
/// Offset from the start of the time slot to the start of the CCA in
544+
/// microseconds.
541545
cca_offset: Duration,
542546
/// Duration of the CCA in microseconds.
543547
cca: Duration,
544548
/// Radio turnaround time in microseconds.
545549
rx_tx: Duration,
546550

547-
/// Offset from the start of the time slot to the start of the TX in microseconds.
551+
/// Offset from the start of the time slot to the start of the TX in
552+
/// microseconds.
548553
tx_offset: Duration,
549554
/// Maximum transmission time for a frame in microseconds.
550555
max_tx: Duration,
551-
/// Wait time between the end of the TX and the start of the ACK RX in microseconds.
556+
/// Wait time between the end of the TX and the start of the ACK RX in
557+
/// microseconds.
552558
rx_ack_delay: Duration,
553559
/// Maximum time to wait for receiving an ACK.
554560
ack_wait: Duration,
555561

556-
/// Offset from the start of the time slot to the start of the RX in microseconds.
562+
/// Offset from the start of the time slot to the start of the RX in
563+
/// microseconds.
557564
rx_offset: Duration,
558565
/// Maximum time to wait for receiving a frame.
559566
rx_wait: Duration,
560-
/// Wait time between the end of the RX and the start of the ACK TX in microseconds.
567+
/// Wait time between the end of the RX and the start of the ACK TX in
568+
/// microseconds.
561569
tx_ack_delay: Duration,
562570
/// Maximum transmission time for an ACK in microseconds.
563571
max_ack: Duration,
@@ -1078,7 +1086,8 @@ impl<T: AsRef<[u8]>> ChannelHopping<T> {
10781086
!self.data.as_ref().is_empty()
10791087
}
10801088

1081-
/// Create a new [`ChannelHopping`] reader/writer from a given buffer without checking the length.
1089+
/// Create a new [`ChannelHopping`] reader/writer from a given buffer
1090+
/// without checking the length.
10821091
pub fn new_unchecked(data: T) -> Self {
10831092
Self { data }
10841093
}

0 commit comments

Comments
 (0)