This commit is contained in:
+1
-9
@@ -280,15 +280,7 @@ impl<
|
|||||||
RemoteCfgTable: RemoteEntityConfigProvider,
|
RemoteCfgTable: RemoteEntityConfigProvider,
|
||||||
TimerCreator: TimerCreatorProvider<Countdown = Countdown>,
|
TimerCreator: TimerCreatorProvider<Countdown = Countdown>,
|
||||||
Countdown: CountdownProvider,
|
Countdown: CountdownProvider,
|
||||||
>
|
> DestinationHandler<PduSender, UserFaultHook, Vfs, RemoteCfgTable, TimerCreator, Countdown>
|
||||||
DestinationHandler<
|
|
||||||
PduSender,
|
|
||||||
UserFaultHook,
|
|
||||||
Vfs,
|
|
||||||
RemoteCfgTable,
|
|
||||||
TimerCreator,
|
|
||||||
Countdown,
|
|
||||||
>
|
|
||||||
{
|
{
|
||||||
/// Constructs a new destination handler.
|
/// Constructs a new destination handler.
|
||||||
///
|
///
|
||||||
|
|||||||
+18
-24
@@ -40,6 +40,7 @@ use hashbrown::HashMap;
|
|||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
pub use alloc_mod::*;
|
pub use alloc_mod::*;
|
||||||
|
use core::time::Duration;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use spacepackets::{
|
use spacepackets::{
|
||||||
@@ -50,8 +51,6 @@ use spacepackets::{
|
|||||||
util::{UnsignedByteField, UnsignedEnum},
|
util::{UnsignedByteField, UnsignedEnum},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::time::Duration;
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
pub use std_mod::*;
|
pub use std_mod::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@@ -67,10 +66,10 @@ pub enum TimerContext {
|
|||||||
entity_type: EntityType,
|
entity_type: EntityType,
|
||||||
},
|
},
|
||||||
NakActivity {
|
NakActivity {
|
||||||
expiry_time_seconds: f32,
|
expiry_time: Duration,
|
||||||
},
|
},
|
||||||
PositiveAck {
|
PositiveAck {
|
||||||
expiry_time_seconds: f32,
|
expiry_time: Duration,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,27 +591,26 @@ pub mod std_mod {
|
|||||||
/// It also assumes that a second accuracy of the check timer period is sufficient.
|
/// It also assumes that a second accuracy of the check timer period is sufficient.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StdCountdown {
|
pub struct StdCountdown {
|
||||||
expiry_time_seconds: u64,
|
expiry_time: Duration,
|
||||||
start_time: std::time::Instant,
|
start_time: std::time::Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdCountdown {
|
impl StdCountdown {
|
||||||
pub fn new(expiry_time_seconds: u64) -> Self {
|
pub fn new(expiry_time: Duration) -> Self {
|
||||||
Self {
|
Self {
|
||||||
expiry_time_seconds,
|
expiry_time,
|
||||||
start_time: std::time::Instant::now(),
|
start_time: std::time::Instant::now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expiry_time_seconds(&self) -> u64 {
|
pub fn expiry_time_seconds(&self) -> u64 {
|
||||||
self.expiry_time_seconds
|
self.expiry_time.as_secs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CountdownProvider for StdCountdown {
|
impl CountdownProvider for StdCountdown {
|
||||||
fn has_expired(&self) -> bool {
|
fn has_expired(&self) -> bool {
|
||||||
let elapsed_time = self.start_time.elapsed();
|
if self.start_time.elapsed() > self.expiry_time {
|
||||||
if elapsed_time.as_nanos() > self.expiry_time_seconds as u128 * 1_000_000_000 {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
@@ -624,20 +622,20 @@ pub mod std_mod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct StdTimerCreator {
|
pub struct StdTimerCreator {
|
||||||
pub check_limit_timeout_secs: u64,
|
pub check_limit_timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdTimerCreator {
|
impl StdTimerCreator {
|
||||||
pub const fn new(check_limit_timeout_secs: u64) -> Self {
|
pub const fn new(check_limit_timeout: Duration) -> Self {
|
||||||
Self {
|
Self {
|
||||||
check_limit_timeout_secs,
|
check_limit_timeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StdTimerCreator {
|
impl Default for StdTimerCreator {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new(5)
|
Self::new(Duration::from_secs(5))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,13 +648,9 @@ pub mod std_mod {
|
|||||||
local_id: _,
|
local_id: _,
|
||||||
remote_id: _,
|
remote_id: _,
|
||||||
entity_type: _,
|
entity_type: _,
|
||||||
} => StdCountdown::new(self.check_limit_timeout_secs),
|
} => StdCountdown::new(self.check_limit_timeout),
|
||||||
TimerContext::NakActivity {
|
TimerContext::NakActivity { expiry_time } => StdCountdown::new(expiry_time),
|
||||||
expiry_time_seconds,
|
TimerContext::PositiveAck { expiry_time } => StdCountdown::new(expiry_time),
|
||||||
} => StdCountdown::new(Duration::from_secs_f32(expiry_time_seconds).as_secs()),
|
|
||||||
TimerContext::PositiveAck {
|
|
||||||
expiry_time_seconds,
|
|
||||||
} => StdCountdown::new(Duration::from_secs_f32(expiry_time_seconds).as_secs()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1300,7 +1294,7 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_std_check_timer() {
|
fn test_std_check_timer() {
|
||||||
let mut std_check_timer = StdCountdown::new(1);
|
let mut std_check_timer = StdCountdown::new(Duration::from_secs(1));
|
||||||
assert!(!std_check_timer.has_expired());
|
assert!(!std_check_timer.has_expired());
|
||||||
assert_eq!(std_check_timer.expiry_time_seconds(), 1);
|
assert_eq!(std_check_timer.expiry_time_seconds(), 1);
|
||||||
std::thread::sleep(Duration::from_millis(800));
|
std::thread::sleep(Duration::from_millis(800));
|
||||||
@@ -1313,9 +1307,9 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_std_check_timer_creator() {
|
fn test_std_check_timer_creator() {
|
||||||
let std_check_timer_creator = StdTimerCreator::new(1);
|
let std_check_timer_creator = StdTimerCreator::new(Duration::from_secs(1));
|
||||||
let check_timer = std_check_timer_creator.create_countdown(TimerContext::NakActivity {
|
let check_timer = std_check_timer_creator.create_countdown(TimerContext::NakActivity {
|
||||||
expiry_time_seconds: 1.0,
|
expiry_time: Duration::from_secs(1),
|
||||||
});
|
});
|
||||||
assert_eq!(check_timer.expiry_time_seconds(), 1);
|
assert_eq!(check_timer.expiry_time_seconds(), 1);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1155,7 +1155,7 @@ mod tests {
|
|||||||
max_packet_len,
|
max_packet_len,
|
||||||
crc_on_transmission_by_default,
|
crc_on_transmission_by_default,
|
||||||
),
|
),
|
||||||
StdTimerCreator::new(1),
|
StdTimerCreator::new(core::time::Duration::from_millis(100)),
|
||||||
SeqCountProviderSimple::default(),
|
SeqCountProviderSimple::default(),
|
||||||
),
|
),
|
||||||
srcfile_handle,
|
srcfile_handle,
|
||||||
|
|||||||
Reference in New Issue
Block a user