From a5941751d731147d3064c41990f6c4f7f2ad3684 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Mar 2024 16:22:40 +0100 Subject: [PATCH] Simplify low-level PUS API for verification and events --- satrs-example/Cargo.toml | 2 +- satrs-example/src/acs.rs | 6 +- satrs-example/src/events.rs | 6 +- satrs-example/src/main.rs | 4 +- satrs-example/src/pus/mod.rs | 6 +- satrs-example/src/pus/test.rs | 4 +- satrs-mib/Cargo.toml | 1 + satrs-mib/codegen/Cargo.toml | 5 +- satrs-shared/Cargo.toml | 4 +- satrs/Cargo.toml | 9 +- satrs/src/pus/event.rs | 185 +++++----- satrs/src/pus/mod.rs | 32 +- satrs/src/pus/scheduler.rs | 379 ++++++++++---------- satrs/src/pus/scheduler_srv.rs | 10 +- satrs/src/pus/verification.rs | 612 +++++++++++--------------------- satrs/src/tmtc/ccsds_distrib.rs | 2 +- satrs/src/tmtc/tm_helper.rs | 10 +- satrs/tests/hk_helpers.rs | 6 +- 18 files changed, 547 insertions(+), 736 deletions(-) diff --git a/satrs-example/Cargo.toml b/satrs-example/Cargo.toml index 27ffee9..d874a9c 100644 --- a/satrs-example/Cargo.toml +++ b/satrs-example/Cargo.toml @@ -25,7 +25,7 @@ path = "../satrs" [dependencies.satrs-mib] version = "0.1.1" -# path = "../satrs-mib" +path = "../satrs-mib" [features] dyn_tmtc = [] diff --git a/satrs-example/src/acs.rs b/satrs-example/src/acs.rs index 4fbea90..d7add5e 100644 --- a/satrs-example/src/acs.rs +++ b/satrs-example/src/acs.rs @@ -9,7 +9,7 @@ use satrs::{ hk::HkRequest, spacepackets::{ ecss::tm::{PusTmCreator, PusTmSecondaryHeader}, - time::cds::{DaysLen16Bits, TimeProvider}, + time::cds::{CdsTime, DaysLen16Bits}, SequenceFlags, SpHeader, }, }; @@ -23,7 +23,7 @@ use crate::{ pub struct AcsTask { timestamp: [u8; 7], - time_provider: TimeProvider, + time_provider: CdsTime, verif_reporter: VerificationReporter, tm_sender: Box, request_rx: mpsc::Receiver, @@ -37,7 +37,7 @@ impl AcsTask Self { Self { timestamp: [0; 7], - time_provider: TimeProvider::new_with_u16_days(0, 0), + time_provider: CdsTime::new_with_u16_days(0, 0), verif_reporter, tm_sender: Box::new(tm_sender), request_rx, diff --git a/satrs-example/src/events.rs b/satrs-example/src/events.rs index a6a0d86..4cb2cda 100644 --- a/satrs-example/src/events.rs +++ b/satrs-example/src/events.rs @@ -14,7 +14,7 @@ use satrs::{ verification::{TcStateStarted, VerificationReportingProvider, VerificationToken}, EcssTmSender, }, - spacepackets::time::cds::{self, TimeProvider}, + spacepackets::time::cds::{self, CdsTime}, }; use satrs_example::config::PUS_APID; @@ -25,7 +25,7 @@ pub struct PusEventHandler pus_event_dispatcher: DefaultPusEventU32Dispatcher<()>, pus_event_man_rx: mpsc::Receiver<(EventU32, Option)>, tm_sender: Box, - time_provider: TimeProvider, + time_provider: CdsTime, timestamp: [u8; 7], verif_handler: VerificationReporter, } @@ -57,7 +57,7 @@ impl PusEventHandler { } struct TimeStampHelper { - stamper: TimeProvider, + stamper: CdsTime, time_stamp: [u8; 7], } impl TimeStampHelper { pub fn new() -> Self { Self { - stamper: TimeProvider::new_with_u16_days(0, 0), + stamper: CdsTime::new_with_u16_days(0, 0), time_stamp: [0; 7], } } diff --git a/satrs-example/src/pus/test.rs b/satrs-example/src/pus/test.rs index 17822a3..4b0164b 100644 --- a/satrs-example/src/pus/test.rs +++ b/satrs-example/src/pus/test.rs @@ -14,7 +14,7 @@ use satrs::pus::{ }; use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::PusPacket; -use satrs::spacepackets::time::cds::TimeProvider; +use satrs::spacepackets::time::cds::CdsTime; use satrs::spacepackets::time::TimeWriter; use satrs::tmtc::tm_helper::SharedTmPool; use satrs::ChannelId; @@ -139,7 +139,7 @@ impl< .tc_slice_raw(), ) .unwrap(); - let time_stamper = TimeProvider::from_now_with_u16_days().unwrap(); + let time_stamper = CdsTime::now_with_u16_days().unwrap(); let mut stamp_buf: [u8; 7] = [0; 7]; time_stamper.write_to_bytes(&mut stamp_buf).unwrap(); if subservice == 128 { diff --git a/satrs-mib/Cargo.toml b/satrs-mib/Cargo.toml index eeca52f..9024b86 100644 --- a/satrs-mib/Cargo.toml +++ b/satrs-mib/Cargo.toml @@ -23,6 +23,7 @@ version = "1" optional = true [dependencies.satrs-shared] +path = "../satrs-shared" version = "0.1.2" features = ["serde"] diff --git a/satrs-mib/codegen/Cargo.toml b/satrs-mib/codegen/Cargo.toml index 0d9522e..a25358d 100644 --- a/satrs-mib/codegen/Cargo.toml +++ b/satrs-mib/codegen/Cargo.toml @@ -26,7 +26,10 @@ features = ["full"] [dev-dependencies] trybuild = { version = "1", features = ["diff"] } -satrs-shared = "0.1.2" + +[dev-dependencies.satrs-shared] +version = "0.1.2" +path = "../../satrs-shared" [dev-dependencies.satrs-mib] path = ".." diff --git a/satrs-shared/Cargo.toml b/satrs-shared/Cargo.toml index e2998e9..e706d6a 100644 --- a/satrs-shared/Cargo.toml +++ b/satrs-shared/Cargo.toml @@ -18,7 +18,9 @@ default-features = false optional = true [dependencies.spacepackets] -version = "0.10" +git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" +version = "0.11.0-rc.0" +branch = "main" default-features = false [features] diff --git a/satrs/Cargo.toml b/satrs/Cargo.toml index 5e3b27d..ad11272 100644 --- a/satrs/Cargo.toml +++ b/satrs/Cargo.toml @@ -17,7 +17,10 @@ delegate = ">0.7, <=0.10" paste = "1" smallvec = "1" crc = "3" -satrs-shared = "0.1.2" + +[dependencies.satrs-shared] +version = "0.1.2" +path = "../satrs-shared" [dependencies.num_enum] version = ">0.5, <=0.7" @@ -68,7 +71,9 @@ features = ["all"] optional = true [dependencies.spacepackets] -version = "0.10" +git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" +version = "0.11.0-rc.0" +branch = "main" default-features = false [dependencies.cobs] diff --git a/satrs/src/pus/event.rs b/satrs/src/pus/event.rs index 5cde422..4165601 100644 --- a/satrs/src/pus/event.rs +++ b/satrs/src/pus/event.rs @@ -2,6 +2,7 @@ use crate::pus::{source_buffer_large_enough, EcssTmtcError}; use spacepackets::ecss::tm::PusTmCreator; use spacepackets::ecss::tm::PusTmSecondaryHeader; use spacepackets::ecss::{EcssEnumeration, PusError}; +use spacepackets::ByteConversionError; use spacepackets::{SpHeader, MAX_APID}; use crate::pus::EcssTmSenderCore; @@ -9,145 +10,125 @@ use crate::pus::EcssTmSenderCore; pub use alloc_mod::EventReporter; pub use spacepackets::ecss::event::*; -pub struct EventReporterBase { - msg_count: u16, +pub struct EventReportCreator { apid: u16, pub dest_id: u16, } -impl EventReporterBase { +impl EventReportCreator { pub fn new(apid: u16) -> Option { if apid > MAX_APID { return None; } Some(Self { - msg_count: 0, + // msg_count: 0, dest_id: 0, apid, }) } - pub fn event_info( + pub fn event_info<'time, 'src_data>( &mut self, - buf: &mut [u8], - sender: &mut (impl EcssTmSenderCore + ?Sized), - time_stamp: &[u8], + src_data_buf: &'src_data mut [u8], + time_stamp: &'time [u8], event_id: impl EcssEnumeration, - aux_data: Option<&[u8]>, - ) -> Result<(), EcssTmtcError> { + aux_data: Option<&'src_data [u8]>, + ) -> Result, ByteConversionError> { self.generate_and_send_generic_tm( - buf, + src_data_buf, Subservice::TmInfoReport, - sender, time_stamp, event_id, aux_data, ) } - pub fn event_low_severity( + pub fn event_low_severity<'time, 'src_data>( &mut self, - buf: &mut [u8], - sender: &mut (impl EcssTmSenderCore + ?Sized), - time_stamp: &[u8], + src_data_buf: &'src_data mut [u8], + time_stamp: &'time [u8], event_id: impl EcssEnumeration, - aux_data: Option<&[u8]>, - ) -> Result<(), EcssTmtcError> { + aux_data: Option<&'src_data [u8]>, + ) -> Result, ByteConversionError> { self.generate_and_send_generic_tm( - buf, + src_data_buf, Subservice::TmLowSeverityReport, - sender, time_stamp, event_id, aux_data, ) } - pub fn event_medium_severity( + pub fn event_medium_severity<'time, 'src_data>( &mut self, - buf: &mut [u8], - sender: &mut (impl EcssTmSenderCore + ?Sized), - time_stamp: &[u8], + buf: &'src_data mut [u8], + time_stamp: &'time [u8], event_id: impl EcssEnumeration, - aux_data: Option<&[u8]>, - ) -> Result<(), EcssTmtcError> { + aux_data: Option<&'src_data [u8]>, + ) -> Result, ByteConversionError> { self.generate_and_send_generic_tm( buf, Subservice::TmMediumSeverityReport, - sender, time_stamp, event_id, aux_data, ) } - pub fn event_high_severity( + pub fn event_high_severity<'time, 'src_data>( &mut self, - buf: &mut [u8], - sender: &mut (impl EcssTmSenderCore + ?Sized), - time_stamp: &[u8], + src_data_buf: &'src_data mut [u8], + time_stamp: &'time [u8], event_id: impl EcssEnumeration, - aux_data: Option<&[u8]>, - ) -> Result<(), EcssTmtcError> { + aux_data: Option<&'src_data [u8]>, + ) -> Result, ByteConversionError> { self.generate_and_send_generic_tm( - buf, + src_data_buf, Subservice::TmHighSeverityReport, - sender, time_stamp, event_id, aux_data, ) } - fn generate_and_send_generic_tm( + fn generate_and_send_generic_tm<'time, 'src_data>( &mut self, - buf: &mut [u8], + src_data_buf: &'src_data mut [u8], subservice: Subservice, - sender: &mut (impl EcssTmSenderCore + ?Sized), - time_stamp: &[u8], + time_stamp: &'time [u8], event_id: impl EcssEnumeration, - aux_data: Option<&[u8]>, - ) -> Result<(), EcssTmtcError> { - let tm = self.generate_generic_event_tm(buf, subservice, time_stamp, event_id, aux_data)?; - sender.send_tm(tm.into())?; - self.msg_count += 1; - Ok(()) + aux_data: Option<&'src_data [u8]>, + ) -> Result, ByteConversionError> { + self.generate_generic_event_tm(src_data_buf, subservice, time_stamp, event_id, aux_data) } - fn generate_generic_event_tm<'a>( - &'a self, - buf: &'a mut [u8], + fn generate_generic_event_tm<'time, 'src_data>( + &self, + src_data_buf: &'src_data mut [u8], subservice: Subservice, - time_stamp: &'a [u8], + time_stamp: &'time [u8], event_id: impl EcssEnumeration, - aux_data: Option<&[u8]>, - ) -> Result { + aux_data: Option<&'src_data [u8]>, + ) -> Result, ByteConversionError> { let mut src_data_len = event_id.size(); if let Some(aux_data) = aux_data { src_data_len += aux_data.len(); } - source_buffer_large_enough(buf.len(), src_data_len)?; + source_buffer_large_enough(src_data_buf.len(), src_data_len)?; let mut sp_header = SpHeader::tm_unseg(self.apid, 0, 0).unwrap(); - let sec_header = PusTmSecondaryHeader::new( - 5, - subservice.into(), - self.msg_count, - self.dest_id, - Some(time_stamp), - ); + let sec_header = + PusTmSecondaryHeader::new(5, subservice.into(), 0, self.dest_id, Some(time_stamp)); let mut current_idx = 0; - event_id - .write_to_be_bytes(&mut buf[0..event_id.size()]) - .map_err(PusError::ByteConversion)?; + event_id.write_to_be_bytes(&mut src_data_buf[0..event_id.size()])?; current_idx += event_id.size(); if let Some(aux_data) = aux_data { - buf[current_idx..current_idx + aux_data.len()].copy_from_slice(aux_data); + src_data_buf[current_idx..current_idx + aux_data.len()].copy_from_slice(aux_data); current_idx += aux_data.len(); } Ok(PusTmCreator::new( &mut sp_header, sec_header, - &buf[0..current_idx], + &src_data_buf[0..current_idx], true, )) } @@ -161,12 +142,12 @@ mod alloc_mod { pub struct EventReporter { source_data_buf: Vec, - pub reporter: EventReporterBase, + pub reporter: EventReportCreator, } impl EventReporter { pub fn new(apid: u16, max_event_id_and_aux_data_size: usize) -> Option { - let reporter = EventReporterBase::new(apid)?; + let reporter = EventReportCreator::new(apid)?; Some(Self { source_data_buf: vec![0; max_event_id_and_aux_data_size], reporter, @@ -179,13 +160,17 @@ mod alloc_mod { event_id: impl EcssEnumeration, aux_data: Option<&[u8]>, ) -> Result<(), EcssTmtcError> { - self.reporter.event_info( - self.source_data_buf.as_mut_slice(), - sender, - time_stamp, - event_id, - aux_data, - ) + let tm_creator = self + .reporter + .event_info( + self.source_data_buf.as_mut_slice(), + time_stamp, + event_id, + aux_data, + ) + .map_err(PusError::ByteConversion)?; + sender.send_tm(tm_creator.into())?; + Ok(()) } pub fn event_low_severity( @@ -195,13 +180,17 @@ mod alloc_mod { event_id: impl EcssEnumeration, aux_data: Option<&[u8]>, ) -> Result<(), EcssTmtcError> { - self.reporter.event_low_severity( - self.source_data_buf.as_mut_slice(), - sender, - time_stamp, - event_id, - aux_data, - ) + let tm_creator = self + .reporter + .event_low_severity( + self.source_data_buf.as_mut_slice(), + time_stamp, + event_id, + aux_data, + ) + .map_err(PusError::ByteConversion)?; + sender.send_tm(tm_creator.into())?; + Ok(()) } pub fn event_medium_severity( @@ -211,13 +200,17 @@ mod alloc_mod { event_id: impl EcssEnumeration, aux_data: Option<&[u8]>, ) -> Result<(), EcssTmtcError> { - self.reporter.event_medium_severity( - self.source_data_buf.as_mut_slice(), - sender, - time_stamp, - event_id, - aux_data, - ) + let tm_creator = self + .reporter + .event_medium_severity( + self.source_data_buf.as_mut_slice(), + time_stamp, + event_id, + aux_data, + ) + .map_err(PusError::ByteConversion)?; + sender.send_tm(tm_creator.into())?; + Ok(()) } pub fn event_high_severity( @@ -227,13 +220,17 @@ mod alloc_mod { event_id: impl EcssEnumeration, aux_data: Option<&[u8]>, ) -> Result<(), EcssTmtcError> { - self.reporter.event_high_severity( - self.source_data_buf.as_mut_slice(), - sender, - time_stamp, - event_id, - aux_data, - ) + let tm_creator = self + .reporter + .event_high_severity( + self.source_data_buf.as_mut_slice(), + time_stamp, + event_id, + aux_data, + ) + .map_err(PusError::ByteConversion)?; + sender.send_tm(tm_creator.into())?; + Ok(()) } } } diff --git a/satrs/src/pus/mod.rs b/satrs/src/pus/mod.rs index 60509ef..37d69ef 100644 --- a/satrs/src/pus/mod.rs +++ b/satrs/src/pus/mod.rs @@ -40,19 +40,19 @@ pub use alloc_mod::*; pub use std_mod::*; #[derive(Debug, PartialEq, Eq, Clone)] -pub enum PusTmWrapper<'tm> { +pub enum PusTmWrapper<'time, 'src_data> { InStore(StoreAddr), - Direct(PusTmCreator<'tm>), + Direct(PusTmCreator<'time, 'src_data>), } -impl From for PusTmWrapper<'_> { +impl From for PusTmWrapper<'_, '_> { fn from(value: StoreAddr) -> Self { Self::InStore(value) } } -impl<'tm> From> for PusTmWrapper<'tm> { - fn from(value: PusTmCreator<'tm>) -> Self { +impl<'time, 'src_data> From> for PusTmWrapper<'time, 'src_data> { + fn from(value: PusTmCreator<'time, 'src_data>) -> Self { Self::Direct(value) } } @@ -380,7 +380,7 @@ pub mod std_mod { use spacepackets::ecss::tc::PusTcReader; use spacepackets::ecss::tm::PusTmCreator; use spacepackets::ecss::{PusError, WritablePusPacket}; - use spacepackets::time::cds::TimeProvider; + use spacepackets::time::cds::CdsTime; use spacepackets::time::StdTimestampError; use spacepackets::time::TimeWriter; use std::string::String; @@ -860,8 +860,7 @@ pub mod std_mod { partial_error: &mut Option, ) -> [u8; 7] { let mut time_stamp: [u8; 7] = [0; 7]; - let time_provider = - TimeProvider::from_now_with_u16_days().map_err(PartialPusHandlingError::Time); + let time_provider = CdsTime::now_with_u16_days().map_err(PartialPusHandlingError::Time); if let Ok(time_provider) = time_provider { // Can't fail, we have a buffer with the exact required size. time_provider.write_to_bytes(&mut time_stamp).unwrap(); @@ -981,15 +980,16 @@ pub mod std_mod { >; } -pub(crate) fn source_buffer_large_enough(cap: usize, len: usize) -> Result<(), EcssTmtcError> { +pub(crate) fn source_buffer_large_enough( + cap: usize, + len: usize, +) -> Result<(), ByteConversionError> { if len > cap { - return Err( - PusError::ByteConversion(ByteConversionError::ToSliceTooSmall { - found: cap, - expected: len, - }) - .into(), - ); + return Err(ByteConversionError::ToSliceTooSmall { + found: cap, + expected: len, + } + .into()); } Ok(()) } diff --git a/satrs/src/pus/scheduler.rs b/satrs/src/pus/scheduler.rs index cebcf2c..0c2f4db 100644 --- a/satrs/src/pus/scheduler.rs +++ b/satrs/src/pus/scheduler.rs @@ -9,9 +9,7 @@ use serde::{Deserialize, Serialize}; use spacepackets::ecss::scheduling::TimeWindowType; use spacepackets::ecss::tc::{GenericPusTcSecondaryHeader, IsPusTelecommand, PusTcReader}; use spacepackets::ecss::{PusError, PusPacket, WritablePusPacket}; -use spacepackets::time::{ - CcsdsTimeProvider, TimeReader, TimeWriter, TimestampError, UnixTimestamp, -}; +use spacepackets::time::{CcsdsTimeProvider, TimeReader, TimeWriter, TimestampError, UnixTime}; use spacepackets::{ByteConversionError, CcsdsPacket}; #[cfg(feature = "std")] use std::error::Error; @@ -147,9 +145,9 @@ pub enum ScheduleError { /// The first parameter is the current time, the second one the time margin, and the third one /// the release time. ReleaseTimeInTimeMargin { - current_time: UnixTimestamp, + current_time: UnixTime, time_margin: Duration, - release_time: UnixTimestamp, + release_time: UnixTime, }, /// Nested time-tagged commands are not allowed. NestedScheduledTc, @@ -256,7 +254,7 @@ pub trait PusSchedulerProvider { /// inside the telecommand packet pool. fn insert_unwrapped_and_stored_tc( &mut self, - time_stamp: UnixTimestamp, + time_stamp: UnixTime, info: TcInfo, ) -> Result<(), ScheduleError>; @@ -280,7 +278,7 @@ pub trait PusSchedulerProvider { } let user_data = pus_tc.user_data(); let stamp: Self::TimeProvider = TimeReader::from_bytes(user_data)?; - let unix_stamp = stamp.unix_stamp(); + let unix_stamp = stamp.unix_time(); let stamp_len = stamp.len_as_bytes(); self.insert_unwrapped_tc(unix_stamp, &user_data[stamp_len..], pool) } @@ -289,7 +287,7 @@ pub trait PusSchedulerProvider { /// needs to be stored inside the telecommand pool. fn insert_unwrapped_tc( &mut self, - time_stamp: UnixTimestamp, + time_stamp: UnixTime, tc: &[u8], pool: &mut (impl PoolProvider + ?Sized), ) -> Result { @@ -347,7 +345,10 @@ pub mod alloc_mod { }, vec::Vec, }; - use spacepackets::time::cds::{self, DaysLen24Bits}; + use spacepackets::time::{ + cds::{self, DaysLen24Bits}, + UnixTime, + }; use crate::pool::StoreAddr; @@ -397,8 +398,9 @@ pub mod alloc_mod { /// Currently, sub-schedules and groups are not supported. #[derive(Debug)] pub struct PusScheduler { - tc_map: BTreeMap>, - pub(crate) current_time: UnixTimestamp, + // TODO: Use MonotonicTime from tai-time crate instead of UnixTime and cache leap seconds. + tc_map: BTreeMap>, + pub(crate) current_time: UnixTime, time_margin: Duration, enabled: bool, } @@ -413,7 +415,7 @@ pub mod alloc_mod { /// added to the current time, it will not be inserted into the schedule. /// * `tc_buf_size` - Buffer for temporary storage of telecommand packets. This buffer /// should be large enough to accomodate the largest expected TC packets. - pub fn new(init_current_time: UnixTimestamp, time_margin: Duration) -> Self { + pub fn new(init_current_time: UnixTime, time_margin: Duration) -> Self { PusScheduler { tc_map: Default::default(), current_time: init_current_time, @@ -426,7 +428,7 @@ pub mod alloc_mod { #[cfg(feature = "std")] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] pub fn new_with_current_init_time(time_margin: Duration) -> Result { - Ok(Self::new(UnixTimestamp::from_now()?, time_margin)) + Ok(Self::new(UnixTime::now()?, time_margin)) } pub fn num_scheduled_telecommands(&self) -> u64 { @@ -437,11 +439,11 @@ pub mod alloc_mod { num_entries } - pub fn update_time(&mut self, current_time: UnixTimestamp) { + pub fn update_time(&mut self, current_time: UnixTime) { self.current_time = current_time; } - pub fn current_time(&self) -> &UnixTimestamp { + pub fn current_time(&self) -> &UnixTime { &self.current_time } @@ -449,7 +451,7 @@ pub mod alloc_mod { /// inside the telecommand packet pool. pub fn insert_unwrapped_and_stored_tc( &mut self, - time_stamp: UnixTimestamp, + time_stamp: UnixTime, info: TcInfo, ) -> Result<(), ScheduleError> { if time_stamp < self.current_time + self.time_margin { @@ -474,7 +476,7 @@ pub mod alloc_mod { /// needs to be stored inside the telecommand pool. pub fn insert_unwrapped_tc( &mut self, - time_stamp: UnixTimestamp, + time_stamp: UnixTime, tc: &[u8], pool: &mut (impl PoolProvider + ?Sized), ) -> Result { @@ -501,7 +503,7 @@ pub mod alloc_mod { pus_tc: &(impl IsPusTelecommand + PusPacket + GenericPusTcSecondaryHeader), pool: &mut (impl PoolProvider + ?Sized), ) -> Result { - self.insert_wrapped_tc::(pus_tc, pool) + self.insert_wrapped_tc::(pus_tc, pool) } /// Insert a telecommand based on the fully wrapped time-tagged telecommand using a CDS @@ -511,7 +513,7 @@ pub mod alloc_mod { pus_tc: &(impl IsPusTelecommand + PusPacket + GenericPusTcSecondaryHeader), pool: &mut (impl PoolProvider + ?Sized), ) -> Result { - self.insert_wrapped_tc::>(pus_tc, pool) + self.insert_wrapped_tc::>(pus_tc, pool) } /// This function uses [Self::retrieve_by_time_filter] to extract all scheduled commands inside @@ -557,14 +559,13 @@ pub mod alloc_mod { &mut self, pool: &mut (impl PoolProvider + ?Sized), ) -> Result { - self.delete_by_time_filter(TimeWindow::::new_select_all(), pool) + self.delete_by_time_filter(TimeWindow::::new_select_all(), pool) } /// Retrieve a range over all scheduled commands. pub fn retrieve_all( &mut self, - ) -> alloc::collections::btree_map::Range<'_, UnixTimestamp, alloc::vec::Vec> - { + ) -> alloc::collections::btree_map::Range<'_, UnixTime, alloc::vec::Vec> { self.tc_map.range(..) } @@ -575,23 +576,23 @@ pub mod alloc_mod { pub fn retrieve_by_time_filter( &mut self, time_window: TimeWindow, - ) -> Range<'_, UnixTimestamp, alloc::vec::Vec> { + ) -> Range<'_, UnixTime, alloc::vec::Vec> { match time_window.time_window_type() { TimeWindowType::SelectAll => self.tc_map.range(..), TimeWindowType::TimeTagToTimeTag => { // This should be guaranteed to be valid by library API, so unwrap is okay - let start_time = time_window.start_time().unwrap().unix_stamp(); - let end_time = time_window.end_time().unwrap().unix_stamp(); + let start_time = time_window.start_time().unwrap().unix_time(); + let end_time = time_window.end_time().unwrap().unix_time(); self.tc_map.range(start_time..=end_time) } TimeWindowType::FromTimeTag => { // This should be guaranteed to be valid by library API, so unwrap is okay - let start_time = time_window.start_time().unwrap().unix_stamp(); + let start_time = time_window.start_time().unwrap().unix_time(); self.tc_map.range(start_time..) } TimeWindowType::ToTimeTag => { // This should be guaranteed to be valid by library API, so unwrap is okay - let end_time = time_window.end_time().unwrap().unix_stamp(); + let end_time = time_window.end_time().unwrap().unix_time(); self.tc_map.range(..=end_time) } } @@ -671,7 +672,7 @@ pub mod alloc_mod { #[cfg(feature = "std")] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] pub fn update_time_from_now(&mut self) -> Result<(), SystemTimeError> { - self.current_time = UnixTimestamp::from_now()?; + self.current_time = UnixTime::now()?; Ok(()) } @@ -781,13 +782,13 @@ pub mod alloc_mod { } /// Retrieve all telecommands which should be release based on the current time. - pub fn telecommands_to_release(&self) -> Range<'_, UnixTimestamp, Vec> { + pub fn telecommands_to_release(&self) -> Range<'_, UnixTime, Vec> { self.tc_map.range(..=self.current_time) } } impl PusSchedulerProvider for PusScheduler { - type TimeProvider = cds::TimeProvider; + type TimeProvider = cds::CdsTime; /// This will disable the scheduler and clear the schedule as specified in 6.11.4.4. /// Be careful with this command as it will delete all the commands in the schedule. @@ -826,7 +827,7 @@ pub mod alloc_mod { fn insert_unwrapped_and_stored_tc( &mut self, - time_stamp: UnixTimestamp, + time_stamp: UnixTime, info: TcInfo, ) -> Result<(), ScheduleError> { if time_stamp < self.current_time + self.time_margin { @@ -858,15 +859,17 @@ mod tests { use alloc::collections::btree_map::Range; use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader}; use spacepackets::ecss::WritablePusPacket; - use spacepackets::time::{cds, TimeWriter, UnixTimestamp}; + use spacepackets::time::{cds, TimeWriter, UnixTime}; use spacepackets::{PacketId, PacketSequenceCtrl, PacketType, SequenceFlags, SpHeader}; use std::time::Duration; use std::vec::Vec; #[allow(unused_imports)] use std::{println, vec}; - fn pus_tc_base(timestamp: UnixTimestamp, buf: &mut [u8]) -> (SpHeader, usize) { - let cds_time = cds::TimeProvider::from_unix_secs_with_u16_days(×tamp).unwrap(); + fn pus_tc_base(timestamp: UnixTime, buf: &mut [u8]) -> (SpHeader, usize) { + let cds_time = + cds::CdsTime::from_unix_time_with_u16_days(×tamp, cds::SubmillisPrecision::Absent) + .unwrap(); let len_time_stamp = cds_time.write_to_bytes(buf).unwrap(); let len_packet = base_ping_tc_simple_ctor(0, None) .write_to_bytes(&mut buf[len_time_stamp..]) @@ -877,23 +880,25 @@ mod tests { ) } - fn scheduled_tc(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTcCreator { + fn scheduled_tc(timestamp: UnixTime, buf: &mut [u8]) -> PusTcCreator { let (mut sph, len_app_data) = pus_tc_base(timestamp, buf); PusTcCreator::new_simple(&mut sph, 11, 4, Some(&buf[..len_app_data]), true) } - fn wrong_tc_service(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTcCreator { + fn wrong_tc_service(timestamp: UnixTime, buf: &mut [u8]) -> PusTcCreator { let (mut sph, len_app_data) = pus_tc_base(timestamp, buf); PusTcCreator::new_simple(&mut sph, 12, 4, Some(&buf[..len_app_data]), true) } - fn wrong_tc_subservice(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTcCreator { + fn wrong_tc_subservice(timestamp: UnixTime, buf: &mut [u8]) -> PusTcCreator { let (mut sph, len_app_data) = pus_tc_base(timestamp, buf); PusTcCreator::new_simple(&mut sph, 11, 5, Some(&buf[..len_app_data]), true) } - fn double_wrapped_time_tagged_tc(timestamp: UnixTimestamp, buf: &mut [u8]) -> PusTcCreator { - let cds_time = cds::TimeProvider::from_unix_secs_with_u16_days(×tamp).unwrap(); + fn double_wrapped_time_tagged_tc(timestamp: UnixTime, buf: &mut [u8]) -> PusTcCreator { + let cds_time = + cds::CdsTime::from_unix_time_with_u16_days(×tamp, cds::SubmillisPrecision::Absent) + .unwrap(); let len_time_stamp = cds_time.write_to_bytes(buf).unwrap(); let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap(); // app data should not matter, double wrapped time-tagged commands should be rejected right @@ -938,8 +943,7 @@ mod tests { #[test] fn test_enable_api() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); assert!(scheduler.is_enabled()); scheduler.disable(); assert!(!scheduler.is_enabled()); @@ -950,15 +954,14 @@ mod tests { #[test] fn test_reset() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler .insert_unwrapped_and_stored_tc( - UnixTimestamp::new_only_seconds(100), + UnixTime::new_only_secs(100), TcInfo::new(tc_info_0.addr, tc_info_0.request_id), ) .unwrap(); @@ -967,7 +970,7 @@ mod tests { let tc_info_1 = ping_tc_to_store(&mut pool, &mut buf, 1, Some(app_data)); scheduler .insert_unwrapped_and_stored_tc( - UnixTimestamp::new_only_seconds(200), + UnixTime::new_only_secs(200), TcInfo::new(tc_info_1.addr, tc_info_1.request_id), ) .unwrap(); @@ -976,7 +979,7 @@ mod tests { let tc_info_2 = ping_tc_to_store(&mut pool, &mut buf, 2, Some(app_data)); scheduler .insert_unwrapped_and_stored_tc( - UnixTimestamp::new_only_seconds(300), + UnixTime::new_only_secs(300), TcInfo::new(tc_info_2.addr(), tc_info_2.request_id()), ) .unwrap(); @@ -993,12 +996,11 @@ mod tests { #[test] fn insert_multi_with_same_time() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); scheduler .insert_unwrapped_and_stored_tc( - UnixTimestamp::new_only_seconds(100), + UnixTime::new_only_secs(100), TcInfo::new( StoreAddr::from(StaticPoolAddr { pool_idx: 0, @@ -1015,7 +1017,7 @@ mod tests { scheduler .insert_unwrapped_and_stored_tc( - UnixTimestamp::new_only_seconds(100), + UnixTime::new_only_secs(100), TcInfo::new( StoreAddr::from(StaticPoolAddr { pool_idx: 0, @@ -1032,7 +1034,7 @@ mod tests { scheduler .insert_unwrapped_and_stored_tc( - UnixTimestamp::new_only_seconds(300), + UnixTime::new_only_secs(300), TcInfo::new( StaticPoolAddr { pool_idx: 0, @@ -1053,9 +1055,8 @@ mod tests { #[test] fn test_time_update() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); - let time = UnixTimestamp::new(1, 2).unwrap(); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); + let time = UnixTime::new(1, 2_000_000); scheduler.update_time(time); assert_eq!(scheduler.current_time(), &time); } @@ -1102,19 +1103,18 @@ mod tests { #[test] fn test_release_telecommands() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("insertion failed"); let tc_info_1 = ping_tc_to_store(&mut pool, &mut buf, 1, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(200), tc_info_1) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(200), tc_info_1) .expect("insertion failed"); let mut i = 0; @@ -1124,7 +1124,7 @@ mod tests { }; // test 1: too early, no tcs - scheduler.update_time(UnixTimestamp::new_only_seconds(99)); + scheduler.update_time(UnixTime::new_only_secs(99)); let mut tc_buf: [u8; 128] = [0; 128]; scheduler @@ -1132,7 +1132,7 @@ mod tests { .expect("deletion failed"); // test 2: exact time stamp of tc, releases 1 tc - scheduler.update_time(UnixTimestamp::new_only_seconds(100)); + scheduler.update_time(UnixTime::new_only_secs(100)); let mut released = scheduler .release_telecommands(&mut test_closure_1, &mut pool) @@ -1147,7 +1147,7 @@ mod tests { true }; - scheduler.update_time(UnixTimestamp::new_only_seconds(206)); + scheduler.update_time(UnixTime::new_only_secs(206)); released = scheduler .release_telecommands_with_buffer(&mut test_closure_2, &mut pool, &mut tc_buf) @@ -1168,19 +1168,18 @@ mod tests { #[test] fn release_multi_with_same_time() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("insertion failed"); let tc_info_1 = ping_tc_to_store(&mut pool, &mut buf, 1, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_1) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_1) .expect("insertion failed"); let mut i = 0; @@ -1195,7 +1194,7 @@ mod tests { }; // test 1: too early, no tcs - scheduler.update_time(UnixTimestamp::new_only_seconds(99)); + scheduler.update_time(UnixTime::new_only_secs(99)); let mut tc_buf: [u8; 128] = [0; 128]; let mut released = scheduler @@ -1204,7 +1203,7 @@ mod tests { assert_eq!(released, 0); // test 2: exact time stamp of tc, releases 2 tc - scheduler.update_time(UnixTimestamp::new_only_seconds(100)); + scheduler.update_time(UnixTime::new_only_secs(100)); released = scheduler .release_telecommands(&mut test_closure, &mut pool) @@ -1226,8 +1225,7 @@ mod tests { #[test] fn release_with_scheduler_disabled() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); scheduler.disable(); @@ -1235,12 +1233,12 @@ mod tests { let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("insertion failed"); let tc_info_1 = ping_tc_to_store(&mut pool, &mut buf, 1, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(200), tc_info_1) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(200), tc_info_1) .expect("insertion failed"); let mut i = 0; @@ -1252,14 +1250,14 @@ mod tests { let mut tc_buf: [u8; 128] = [0; 128]; // test 1: too early, no tcs - scheduler.update_time(UnixTimestamp::new_only_seconds(99)); + scheduler.update_time(UnixTime::new_only_secs(99)); scheduler .release_telecommands_with_buffer(&mut test_closure_1, &mut pool, &mut tc_buf) .expect("deletion failed"); // test 2: exact time stamp of tc, releases 1 tc - scheduler.update_time(UnixTimestamp::new_only_seconds(100)); + scheduler.update_time(UnixTime::new_only_secs(100)); let mut released = scheduler .release_telecommands(&mut test_closure_1, &mut pool) @@ -1273,7 +1271,7 @@ mod tests { true }; - scheduler.update_time(UnixTimestamp::new_only_seconds(206)); + scheduler.update_time(UnixTime::new_only_secs(206)); released = scheduler .release_telecommands(&mut test_closure_2, &mut pool) @@ -1292,8 +1290,7 @@ mod tests { #[test] fn insert_unwrapped_tc() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); let mut buf: [u8; 32] = [0; 32]; @@ -1301,7 +1298,7 @@ mod tests { let info = scheduler .insert_unwrapped_tc( - UnixTimestamp::new_only_seconds(100), + UnixTime::new_only_secs(100), &buf[..pool.len_of_data(&tc_info_0.addr()).unwrap()], &mut pool, ) @@ -1316,7 +1313,7 @@ mod tests { assert_eq!(scheduler.num_scheduled_telecommands(), 1); - scheduler.update_time(UnixTimestamp::new_only_seconds(101)); + scheduler.update_time(UnixTime::new_only_secs(101)); let mut addr_vec = Vec::new(); @@ -1340,15 +1337,14 @@ mod tests { #[test] fn insert_wrapped_tc() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); let mut buf: [u8; 32] = [0; 32]; - let tc = scheduled_tc(UnixTimestamp::new_only_seconds(100), &mut buf); + let tc = scheduled_tc(UnixTime::new_only_secs(100), &mut buf); - let info = match scheduler.insert_wrapped_tc::(&tc, &mut pool) { + let info = match scheduler.insert_wrapped_tc::(&tc, &mut pool) { Ok(addr) => addr, Err(e) => { panic!("unexpected error {e}"); @@ -1364,7 +1360,7 @@ mod tests { assert_eq!(scheduler.num_scheduled_telecommands(), 1); - scheduler.update_time(UnixTimestamp::new_only_seconds(101)); + scheduler.update_time(UnixTime::new_only_secs(101)); let mut addr_vec = Vec::new(); @@ -1390,15 +1386,14 @@ mod tests { #[test] fn insert_wrong_service() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); let mut buf: [u8; 32] = [0; 32]; - let tc = wrong_tc_service(UnixTimestamp::new_only_seconds(100), &mut buf); + let tc = wrong_tc_service(UnixTime::new_only_secs(100), &mut buf); - let err = scheduler.insert_wrapped_tc::(&tc, &mut pool); + let err = scheduler.insert_wrapped_tc::(&tc, &mut pool); assert!(err.is_err()); let err = err.unwrap_err(); match err { @@ -1413,15 +1408,14 @@ mod tests { #[test] fn insert_wrong_subservice() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); let mut buf: [u8; 32] = [0; 32]; - let tc = wrong_tc_subservice(UnixTimestamp::new_only_seconds(100), &mut buf); + let tc = wrong_tc_subservice(UnixTime::new_only_secs(100), &mut buf); - let err = scheduler.insert_wrapped_tc::(&tc, &mut pool); + let err = scheduler.insert_wrapped_tc::(&tc, &mut pool); assert!(err.is_err()); let err = err.unwrap_err(); match err { @@ -1436,11 +1430,10 @@ mod tests { #[test] fn insert_wrapped_tc_faulty_app_data() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); let tc = invalid_time_tagged_cmd(); - let insert_res = scheduler.insert_wrapped_tc::(&tc, &mut pool); + let insert_res = scheduler.insert_wrapped_tc::(&tc, &mut pool); assert!(insert_res.is_err()); let err = insert_res.unwrap_err(); match err { @@ -1451,12 +1444,11 @@ mod tests { #[test] fn insert_doubly_wrapped_time_tagged_cmd() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); let mut buf: [u8; 64] = [0; 64]; - let tc = double_wrapped_time_tagged_tc(UnixTimestamp::new_only_seconds(50), &mut buf); - let insert_res = scheduler.insert_wrapped_tc::(&tc, &mut pool); + let tc = double_wrapped_time_tagged_tc(UnixTime::new_only_secs(50), &mut buf); + let insert_res = scheduler.insert_wrapped_tc::(&tc, &mut pool); assert!(insert_res.is_err()); let err = insert_res.unwrap_err(); match err { @@ -1470,31 +1462,29 @@ mod tests { let scheduler = PusScheduler::new_with_current_init_time(Duration::from_secs(5)) .expect("creation from current time failed"); let current_time = scheduler.current_time; - assert!(current_time.unix_seconds > 0); + assert!(current_time.as_secs() > 0); } #[test] fn test_update_from_current() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); - assert_eq!(scheduler.current_time.unix_seconds, 0); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); + assert_eq!(scheduler.current_time.as_secs(), 0); scheduler .update_time_from_now() .expect("updating scheduler time from now failed"); - assert!(scheduler.current_time.unix_seconds > 0); + assert!(scheduler.current_time.as_secs() > 0); } #[test] fn release_time_within_time_margin() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); let mut buf: [u8; 32] = [0; 32]; - let tc = scheduled_tc(UnixTimestamp::new_only_seconds(4), &mut buf); - let insert_res = scheduler.insert_wrapped_tc::(&tc, &mut pool); + let tc = scheduled_tc(UnixTime::new_only_secs(4), &mut buf); + let insert_res = scheduler.insert_wrapped_tc::(&tc, &mut pool); assert!(insert_res.is_err()); let err = insert_res.unwrap_err(); match err { @@ -1503,9 +1493,9 @@ mod tests { time_margin, release_time, } => { - assert_eq!(current_time, UnixTimestamp::new_only_seconds(0)); + assert_eq!(current_time, UnixTime::new_only_secs(0)); assert_eq!(time_margin, Duration::from_secs(5)); - assert_eq!(release_time, UnixTimestamp::new_only_seconds(4)); + assert_eq!(release_time, UnixTime::new_only_secs(4)); } _ => panic!("unexepcted error {err}"), } @@ -1514,12 +1504,11 @@ mod tests { #[test] fn test_store_error_propagation_release() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("insertion failed"); let mut i = 0; @@ -1532,7 +1521,7 @@ mod tests { pool.delete(tc_info_0.addr()).expect("deletion failed"); // scheduler will only auto-delete if it is disabled. scheduler.disable(); - scheduler.update_time(UnixTimestamp::new_only_seconds(100)); + scheduler.update_time(UnixTime::new_only_secs(100)); let release_res = scheduler.release_telecommands(test_closure_1, &mut pool); assert!(release_res.is_err()); let err = release_res.unwrap_err(); @@ -1549,12 +1538,11 @@ mod tests { #[test] fn test_store_error_propagation_reset() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("insertion failed"); // premature deletion @@ -1573,12 +1561,11 @@ mod tests { #[test] fn test_delete_by_req_id_simple_retrieve_addr() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("inserting tc failed"); assert_eq!(scheduler.num_scheduled_telecommands(), 1); let addr = scheduler @@ -1592,12 +1579,11 @@ mod tests { #[test] fn test_delete_by_req_id_simple_delete_all() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("inserting tc failed"); assert_eq!(scheduler.num_scheduled_telecommands(), 1); let del_res = @@ -1611,20 +1597,19 @@ mod tests { #[test] fn test_delete_by_req_id_complex() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("inserting tc failed"); let tc_info_1 = ping_tc_to_store(&mut pool, &mut buf, 1, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_1) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_1) .expect("inserting tc failed"); let tc_info_2 = ping_tc_to_store(&mut pool, &mut buf, 2, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_2) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_2) .expect("inserting tc failed"); assert_eq!(scheduler.num_scheduled_telecommands(), 3); @@ -1654,17 +1639,16 @@ mod tests { #[test] fn insert_full_store_test() { - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(1, 64)], false)); let mut buf: [u8; 32] = [0; 32]; // Store is full after this. pool.add(&[0, 1, 2]).unwrap(); - let tc = scheduled_tc(UnixTimestamp::new_only_seconds(100), &mut buf); + let tc = scheduled_tc(UnixTime::new_only_secs(100), &mut buf); - let insert_res = scheduler.insert_wrapped_tc::(&tc, &mut pool); + let insert_res = scheduler.insert_wrapped_tc::(&tc, &mut pool); assert!(insert_res.is_err()); let err = insert_res.unwrap_err(); match err { @@ -1686,10 +1670,7 @@ mod tests { let tc_info = ping_tc_to_store(pool, &mut buf, seq_count, None); scheduler - .insert_unwrapped_and_stored_tc( - UnixTimestamp::new_only_seconds(release_secs as i64), - tc_info, - ) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(release_secs as i64), tc_info) .expect("inserting tc failed"); tc_info } @@ -1697,21 +1678,20 @@ mod tests { #[test] fn test_time_window_retrieval_select_all() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let tc_info_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50); let tc_info_1 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); assert_eq!(scheduler.num_scheduled_telecommands(), 2); - let check_range = |range: Range>| { + let check_range = |range: Range>| { let mut tcs_in_range = 0; for (idx, time_bucket) in range.enumerate() { tcs_in_range += 1; if idx == 0 { - assert_eq!(*time_bucket.0, UnixTimestamp::new_only_seconds(50)); + assert_eq!(*time_bucket.0, UnixTime::new_only_secs(50)); assert_eq!(time_bucket.1.len(), 1); assert_eq!(time_bucket.1[0].request_id, tc_info_0.request_id); } else if idx == 1 { - assert_eq!(*time_bucket.0, UnixTimestamp::new_only_seconds(100)); + assert_eq!(*time_bucket.0, UnixTime::new_only_secs(100)); assert_eq!(time_bucket.1.len(), 1); assert_eq!(time_bucket.1[0].request_id, tc_info_1.request_id); } @@ -1720,22 +1700,22 @@ mod tests { }; let range = scheduler.retrieve_all(); check_range(range); - let range = - scheduler.retrieve_by_time_filter(TimeWindow::::new_select_all()); + let range = scheduler.retrieve_by_time_filter(TimeWindow::::new_select_all()); check_range(range); } #[test] fn test_time_window_retrieval_select_from_stamp() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let _ = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50); let tc_info_1 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); let tc_info_2 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 150); - let start_stamp = - cds::TimeProvider::from_unix_secs_with_u16_days(&UnixTimestamp::new_only_seconds(100)) - .expect("creating start stamp failed"); + let start_stamp = cds::CdsTime::from_unix_time_with_u16_days( + &UnixTime::new_only_secs(100), + cds::SubmillisPrecision::Absent, + ) + .expect("creating start stamp failed"); let time_window = TimeWindow::new_from_time(&start_stamp); assert_eq!(scheduler.num_scheduled_telecommands(), 3); @@ -1744,11 +1724,11 @@ mod tests { for (idx, time_bucket) in range.enumerate() { tcs_in_range += 1; if idx == 0 { - assert_eq!(*time_bucket.0, UnixTimestamp::new_only_seconds(100)); + assert_eq!(*time_bucket.0, UnixTime::new_only_secs(100)); assert_eq!(time_bucket.1.len(), 1); assert_eq!(time_bucket.1[0].request_id, tc_info_1.request_id()); } else if idx == 1 { - assert_eq!(*time_bucket.0, UnixTimestamp::new_only_seconds(150)); + assert_eq!(*time_bucket.0, UnixTime::new_only_secs(150)); assert_eq!(time_bucket.1.len(), 1); assert_eq!(time_bucket.1[0].request_id, tc_info_2.request_id()); } @@ -1759,27 +1739,28 @@ mod tests { #[test] fn test_time_window_retrieval_select_to_time() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let tc_info_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50); let tc_info_1 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); let _ = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 150); assert_eq!(scheduler.num_scheduled_telecommands(), 3); - let end_stamp = - cds::TimeProvider::from_unix_secs_with_u16_days(&UnixTimestamp::new_only_seconds(100)) - .expect("creating start stamp failed"); + let end_stamp = cds::CdsTime::from_unix_time_with_u16_days( + &UnixTime::new_only_secs(100), + cds::SubmillisPrecision::Absent, + ) + .expect("creating start stamp failed"); let time_window = TimeWindow::new_to_time(&end_stamp); let range = scheduler.retrieve_by_time_filter(time_window); let mut tcs_in_range = 0; for (idx, time_bucket) in range.enumerate() { tcs_in_range += 1; if idx == 0 { - assert_eq!(*time_bucket.0, UnixTimestamp::new_only_seconds(50)); + assert_eq!(*time_bucket.0, UnixTime::new_only_secs(50)); assert_eq!(time_bucket.1.len(), 1); assert_eq!(time_bucket.1[0].request_id, tc_info_0.request_id()); } else if idx == 1 { - assert_eq!(*time_bucket.0, UnixTimestamp::new_only_seconds(100)); + assert_eq!(*time_bucket.0, UnixTime::new_only_secs(100)); assert_eq!(time_bucket.1.len(), 1); assert_eq!(time_bucket.1[0].request_id, tc_info_1.request_id()); } @@ -1790,31 +1771,34 @@ mod tests { #[test] fn test_time_window_retrieval_select_from_time_to_time() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let _ = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50); let tc_info_1 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); let tc_info_2 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 150); let _ = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 200); assert_eq!(scheduler.num_scheduled_telecommands(), 4); - let start_stamp = - cds::TimeProvider::from_unix_secs_with_u16_days(&UnixTimestamp::new_only_seconds(100)) - .expect("creating start stamp failed"); - let end_stamp = - cds::TimeProvider::from_unix_secs_with_u16_days(&UnixTimestamp::new_only_seconds(150)) - .expect("creating end stamp failed"); + let start_stamp = cds::CdsTime::from_unix_time_with_u16_days( + &UnixTime::new_only_secs(100), + cds::SubmillisPrecision::Absent, + ) + .expect("creating start stamp failed"); + let end_stamp = cds::CdsTime::from_unix_time_with_u16_days( + &UnixTime::new_only_secs(150), + cds::SubmillisPrecision::Absent, + ) + .expect("creating end stamp failed"); let time_window = TimeWindow::new_from_time_to_time(&start_stamp, &end_stamp); let range = scheduler.retrieve_by_time_filter(time_window); let mut tcs_in_range = 0; for (idx, time_bucket) in range.enumerate() { tcs_in_range += 1; if idx == 0 { - assert_eq!(*time_bucket.0, UnixTimestamp::new_only_seconds(100)); + assert_eq!(*time_bucket.0, UnixTime::new_only_secs(100)); assert_eq!(time_bucket.1.len(), 1); assert_eq!(time_bucket.1[0].request_id, tc_info_1.request_id()); } else if idx == 1 { - assert_eq!(*time_bucket.0, UnixTimestamp::new_only_seconds(150)); + assert_eq!(*time_bucket.0, UnixTime::new_only_secs(150)); assert_eq!(time_bucket.1.len(), 1); assert_eq!(time_bucket.1[0].request_id, tc_info_2.request_id()); } @@ -1825,8 +1809,7 @@ mod tests { #[test] fn test_deletion_all() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50); insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); assert_eq!(scheduler.num_scheduled_telecommands(), 2); @@ -1841,7 +1824,7 @@ mod tests { insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); assert_eq!(scheduler.num_scheduled_telecommands(), 2); let del_res = scheduler - .delete_by_time_filter(TimeWindow::::new_select_all(), &mut pool); + .delete_by_time_filter(TimeWindow::::new_select_all(), &mut pool); assert!(del_res.is_ok()); assert_eq!(del_res.unwrap(), 2); assert_eq!(scheduler.num_scheduled_telecommands(), 0); @@ -1852,15 +1835,16 @@ mod tests { #[test] fn test_deletion_from_start_time() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50); let cmd_0_to_delete = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); let cmd_1_to_delete = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 150); assert_eq!(scheduler.num_scheduled_telecommands(), 3); - let start_stamp = - cds::TimeProvider::from_unix_secs_with_u16_days(&UnixTimestamp::new_only_seconds(100)) - .expect("creating start stamp failed"); + let start_stamp = cds::CdsTime::from_unix_time_with_u16_days( + &UnixTime::new_only_secs(100), + cds::SubmillisPrecision::Absent, + ) + .expect("creating start stamp failed"); let time_window = TimeWindow::new_from_time(&start_stamp); let del_res = scheduler.delete_by_time_filter(time_window, &mut pool); assert!(del_res.is_ok()); @@ -1873,16 +1857,17 @@ mod tests { #[test] fn test_deletion_to_end_time() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let cmd_0_to_delete = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50); let cmd_1_to_delete = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); insert_command_with_release_time(&mut pool, &mut scheduler, 0, 150); assert_eq!(scheduler.num_scheduled_telecommands(), 3); - let end_stamp = - cds::TimeProvider::from_unix_secs_with_u16_days(&UnixTimestamp::new_only_seconds(100)) - .expect("creating start stamp failed"); + let end_stamp = cds::CdsTime::from_unix_time_with_u16_days( + &UnixTime::new_only_secs(100), + cds::SubmillisPrecision::Absent, + ) + .expect("creating start stamp failed"); let time_window = TimeWindow::new_to_time(&end_stamp); let del_res = scheduler.delete_by_time_filter(time_window, &mut pool); assert!(del_res.is_ok()); @@ -1895,8 +1880,7 @@ mod tests { #[test] fn test_deletion_from_start_time_to_end_time() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let cmd_out_of_range_0 = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 50); let cmd_0_to_delete = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 100); let cmd_1_to_delete = insert_command_with_release_time(&mut pool, &mut scheduler, 0, 150); @@ -1904,12 +1888,16 @@ mod tests { insert_command_with_release_time(&mut pool, &mut scheduler, 0, 200); assert_eq!(scheduler.num_scheduled_telecommands(), 4); - let start_stamp = - cds::TimeProvider::from_unix_secs_with_u16_days(&UnixTimestamp::new_only_seconds(100)) - .expect("creating start stamp failed"); - let end_stamp = - cds::TimeProvider::from_unix_secs_with_u16_days(&UnixTimestamp::new_only_seconds(150)) - .expect("creating end stamp failed"); + let start_stamp = cds::CdsTime::from_unix_time_with_u16_days( + &UnixTime::new_only_secs(100), + cds::SubmillisPrecision::Absent, + ) + .expect("creating start stamp failed"); + let end_stamp = cds::CdsTime::from_unix_time_with_u16_days( + &UnixTime::new_only_secs(150), + cds::SubmillisPrecision::Absent, + ) + .expect("creating end stamp failed"); let time_window = TimeWindow::new_from_time_to_time(&start_stamp, &end_stamp); let del_res = scheduler.delete_by_time_filter(time_window, &mut pool); assert!(del_res.is_ok()); @@ -1924,19 +1912,18 @@ mod tests { #[test] fn test_release_without_deletion() { let mut pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(10, 32), (5, 64)], false)); - let mut scheduler = - PusScheduler::new(UnixTimestamp::new_only_seconds(0), Duration::from_secs(5)); + let mut scheduler = PusScheduler::new(UnixTime::new_only_secs(0), Duration::from_secs(5)); let mut buf: [u8; 32] = [0; 32]; let tc_info_0 = ping_tc_to_store(&mut pool, &mut buf, 0, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), tc_info_0) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(100), tc_info_0) .expect("insertion failed"); let tc_info_1 = ping_tc_to_store(&mut pool, &mut buf, 1, None); scheduler - .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(200), tc_info_1) + .insert_unwrapped_and_stored_tc(UnixTime::new_only_secs(200), tc_info_1) .expect("insertion failed"); let mut i = 0; @@ -1949,7 +1936,7 @@ mod tests { ); }; - scheduler.update_time(UnixTimestamp::new_only_seconds(205)); + scheduler.update_time(UnixTime::new_only_secs(205)); let mut tc_buf: [u8; 64] = [0; 64]; let tc_info_vec = scheduler @@ -1961,7 +1948,7 @@ mod tests { #[test] fn test_generic_insert_app_data_test() { - let time_writer = cds::TimeProvider::new_with_u16_days(1, 1); + let time_writer = cds::CdsTime::new_with_u16_days(1, 1); let mut sph = SpHeader::new( PacketId::const_new(PacketType::Tc, true, 0x002), PacketSequenceCtrl::const_new(SequenceFlags::Unsegmented, 5), @@ -1975,7 +1962,7 @@ mod tests { assert_eq!(result.unwrap(), 2 + 7 + ping_tc.len_written()); let n = u16::from_be_bytes(buf[0..2].try_into().unwrap()); assert_eq!(n, 1); - let time_reader = cds::TimeProvider::from_bytes_with_u16_days(&buf[2..2 + 7]).unwrap(); + let time_reader = cds::CdsTime::from_bytes_with_u16_days(&buf[2..2 + 7]).unwrap(); assert_eq!(time_reader, time_writer); let pus_tc_reader = PusTcReader::new(&buf[9..]).unwrap().0; assert_eq!(pus_tc_reader, ping_tc); @@ -1983,7 +1970,7 @@ mod tests { #[test] fn test_generic_insert_app_data_test_byte_conv_error() { - let time_writer = cds::TimeProvider::new_with_u16_days(1, 1); + let time_writer = cds::CdsTime::new_with_u16_days(1, 1); let mut sph = SpHeader::new( PacketId::const_new(PacketType::Tc, true, 0x002), PacketSequenceCtrl::const_new(SequenceFlags::Unsegmented, 5), @@ -2012,7 +1999,7 @@ mod tests { #[test] fn test_generic_insert_app_data_test_as_vec() { - let time_writer = cds::TimeProvider::new_with_u16_days(1, 1); + let time_writer = cds::CdsTime::new_with_u16_days(1, 1); let mut sph = SpHeader::new( PacketId::const_new(PacketType::Tc, true, 0x002), PacketSequenceCtrl::const_new(SequenceFlags::Unsegmented, 5), diff --git a/satrs/src/pus/scheduler_srv.rs b/satrs/src/pus/scheduler_srv.rs index 9cfb920..cc75fe0 100644 --- a/satrs/src/pus/scheduler_srv.rs +++ b/satrs/src/pus/scheduler_srv.rs @@ -14,7 +14,7 @@ use crate::pool::PoolProvider; use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError}; use alloc::string::ToString; use spacepackets::ecss::{scheduling, PusPacket}; -use spacepackets::time::cds::TimeProvider; +use spacepackets::time::cds::CdsTime; /// This is a helper class for [std] environments to handle generic PUS 11 (scheduling service) /// packets. This handler is able to handle the most important PUS requests for a scheduling @@ -168,7 +168,7 @@ impl< // let mut pool = self.sched_tc_pool.write().expect("locking pool failed"); self.scheduler - .insert_wrapped_tc::(&tc, sched_tc_pool) + .insert_wrapped_tc::(&tc, sched_tc_pool) .expect("insertion of activity into pool failed"); self.service_helper @@ -303,7 +303,7 @@ mod tests { } impl PusSchedulerProvider for TestScheduler { - type TimeProvider = cds::TimeProvider; + type TimeProvider = cds::CdsTime; fn reset( &mut self, @@ -329,7 +329,7 @@ mod tests { fn insert_unwrapped_and_stored_tc( &mut self, - _time_stamp: spacepackets::time::UnixTimestamp, + _time_stamp: spacepackets::time::UnixTime, info: crate::pus::scheduler::TcInfo, ) -> Result<(), crate::pus::scheduler::ScheduleError> { self.inserted_tcs.push_back(info); @@ -390,7 +390,7 @@ mod tests { let mut sec_header = PusTcSecondaryHeader::new_simple(17, 1); let ping_tc = PusTcCreator::new(&mut reply_header, sec_header, &[], true); let req_id_ping_tc = scheduler::RequestId::from_tc(&ping_tc); - let stamper = cds::TimeProvider::from_now_with_u16_days().expect("time provider failed"); + let stamper = cds::CdsTime::now_with_u16_days().expect("time provider failed"); let mut sched_app_data: [u8; 64] = [0; 64]; let mut written_len = stamper.write_to_bytes(&mut sched_app_data).unwrap(); let ping_raw = ping_tc.to_vec().expect("generating raw tc failed"); diff --git a/satrs/src/pus/verification.rs b/satrs/src/pus/verification.rs index 89ce9b9..e44bc73 100644 --- a/satrs/src/pus/verification.rs +++ b/satrs/src/pus/verification.rs @@ -87,8 +87,8 @@ use delegate::delegate; use serde::{Deserialize, Serialize}; use spacepackets::ecss::tc::IsPusTelecommand; use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; -use spacepackets::ecss::{EcssEnumeration, PusError, WritablePusPacket}; -use spacepackets::{CcsdsPacket, PacketId, PacketSequenceCtrl}; +use spacepackets::ecss::{EcssEnumeration, PusError}; +use spacepackets::{ByteConversionError, CcsdsPacket, PacketId, PacketSequenceCtrl}; use spacepackets::{SpHeader, MAX_APID}; pub use crate::seq_count::SeqCountProviderSimple; @@ -328,87 +328,6 @@ impl<'stamp, 'fargs> FailParamsWithStep<'stamp, 'fargs> { } } -#[derive(Clone)] -pub struct VerificationReporterCore { - pub dest_id: u16, - apid: u16, -} - -pub enum VerifSuccess {} -pub enum VerifFailure {} - -/// Abstraction for a sendable PUS TM. The user is expected to send the TM packet to a TM sink. -/// -/// This struct generally mutably borrows the source data buffer. -pub struct VerificationSendable<'src_data, State, SuccessOrFailure> { - token: Option>, - pus_tm: Option>, - phantom: PhantomData, -} - -impl<'src_data, State, SuccessOrFailure> VerificationSendable<'src_data, State, SuccessOrFailure> { - pub(crate) fn new(pus_tm: PusTmCreator<'src_data>, token: VerificationToken) -> Self { - Self { - token: Some(token), - pus_tm: Some(pus_tm), - phantom: PhantomData, - } - } - pub(crate) fn new_no_token(pus_tm: PusTmCreator<'src_data>) -> Self { - Self { - token: None, - pus_tm: Some(pus_tm), - phantom: PhantomData, - } - } - - pub fn len_packed(&self) -> usize { - self.pus_tm.as_ref().unwrap().len_written() - } - - pub fn pus_tm(&self) -> &PusTmCreator<'src_data> { - self.pus_tm.as_ref().unwrap() - } - - pub fn pus_tm_mut(&mut self) -> &mut PusTmCreator<'src_data> { - self.pus_tm.as_mut().unwrap() - } -} - -impl<'src_data, State> VerificationSendable<'src_data, State, VerifFailure> { - pub fn send_success_verif_failure(self) {} -} - -impl<'src_data, State> VerificationSendable<'src_data, State, VerifFailure> { - pub fn send_failure(self) -> (PusTmCreator<'src_data>, VerificationToken) { - (self.pus_tm.unwrap(), self.token.unwrap()) - } -} - -impl<'src_data> VerificationSendable<'src_data, TcStateNone, VerifSuccess> { - pub fn send_success_acceptance_success(self) -> VerificationToken { - VerificationToken { - state: PhantomData, - req_id: self.token.unwrap().req_id(), - } - } -} - -impl<'src_data> VerificationSendable<'src_data, TcStateAccepted, VerifSuccess> { - pub fn send_success_start_success(self) -> VerificationToken { - VerificationToken { - state: PhantomData, - req_id: self.token.unwrap().req_id(), - } - } -} - -impl<'src_data, TcState: WasAtLeastAccepted + Copy> - VerificationSendable<'src_data, TcState, VerifSuccess> -{ - pub fn send_success_step_or_completion_success(self) {} -} - pub trait VerificationReportingProvider { fn add_tc( &mut self, @@ -423,25 +342,25 @@ pub trait VerificationReportingProvider { &self, token: VerificationToken, time_stamp: &[u8], - ) -> Result, VerificationOrSendErrorWithToken>; + ) -> Result, EcssTmtcError>; fn acceptance_failure( &self, token: VerificationToken, params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken>; + ) -> Result<(), EcssTmtcError>; fn start_success( &self, token: VerificationToken, time_stamp: &[u8], - ) -> Result, VerificationOrSendErrorWithToken>; + ) -> Result, EcssTmtcError>; fn start_failure( &self, token: VerificationToken, params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken>; + ) -> Result<(), EcssTmtcError>; fn step_success( &self, @@ -454,29 +373,35 @@ pub trait VerificationReportingProvider { &self, token: VerificationToken, params: FailParamsWithStep, - ) -> Result<(), VerificationOrSendErrorWithToken>; + ) -> Result<(), EcssTmtcError>; fn completion_success( &self, token: VerificationToken, time_stamp: &[u8], - ) -> Result<(), VerificationOrSendErrorWithToken>; + ) -> Result<(), EcssTmtcError>; fn completion_failure( &self, token: VerificationToken, params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken>; + ) -> Result<(), EcssTmtcError>; } -/// Primary verification handler. It provides an API to send PUS 1 verification telemetry packets -/// and verify the various steps of telecommand handling as specified in the PUS standard. +/// Primary verification handler. It provides an API to generate PUS 1 verification telemetry +/// packets and verify the various steps of telecommand handling as specified in the PUS standard. /// /// This is the core component which can be used without [`alloc`] support. Please note that /// the buffer passed to the API exposes by this struct will be used to serialize the source data. /// This buffer may not be re-used to serialize the whole telemetry because that would overwrite /// the source data itself. -impl VerificationReporterCore { +#[derive(Clone)] +pub struct VerificationReportCreator { + pub dest_id: u16, + apid: u16, +} + +impl VerificationReportCreator { pub fn new(apid: u16) -> Option { if apid > MAX_APID { return None; @@ -519,36 +444,30 @@ impl VerificationReporterCore { VerificationToken::::new(req_id) } - fn sendable_success_no_step<'src_data, State: Copy>( + fn success_verification_no_step<'time, 'src_data, State: Copy>( &self, src_data_buf: &'src_data mut [u8], subservice: u8, token: VerificationToken, seq_count: u16, msg_count: u16, - time_stamp: &'src_data [u8], - ) -> Result< - VerificationSendable<'src_data, State, VerifSuccess>, - VerificationErrorWithToken, - > { - Ok(VerificationSendable::new( - self.create_pus_verif_success_tm( - src_data_buf, - subservice, - seq_count, - msg_count, - &token.req_id, - time_stamp, - None::<&dyn EcssEnumeration>, - ) - .map_err(|e| VerificationErrorWithToken(e, token))?, - token, - )) + time_stamp: &'time [u8], + ) -> Result, ByteConversionError> { + let tm_creator = self.create_pus_verif_success_tm( + src_data_buf, + subservice, + seq_count, + msg_count, + &token.req_id, + time_stamp, + None::<&dyn EcssEnumeration>, + )?; + Ok(tm_creator) } // Internal helper function, too many arguments is acceptable for this case. #[allow(clippy::too_many_arguments)] - fn sendable_failure_no_step<'src_data, State: Copy>( + fn failure_verification_no_step<'time, 'src_data, State: Copy>( &self, src_data_buf: &'src_data mut [u8], subservice: u8, @@ -556,85 +475,62 @@ impl VerificationReporterCore { seq_count: u16, msg_count: u16, step: Option<&(impl EcssEnumeration + ?Sized)>, - params: &FailParams<'src_data, '_>, - ) -> Result< - VerificationSendable<'src_data, State, VerifFailure>, - VerificationErrorWithToken, - > { - Ok(VerificationSendable::new( - self.create_pus_verif_fail_tm( - src_data_buf, - subservice, - seq_count, - msg_count, - &token.req_id, - step, - params, - ) - .map_err(|e| VerificationErrorWithToken(e, token))?, - token, - )) + params: &FailParams<'time, '_>, + ) -> Result, ByteConversionError> { + let tm_creator = self.create_pus_verif_fail_tm( + src_data_buf, + subservice, + seq_count, + msg_count, + &token.req_id, + step, + params, + )?; + Ok(tm_creator) } /// Package a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard. - pub fn acceptance_success<'src_data>( + pub fn acceptance_success<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], token: VerificationToken, seq_count: u16, msg_count: u16, - time_stamp: &'src_data [u8], + time_stamp: &'time [u8], ) -> Result< - VerificationSendable<'src_data, TcStateNone, VerifSuccess>, - VerificationErrorWithToken, + ( + PusTmCreator<'time, 'src_data>, + VerificationToken, + ), + ByteConversionError, > { - self.sendable_success_no_step( + let tm_creator = self.success_verification_no_step( src_data_buf, Subservice::TmAcceptanceSuccess.into(), token, seq_count, msg_count, time_stamp, - ) - } - - pub fn send_acceptance_success( - &self, - mut sendable: VerificationSendable<'_, TcStateNone, VerifSuccess>, - sender: &(impl EcssTmSenderCore + ?Sized), - ) -> Result, VerificationOrSendErrorWithToken> - { - sender - .send_tm(sendable.pus_tm.take().unwrap().into()) - .map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?; - Ok(sendable.send_success_acceptance_success()) - } - - pub fn send_acceptance_failure( - &self, - mut sendable: VerificationSendable<'_, TcStateNone, VerifFailure>, - sender: &(impl EcssTmSenderCore + ?Sized), - ) -> Result<(), VerificationOrSendErrorWithToken> { - sender - .send_tm(sendable.pus_tm.take().unwrap().into()) - .map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?; - sendable.send_success_verif_failure(); - Ok(()) + )?; + Ok(( + tm_creator, + VerificationToken { + state: PhantomData, + req_id: token.req_id, + }, + )) } /// Package a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard. - pub fn acceptance_failure<'src_data>( + pub fn acceptance_failure<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], token: VerificationToken, seq_count: u16, msg_count: u16, - params: FailParams<'src_data, '_>, - ) -> Result< - VerificationSendable<'src_data, TcStateNone, VerifFailure>, - VerificationErrorWithToken, - > { - self.sendable_failure_no_step( + params: FailParams<'time, '_>, + ) -> Result, ByteConversionError> { + self.failure_verification_no_step( src_data_buf, Subservice::TmAcceptanceFailure.into(), token, @@ -648,55 +544,50 @@ impl VerificationReporterCore { /// Package and send a PUS TM\[1, 3\] packet, see 8.1.2.3 of the PUS standard. /// /// Requires a token previously acquired by calling [Self::acceptance_success]. - pub fn start_success<'src_data>( + pub fn start_success<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], token: VerificationToken, seq_count: u16, msg_count: u16, - time_stamp: &'src_data [u8], + time_stamp: &'time [u8], ) -> Result< - VerificationSendable<'src_data, TcStateAccepted, VerifSuccess>, - VerificationErrorWithToken, + ( + PusTmCreator<'time, 'src_data>, + VerificationToken, + ), + ByteConversionError, > { - self.sendable_success_no_step( + let tm_creator = self.success_verification_no_step( src_data_buf, Subservice::TmStartSuccess.into(), token, seq_count, msg_count, time_stamp, - ) - } - - pub fn send_start_success( - &self, - mut sendable: VerificationSendable<'_, TcStateAccepted, VerifSuccess>, - sender: &(impl EcssTmSenderCore + ?Sized), - ) -> Result, VerificationOrSendErrorWithToken> - { - sender - .send_tm(sendable.pus_tm.take().unwrap().into()) - .map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?; - Ok(sendable.send_success_start_success()) + )?; + Ok(( + tm_creator, + VerificationToken { + state: PhantomData, + req_id: token.req_id, + }, + )) } /// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard. /// /// Requires a token previously acquired by calling [Self::acceptance_success]. It consumes /// the token because verification handling is done. - pub fn start_failure<'src_data>( + pub fn start_failure<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], token: VerificationToken, seq_count: u16, msg_count: u16, - params: FailParams<'src_data, '_>, - ) -> Result< - VerificationSendable<'src_data, TcStateAccepted, VerifFailure>, - VerificationErrorWithToken, - > { - self.sendable_failure_no_step( + params: FailParams<'time, '_>, + ) -> Result, ByteConversionError> { + self.failure_verification_no_step( src_data_buf, Subservice::TmStartFailure.into(), token, @@ -707,89 +598,65 @@ impl VerificationReporterCore { ) } - pub fn send_start_failure( - &self, - mut sendable: VerificationSendable<'_, TcStateAccepted, VerifFailure>, - sender: &(impl EcssTmSenderCore + ?Sized), - ) -> Result<(), VerificationOrSendErrorWithToken> { - sender - .send_tm(sendable.pus_tm.take().unwrap().into()) - .map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?; - sendable.send_success_verif_failure(); - Ok(()) - } - /// Package and send a PUS TM\[1, 5\] packet, see 8.1.2.5 of the PUS standard. /// /// Requires a token previously acquired by calling [Self::start_success]. - pub fn step_success<'src_data>( + pub fn step_success<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], token: &VerificationToken, seq_count: u16, msg_count: u16, - time_stamp: &'src_data [u8], + time_stamp: &'time [u8], step: impl EcssEnumeration, - ) -> Result, EcssTmtcError> { - Ok(VerificationSendable::new_no_token( - self.create_pus_verif_success_tm( - src_data_buf, - Subservice::TmStepSuccess.into(), - seq_count, - msg_count, - &token.req_id, - time_stamp, - Some(&step), - )?, - )) + ) -> Result, ByteConversionError> { + self.create_pus_verif_success_tm( + src_data_buf, + Subservice::TmStepSuccess.into(), + seq_count, + msg_count, + &token.req_id, + time_stamp, + Some(&step), + ) } /// Package and send a PUS TM\[1, 6\] packet, see 8.1.2.6 of the PUS standard. /// /// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// token because verification handling is done. - pub fn step_failure<'src_data>( + pub fn step_failure<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], token: VerificationToken, seq_count: u16, msg_count: u16, - params: FailParamsWithStep<'src_data, '_>, - ) -> Result< - VerificationSendable<'src_data, TcStateStarted, VerifFailure>, - VerificationErrorWithToken, - > { - Ok(VerificationSendable::new( - self.create_pus_verif_fail_tm( - src_data_buf, - Subservice::TmStepFailure.into(), - seq_count, - msg_count, - &token.req_id, - Some(params.step), - ¶ms.bp, - ) - .map_err(|e| VerificationErrorWithToken(e, token))?, - token, - )) + params: FailParamsWithStep<'time, '_>, + ) -> Result, ByteConversionError> { + self.create_pus_verif_fail_tm( + src_data_buf, + Subservice::TmStepFailure.into(), + seq_count, + msg_count, + &token.req_id, + Some(params.step), + ¶ms.bp, + ) } /// Package and send a PUS TM\[1, 7\] packet, see 8.1.2.7 of the PUS standard. /// /// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// token because verification handling is done. - pub fn completion_success<'src_data, TcState: WasAtLeastAccepted + Copy>( + pub fn completion_success<'time, 'src_data, TcState: WasAtLeastAccepted + Copy>( &self, src_data_buf: &'src_data mut [u8], token: VerificationToken, seq_counter: u16, msg_counter: u16, - time_stamp: &'src_data [u8], - ) -> Result< - VerificationSendable<'src_data, TcState, VerifSuccess>, - VerificationErrorWithToken, - > { - self.sendable_success_no_step( + time_stamp: &'time [u8], + ) -> Result, ByteConversionError> { + self.success_verification_no_step( src_data_buf, Subservice::TmCompletionSuccess.into(), token, @@ -803,18 +670,15 @@ impl VerificationReporterCore { /// /// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// token because verification handling is done. - pub fn completion_failure<'src_data, TcState: WasAtLeastAccepted + Copy>( + pub fn completion_failure<'time, 'src_data, TcState: WasAtLeastAccepted + Copy>( &self, src_data_buf: &'src_data mut [u8], token: VerificationToken, seq_count: u16, msg_count: u16, - params: FailParams<'src_data, '_>, - ) -> Result< - VerificationSendable<'src_data, TcState, VerifFailure>, - VerificationErrorWithToken, - > { - self.sendable_failure_no_step( + params: FailParams<'time, '_>, + ) -> Result, ByteConversionError> { + self.failure_verification_no_step( src_data_buf, Subservice::TmCompletionFailure.into(), token, @@ -825,42 +689,18 @@ impl VerificationReporterCore { ) } - pub fn send_step_or_completion_success( - &self, - mut sendable: VerificationSendable<'_, TcState, VerifSuccess>, - sender: &(impl EcssTmSenderCore + ?Sized), - ) -> Result<(), VerificationOrSendErrorWithToken> { - sender - .send_tm(sendable.pus_tm.take().unwrap().into()) - .map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?; - sendable.send_success_step_or_completion_success(); - Ok(()) - } - - pub fn send_step_or_completion_failure( - &self, - mut sendable: VerificationSendable<'_, TcState, VerifFailure>, - sender: &(impl EcssTmSenderCore + ?Sized), - ) -> Result<(), VerificationOrSendErrorWithToken> { - sender - .send_tm(sendable.pus_tm.take().unwrap().into()) - .map_err(|e| VerificationOrSendErrorWithToken(e, sendable.token.unwrap()))?; - sendable.send_success_verif_failure(); - Ok(()) - } - // Internal helper function, too many arguments is acceptable for this case. #[allow(clippy::too_many_arguments)] - fn create_pus_verif_success_tm<'src_data>( + fn create_pus_verif_success_tm<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], subservice: u8, seq_count: u16, msg_counter: u16, req_id: &RequestId, - time_stamp: &'src_data [u8], + time_stamp: &'time [u8], step: Option<&(impl EcssEnumeration + ?Sized)>, - ) -> Result, EcssTmtcError> { + ) -> Result, ByteConversionError> { let mut source_data_len = size_of::(); if let Some(step) = step { source_data_len += step.size(); @@ -887,7 +727,7 @@ impl VerificationReporterCore { // Internal helper function, too many arguments is acceptable for this case. #[allow(clippy::too_many_arguments)] - fn create_pus_verif_fail_tm<'src_data>( + fn create_pus_verif_fail_tm<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], subservice: u8, @@ -895,8 +735,8 @@ impl VerificationReporterCore { msg_counter: u16, req_id: &RequestId, step: Option<&(impl EcssEnumeration + ?Sized)>, - params: &FailParams<'src_data, '_>, - ) -> Result, EcssTmtcError> { + params: &FailParams<'time, '_>, + ) -> Result, ByteConversionError> { let mut idx = 0; let mut source_data_len = RequestId::SIZE_AS_BYTES + params.failure_code.size(); if let Some(step) = step { @@ -914,8 +754,7 @@ impl VerificationReporterCore { } params .failure_code - .write_to_be_bytes(&mut src_data_buf[idx..idx + params.failure_code.size()]) - .map_err(PusError::ByteConversion)?; + .write_to_be_bytes(&mut src_data_buf[idx..idx + params.failure_code.size()])?; idx += params.failure_code.size(); src_data_buf[idx..idx + params.failure_data.len()].copy_from_slice(params.failure_data); let mut sp_header = SpHeader::tm_unseg(self.apid(), seq_count, 0).unwrap(); @@ -929,15 +768,15 @@ impl VerificationReporterCore { )) } - fn create_pus_verif_tm_base<'src_data>( + fn create_pus_verif_tm_base<'time, 'src_data>( &self, src_data_buf: &'src_data mut [u8], subservice: u8, msg_counter: u16, sp_header: &mut SpHeader, - time_stamp: &'src_data [u8], + time_stamp: &'time [u8], source_data_len: usize, - ) -> PusTmCreator<'src_data> { + ) -> PusTmCreator<'time, 'src_data> { let tm_sec_header = PusTmSecondaryHeader::new(1, subservice, msg_counter, self.dest_id, Some(time_stamp)); PusTmCreator::new( @@ -953,7 +792,7 @@ impl VerificationReporterCore { pub mod alloc_mod { use super::*; use crate::{ - pus::{TmAsVecSenderWithId, TmInSharedPoolSenderWithId}, + pus::{PusTmWrapper, TmAsVecSenderWithId, TmInSharedPoolSenderWithId}, seq_count::SequenceCountProvider, }; use core::cell::RefCell; @@ -994,12 +833,12 @@ pub mod alloc_mod { source_data_buf: RefCell>, pub seq_count_provider: Option + Send>>, pub msg_count_provider: Option + Send>>, - pub reporter: VerificationReporterCore, + pub reporter: VerificationReportCreator, } impl VerificationReporter { pub fn new(cfg: &VerificationReporterCfg) -> Self { - let reporter = VerificationReporterCore::new(cfg.apid).unwrap(); + let reporter = VerificationReportCreator::new(cfg.apid).unwrap(); Self { source_data_buf: RefCell::new(alloc::vec![ 0; @@ -1035,8 +874,7 @@ pub mod alloc_mod { token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), time_stamp: &[u8], - ) -> Result, VerificationOrSendErrorWithToken> - { + ) -> Result, EcssTmtcError> { let seq_count = self .seq_count_provider .as_ref() @@ -1046,14 +884,18 @@ pub mod alloc_mod { .as_ref() .map_or(0, |v| v.get_and_increment()); let mut source_data_buf = self.source_data_buf.borrow_mut(); - let sendable = self.reporter.acceptance_success( - source_data_buf.as_mut_slice(), - token, - seq_count, - msg_count, - time_stamp, - )?; - self.reporter.send_acceptance_success(sendable, sender) + let (tm_creator, token) = self + .reporter + .acceptance_success( + source_data_buf.as_mut_slice(), + token, + seq_count, + msg_count, + time_stamp, + ) + .map_err(PusError::ByteConversion)?; + sender.send_tm(PusTmWrapper::Direct(tm_creator))?; + Ok(token) } /// Package and send a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard @@ -1062,7 +904,7 @@ pub mod alloc_mod { token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let seq_count = self .seq_count_provider .as_ref() @@ -1072,14 +914,12 @@ pub mod alloc_mod { .as_ref() .map_or(0, |v| v.get_and_increment()); let mut buf = self.source_data_buf.borrow_mut(); - let sendable = self.reporter.acceptance_failure( - buf.as_mut_slice(), - token, - seq_count, - msg_count, - params, - )?; - self.reporter.send_acceptance_failure(sendable, sender) + let sendable = self + .reporter + .acceptance_failure(buf.as_mut_slice(), token, seq_count, msg_count, params) + .map_err(PusError::ByteConversion)?; + sender.send_tm(PusTmWrapper::Direct(sendable))?; + Ok(()) } /// Package and send a PUS TM\[1, 3\] packet, see 8.1.2.3 of the PUS standard. @@ -1090,10 +930,7 @@ pub mod alloc_mod { token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), time_stamp: &[u8], - ) -> Result< - VerificationToken, - VerificationOrSendErrorWithToken, - > { + ) -> Result, EcssTmtcError> { let seq_count = self .seq_count_provider .as_ref() @@ -1103,14 +940,13 @@ pub mod alloc_mod { .as_ref() .map_or(0, |v| v.get_and_increment()); let mut buf = self.source_data_buf.borrow_mut(); - let sendable = self.reporter.start_success( - buf.as_mut_slice(), - token, - seq_count, - msg_count, - time_stamp, - )?; - self.reporter.send_start_success(sendable, sender) + let (tm_creator, started_token) = self + .reporter + .start_success(buf.as_mut_slice(), token, seq_count, msg_count, time_stamp) + .map_err(PusError::ByteConversion)?; + sender.send_tm(PusTmWrapper::Direct(tm_creator))?; + Ok(started_token) + //self.reporter.send_start_success(sendable, sender) } /// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard. @@ -1122,7 +958,7 @@ pub mod alloc_mod { token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let seq_count = self .seq_count_provider .as_ref() @@ -1132,14 +968,12 @@ pub mod alloc_mod { .as_ref() .map_or(0, |v| v.get_and_increment()); let mut buf = self.source_data_buf.borrow_mut(); - let sendable = self.reporter.start_failure( - buf.as_mut_slice(), - token, - seq_count, - msg_count, - params, - )?; - self.reporter.send_start_failure(sendable, sender) + let sendable = self + .reporter + .start_failure(buf.as_mut_slice(), token, seq_count, msg_count, params) + .map_err(PusError::ByteConversion)?; + sender.send_tm(PusTmWrapper::Direct(sendable))?; + Ok(()) } /// Package and send a PUS TM\[1, 5\] packet, see 8.1.2.5 of the PUS standard. @@ -1161,17 +995,19 @@ pub mod alloc_mod { .as_ref() .map_or(0, |v| v.get_and_increment()); let mut buf = self.source_data_buf.borrow_mut(); - let sendable = self.reporter.step_success( - buf.as_mut_slice(), - token, - seq_count, - msg_count, - time_stamp, - step, - )?; - self.reporter - .send_step_or_completion_success(sendable, sender) - .map_err(|e| e.0) + let sendable = self + .reporter + .step_success( + buf.as_mut_slice(), + token, + seq_count, + msg_count, + time_stamp, + step, + ) + .map_err(PusError::ByteConversion)?; + sender.send_tm(PusTmWrapper::Direct(sendable))?; + Ok(()) } /// Package and send a PUS TM\[1, 6\] packet, see 8.1.2.6 of the PUS standard. @@ -1183,7 +1019,7 @@ pub mod alloc_mod { token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), params: FailParamsWithStep, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let seq_count = self .seq_count_provider .as_ref() @@ -1193,15 +1029,12 @@ pub mod alloc_mod { .as_ref() .map_or(0, |v| v.get_and_increment()); let mut buf = self.source_data_buf.borrow_mut(); - let sendable = self.reporter.step_failure( - buf.as_mut_slice(), - token, - seq_count, - msg_count, - params, - )?; - self.reporter - .send_step_or_completion_failure(sendable, sender) + let sendable = self + .reporter + .step_failure(buf.as_mut_slice(), token, seq_count, msg_count, params) + .map_err(PusError::ByteConversion)?; + sender.send_tm(PusTmWrapper::Direct(sendable))?; + Ok(()) } /// Package and send a PUS TM\[1, 7\] packet, see 8.1.2.7 of the PUS standard. @@ -1213,7 +1046,7 @@ pub mod alloc_mod { token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), time_stamp: &[u8], - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let seq_count = self .seq_count_provider .as_ref() @@ -1223,15 +1056,12 @@ pub mod alloc_mod { .as_ref() .map_or(0, |v| v.get_and_increment()); let mut buf = self.source_data_buf.borrow_mut(); - let sendable = self.reporter.completion_success( - buf.as_mut_slice(), - token, - seq_count, - msg_count, - time_stamp, - )?; - self.reporter - .send_step_or_completion_success(sendable, sender) + let sendable = self + .reporter + .completion_success(buf.as_mut_slice(), token, seq_count, msg_count, time_stamp) + .map_err(PusError::ByteConversion)?; + sender.send_tm(PusTmWrapper::Direct(sendable))?; + Ok(()) } /// Package and send a PUS TM\[1, 8\] packet, see 8.1.2.8 of the PUS standard. @@ -1243,7 +1073,7 @@ pub mod alloc_mod { token: VerificationToken, sender: &(impl EcssTmSenderCore + ?Sized), params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let seq_count = self .seq_count_provider .as_ref() @@ -1253,15 +1083,12 @@ pub mod alloc_mod { .as_ref() .map_or(0, |v| v.get_and_increment()); let mut buf = self.source_data_buf.borrow_mut(); - let sendable = self.reporter.completion_failure( - buf.as_mut_slice(), - token, - seq_count, - msg_count, - params, - )?; - self.reporter - .send_step_or_completion_failure(sendable, sender) + let sendable = self + .reporter + .completion_failure(buf.as_mut_slice(), token, seq_count, msg_count, params) + .map_err(PusError::ByteConversion)?; + sender.send_tm(PusTmWrapper::Direct(sendable))?; + Ok(()) } } @@ -1310,8 +1137,7 @@ pub mod alloc_mod { &self, token: VerificationToken, time_stamp: &[u8], - ) -> Result, VerificationOrSendErrorWithToken> - { + ) -> Result, EcssTmtcError> { self.reporter .acceptance_success(token, &self.sender, time_stamp) } @@ -1320,7 +1146,7 @@ pub mod alloc_mod { &self, token: VerificationToken, params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { self.reporter .acceptance_failure(token, &self.sender, params) } @@ -1329,10 +1155,7 @@ pub mod alloc_mod { &self, token: VerificationToken, time_stamp: &[u8], - ) -> Result< - VerificationToken, - VerificationOrSendErrorWithToken, - > { + ) -> Result, EcssTmtcError> { self.reporter.start_success(token, &self.sender, time_stamp) } @@ -1340,7 +1163,7 @@ pub mod alloc_mod { &self, token: VerificationToken, params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { self.reporter.start_failure(token, &self.sender, params) } @@ -1358,7 +1181,7 @@ pub mod alloc_mod { &self, token: VerificationToken, params: FailParamsWithStep, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { self.reporter.step_failure(token, &self.sender, params) } @@ -1366,7 +1189,7 @@ pub mod alloc_mod { &self, token: VerificationToken, time_stamp: &[u8], - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { self.reporter .completion_success(token, &self.sender, time_stamp) } @@ -1375,7 +1198,7 @@ pub mod alloc_mod { &self, token: VerificationToken, params: FailParams, - ) -> Result<(), VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { self.reporter .completion_failure(token, &self.sender, params) } @@ -1490,10 +1313,7 @@ pub mod tests { &self, token: VerificationToken, _time_stamp: &[u8], - ) -> Result< - VerificationToken, - super::VerificationOrSendErrorWithToken, - > { + ) -> Result, EcssTmtcError> { let verif_map = self.verification_map.lock().unwrap(); match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => entry.accepted = Some(true), @@ -1512,7 +1332,7 @@ pub mod tests { &self, token: VerificationToken, params: FailParams, - ) -> Result<(), super::VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let verif_map = self.verification_map.lock().unwrap(); match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => { @@ -1532,10 +1352,7 @@ pub mod tests { &self, token: VerificationToken, _time_stamp: &[u8], - ) -> Result< - VerificationToken, - super::VerificationOrSendErrorWithToken, - > { + ) -> Result, EcssTmtcError> { let verif_map = self.verification_map.lock().unwrap(); match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => entry.started = Some(true), @@ -1551,7 +1368,7 @@ pub mod tests { &self, token: VerificationToken, params: FailParams, - ) -> Result<(), super::VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let verif_map = self.verification_map.lock().unwrap(); match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => { @@ -1585,7 +1402,7 @@ pub mod tests { &self, token: VerificationToken, _params: FailParamsWithStep, - ) -> Result<(), super::VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let verif_map = self.verification_map.lock().unwrap(); match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => { @@ -1600,7 +1417,7 @@ pub mod tests { &self, token: VerificationToken, _time_stamp: &[u8], - ) -> Result<(), super::VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let verif_map = self.verification_map.lock().unwrap(); match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => entry.completed = Some(true), @@ -1616,7 +1433,7 @@ pub mod tests { &self, token: VerificationToken, params: FailParams, - ) -> Result<(), super::VerificationOrSendErrorWithToken> { + ) -> Result<(), EcssTmtcError> { let verif_map = self.verification_map.lock().unwrap(); match verif_map.borrow_mut().get_mut(&token.req_id) { Some(entry) => { @@ -1860,8 +1677,7 @@ pub mod tests { let res = b.helper.acceptance_failure(tok, fail_params); assert!(res.is_err()); let err_with_token = res.unwrap_err(); - assert_eq!(err_with_token.1, tok); - match err_with_token.0 { + match err_with_token { EcssTmtcError::Pus(PusError::ByteConversion(e)) => match e { ByteConversionError::ToSliceTooSmall { found, expected } => { assert_eq!( @@ -1875,7 +1691,7 @@ pub mod tests { } }, _ => { - panic!("{}", format!("Unexpected error {:?}", err_with_token.0)) + panic!("{}", format!("Unexpected error {:?}", err_with_token)) } } } diff --git a/satrs/src/tmtc/ccsds_distrib.rs b/satrs/src/tmtc/ccsds_distrib.rs index a0d01b0..10ee80e 100644 --- a/satrs/src/tmtc/ccsds_distrib.rs +++ b/satrs/src/tmtc/ccsds_distrib.rs @@ -22,7 +22,7 @@ //! use satrs::tmtc::{ReceivesTc, ReceivesTcCore}; //! use spacepackets::{CcsdsPacket, SpHeader}; //! use spacepackets::ecss::WritablePusPacket; -//! use spacepackets::ecss::tc::{PusTc, PusTcCreator}; +//! use spacepackets::ecss::tc::PusTcCreator; //! //! #[derive (Default)] //! struct ConcreteApidHandler { diff --git a/satrs/src/tmtc/tm_helper.rs b/satrs/src/tmtc/tm_helper.rs index 192d574..005625a 100644 --- a/satrs/src/tmtc/tm_helper.rs +++ b/satrs/src/tmtc/tm_helper.rs @@ -1,5 +1,5 @@ use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; -use spacepackets::time::cds::TimeProvider; +use spacepackets::time::cds::CdsTime; use spacepackets::time::TimeWriter; use spacepackets::SpHeader; @@ -66,7 +66,7 @@ impl PusTmWithCdsShortHelper { source_data: &'a [u8], seq_count: u16, ) -> PusTmCreator { - let time_stamp = TimeProvider::from_now_with_u16_days().unwrap(); + let time_stamp = CdsTime::now_with_u16_days().unwrap(); time_stamp.write_to_bytes(&mut self.cds_short_buf).unwrap(); self.create_pus_tm_common(service, subservice, source_data, seq_count) } @@ -76,7 +76,7 @@ impl PusTmWithCdsShortHelper { service: u8, subservice: u8, source_data: &'a [u8], - stamper: &TimeProvider, + stamper: &CdsTime, seq_count: u16, ) -> PusTmCreator { stamper.write_to_bytes(&mut self.cds_short_buf).unwrap(); @@ -98,14 +98,14 @@ impl PusTmWithCdsShortHelper { #[cfg(test)] mod tests { - use spacepackets::{ecss::PusPacket, time::cds::TimeProvider, CcsdsPacket}; + use spacepackets::{ecss::PusPacket, time::cds::CdsTime, CcsdsPacket}; use super::PusTmWithCdsShortHelper; #[test] fn test_helper_with_stamper() { let mut pus_tm_helper = PusTmWithCdsShortHelper::new(0x123); - let stamper = TimeProvider::new_with_u16_days(0, 0); + let stamper = CdsTime::new_with_u16_days(0, 0); let tm = pus_tm_helper.create_pus_tm_with_stamper(17, 1, &[1, 2, 3, 4], &stamper, 25); assert_eq!(tm.service(), 17); assert_eq!(tm.subservice(), 1); diff --git a/satrs/tests/hk_helpers.rs b/satrs/tests/hk_helpers.rs index 8791b1e..d1b545e 100644 --- a/satrs/tests/hk_helpers.rs +++ b/satrs/tests/hk_helpers.rs @@ -2,7 +2,7 @@ use core::mem::size_of; use serde::{Deserialize, Serialize}; use spacepackets::ecss::{PfcReal, PfcUnsigned, Ptc}; -use spacepackets::time::cds::TimeProvider; +use spacepackets::time::cds::CdsTime; use spacepackets::time::{CcsdsTimeProvider, TimeWriter}; enum NumOfParamsInfo { @@ -36,7 +36,7 @@ struct TestMgmHkWithIndividualValidity { #[derive(Serialize, Deserialize)] struct TestMgmHkWithGroupValidity { - last_valid_stamp: TimeProvider, + last_valid_stamp: CdsTime, valid: bool, temp: f32, mgm_vals: [u16; 3], @@ -150,7 +150,7 @@ pub fn main() { // The easiest and probably best approach, trading off big advantages for TM downlink capacity: // Use a JSON format let mgm_hk_group_validity = TestMgmHkWithGroupValidity { - last_valid_stamp: TimeProvider::from_now_with_u16_days().unwrap(), + last_valid_stamp: CdsTime::now_with_u16_days().unwrap(), valid: false, temp: 20.0, mgm_vals: [0x1f1f, 0x2f2f, 0x3f3f],