From c72c5ad4aaca277754e94a16377a7d4a6eff5d8e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 3 Sep 2022 20:54:37 +0200 Subject: [PATCH] extensions - Add source_data getter for PusTm - Add std time info updater for CDS short time stamp provider --- src/tc.rs | 2 +- src/time.rs | 15 +++++++++++++-- src/tm.rs | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/tc.rs b/src/tc.rs index 185575f..19818f9 100644 --- a/src/tc.rs +++ b/src/tc.rs @@ -418,7 +418,7 @@ impl<'slice> PusTc<'slice> { if raw_data_len < total_len || total_len < PUS_TC_MIN_LEN_WITHOUT_APP_DATA { return Err(PusError::RawDataTooShort(raw_data_len)); } - let sec_header = crate::tc::zc::PusTcSecondaryHeader::from_bytes( + let sec_header = zc::PusTcSecondaryHeader::from_bytes( &slice[current_idx..current_idx + PUC_TC_SECONDARY_HEADER_LEN], ) .ok_or(PusError::PacketError( diff --git a/src/time.rs b/src/time.rs index bd2d3c8..8d8f0df 100644 --- a/src/time.rs +++ b/src/time.rs @@ -94,7 +94,7 @@ pub trait CcsdsTimeProvider { fn date_time(&self) -> DateTime; } -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Default)] pub struct CdsShortTimeProvider { pfield: u8, ccsds_days: u16, @@ -125,7 +125,7 @@ impl CdsShortTimeProvider { let unix_days_seconds = epoch - secs_of_day; let ms_of_day = secs_of_day * 1000 + now.subsec_millis() as u64; let provider = Self { - pfield: (CcsdsTimeCodes::Cds as u8) << 4, + pfield: (Cds as u8) << 4, ccsds_days: unix_to_ccsds_days((unix_days_seconds / SECONDS_PER_DAY as u64) as i32) as u16, ms_of_day: ms_of_day as u32, @@ -135,6 +135,17 @@ impl CdsShortTimeProvider { Ok(provider.setup(unix_days_seconds as i64, ms_of_day)) } + #[cfg(feature = "std")] + pub fn update_from_now(&mut self) -> Result<(), SystemTimeError> { + let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; + let epoch = now.as_secs(); + let secs_of_day = epoch % SECONDS_PER_DAY as u64; + let unix_days_seconds = epoch - secs_of_day; + let ms_of_day = secs_of_day * 1000 + now.subsec_millis() as u64; + self.setup(unix_days_seconds as i64, ms_of_day); + Ok(()) + } + fn setup(mut self, unix_days_seconds: i64, ms_of_day: u64) -> Self { self.calc_unix_seconds(unix_days_seconds, ms_of_day); self.calc_date_time((ms_of_day % 1000) as u32); diff --git a/src/tm.rs b/src/tm.rs index 15a3bff..0a3523b 100644 --- a/src/tm.rs +++ b/src/tm.rs @@ -259,6 +259,10 @@ impl<'slice> PusTm<'slice> { self.sec_header.time_stamp } + pub fn source_data(&self) -> Option<&'slice [u8]> { + self.source_data + } + pub fn set_dest_id(&mut self, dest_id: u16) { self.sec_header.dest_id = dest_id; }