even Downcast requires alloc..
This commit is contained in:
parent
f8cd28c4f5
commit
61303a9841
@ -29,6 +29,7 @@ default-features = false
|
||||
[dependencies.downcast-rs]
|
||||
version = "1.2"
|
||||
default-features = false
|
||||
optional = true
|
||||
|
||||
[dependencies.bus]
|
||||
version = "2.2"
|
||||
@ -61,7 +62,7 @@ version = "1.0"
|
||||
[features]
|
||||
default = ["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"]
|
||||
crossbeam = ["crossbeam-channel"]
|
||||
heapless = ["dep:heapless"]
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! UDP server helper components
|
||||
use crate::tmtc::ReceivesTc;
|
||||
use crate::tmtc::{ReceivesTc, ReceivesTcBase};
|
||||
use std::boxed::Box;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
|
||||
@ -19,19 +19,20 @@ use std::vec::Vec;
|
||||
/// ```
|
||||
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
|
||||
/// use satrs_core::hal::host::udp_server::UdpTcServer;
|
||||
/// use satrs_core::tmtc::ReceivesTc;
|
||||
/// use satrs_core::tmtc::{ReceivesTc, ReceivesTcBase};
|
||||
/// use spacepackets::SpHeader;
|
||||
/// use spacepackets::tc::PusTc;
|
||||
///
|
||||
/// #[derive (Default)]
|
||||
/// struct PingReceiver {}
|
||||
/// impl ReceivesTc for PingReceiver {
|
||||
/// impl ReceivesTcBase for PingReceiver {
|
||||
/// type Error = ();
|
||||
/// fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
/// assert_eq!(tc_raw.len(), 13);
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// }
|
||||
/// impl ReceivesTc for PingReceiver {}
|
||||
///
|
||||
/// let mut buf = [0; 32];
|
||||
/// 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: 'static> ReceivesTc for UdpTcServer<E> {
|
||||
impl<E: 'static> ReceivesTcBase for UdpTcServer<E> {
|
||||
type Error = E;
|
||||
|
||||
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> {
|
||||
pub fn new<A: ToSocketAddrs>(
|
||||
addr: A,
|
||||
@ -140,7 +143,7 @@ impl<E: 'static> UdpTcServer<E> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::hal::host::udp_server::{ReceiveResult, UdpTcServer};
|
||||
use crate::tmtc::ReceivesTc;
|
||||
use crate::tmtc::{ReceivesTc, ReceivesTcBase};
|
||||
use spacepackets::tc::PusTc;
|
||||
use spacepackets::SpHeader;
|
||||
use std::boxed::Box;
|
||||
@ -155,7 +158,7 @@ mod tests {
|
||||
pub sent_cmds: VecDeque<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl ReceivesTc for PingReceiver {
|
||||
impl ReceivesTcBase for PingReceiver {
|
||||
type Error = ();
|
||||
|
||||
fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
@ -166,6 +169,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
impl ReceivesTc for PingReceiver {}
|
||||
|
||||
#[test]
|
||||
fn basic_test() {
|
||||
let mut buf = [0; 32];
|
||||
|
@ -11,6 +11,7 @@
|
||||
#![cfg_attr(doc_cfg, feature(doc_cfg))]
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate downcast_rs;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
extern crate std;
|
||||
|
@ -53,6 +53,9 @@
|
||||
//! ```
|
||||
#[cfg(feature = "alloc")]
|
||||
use alloc::boxed::Box;
|
||||
#[cfg(feature = "alloc")]
|
||||
pub use alloc_mod::*;
|
||||
#[cfg(feature = "alloc")]
|
||||
use downcast_rs::Downcast;
|
||||
#[cfg(feature = "alloc")]
|
||||
use hashbrown::HashMap;
|
||||
@ -65,34 +68,38 @@ pub struct ObjectId {
|
||||
pub name: &'static str,
|
||||
}
|
||||
|
||||
/// Each object which is stored inside the [object manager][ObjectManager] needs to implemented
|
||||
/// this trait
|
||||
pub trait SystemObject: Downcast {
|
||||
#[cfg(feature = "alloc")]
|
||||
pub mod alloc_mod {
|
||||
use super::*;
|
||||
|
||||
/// 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);
|
||||
}
|
||||
downcast_rs::impl_downcast!(SystemObject assoc Error);
|
||||
|
||||
pub trait ManagedSystemObject: SystemObject + Send {}
|
||||
downcast_rs::impl_downcast!(ManagedSystemObject 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")]
|
||||
pub struct ObjectManager<E> {
|
||||
/// Helper module to manage multiple [ManagedSystemObjects][ManagedSystemObject] by mapping them
|
||||
/// 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> {
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<E: 'static> Default for ObjectManager<E> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<E: 'static> ObjectManager<E> {
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<E: 'static> ObjectManager<E> {
|
||||
pub fn new() -> Self {
|
||||
ObjectManager {
|
||||
obj_map: HashMap::new(),
|
||||
@ -128,11 +135,15 @@ impl<E: 'static> ObjectManager<E> {
|
||||
/// 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> {
|
||||
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>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -4,7 +4,7 @@ use spacepackets::tm::PusTm;
|
||||
use spacepackets::tm::PusTmSecondaryHeader;
|
||||
use spacepackets::{SpHeader, MAX_APID};
|
||||
|
||||
use crate::pus::EcssTmSender;
|
||||
use crate::pus::EcssTmSenderBase;
|
||||
#[cfg(feature = "alloc")]
|
||||
pub use allocvec::EventReporter;
|
||||
|
||||
@ -78,7 +78,7 @@ impl EventReporterBase {
|
||||
pub fn event_info<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -96,7 +96,7 @@ impl EventReporterBase {
|
||||
pub fn event_low_severity<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -114,7 +114,7 @@ impl EventReporterBase {
|
||||
pub fn event_medium_severity<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -132,7 +132,7 @@ impl EventReporterBase {
|
||||
pub fn event_high_severity<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -151,7 +151,7 @@ impl EventReporterBase {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
subservice: Subservices,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -220,7 +220,7 @@ mod allocvec {
|
||||
}
|
||||
pub fn event_info<E>(
|
||||
&mut self,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -236,7 +236,7 @@ mod allocvec {
|
||||
|
||||
pub fn event_low_severity<E>(
|
||||
&mut self,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -252,7 +252,7 @@ mod allocvec {
|
||||
|
||||
pub fn event_medium_severity<E>(
|
||||
&mut self,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -268,7 +268,7 @@ mod allocvec {
|
||||
|
||||
pub fn event_high_severity<E>(
|
||||
&mut self,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event_id: impl EcssEnumeration,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -311,7 +311,7 @@ mod tests {
|
||||
pub service_queue: VecDeque<TmInfo>,
|
||||
}
|
||||
|
||||
impl EcssTmSender for TestSender {
|
||||
impl EcssTmSenderBase for TestSender {
|
||||
type Error = ();
|
||||
|
||||
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> {
|
||||
|
@ -13,7 +13,7 @@ pub use crate::pus::event::EventReporter;
|
||||
use crate::pus::verification::{TcStateStarted, VerificationToken};
|
||||
use crate::pus::EcssTmError;
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::pus::EcssTmSender;
|
||||
use crate::pus::EcssTmSenderBase;
|
||||
#[cfg(feature = "alloc")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
|
||||
pub use alloc_mod::*;
|
||||
@ -175,7 +175,7 @@ pub mod alloc_mod {
|
||||
|
||||
pub fn generate_pus_event_tm_generic<E>(
|
||||
&mut self,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event: Event,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -225,7 +225,7 @@ pub mod alloc_mod {
|
||||
|
||||
pub fn generate_pus_event_tm<E, Severity: HasSeverity>(
|
||||
&mut self,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
event: EventU32TypedSev<Severity>,
|
||||
aux_data: Option<&[u8]>,
|
||||
@ -252,7 +252,7 @@ mod tests {
|
||||
sender: std::sync::mpsc::Sender<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl EcssTmSender for EventTmSender {
|
||||
impl EcssTmSenderBase for EventTmSender {
|
||||
type Error = SendError<Vec<u8>>;
|
||||
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
|
||||
let mut vec = Vec::new();
|
||||
|
@ -3,6 +3,7 @@
|
||||
//! Currenty includes:
|
||||
//!
|
||||
//! 1. PUS Verification Service 1 module inside [verification]. Requires [alloc] support.
|
||||
#[cfg(feature = "alloc")]
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
#[cfg(feature = "alloc")]
|
||||
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
|
||||
/// is implemented to allow passing the sender as a boxed trait object and still retrieve the
|
||||
/// concrete type at a later point.
|
||||
pub trait EcssTmSender: Downcast + Send {
|
||||
pub trait EcssTmSenderBase: Send {
|
||||
type Error;
|
||||
|
||||
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>>;
|
||||
}
|
||||
|
||||
impl_downcast!(EcssTmSender assoc Error);
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub mod alloc_mod {
|
||||
use super::*;
|
||||
|
||||
pub trait EcssTmSenderClonable: EcssTmSender + Downcast + DynClone {}
|
||||
dyn_clone::clone_trait_object!(<T> EcssTmSenderClonable<Error=T>);
|
||||
impl_downcast!(EcssTmSenderClonable assoc Error);
|
||||
pub trait EcssTmSender: EcssTmSenderBase + Downcast + DynClone {}
|
||||
dyn_clone::clone_trait_object!(<T> EcssTmSender<Error=T>);
|
||||
impl_downcast!(EcssTmSender assoc Error);
|
||||
}
|
||||
|
||||
pub(crate) fn source_buffer_large_enough<E>(cap: usize, len: usize) -> Result<(), EcssTmError<E>> {
|
||||
|
@ -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)
|
||||
//! for the verification module contains examples how this module could be used in a more complex
|
||||
//! 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::hash::{Hash, Hasher};
|
||||
use core::marker::PhantomData;
|
||||
@ -339,7 +339,7 @@ impl VerificationReporterBasic {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
|
||||
@ -370,7 +370,7 @@ impl VerificationReporterBasic {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
|
||||
@ -398,7 +398,7 @@ impl VerificationReporterBasic {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
|
||||
@ -431,7 +431,7 @@ impl VerificationReporterBasic {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
|
||||
@ -459,7 +459,7 @@ impl VerificationReporterBasic {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: &VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
step: impl EcssEnumeration,
|
||||
@ -485,7 +485,7 @@ impl VerificationReporterBasic {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
|
||||
params: FailParamsWithStep,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
@ -514,7 +514,7 @@ impl VerificationReporterBasic {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
@ -543,7 +543,7 @@ impl VerificationReporterBasic {
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProvider<u16> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
@ -664,7 +664,7 @@ impl VerificationReporterBasic {
|
||||
#[cfg(feature = "alloc")]
|
||||
mod alloc_mod {
|
||||
use super::*;
|
||||
use crate::pus::alloc_mod::EcssTmSenderClonable;
|
||||
use crate::pus::alloc_mod::EcssTmSender;
|
||||
use crate::seq_count::SequenceCountProviderClonable;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::vec;
|
||||
@ -744,7 +744,7 @@ mod alloc_mod {
|
||||
pub fn acceptance_success<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
|
||||
{
|
||||
@ -761,7 +761,7 @@ mod alloc_mod {
|
||||
pub fn acceptance_failure<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
|
||||
self.reporter.acceptance_failure(
|
||||
@ -779,7 +779,7 @@ mod alloc_mod {
|
||||
pub fn start_success<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
|
||||
{
|
||||
@ -799,7 +799,7 @@ mod alloc_mod {
|
||||
pub fn start_failure<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
|
||||
self.reporter.start_failure(
|
||||
@ -817,7 +817,7 @@ mod alloc_mod {
|
||||
pub fn step_success<E>(
|
||||
&mut self,
|
||||
token: &VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
step: impl EcssEnumeration,
|
||||
) -> Result<(), EcssTmError<E>> {
|
||||
@ -838,7 +838,7 @@ mod alloc_mod {
|
||||
pub fn step_failure<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
params: FailParamsWithStep,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter.step_failure(
|
||||
@ -857,7 +857,7 @@ mod alloc_mod {
|
||||
pub fn completion_success<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter.completion_success(
|
||||
@ -876,7 +876,7 @@ mod alloc_mod {
|
||||
pub fn completion_failure<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
sender: &mut (impl EcssTmSenderBase<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter.completion_failure(
|
||||
@ -894,13 +894,13 @@ mod alloc_mod {
|
||||
#[derive(Clone)]
|
||||
pub struct VerificationReporterWithSender<E> {
|
||||
pub reporter: VerificationReporterWithBuf,
|
||||
pub sender: Box<dyn EcssTmSenderClonable<Error = E>>,
|
||||
pub sender: Box<dyn EcssTmSender<Error = E>>,
|
||||
}
|
||||
|
||||
impl<E: 'static> VerificationReporterWithSender<E> {
|
||||
pub fn new(
|
||||
cfg: &VerificationReporterCfg,
|
||||
sender: Box<dyn EcssTmSenderClonable<Error = E>>,
|
||||
sender: Box<dyn EcssTmSender<Error = E>>,
|
||||
) -> Self {
|
||||
let reporter = VerificationReporterWithBuf::new(cfg);
|
||||
Self::new_from_reporter(reporter, sender)
|
||||
@ -908,7 +908,7 @@ mod alloc_mod {
|
||||
|
||||
pub fn new_from_reporter(
|
||||
reporter: VerificationReporterWithBuf,
|
||||
sender: Box<dyn EcssTmSenderClonable<Error = E>>,
|
||||
sender: Box<dyn EcssTmSender<Error = E>>,
|
||||
) -> Self {
|
||||
Self { reporter, sender }
|
||||
}
|
||||
@ -1006,7 +1006,7 @@ mod stdmod {
|
||||
use super::alloc_mod::VerificationReporterWithSender;
|
||||
use super::*;
|
||||
use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError};
|
||||
use crate::pus::alloc_mod::EcssTmSenderClonable;
|
||||
use crate::pus::alloc_mod::EcssTmSender;
|
||||
use delegate::delegate;
|
||||
use spacepackets::tm::PusTm;
|
||||
use std::sync::{mpsc, Arc, Mutex, RwLockWriteGuard};
|
||||
@ -1069,7 +1069,7 @@ mod stdmod {
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
pub fn new(tm_store: SharedPool, tx: mpsc::Sender<StoreAddr>) -> Self {
|
||||
Self {
|
||||
@ -1079,7 +1079,7 @@ mod stdmod {
|
||||
}
|
||||
|
||||
//noinspection RsTraitImplementation
|
||||
impl EcssTmSender for MpscVerifSender {
|
||||
impl EcssTmSenderBase for MpscVerifSender {
|
||||
type Error = StdVerifSenderError;
|
||||
|
||||
delegate!(
|
||||
@ -1089,7 +1089,7 @@ mod stdmod {
|
||||
);
|
||||
}
|
||||
|
||||
impl EcssTmSenderClonable for MpscVerifSender {}
|
||||
impl EcssTmSender for MpscVerifSender {}
|
||||
|
||||
impl SendBackend for crossbeam_channel::Sender<StoreAddr> {
|
||||
fn send(&self, addr: StoreAddr) -> Result<(), StoreAddr> {
|
||||
@ -1098,7 +1098,7 @@ mod stdmod {
|
||||
}
|
||||
|
||||
/// 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")]
|
||||
#[derive(Clone)]
|
||||
pub struct CrossbeamVerifSender {
|
||||
@ -1116,7 +1116,7 @@ mod stdmod {
|
||||
|
||||
//noinspection RsTraitImplementation
|
||||
#[cfg(feature = "crossbeam")]
|
||||
impl EcssTmSender for CrossbeamVerifSender {
|
||||
impl EcssTmSenderBase for CrossbeamVerifSender {
|
||||
type Error = StdVerifSenderError;
|
||||
|
||||
delegate!(
|
||||
@ -1127,9 +1127,9 @@ mod stdmod {
|
||||
}
|
||||
|
||||
#[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;
|
||||
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
|
||||
let operation = |mut mg: RwLockWriteGuard<ShareablePoolProvider>| {
|
||||
@ -1158,10 +1158,10 @@ mod stdmod {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
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::verification::{
|
||||
EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, MpscVerifSender, RequestId,
|
||||
EcssTmError, EcssTmSenderBase, FailParams, FailParamsWithStep, MpscVerifSender, RequestId,
|
||||
TcStateNone, VerificationReporterCfg, VerificationReporterWithBuf,
|
||||
VerificationReporterWithSender, VerificationToken,
|
||||
};
|
||||
@ -1196,7 +1196,7 @@ mod tests {
|
||||
pub service_queue: VecDeque<TmInfo>,
|
||||
}
|
||||
|
||||
impl EcssTmSender for TestSender {
|
||||
impl EcssTmSenderBase for TestSender {
|
||||
type Error = ();
|
||||
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
|
||||
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)]
|
||||
struct DummyError {}
|
||||
#[derive(Default, Clone)]
|
||||
struct FallibleSender {}
|
||||
|
||||
impl EcssTmSender for FallibleSender {
|
||||
impl EcssTmSenderBase for FallibleSender {
|
||||
type Error = DummyError;
|
||||
fn send_tm(&mut self, _: PusTm) -> Result<(), EcssTmError<DummyError>> {
|
||||
Err(EcssTmError::SendError(DummyError {}))
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssTmSenderClonable for FallibleSender {}
|
||||
impl EcssTmSender for FallibleSender {}
|
||||
|
||||
struct TestBase<'a> {
|
||||
vr: VerificationReporterWithBuf,
|
||||
|
@ -19,7 +19,7 @@
|
||||
//!
|
||||
//! ```rust
|
||||
//! 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::tc::PusTc;
|
||||
//!
|
||||
@ -84,7 +84,7 @@
|
||||
//! .expect("Casting back to concrete type failed");
|
||||
//! mutable_ref.mutable_foo();
|
||||
//! ```
|
||||
use crate::tmtc::{ReceivesCcsdsTc, ReceivesTc};
|
||||
use crate::tmtc::{ReceivesCcsdsTc, ReceivesTc, ReceivesTcBase};
|
||||
use alloc::boxed::Box;
|
||||
use downcast_rs::Downcast;
|
||||
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>;
|
||||
|
||||
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> {
|
||||
pub fn new(apid_handler: Box<dyn CcsdsPacketHandler<Error = E>>) -> Self {
|
||||
CcsdsDistributor { apid_handler }
|
||||
|
@ -5,6 +5,7 @@
|
||||
//! 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
|
||||
//! routing without the overhead and complication of using message queues. However, it also requires
|
||||
#[cfg(feature = "alloc")]
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -62,11 +63,14 @@ impl AddressableId {
|
||||
/// 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
|
||||
/// raw byte format into them.
|
||||
pub trait ReceivesTc: Downcast + Send {
|
||||
pub trait ReceivesTcBase: Send {
|
||||
type 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);
|
||||
|
||||
/// Generic trait for object which can receive CCSDS space packets, for fsrc-example ECSS PUS packets
|
||||
|
@ -18,7 +18,7 @@
|
||||
//!
|
||||
//! ```rust
|
||||
//! use satrs_core::tmtc::pus_distrib::{PusDistributor, PusServiceProvider};
|
||||
//! use satrs_core::tmtc::ReceivesTc;
|
||||
//! use satrs_core::tmtc::{ReceivesTc, ReceivesTcBase};
|
||||
//! use spacepackets::SpHeader;
|
||||
//! use spacepackets::tc::PusTc;
|
||||
//! struct ConcretePusHandler {
|
||||
@ -60,7 +60,7 @@
|
||||
//! .expect("Casting back to concrete type failed");
|
||||
//! 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 downcast_rs::Downcast;
|
||||
use spacepackets::ecss::{PusError, PusPacket};
|
||||
@ -94,7 +94,7 @@ pub enum PusDistribError<E> {
|
||||
PusError(PusError),
|
||||
}
|
||||
|
||||
impl<E: 'static> ReceivesTc for PusDistributor<E> {
|
||||
impl<E: 'static> ReceivesTcBase for PusDistributor<E> {
|
||||
type Error = PusDistribError<E>;
|
||||
fn pass_tc(&mut self, tm_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
// 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> {
|
||||
type Error = PusDistribError<E>;
|
||||
fn pass_ccsds(&mut self, header: &SpHeader, tm_raw: &[u8]) -> Result<(), Self::Error> {
|
||||
|
@ -7,7 +7,7 @@ use satrs_core::params::{Params, ParamsHeapless, WritableToBeBytes};
|
||||
use satrs_core::pus::event_man::{
|
||||
DefaultPusMgmtBackendProvider, EventReporter, PusEventDispatcher,
|
||||
};
|
||||
use satrs_core::pus::{EcssTmError, EcssTmSender};
|
||||
use satrs_core::pus::{EcssTmError, EcssTmSenderBase};
|
||||
use spacepackets::ecss::PusPacket;
|
||||
use spacepackets::tm::PusTm;
|
||||
use std::sync::mpsc::{channel, SendError, TryRecvError};
|
||||
@ -23,7 +23,7 @@ struct EventTmSender {
|
||||
sender: std::sync::mpsc::Sender<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl EcssTmSender for EventTmSender {
|
||||
impl EcssTmSenderBase for EventTmSender {
|
||||
type Error = SendError<Vec<u8>>;
|
||||
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
|
||||
let mut vec = Vec::new();
|
||||
|
@ -22,7 +22,7 @@ use satrs_core::pus::hk::Subservice;
|
||||
use satrs_core::pus::verification::{
|
||||
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
|
||||
};
|
||||
use satrs_core::pus::{EcssTmError, EcssTmSender};
|
||||
use satrs_core::pus::{EcssTmError, EcssTmSenderBase};
|
||||
use satrs_core::seq_count::SimpleSeqCountProvider;
|
||||
use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT};
|
||||
use spacepackets::time::cds::TimeProvider;
|
||||
@ -51,7 +51,7 @@ impl EventTmSender {
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssTmSender for EventTmSender {
|
||||
impl EcssTmSenderBase for EventTmSender {
|
||||
type Error = mpsc::SendError<StoreAddr>;
|
||||
|
||||
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
|
||||
|
Loading…
Reference in New Issue
Block a user