From c606bfae5a18f9d57fa67f1bd77e3cd652207edb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 Jan 2023 13:09:14 +0100 Subject: [PATCH] add SequenceCountProvider blanket impl --- satrs-core/src/pus/verification.rs | 26 +++++++++++++------------- satrs-core/src/seq_count.rs | 18 ++++++++---------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/satrs-core/src/pus/verification.rs b/satrs-core/src/pus/verification.rs index cf2f7e4..6ec92b8 100644 --- a/satrs-core/src/pus/verification.rs +++ b/satrs-core/src/pus/verification.rs @@ -94,7 +94,7 @@ pub use alloc_mod::{ VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender, }; -use crate::seq_count::SequenceCountProvider; +use crate::seq_count::SequenceCountProviderCore; #[cfg(all(feature = "crossbeam", feature = "std"))] pub use stdmod::CrossbeamVerifSender; #[cfg(feature = "std")] @@ -340,7 +340,7 @@ impl VerificationReporterCore { buf: &mut [u8], token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), - seq_counter: &mut (impl SequenceCountProvider + ?Sized), + seq_counter: &mut (impl SequenceCountProviderCore + ?Sized), time_stamp: &[u8], ) -> Result, VerificationErrorWithToken> { @@ -371,7 +371,7 @@ impl VerificationReporterCore { buf: &mut [u8], token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), - seq_counter: &mut (impl SequenceCountProvider + ?Sized), + seq_counter: &mut (impl SequenceCountProviderCore + ?Sized), params: FailParams, ) -> Result<(), VerificationErrorWithToken> { let tm = self @@ -399,7 +399,7 @@ impl VerificationReporterCore { buf: &mut [u8], token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), - seq_counter: &mut (impl SequenceCountProvider + ?Sized), + seq_counter: &mut (impl SequenceCountProviderCore + ?Sized), time_stamp: &[u8], ) -> Result, VerificationErrorWithToken> { @@ -432,7 +432,7 @@ impl VerificationReporterCore { buf: &mut [u8], token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), - seq_counter: &mut (impl SequenceCountProvider + ?Sized), + seq_counter: &mut (impl SequenceCountProviderCore + ?Sized), params: FailParams, ) -> Result<(), VerificationErrorWithToken> { let tm = self @@ -460,7 +460,7 @@ impl VerificationReporterCore { buf: &mut [u8], token: &VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), - seq_counter: &mut (impl SequenceCountProvider + ?Sized), + seq_counter: &mut (impl SequenceCountProviderCore + ?Sized), time_stamp: &[u8], step: impl EcssEnumeration, ) -> Result<(), EcssTmError> { @@ -486,7 +486,7 @@ impl VerificationReporterCore { buf: &mut [u8], token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), - seq_counter: &mut (impl SequenceCountProvider + ?Sized), + seq_counter: &mut (impl SequenceCountProviderCore + ?Sized), params: FailParamsWithStep, ) -> Result<(), VerificationErrorWithToken> { let tm = self @@ -515,7 +515,7 @@ impl VerificationReporterCore { buf: &mut [u8], token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), - seq_counter: &mut (impl SequenceCountProvider + ?Sized), + seq_counter: &mut (impl SequenceCountProviderCore + ?Sized), time_stamp: &[u8], ) -> Result<(), VerificationErrorWithToken> { let tm = self @@ -544,7 +544,7 @@ impl VerificationReporterCore { buf: &mut [u8], token: VerificationToken, sender: &mut (impl EcssTmSenderCore + ?Sized), - seq_counter: &mut (impl SequenceCountProvider + ?Sized), + seq_counter: &mut (impl SequenceCountProviderCore + ?Sized), params: FailParams, ) -> Result<(), VerificationErrorWithToken> { let tm = self @@ -665,7 +665,7 @@ impl VerificationReporterCore { mod alloc_mod { use super::*; use crate::pus::alloc_mod::EcssTmSender; - use crate::seq_count::SequenceCountProviderClonable; + use crate::seq_count::SequenceCountProvider; use alloc::boxed::Box; use alloc::vec; use alloc::vec::Vec; @@ -673,7 +673,7 @@ mod alloc_mod { #[derive(Clone)] pub struct VerificationReporterCfg { apid: u16, - seq_counter: Box + Send>, + seq_counter: Box + Send>, pub step_field_width: usize, pub fail_code_field_width: usize, pub max_fail_data_len: usize, @@ -682,7 +682,7 @@ mod alloc_mod { impl VerificationReporterCfg { pub fn new( apid: u16, - seq_counter: Box + Send>, + seq_counter: Box + Send>, step_field_width: usize, fail_code_field_width: usize, max_fail_data_len: usize, @@ -705,7 +705,7 @@ mod alloc_mod { #[derive(Clone)] pub struct VerificationReporter { source_data_buf: Vec, - seq_counter: Box + Send + 'static>, + seq_counter: Box + Send + 'static>, pub reporter: VerificationReporterCore, } diff --git a/satrs-core/src/seq_count.rs b/satrs-core/src/seq_count.rs index 8e3c1dd..6a17647 100644 --- a/satrs-core/src/seq_count.rs +++ b/satrs-core/src/seq_count.rs @@ -3,7 +3,8 @@ use dyn_clone::DynClone; #[cfg(feature = "std")] pub use stdmod::*; -pub trait SequenceCountProvider { +/// Core trait for objects which can provide a sequence count. +pub trait SequenceCountProviderCore { fn get(&self) -> Raw; fn increment(&mut self); fn get_and_increment(&mut self) -> Raw { @@ -14,16 +15,18 @@ pub trait SequenceCountProvider { } #[cfg(feature = "alloc")] -pub trait SequenceCountProviderClonable: SequenceCountProvider + DynClone {} +pub trait SequenceCountProvider: SequenceCountProviderCore + DynClone {} #[cfg(feature = "alloc")] -dyn_clone::clone_trait_object!(SequenceCountProviderClonable); +dyn_clone::clone_trait_object!(SequenceCountProvider); +#[cfg(feature = "alloc")] +impl SequenceCountProvider for T where T: SequenceCountProviderCore + Clone {} #[derive(Default, Clone)] pub struct SimpleSeqCountProvider { seq_count: u16, } -impl SequenceCountProvider for SimpleSeqCountProvider { +impl SequenceCountProviderCore for SimpleSeqCountProvider { fn get(&self) -> u16 { self.seq_count } @@ -37,9 +40,6 @@ impl SequenceCountProvider for SimpleSeqCountProvider { } } -#[cfg(feature = "alloc")] -impl SequenceCountProviderClonable for SimpleSeqCountProvider {} - #[cfg(feature = "std")] pub mod stdmod { use super::*; @@ -51,7 +51,7 @@ pub mod stdmod { seq_count: Arc, } - impl SequenceCountProvider for SyncSeqCountProvider { + impl SequenceCountProviderCore for SyncSeqCountProvider { fn get(&self) -> u16 { self.seq_count.load(Ordering::SeqCst) } @@ -64,6 +64,4 @@ pub mod stdmod { self.seq_count.fetch_add(1, Ordering::SeqCst) } } - - impl SequenceCountProviderClonable for SyncSeqCountProvider {} }