even Downcast requires alloc..

This commit is contained in:
Robin Müller 2023-01-03 01:15:17 +01:00
parent f8cd28c4f5
commit 61303a9841
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
13 changed files with 155 additions and 130 deletions

View File

@ -29,6 +29,7 @@ default-features = false
[dependencies.downcast-rs] [dependencies.downcast-rs]
version = "1.2" version = "1.2"
default-features = false default-features = false
optional = true
[dependencies.bus] [dependencies.bus]
version = "2.2" version = "2.2"
@ -61,7 +62,7 @@ version = "1.0"
[features] [features]
default = ["std"] default = ["std"]
std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std", "spacepackets/std"] std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std", "spacepackets/std"]
alloc = ["serde/alloc", "spacepackets/alloc", "hashbrown", "dyn-clone"] alloc = ["serde/alloc", "spacepackets/alloc", "hashbrown", "dyn-clone", "downcast-rs"]
serde = ["dep:serde", "spacepackets/serde"] serde = ["dep:serde", "spacepackets/serde"]
crossbeam = ["crossbeam-channel"] crossbeam = ["crossbeam-channel"]
heapless = ["dep:heapless"] heapless = ["dep:heapless"]

View File

@ -1,5 +1,5 @@
//! UDP server helper components //! UDP server helper components
use crate::tmtc::ReceivesTc; use crate::tmtc::{ReceivesTc, ReceivesTcBase};
use std::boxed::Box; use std::boxed::Box;
use std::io::{Error, ErrorKind}; use std::io::{Error, ErrorKind};
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket}; use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
@ -19,19 +19,20 @@ use std::vec::Vec;
/// ``` /// ```
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket}; /// use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
/// use satrs_core::hal::host::udp_server::UdpTcServer; /// use satrs_core::hal::host::udp_server::UdpTcServer;
/// use satrs_core::tmtc::ReceivesTc; /// use satrs_core::tmtc::{ReceivesTc, ReceivesTcBase};
/// use spacepackets::SpHeader; /// use spacepackets::SpHeader;
/// use spacepackets::tc::PusTc; /// use spacepackets::tc::PusTc;
/// ///
/// #[derive (Default)] /// #[derive (Default)]
/// struct PingReceiver {} /// struct PingReceiver {}
/// impl ReceivesTc for PingReceiver { /// impl ReceivesTcBase for PingReceiver {
/// type Error = (); /// type Error = ();
/// fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> { /// fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> {
/// assert_eq!(tc_raw.len(), 13); /// assert_eq!(tc_raw.len(), 13);
/// Ok(()) /// Ok(())
/// } /// }
/// } /// }
/// impl ReceivesTc for PingReceiver {}
/// ///
/// let mut buf = [0; 32]; /// let mut buf = [0; 32];
/// let dest_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7777); /// let dest_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7777);
@ -89,7 +90,7 @@ impl<E: PartialEq> PartialEq for ReceiveResult<E> {
impl<E: Eq + PartialEq> Eq for ReceiveResult<E> {} impl<E: Eq + PartialEq> Eq for ReceiveResult<E> {}
impl<E: 'static> ReceivesTc for UdpTcServer<E> { impl<E: 'static> ReceivesTcBase for UdpTcServer<E> {
type Error = E; type Error = E;
fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> { fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> {
@ -97,6 +98,8 @@ impl<E: 'static> ReceivesTc for UdpTcServer<E> {
} }
} }
impl<E: 'static> ReceivesTc for UdpTcServer<E> {}
impl<E: 'static> UdpTcServer<E> { impl<E: 'static> UdpTcServer<E> {
pub fn new<A: ToSocketAddrs>( pub fn new<A: ToSocketAddrs>(
addr: A, addr: A,
@ -140,7 +143,7 @@ impl<E: 'static> UdpTcServer<E> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::hal::host::udp_server::{ReceiveResult, UdpTcServer}; use crate::hal::host::udp_server::{ReceiveResult, UdpTcServer};
use crate::tmtc::ReceivesTc; use crate::tmtc::{ReceivesTc, ReceivesTcBase};
use spacepackets::tc::PusTc; use spacepackets::tc::PusTc;
use spacepackets::SpHeader; use spacepackets::SpHeader;
use std::boxed::Box; use std::boxed::Box;
@ -155,7 +158,7 @@ mod tests {
pub sent_cmds: VecDeque<Vec<u8>>, pub sent_cmds: VecDeque<Vec<u8>>,
} }
impl ReceivesTc for PingReceiver { impl ReceivesTcBase for PingReceiver {
type Error = (); type Error = ();
fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> { fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> {
@ -166,6 +169,8 @@ mod tests {
} }
} }
impl ReceivesTc for PingReceiver {}
#[test] #[test]
fn basic_test() { fn basic_test() {
let mut buf = [0; 32]; let mut buf = [0; 32];

View File

@ -11,6 +11,7 @@
#![cfg_attr(doc_cfg, feature(doc_cfg))] #![cfg_attr(doc_cfg, feature(doc_cfg))]
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
extern crate alloc; extern crate alloc;
#[cfg(feature = "alloc")]
extern crate downcast_rs; extern crate downcast_rs;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
extern crate std; extern crate std;

View File

@ -53,6 +53,9 @@
//! ``` //! ```
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use alloc::boxed::Box; use alloc::boxed::Box;
#[cfg(feature = "alloc")]
pub use alloc_mod::*;
#[cfg(feature = "alloc")]
use downcast_rs::Downcast; use downcast_rs::Downcast;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use hashbrown::HashMap; use hashbrown::HashMap;
@ -65,73 +68,81 @@ pub struct ObjectId {
pub name: &'static str, pub name: &'static str,
} }
/// Each object which is stored inside the [object manager][ObjectManager] needs to implemented
/// this trait
pub trait SystemObject: Downcast {
type Error;
fn get_object_id(&self) -> &ObjectId;
fn initialize(&mut self) -> Result<(), Self::Error>;
}
downcast_rs::impl_downcast!(SystemObject assoc Error);
pub trait ManagedSystemObject: SystemObject + Send {}
downcast_rs::impl_downcast!(ManagedSystemObject assoc Error);
/// Helper module to manage multiple [ManagedSystemObjects][ManagedSystemObject] by mapping them
/// using an [object ID][ObjectId]
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub struct ObjectManager<E> { pub mod alloc_mod {
obj_map: HashMap<ObjectId, Box<dyn ManagedSystemObject<Error = E>>>, use super::*;
}
#[cfg(feature = "alloc")] /// Each object which is stored inside the [object manager][ObjectManager] needs to implemented
impl<E: 'static> Default for ObjectManager<E> { /// this trait
fn default() -> Self { pub trait SystemObject: Downcast {
Self::new() type Error;
fn get_object_id(&self) -> &ObjectId;
fn initialize(&mut self) -> Result<(), Self::Error>;
} }
} downcast_rs::impl_downcast!(SystemObject assoc Error);
#[cfg(feature = "alloc")] pub trait ManagedSystemObject: SystemObject + Send {}
impl<E: 'static> ObjectManager<E> { downcast_rs::impl_downcast!(ManagedSystemObject assoc Error);
pub fn new() -> Self {
ObjectManager { /// Helper module to manage multiple [ManagedSystemObjects][ManagedSystemObject] by mapping them
obj_map: HashMap::new(), /// using an [object ID][ObjectId]
#[cfg(feature = "alloc")]
pub struct ObjectManager<E> {
obj_map: HashMap<ObjectId, Box<dyn ManagedSystemObject<Error = E>>>,
}
#[cfg(feature = "alloc")]
impl<E: 'static> Default for ObjectManager<E> {
fn default() -> Self {
Self::new()
} }
} }
pub fn insert(&mut self, sys_obj: Box<dyn ManagedSystemObject<Error = E>>) -> bool {
let obj_id = sys_obj.get_object_id();
if self.obj_map.contains_key(obj_id) {
return false;
}
self.obj_map.insert(*obj_id, sys_obj).is_none()
}
/// Initializes all System Objects in the hash map and returns the number of successful #[cfg(feature = "alloc")]
/// initializations impl<E: 'static> ObjectManager<E> {
pub fn initialize(&mut self) -> Result<u32, Box<dyn Error>> { pub fn new() -> Self {
let mut init_success = 0; ObjectManager {
for val in self.obj_map.values_mut() { obj_map: HashMap::new(),
if val.initialize().is_ok() {
init_success += 1
} }
} }
Ok(init_success) pub fn insert(&mut self, sys_obj: Box<dyn ManagedSystemObject<Error = E>>) -> bool {
} let obj_id = sys_obj.get_object_id();
if self.obj_map.contains_key(obj_id) {
return false;
}
self.obj_map.insert(*obj_id, sys_obj).is_none()
}
/// Retrieve a reference to an object stored inside the manager. The type to retrieve needs to /// Initializes all System Objects in the hash map and returns the number of successful
/// be explicitly passed as a generic parameter or specified on the left hand side of the /// initializations
/// expression. pub fn initialize(&mut self) -> Result<u32, Box<dyn Error>> {
pub fn get_ref<T: ManagedSystemObject<Error = E>>(&self, key: &ObjectId) -> Option<&T> { let mut init_success = 0;
self.obj_map.get(key).and_then(|o| o.downcast_ref::<T>()) for val in self.obj_map.values_mut() {
} if val.initialize().is_ok() {
init_success += 1
}
}
Ok(init_success)
}
/// Retrieve a mutable reference to an object stored inside the manager. The type to retrieve /// Retrieve a reference to an object stored inside the manager. The type to retrieve needs to
/// needs to be explicitly passed as a generic parameter or specified on the left hand side /// be explicitly passed as a generic parameter or specified on the left hand side of the
/// of the expression. /// expression.
pub fn get_mut<T: ManagedSystemObject<Error = E>>(&mut self, key: &ObjectId) -> Option<&mut T> { pub fn get_ref<T: ManagedSystemObject<Error = E>>(&self, key: &ObjectId) -> Option<&T> {
self.obj_map self.obj_map.get(key).and_then(|o| o.downcast_ref::<T>())
.get_mut(key) }
.and_then(|o| o.downcast_mut::<T>())
/// Retrieve a mutable reference to an object stored inside the manager. The type to retrieve
/// needs to be explicitly passed as a generic parameter or specified on the left hand side
/// of the expression.
pub fn get_mut<T: ManagedSystemObject<Error = E>>(
&mut self,
key: &ObjectId,
) -> Option<&mut T> {
self.obj_map
.get_mut(key)
.and_then(|o| o.downcast_mut::<T>())
}
} }
} }

View File

@ -4,7 +4,7 @@ use spacepackets::tm::PusTm;
use spacepackets::tm::PusTmSecondaryHeader; use spacepackets::tm::PusTmSecondaryHeader;
use spacepackets::{SpHeader, MAX_APID}; use spacepackets::{SpHeader, MAX_APID};
use crate::pus::EcssTmSender; use crate::pus::EcssTmSenderBase;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub use allocvec::EventReporter; pub use allocvec::EventReporter;
@ -78,7 +78,7 @@ impl EventReporterBase {
pub fn event_info<E>( pub fn event_info<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -96,7 +96,7 @@ impl EventReporterBase {
pub fn event_low_severity<E>( pub fn event_low_severity<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -114,7 +114,7 @@ impl EventReporterBase {
pub fn event_medium_severity<E>( pub fn event_medium_severity<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -132,7 +132,7 @@ impl EventReporterBase {
pub fn event_high_severity<E>( pub fn event_high_severity<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -151,7 +151,7 @@ impl EventReporterBase {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
subservice: Subservices, subservice: Subservices,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -220,7 +220,7 @@ mod allocvec {
} }
pub fn event_info<E>( pub fn event_info<E>(
&mut self, &mut self,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -236,7 +236,7 @@ mod allocvec {
pub fn event_low_severity<E>( pub fn event_low_severity<E>(
&mut self, &mut self,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -252,7 +252,7 @@ mod allocvec {
pub fn event_medium_severity<E>( pub fn event_medium_severity<E>(
&mut self, &mut self,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -268,7 +268,7 @@ mod allocvec {
pub fn event_high_severity<E>( pub fn event_high_severity<E>(
&mut self, &mut self,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -311,7 +311,7 @@ mod tests {
pub service_queue: VecDeque<TmInfo>, pub service_queue: VecDeque<TmInfo>,
} }
impl EcssTmSender for TestSender { impl EcssTmSenderBase for TestSender {
type Error = (); type Error = ();
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> { fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> {

View File

@ -13,7 +13,7 @@ pub use crate::pus::event::EventReporter;
use crate::pus::verification::{TcStateStarted, VerificationToken}; use crate::pus::verification::{TcStateStarted, VerificationToken};
use crate::pus::EcssTmError; use crate::pus::EcssTmError;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use crate::pus::EcssTmSender; use crate::pus::EcssTmSenderBase;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub use alloc_mod::*; pub use alloc_mod::*;
@ -175,7 +175,7 @@ pub mod alloc_mod {
pub fn generate_pus_event_tm_generic<E>( pub fn generate_pus_event_tm_generic<E>(
&mut self, &mut self,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event: Event, event: Event,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -225,7 +225,7 @@ pub mod alloc_mod {
pub fn generate_pus_event_tm<E, Severity: HasSeverity>( pub fn generate_pus_event_tm<E, Severity: HasSeverity>(
&mut self, &mut self,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event: EventU32TypedSev<Severity>, event: EventU32TypedSev<Severity>,
aux_data: Option<&[u8]>, aux_data: Option<&[u8]>,
@ -252,7 +252,7 @@ mod tests {
sender: std::sync::mpsc::Sender<Vec<u8>>, sender: std::sync::mpsc::Sender<Vec<u8>>,
} }
impl EcssTmSender for EventTmSender { impl EcssTmSenderBase for EventTmSender {
type Error = SendError<Vec<u8>>; type Error = SendError<Vec<u8>>;
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> { fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
let mut vec = Vec::new(); let mut vec = Vec::new();

View File

@ -3,6 +3,7 @@
//! Currenty includes: //! Currenty includes:
//! //!
//! 1. PUS Verification Service 1 module inside [verification]. Requires [alloc] support. //! 1. PUS Verification Service 1 module inside [verification]. Requires [alloc] support.
#[cfg(feature = "alloc")]
use downcast_rs::{impl_downcast, Downcast}; use downcast_rs::{impl_downcast, Downcast};
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use dyn_clone::DynClone; use dyn_clone::DynClone;
@ -46,21 +47,19 @@ impl<E> From<ByteConversionError> for EcssTmError<E> {
/// This sender object is responsible for sending telemetry to a TM sink. The [Downcast] trait /// This sender object is responsible for sending telemetry to a TM sink. The [Downcast] trait
/// is implemented to allow passing the sender as a boxed trait object and still retrieve the /// is implemented to allow passing the sender as a boxed trait object and still retrieve the
/// concrete type at a later point. /// concrete type at a later point.
pub trait EcssTmSender: Downcast + Send { pub trait EcssTmSenderBase: Send {
type Error; type Error;
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>>; fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>>;
} }
impl_downcast!(EcssTmSender assoc Error);
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub mod alloc_mod { pub mod alloc_mod {
use super::*; use super::*;
pub trait EcssTmSenderClonable: EcssTmSender + Downcast + DynClone {} pub trait EcssTmSender: EcssTmSenderBase + Downcast + DynClone {}
dyn_clone::clone_trait_object!(<T> EcssTmSenderClonable<Error=T>); dyn_clone::clone_trait_object!(<T> EcssTmSender<Error=T>);
impl_downcast!(EcssTmSenderClonable assoc Error); impl_downcast!(EcssTmSender assoc Error);
} }
pub(crate) fn source_buffer_large_enough<E>(cap: usize, len: usize) -> Result<(), EcssTmError<E>> { pub(crate) fn source_buffer_large_enough<E>(cap: usize, len: usize) -> Result<(), EcssTmError<E>> {

View File

@ -72,7 +72,7 @@
//! The [integration test](https://egit.irs.uni-stuttgart.de/rust/fsrc-launchpad/src/branch/main/fsrc-core/tests/verification_test.rs) //! The [integration test](https://egit.irs.uni-stuttgart.de/rust/fsrc-launchpad/src/branch/main/fsrc-core/tests/verification_test.rs)
//! for the verification module contains examples how this module could be used in a more complex //! for the verification module contains examples how this module could be used in a more complex
//! context involving multiple threads //! context involving multiple threads
use crate::pus::{source_buffer_large_enough, EcssTmError, EcssTmSender}; use crate::pus::{source_buffer_large_enough, EcssTmError, EcssTmSenderBase};
use core::fmt::{Display, Formatter}; use core::fmt::{Display, Formatter};
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use core::marker::PhantomData; use core::marker::PhantomData;
@ -339,7 +339,7 @@ impl VerificationReporterBasic {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>> ) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
@ -370,7 +370,7 @@ impl VerificationReporterBasic {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
@ -398,7 +398,7 @@ impl VerificationReporterBasic {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>> ) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
@ -431,7 +431,7 @@ impl VerificationReporterBasic {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
@ -459,7 +459,7 @@ impl VerificationReporterBasic {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: &VerificationToken<TcStateStarted>, token: &VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
step: impl EcssEnumeration, step: impl EcssEnumeration,
@ -485,7 +485,7 @@ impl VerificationReporterBasic {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
@ -514,7 +514,7 @@ impl VerificationReporterBasic {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
@ -543,7 +543,7 @@ impl VerificationReporterBasic {
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized), seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
@ -664,7 +664,7 @@ impl VerificationReporterBasic {
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
mod alloc_mod { mod alloc_mod {
use super::*; use super::*;
use crate::pus::alloc_mod::EcssTmSenderClonable; use crate::pus::alloc_mod::EcssTmSender;
use crate::seq_count::SequenceCountProviderClonable; use crate::seq_count::SequenceCountProviderClonable;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::vec; use alloc::vec;
@ -744,7 +744,7 @@ mod alloc_mod {
pub fn acceptance_success<E>( pub fn acceptance_success<E>(
&mut self, &mut self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>> ) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
{ {
@ -761,7 +761,7 @@ mod alloc_mod {
pub fn acceptance_failure<E>( pub fn acceptance_failure<E>(
&mut self, &mut self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
self.reporter.acceptance_failure( self.reporter.acceptance_failure(
@ -779,7 +779,7 @@ mod alloc_mod {
pub fn start_success<E>( pub fn start_success<E>(
&mut self, &mut self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>> ) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
{ {
@ -799,7 +799,7 @@ mod alloc_mod {
pub fn start_failure<E>( pub fn start_failure<E>(
&mut self, &mut self,
token: VerificationToken<TcStateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
self.reporter.start_failure( self.reporter.start_failure(
@ -817,7 +817,7 @@ mod alloc_mod {
pub fn step_success<E>( pub fn step_success<E>(
&mut self, &mut self,
token: &VerificationToken<TcStateStarted>, token: &VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
step: impl EcssEnumeration, step: impl EcssEnumeration,
) -> Result<(), EcssTmError<E>> { ) -> Result<(), EcssTmError<E>> {
@ -838,7 +838,7 @@ mod alloc_mod {
pub fn step_failure<E>( pub fn step_failure<E>(
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter.step_failure( self.reporter.step_failure(
@ -857,7 +857,7 @@ mod alloc_mod {
pub fn completion_success<E>( pub fn completion_success<E>(
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter.completion_success( self.reporter.completion_success(
@ -876,7 +876,7 @@ mod alloc_mod {
pub fn completion_failure<E>( pub fn completion_failure<E>(
&mut self, &mut self,
token: VerificationToken<TcStateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter.completion_failure( self.reporter.completion_failure(
@ -894,13 +894,13 @@ mod alloc_mod {
#[derive(Clone)] #[derive(Clone)]
pub struct VerificationReporterWithSender<E> { pub struct VerificationReporterWithSender<E> {
pub reporter: VerificationReporterWithBuf, pub reporter: VerificationReporterWithBuf,
pub sender: Box<dyn EcssTmSenderClonable<Error = E>>, pub sender: Box<dyn EcssTmSender<Error = E>>,
} }
impl<E: 'static> VerificationReporterWithSender<E> { impl<E: 'static> VerificationReporterWithSender<E> {
pub fn new( pub fn new(
cfg: &VerificationReporterCfg, cfg: &VerificationReporterCfg,
sender: Box<dyn EcssTmSenderClonable<Error = E>>, sender: Box<dyn EcssTmSender<Error = E>>,
) -> Self { ) -> Self {
let reporter = VerificationReporterWithBuf::new(cfg); let reporter = VerificationReporterWithBuf::new(cfg);
Self::new_from_reporter(reporter, sender) Self::new_from_reporter(reporter, sender)
@ -908,7 +908,7 @@ mod alloc_mod {
pub fn new_from_reporter( pub fn new_from_reporter(
reporter: VerificationReporterWithBuf, reporter: VerificationReporterWithBuf,
sender: Box<dyn EcssTmSenderClonable<Error = E>>, sender: Box<dyn EcssTmSender<Error = E>>,
) -> Self { ) -> Self {
Self { reporter, sender } Self { reporter, sender }
} }
@ -1006,7 +1006,7 @@ mod stdmod {
use super::alloc_mod::VerificationReporterWithSender; use super::alloc_mod::VerificationReporterWithSender;
use super::*; use super::*;
use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError}; use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError};
use crate::pus::alloc_mod::EcssTmSenderClonable; use crate::pus::alloc_mod::EcssTmSender;
use delegate::delegate; use delegate::delegate;
use spacepackets::tm::PusTm; use spacepackets::tm::PusTm;
use std::sync::{mpsc, Arc, Mutex, RwLockWriteGuard}; use std::sync::{mpsc, Arc, Mutex, RwLockWriteGuard};
@ -1069,7 +1069,7 @@ mod stdmod {
} }
/// Verification sender with a [mpsc::Sender] backend. /// Verification sender with a [mpsc::Sender] backend.
/// It implements the [EcssTmSender] trait to be used as PUS Verification TM sender. /// It implements the [EcssTmSenderBase] trait to be used as PUS Verification TM sender.
impl MpscVerifSender { impl MpscVerifSender {
pub fn new(tm_store: SharedPool, tx: mpsc::Sender<StoreAddr>) -> Self { pub fn new(tm_store: SharedPool, tx: mpsc::Sender<StoreAddr>) -> Self {
Self { Self {
@ -1079,7 +1079,7 @@ mod stdmod {
} }
//noinspection RsTraitImplementation //noinspection RsTraitImplementation
impl EcssTmSender for MpscVerifSender { impl EcssTmSenderBase for MpscVerifSender {
type Error = StdVerifSenderError; type Error = StdVerifSenderError;
delegate!( delegate!(
@ -1089,7 +1089,7 @@ mod stdmod {
); );
} }
impl EcssTmSenderClonable for MpscVerifSender {} impl EcssTmSender for MpscVerifSender {}
impl SendBackend for crossbeam_channel::Sender<StoreAddr> { impl SendBackend for crossbeam_channel::Sender<StoreAddr> {
fn send(&self, addr: StoreAddr) -> Result<(), StoreAddr> { fn send(&self, addr: StoreAddr) -> Result<(), StoreAddr> {
@ -1098,7 +1098,7 @@ mod stdmod {
} }
/// Verification sender with a [crossbeam_channel::Sender] backend. /// Verification sender with a [crossbeam_channel::Sender] backend.
/// It implements the [EcssTmSender] trait to be used as PUS Verification TM sender /// It implements the [EcssTmSenderBase] trait to be used as PUS Verification TM sender
#[cfg(feature = "crossbeam")] #[cfg(feature = "crossbeam")]
#[derive(Clone)] #[derive(Clone)]
pub struct CrossbeamVerifSender { pub struct CrossbeamVerifSender {
@ -1116,7 +1116,7 @@ mod stdmod {
//noinspection RsTraitImplementation //noinspection RsTraitImplementation
#[cfg(feature = "crossbeam")] #[cfg(feature = "crossbeam")]
impl EcssTmSender for CrossbeamVerifSender { impl EcssTmSenderBase for CrossbeamVerifSender {
type Error = StdVerifSenderError; type Error = StdVerifSenderError;
delegate!( delegate!(
@ -1127,9 +1127,9 @@ mod stdmod {
} }
#[cfg(feature = "crossbeam")] #[cfg(feature = "crossbeam")]
impl EcssTmSenderClonable for CrossbeamVerifSender {} impl EcssTmSender for CrossbeamVerifSender {}
impl<S: SendBackend + Clone + 'static> EcssTmSender for StdSenderBase<S> { impl<S: SendBackend + Clone + 'static> EcssTmSenderBase for StdSenderBase<S> {
type Error = StdVerifSenderError; type Error = StdVerifSenderError;
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> { fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
let operation = |mut mg: RwLockWriteGuard<ShareablePoolProvider>| { let operation = |mut mg: RwLockWriteGuard<ShareablePoolProvider>| {
@ -1158,10 +1158,10 @@ mod stdmod {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::pool::{LocalPool, PoolCfg, SharedPool}; use crate::pool::{LocalPool, PoolCfg, SharedPool};
use crate::pus::alloc_mod::EcssTmSenderClonable; use crate::pus::alloc_mod::EcssTmSender;
use crate::pus::tests::CommonTmInfo; use crate::pus::tests::CommonTmInfo;
use crate::pus::verification::{ use crate::pus::verification::{
EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, MpscVerifSender, RequestId, EcssTmError, EcssTmSenderBase, FailParams, FailParamsWithStep, MpscVerifSender, RequestId,
TcStateNone, VerificationReporterCfg, VerificationReporterWithBuf, TcStateNone, VerificationReporterCfg, VerificationReporterWithBuf,
VerificationReporterWithSender, VerificationToken, VerificationReporterWithSender, VerificationToken,
}; };
@ -1196,7 +1196,7 @@ mod tests {
pub service_queue: VecDeque<TmInfo>, pub service_queue: VecDeque<TmInfo>,
} }
impl EcssTmSender for TestSender { impl EcssTmSenderBase for TestSender {
type Error = (); type Error = ();
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> { fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
assert_eq!(PusPacket::service(&tm), 1); assert_eq!(PusPacket::service(&tm), 1);
@ -1221,21 +1221,21 @@ mod tests {
} }
} }
impl EcssTmSenderClonable for TestSender {} impl EcssTmSender for TestSender {}
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct DummyError {} struct DummyError {}
#[derive(Default, Clone)] #[derive(Default, Clone)]
struct FallibleSender {} struct FallibleSender {}
impl EcssTmSender for FallibleSender { impl EcssTmSenderBase for FallibleSender {
type Error = DummyError; type Error = DummyError;
fn send_tm(&mut self, _: PusTm) -> Result<(), EcssTmError<DummyError>> { fn send_tm(&mut self, _: PusTm) -> Result<(), EcssTmError<DummyError>> {
Err(EcssTmError::SendError(DummyError {})) Err(EcssTmError::SendError(DummyError {}))
} }
} }
impl EcssTmSenderClonable for FallibleSender {} impl EcssTmSender for FallibleSender {}
struct TestBase<'a> { struct TestBase<'a> {
vr: VerificationReporterWithBuf, vr: VerificationReporterWithBuf,

View File

@ -19,7 +19,7 @@
//! //!
//! ```rust //! ```rust
//! use satrs_core::tmtc::ccsds_distrib::{CcsdsPacketHandler, CcsdsDistributor}; //! use satrs_core::tmtc::ccsds_distrib::{CcsdsPacketHandler, CcsdsDistributor};
//! use satrs_core::tmtc::ReceivesTc; //! use satrs_core::tmtc::{ReceivesTc, ReceivesTcBase};
//! use spacepackets::{CcsdsPacket, SpHeader}; //! use spacepackets::{CcsdsPacket, SpHeader};
//! use spacepackets::tc::PusTc; //! use spacepackets::tc::PusTc;
//! //!
@ -84,7 +84,7 @@
//! .expect("Casting back to concrete type failed"); //! .expect("Casting back to concrete type failed");
//! mutable_ref.mutable_foo(); //! mutable_ref.mutable_foo();
//! ``` //! ```
use crate::tmtc::{ReceivesCcsdsTc, ReceivesTc}; use crate::tmtc::{ReceivesCcsdsTc, ReceivesTc, ReceivesTcBase};
use alloc::boxed::Box; use alloc::boxed::Box;
use downcast_rs::Downcast; use downcast_rs::Downcast;
use spacepackets::{ByteConversionError, CcsdsPacket, SizeMissmatch, SpHeader}; use spacepackets::{ByteConversionError, CcsdsPacket, SizeMissmatch, SpHeader};
@ -136,7 +136,7 @@ impl<E: 'static> ReceivesCcsdsTc for CcsdsDistributor<E> {
} }
} }
impl<E: 'static> ReceivesTc for CcsdsDistributor<E> { impl<E: 'static> ReceivesTcBase for CcsdsDistributor<E> {
type Error = CcsdsError<E>; type Error = CcsdsError<E>;
fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> { fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> {
@ -154,6 +154,8 @@ impl<E: 'static> ReceivesTc for CcsdsDistributor<E> {
} }
} }
impl<E: 'static> ReceivesTc for CcsdsDistributor<E> {}
impl<E: 'static> CcsdsDistributor<E> { impl<E: 'static> CcsdsDistributor<E> {
pub fn new(apid_handler: Box<dyn CcsdsPacketHandler<Error = E>>) -> Self { pub fn new(apid_handler: Box<dyn CcsdsPacketHandler<Error = E>>) -> Self {
CcsdsDistributor { apid_handler } CcsdsDistributor { apid_handler }

View File

@ -5,6 +5,7 @@
//! directly dispatch received packets to packet listeners based on packet fields like the CCSDS //! directly dispatch received packets to packet listeners based on packet fields like the CCSDS
//! Application Process ID (APID) or the ECSS PUS service type. This allows for fast packet //! Application Process ID (APID) or the ECSS PUS service type. This allows for fast packet
//! routing without the overhead and complication of using message queues. However, it also requires //! routing without the overhead and complication of using message queues. However, it also requires
#[cfg(feature = "alloc")]
use downcast_rs::{impl_downcast, Downcast}; use downcast_rs::{impl_downcast, Downcast};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -62,11 +63,14 @@ impl AddressableId {
/// This trait is implemented by both the [crate::tmtc::pus_distrib::PusDistributor] and the /// This trait is implemented by both the [crate::tmtc::pus_distrib::PusDistributor] and the
/// [crate::tmtc::ccsds_distrib::CcsdsDistributor] which allows to pass the respective packets in /// [crate::tmtc::ccsds_distrib::CcsdsDistributor] which allows to pass the respective packets in
/// raw byte format into them. /// raw byte format into them.
pub trait ReceivesTc: Downcast + Send { pub trait ReceivesTcBase: Send {
type Error; type Error;
fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error>; fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error>;
} }
#[cfg(feature = "alloc")]
pub trait ReceivesTc: ReceivesTcBase + Downcast {}
#[cfg(feature = "alloc")]
impl_downcast!(ReceivesTc assoc Error); impl_downcast!(ReceivesTc assoc Error);
/// Generic trait for object which can receive CCSDS space packets, for fsrc-example ECSS PUS packets /// Generic trait for object which can receive CCSDS space packets, for fsrc-example ECSS PUS packets

View File

@ -18,7 +18,7 @@
//! //!
//! ```rust //! ```rust
//! use satrs_core::tmtc::pus_distrib::{PusDistributor, PusServiceProvider}; //! use satrs_core::tmtc::pus_distrib::{PusDistributor, PusServiceProvider};
//! use satrs_core::tmtc::ReceivesTc; //! use satrs_core::tmtc::{ReceivesTc, ReceivesTcBase};
//! use spacepackets::SpHeader; //! use spacepackets::SpHeader;
//! use spacepackets::tc::PusTc; //! use spacepackets::tc::PusTc;
//! struct ConcretePusHandler { //! struct ConcretePusHandler {
@ -60,7 +60,7 @@
//! .expect("Casting back to concrete type failed"); //! .expect("Casting back to concrete type failed");
//! assert_eq!(concrete_handler_ref.handler_call_count, 1); //! assert_eq!(concrete_handler_ref.handler_call_count, 1);
//! ``` //! ```
use crate::tmtc::{ReceivesCcsdsTc, ReceivesEcssPusTc, ReceivesTc}; use crate::tmtc::{ReceivesCcsdsTc, ReceivesEcssPusTc, ReceivesTc, ReceivesTcBase};
use alloc::boxed::Box; use alloc::boxed::Box;
use downcast_rs::Downcast; use downcast_rs::Downcast;
use spacepackets::ecss::{PusError, PusPacket}; use spacepackets::ecss::{PusError, PusPacket};
@ -94,7 +94,7 @@ pub enum PusDistribError<E> {
PusError(PusError), PusError(PusError),
} }
impl<E: 'static> ReceivesTc for PusDistributor<E> { impl<E: 'static> ReceivesTcBase for PusDistributor<E> {
type Error = PusDistribError<E>; type Error = PusDistribError<E>;
fn pass_tc(&mut self, tm_raw: &[u8]) -> Result<(), Self::Error> { fn pass_tc(&mut self, tm_raw: &[u8]) -> Result<(), Self::Error> {
// Convert to ccsds and call pass_ccsds // Convert to ccsds and call pass_ccsds
@ -104,6 +104,8 @@ impl<E: 'static> ReceivesTc for PusDistributor<E> {
} }
} }
impl<E: 'static> ReceivesTc for PusDistributor<E> {}
impl<E: 'static> ReceivesCcsdsTc for PusDistributor<E> { impl<E: 'static> ReceivesCcsdsTc for PusDistributor<E> {
type Error = PusDistribError<E>; type Error = PusDistribError<E>;
fn pass_ccsds(&mut self, header: &SpHeader, tm_raw: &[u8]) -> Result<(), Self::Error> { fn pass_ccsds(&mut self, header: &SpHeader, tm_raw: &[u8]) -> Result<(), Self::Error> {

View File

@ -7,7 +7,7 @@ use satrs_core::params::{Params, ParamsHeapless, WritableToBeBytes};
use satrs_core::pus::event_man::{ use satrs_core::pus::event_man::{
DefaultPusMgmtBackendProvider, EventReporter, PusEventDispatcher, DefaultPusMgmtBackendProvider, EventReporter, PusEventDispatcher,
}; };
use satrs_core::pus::{EcssTmError, EcssTmSender}; use satrs_core::pus::{EcssTmError, EcssTmSenderBase};
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use spacepackets::tm::PusTm; use spacepackets::tm::PusTm;
use std::sync::mpsc::{channel, SendError, TryRecvError}; use std::sync::mpsc::{channel, SendError, TryRecvError};
@ -23,7 +23,7 @@ struct EventTmSender {
sender: std::sync::mpsc::Sender<Vec<u8>>, sender: std::sync::mpsc::Sender<Vec<u8>>,
} }
impl EcssTmSender for EventTmSender { impl EcssTmSenderBase for EventTmSender {
type Error = SendError<Vec<u8>>; type Error = SendError<Vec<u8>>;
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> { fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
let mut vec = Vec::new(); let mut vec = Vec::new();

View File

@ -22,7 +22,7 @@ use satrs_core::pus::hk::Subservice;
use satrs_core::pus::verification::{ use satrs_core::pus::verification::{
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender, MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
}; };
use satrs_core::pus::{EcssTmError, EcssTmSender}; use satrs_core::pus::{EcssTmError, EcssTmSenderBase};
use satrs_core::seq_count::SimpleSeqCountProvider; use satrs_core::seq_count::SimpleSeqCountProvider;
use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT}; use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT};
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::TimeProvider;
@ -51,7 +51,7 @@ impl EventTmSender {
} }
} }
impl EcssTmSender for EventTmSender { impl EcssTmSenderBase for EventTmSender {
type Error = mpsc::SendError<StoreAddr>; type Error = mpsc::SendError<StoreAddr>;
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> { fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {