Skip to content

Commit

Permalink
Revert "fix: fmt"
Browse files Browse the repository at this point in the history
This reverts commit 2322985.
  • Loading branch information
SamClercky committed Feb 22, 2024
1 parent 2322985 commit b79ccd6
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 27 deletions.
12 changes: 7 additions & 5 deletions dot15d4/examples/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use dot15d4::frame::*;

fn main() {
let frame: [u8; 35] = [
0x40, 0xeb, 0xcd, 0xab, 0xff, 0xff, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x3f, 0x11, 0x88,
0x06, 0x1a, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c, 0x00, 0x01, 0xc8, 0x00, 0x01, 0x1b, 0x00,
0x40, 0xeb, 0xcd, 0xab, 0xff, 0xff, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
0x3f, 0x11, 0x88, 0x06, 0x1a, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c, 0x00, 0x01,
0xc8, 0x00, 0x01, 0x1b, 0x00,
];

let frame = Frame::new(&frame[..]).unwrap();
Expand All @@ -12,16 +13,17 @@ fn main() {
println!("{frame:#?}");

let frame = [
0x02, 0x2e, 0x37, 0xcd, 0xab, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x0f, 0xe1, 0x8f,
0x02, 0x2e, 0x37, 0xcd, 0xab, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x0f,
0xe1, 0x8f,
];
let frame = Frame::new(&frame[..]).unwrap();
println!("{frame}");
let frame = FrameRepr::parse(&frame);
println!("{frame:#?}");

let frame = [
0x41, 0xd8, 0x01, 0xcd, 0xab, 0xff, 0xff, 0xc7, 0xd9, 0xb5, 0x14, 0x00, 0x4b, 0x12, 0x00, 0x2b, 0x00, 0x00,
0x00,
0x41, 0xd8, 0x01, 0xcd, 0xab, 0xff, 0xff, 0xc7, 0xd9, 0xb5, 0x14, 0x00, 0x4b, 0x12, 0x00,
0x2b, 0x00, 0x00, 0x00,
];
let frame = Frame::new(&frame[..]).unwrap();
println!("{frame}");
Expand Down
5 changes: 3 additions & 2 deletions dot15d4/examples/tsch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ fn main() {
.init();

let frame: [u8; 35] = [
0x40, 0xeb, 0xcd, 0xab, 0xff, 0xff, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x3f, 0x11, 0x88,
0x06, 0x1a, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c, 0x00, 0x01, 0xc8, 0x00, 0x01, 0x1b, 0x00,
0x40, 0xeb, 0xcd, 0xab, 0xff, 0xff, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
0x3f, 0x11, 0x88, 0x06, 0x1a, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c, 0x00, 0x01,
0xc8, 0x00, 0x01, 0x1b, 0x00,
];

let mut dummy = DummyDevice::new();
Expand Down
14 changes: 12 additions & 2 deletions dot15d4/src/frame/ie/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ impl<T: AsRef<[u8]>> core::fmt::Display for HeaderInformationElement<T> {
write!(f, "{:?}", id)
}
HeaderElementId::SimplifiedSuperframeSpecification => {
write!(f, "{} {:?}", id, SimplifiedSuperframeSpecification::new(self.content()))
write!(
f,
"{} {:?}",
id,
SimplifiedSuperframeSpecification::new(self.content())
)
}
HeaderElementId::TimeCorrection => {
write!(f, "{} {}", id, TimeCorrection::new(self.content()))
Expand Down Expand Up @@ -271,7 +276,12 @@ impl<T: AsRef<[u8]>> TimeCorrection<T> {

impl<T: AsRef<[u8]>> core::fmt::Display for TimeCorrection<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}, nack: {}", self.time_correction(), self.nack() as usize)
write!(
f,
"{}, nack: {}",
self.time_correction(),
self.nack() as usize
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion dot15d4/src/frame/ie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ impl<T: AsRef<[u8]>> InformationElements<T> {

/// Returns an [`Iterator`] over [`PayloadInformationElement`].
pub fn payload_information_elements(&self) -> PayloadInformationElementsIterator {
let start = self.header_information_elements().map(|ie| ie.len() + 2).sum::<usize>();
let start = self
.header_information_elements()
.map(|ie| ie.len() + 2)
.sum::<usize>();

let terminated = start >= self.data.as_ref().len();

Expand Down
28 changes: 20 additions & 8 deletions dot15d4/src/frame/ie/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ impl<T: AsRef<[u8]>> TschTimeslot<T> {
u16::from_le_bytes([b[0], b[1]]) as i64
}),
time_slot_length: Duration::from_us({
let offset = if self.data.as_ref().len() == 25 { 23 } else { 24 };
let offset = if self.data.as_ref().len() == 25 {
23
} else {
24
};
let len = if self.data.as_ref().len() == 25 { 2 } else { 3 };
let b = &self.data.as_ref()[offset..][..len];
// TODO: handle the case where a 3 byte length is used.
Expand Down Expand Up @@ -623,7 +627,10 @@ impl<T: AsRef<[u8]>> TschSlotframeAndLink<T> {

/// Returns an [`Iterator`] over the [`SlotframeDescriptor`]s.
pub fn slotframe_descriptors(&self) -> SlotframeDescriptorIterator {
SlotframeDescriptorIterator::new(self.number_of_slot_frames() as usize, &self.data.as_ref()[1..])
SlotframeDescriptorIterator::new(
self.number_of_slot_frames() as usize,
&self.data.as_ref()[1..],
)
}
}

Expand Down Expand Up @@ -907,21 +914,26 @@ impl NestedInformationElementRepr {
match ie.sub_id() {
NestedSubId::Short(NestedSubIdShort::TschSynchronization) => {
Self::TschSynchronization(TschSynchronizationRepr {
absolute_slot_number: TschSynchronization::new(ie.content()).absolute_slot_number(),
absolute_slot_number: TschSynchronization::new(ie.content())
.absolute_slot_number(),
join_metric: TschSynchronization::new(ie.content()).join_metric(),
})
}
NestedSubId::Short(NestedSubIdShort::TschTimeslot) => Self::TschTimeslot(TschTimeslotRepr {
id: TschTimeslot::new(ie.content()).id(),
}),
NestedSubId::Short(NestedSubIdShort::TschTimeslot) => {
Self::TschTimeslot(TschTimeslotRepr {
id: TschTimeslot::new(ie.content()).id(),
})
}
NestedSubId::Short(NestedSubIdShort::TschSlotframeAndLink) => {
Self::TschSlotframeAndLink(TschSlotframeAndLinkRepr {
number_of_slot_frames: TschSlotframeAndLink::new(ie.content()).number_of_slot_frames(),
number_of_slot_frames: TschSlotframeAndLink::new(ie.content())
.number_of_slot_frames(),
})
}
NestedSubId::Long(NestedSubIdLong::ChannelHopping) => {
Self::TschSlotframeAndLink(TschSlotframeAndLinkRepr {
number_of_slot_frames: TschSlotframeAndLink::new(ie.content()).number_of_slot_frames(),
number_of_slot_frames: TschSlotframeAndLink::new(ie.content())
.number_of_slot_frames(),
})
}
_ => todo!(),
Expand Down
3 changes: 2 additions & 1 deletion dot15d4/src/frame/ie/payloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ impl PayloadInformationElementRepr {
let mut nested_information_elements = Vec::new();

for nested_ie in ie.nested_information_elements() {
nested_information_elements.push(NestedInformationElementRepr::parse(nested_ie));
nested_information_elements
.push(NestedInformationElementRepr::parse(nested_ie));
}

Self::Mlme(nested_information_elements)
Expand Down
4 changes: 3 additions & 1 deletion dot15d4/src/tsch/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ impl EnhancedBeacon {
}
}

if let (Some(asn), Some(join_metric), Some(hopping_sequence_id)) = (asn, join_metric, hopping_sequence_id) {
if let (Some(asn), Some(join_metric), Some(hopping_sequence_id)) =
(asn, join_metric, hopping_sequence_id)
{
Some(Self {
asn,
join_metric,
Expand Down
10 changes: 8 additions & 2 deletions dot15d4/src/tsch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ impl TschDeviceInner {
let j = (i + current_i) % self.slot_frame.slots.len();

if self.slot_frame.slots[j].is_some() {
let i = if i == 0 { i + self.slot_frame.slots.len() } else { i };
let i = if i == 0 {
i + self.slot_frame.slots.len()
} else {
i
};

return now + self.slot_frame.timings.time_slot_length() * i;
}
Expand Down Expand Up @@ -172,7 +176,9 @@ impl TschDeviceInner {
});

let next_radio_wake = self.next_slot_start(timestamp, eb.asn);
self.asn = eb.asn + next_radio_wake.as_us() as u64 / self.slot_frame.timings.time_slot_length().as_us() as u64;
self.asn = eb.asn
+ next_radio_wake.as_us() as u64
/ self.slot_frame.timings.time_slot_length().as_us() as u64;
trace!("TSCH next radio wake at {}", next_radio_wake);
trace!(" --> waking up in {}", next_radio_wake - timestamp);
trace!(" --> Next ASN {}", self.asn);
Expand Down
6 changes: 3 additions & 3 deletions dot15d4/src/tsch/neighbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl<const N: usize> NeighborTable<N> {
/// Return the best time source based on the amount of Enhanced Beacons we received and the
/// join priority of the neighbor.
pub fn get_best_time_source(&self, current: NeighborStats) -> Option<&Neighbor> {
self.neighbors
.iter()
.find(|n| n.stats.rx_count > current.rx_count / 2 && n.stats.join_priority < current.join_priority)
self.neighbors.iter().find(|n| {
n.stats.rx_count > current.rx_count / 2 && n.stats.join_priority < current.join_priority
})
}
}
8 changes: 6 additions & 2 deletions dot15d4/src/tsch/slotframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@ impl<const MAX_HOPS: usize> HoppingSequence<MAX_HOPS> {
/// 16, 17, 23, 18, 26, 15, 25, 22, 19, 11, 12, 13, 24, 14, 20, 21
/// ```
pub fn sequence_16_16() -> Self {
Self::new(&[16, 17, 23, 18, 26, 15, 25, 22, 19, 11, 12, 13, 24, 14, 20, 21])
Self::new(&[
16, 17, 23, 18, 26, 15, 25, 22, 19, 11, 12, 13, 24, 14, 20, 21,
])
}

/// Return the default hopping sequences (16 channels, 4 hops):
/// ```txt
/// 20, 26, 25, 26, 15, 15, 25, 20, 26, 15, 26, 25, 20, 15, 20, 25
/// ```
pub fn sequence_4_16() -> Self {
Self::new(&[20, 26, 25, 26, 15, 15, 25, 20, 26, 15, 26, 25, 20, 15, 20, 25])
Self::new(&[
20, 26, 25, 26, 15, 15, 25, 20, 26, 15, 26, 25, 20, 15, 20, 25,
])
}

/// Return the default hopping sequences (4 channels, 4 hops):
Expand Down

0 comments on commit b79ccd6

Please sign in to comment.