Skip to content

Commit

Permalink
Added utility function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostie314159 committed Feb 19, 2024
1 parent 52efb0e commit 2ee198b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/action_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use scroll::{
Endian, Pread, Pwrite,
};

use core::fmt::Debug;
use core::{fmt::Debug, time::Duration};

use crate::tlvs::{TLVReadIterator, AWDLTLV};

Expand All @@ -26,14 +26,20 @@ pub struct AWDLActionFrame<I> {
pub subtype: AWDLActionFrameSubType,

/// The time the NIC physically started sending the frame, in μs.
pub phy_tx_time: u32,
pub phy_tx_time: Duration,

///The time the driver send the frame to the NIC, in μs.
pub target_tx_time: u32,
/// The time the driver send the frame to the NIC, in μs.
pub target_tx_time: Duration,

/// The TLVs contained in the action frame.
pub tagged_data: I,
}
impl<I> AWDLActionFrame<I> {
/// Calculate the time, between the driver sending the frame to the WNIC and the transmission starting.
pub fn tx_delta(&self) -> Duration {
self.phy_tx_time - self.target_tx_time
}
}
impl<'a, I, MACIterator, LabelIterator, ValueIterator> Debug for AWDLActionFrame<I>
where
AWDLTLV<'a, MACIterator, LabelIterator, ValueIterator>: Debug,
Expand Down Expand Up @@ -84,8 +90,8 @@ impl<'a> TryFromCtx<'a> for AWDLActionFrame<TLVReadIterator<'a>> {
let subtype = AWDLActionFrameSubType::from_representation(from.gread(&mut offset)?);
offset += 1;

let phy_tx_time = from.gread_with(&mut offset, Endian::Little)?;
let target_tx_time = from.gread_with(&mut offset, Endian::Little)?;
let phy_tx_time = Duration::from_micros(from.gread_with::<u32>(&mut offset, Endian::Little)? as u64);
let target_tx_time = Duration::from_micros(from.gread_with::<u32>(&mut offset, Endian::Little)? as u64);
let tagged_data = TLVReadIterator::new(&from[offset..]);

Ok((
Expand All @@ -111,8 +117,8 @@ where
buf.gwrite(0x10u8, &mut offset)?;
buf.gwrite(self.subtype.to_representation(), &mut offset)?;
offset += 1;
buf.gwrite_with(self.phy_tx_time, &mut offset, Endian::Little)?;
buf.gwrite_with(self.target_tx_time, &mut offset, Endian::Little)?;
buf.gwrite_with(self.phy_tx_time.as_micros() as u32, &mut offset, Endian::Little)?;
buf.gwrite_with(self.target_tx_time.as_micros() as u32, &mut offset, Endian::Little)?;
for tlv in self.tagged_data {
buf.gwrite(tlv, &mut offset)?;
}
Expand Down

0 comments on commit 2ee198b

Please sign in to comment.