From 223b637eb8618e5e28f1b36b4be84dcac8e8ddf5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 26 Feb 2024 15:18:15 +0100 Subject: [PATCH 1/2] use generics for the PUS stack --- satrs-example/src/pus/action.rs | 36 +++++-- satrs-example/src/pus/event.rs | 35 +++++-- satrs-example/src/pus/hk.rs | 36 +++++-- satrs-example/src/pus/scheduler.rs | 41 +++++--- satrs-example/src/pus/stack.rs | 36 ++++--- satrs-example/src/pus/test.rs | 32 +++++-- satrs/src/action.rs | 21 +++++ satrs/src/pus/action.rs | 32 +++++-- satrs/src/pus/event_srv.rs | 28 ++++-- satrs/src/pus/hk.rs | 30 ++++-- satrs/src/pus/mod.rs | 145 ++++++++++++++++++----------- satrs/src/pus/scheduler_srv.rs | 35 +++++-- satrs/src/pus/test.rs | 72 +++++++++++--- 13 files changed, 419 insertions(+), 160 deletions(-) diff --git a/satrs-example/src/pus/action.rs b/satrs-example/src/pus/action.rs index eb196b7..ef23786 100644 --- a/satrs-example/src/pus/action.rs +++ b/satrs-example/src/pus/action.rs @@ -10,8 +10,9 @@ use satrs::pus::verification::{ }; use satrs::pus::{ EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, - MpscTcReceiver, PusPacketHandlerResult, PusPacketHandlingError, PusServiceHelper, - TmAsVecSenderWithId, TmInSharedPoolSenderWithId, + EcssTcReceiverCore, EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, + PusPacketHandlingError, PusServiceHelper, TmAsVecSenderWithId, TmAsVecSenderWithMpsc, + TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithId, }; use satrs::request::TargetAndApidId; use satrs::spacepackets::ecss::tc::PusTcReader; @@ -81,8 +82,12 @@ pub fn create_action_service_static( tc_pool: SharedStaticMemoryPool, pus_action_rx: mpsc::Receiver, action_router: GenericRequestRouter, -) -> Pus8Wrapper -{ +) -> Pus8Wrapper< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscBoundedSender, +> { let action_srv_tm_sender = TmInSharedPoolSenderWithId::new( TmSenderId::PusAction as ChannelId, "PUS_8_TM_SENDER", @@ -96,8 +101,8 @@ pub fn create_action_service_static( ); let pus_8_handler = PusService8ActionHandler::new( PusServiceHelper::new( - Box::new(action_srv_receiver), - Box::new(action_srv_tm_sender), + action_srv_receiver, + action_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInSharedStoreConverter::new(tc_pool.clone(), 2048), @@ -114,7 +119,12 @@ pub fn create_action_service_dynamic( verif_reporter: VerificationReporterWithVecMpscSender, pus_action_rx: mpsc::Receiver, action_router: GenericRequestRouter, -) -> Pus8Wrapper { +) -> Pus8Wrapper< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, +> { let action_srv_tm_sender = TmAsVecSenderWithId::new( TmSenderId::PusAction as ChannelId, "PUS_8_TM_SENDER", @@ -127,8 +137,8 @@ pub fn create_action_service_dynamic( ); let pus_8_handler = PusService8ActionHandler::new( PusServiceHelper::new( - Box::new(action_srv_receiver), - Box::new(action_srv_tm_sender), + action_srv_receiver, + action_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInVecConverter::default(), @@ -141,10 +151,14 @@ pub fn create_action_service_dynamic( } pub struct Pus8Wrapper< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { pub(crate) pus_8_handler: PusService8ActionHandler< + TcReceiver, + TmSender, TcInMemConverter, VerificationReporter, ExampleActionRequestConverter, @@ -154,9 +168,11 @@ pub struct Pus8Wrapper< } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > Pus8Wrapper + > Pus8Wrapper { pub fn handle_next_packet(&mut self) -> bool { match self.pus_8_handler.handle_one_tc() { diff --git a/satrs-example/src/pus/event.rs b/satrs-example/src/pus/event.rs index 59f4949..1d16f5c 100644 --- a/satrs-example/src/pus/event.rs +++ b/satrs-example/src/pus/event.rs @@ -10,7 +10,8 @@ use satrs::pus::verification::std_mod::{ use satrs::pus::verification::VerificationReportingProvider; use satrs::pus::{ EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, - MpscTcReceiver, PusPacketHandlerResult, PusServiceHelper, TmAsVecSenderWithId, + EcssTcReceiverCore, EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, PusServiceHelper, + TmAsVecSenderWithId, TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithId, }; use satrs::tmtc::tm_helper::SharedTmPool; @@ -24,8 +25,12 @@ pub fn create_event_service_static( tc_pool: SharedStaticMemoryPool, pus_event_rx: mpsc::Receiver, event_request_tx: mpsc::Sender, -) -> Pus5Wrapper -{ +) -> Pus5Wrapper< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscBoundedSender, +> { let event_srv_tm_sender = TmInSharedPoolSenderWithId::new( TmSenderId::PusEvent as ChannelId, "PUS_5_TM_SENDER", @@ -39,8 +44,8 @@ pub fn create_event_service_static( ); let pus_5_handler = PusService5EventHandler::new( PusServiceHelper::new( - Box::new(event_srv_receiver), - Box::new(event_srv_tm_sender), + event_srv_receiver, + event_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInSharedStoreConverter::new(tc_pool.clone(), 2048), @@ -55,7 +60,12 @@ pub fn create_event_service_dynamic( verif_reporter: VerificationReporterWithVecMpscSender, pus_event_rx: mpsc::Receiver, event_request_tx: mpsc::Sender, -) -> Pus5Wrapper { +) -> Pus5Wrapper< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, +> { let event_srv_tm_sender = TmAsVecSenderWithId::new( TmSenderId::PusEvent as ChannelId, "PUS_5_TM_SENDER", @@ -68,8 +78,8 @@ pub fn create_event_service_dynamic( ); let pus_5_handler = PusService5EventHandler::new( PusServiceHelper::new( - Box::new(event_srv_receiver), - Box::new(event_srv_tm_sender), + event_srv_receiver, + event_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInVecConverter::default(), @@ -80,16 +90,21 @@ pub fn create_event_service_dynamic( } pub struct Pus5Wrapper< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - pub pus_5_handler: PusService5EventHandler, + pub pus_5_handler: + PusService5EventHandler, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > Pus5Wrapper + > Pus5Wrapper { pub fn handle_next_packet(&mut self) -> bool { match self.pus_5_handler.handle_one_tc() { diff --git a/satrs-example/src/pus/hk.rs b/satrs-example/src/pus/hk.rs index 444283a..48a54be 100644 --- a/satrs-example/src/pus/hk.rs +++ b/satrs-example/src/pus/hk.rs @@ -10,8 +10,9 @@ use satrs::pus::verification::{ }; use satrs::pus::{ EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, - MpscTcReceiver, PusPacketHandlerResult, PusPacketHandlingError, PusServiceHelper, - TmAsVecSenderWithId, TmInSharedPoolSenderWithId, + EcssTcReceiverCore, EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, + PusPacketHandlingError, PusServiceHelper, TmAsVecSenderWithId, TmAsVecSenderWithMpsc, + TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithId, }; use satrs::request::TargetAndApidId; use satrs::spacepackets::ecss::tc::PusTcReader; @@ -150,8 +151,12 @@ pub fn create_hk_service_static( tc_pool: SharedStaticMemoryPool, pus_hk_rx: mpsc::Receiver, request_router: GenericRequestRouter, -) -> Pus3Wrapper -{ +) -> Pus3Wrapper< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscBoundedSender, +> { let hk_srv_tm_sender = TmInSharedPoolSenderWithId::new( TmSenderId::PusHk as ChannelId, "PUS_3_TM_SENDER", @@ -162,8 +167,8 @@ pub fn create_hk_service_static( MpscTcReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx); let pus_3_handler = PusService3HkHandler::new( PusServiceHelper::new( - Box::new(hk_srv_receiver), - Box::new(hk_srv_tm_sender), + hk_srv_receiver, + hk_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInSharedStoreConverter::new(tc_pool, 2048), @@ -180,7 +185,12 @@ pub fn create_hk_service_dynamic( verif_reporter: VerificationReporterWithVecMpscSender, pus_hk_rx: mpsc::Receiver, request_router: GenericRequestRouter, -) -> Pus3Wrapper { +) -> Pus3Wrapper< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, +> { let hk_srv_tm_sender = TmAsVecSenderWithId::new( TmSenderId::PusHk as ChannelId, "PUS_3_TM_SENDER", @@ -190,8 +200,8 @@ pub fn create_hk_service_dynamic( MpscTcReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx); let pus_3_handler = PusService3HkHandler::new( PusServiceHelper::new( - Box::new(hk_srv_receiver), - Box::new(hk_srv_tm_sender), + hk_srv_receiver, + hk_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInVecConverter::default(), @@ -204,10 +214,14 @@ pub fn create_hk_service_dynamic( } pub struct Pus3Wrapper< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { pub(crate) pus_3_handler: PusService3HkHandler< + TcReceiver, + TmSender, TcInMemConverter, VerificationReporter, ExampleHkRequestConverter, @@ -217,9 +231,11 @@ pub struct Pus3Wrapper< } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > Pus3Wrapper + > Pus3Wrapper { pub fn handle_next_packet(&mut self) -> bool { match self.pus_3_handler.handle_one_tc() { diff --git a/satrs-example/src/pus/scheduler.rs b/satrs-example/src/pus/scheduler.rs index abb9e3f..c5d2c06 100644 --- a/satrs-example/src/pus/scheduler.rs +++ b/satrs-example/src/pus/scheduler.rs @@ -11,7 +11,8 @@ use satrs::pus::verification::std_mod::{ use satrs::pus::verification::VerificationReportingProvider; use satrs::pus::{ EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, - MpscTcReceiver, PusPacketHandlerResult, PusServiceHelper, TmAsVecSenderWithId, + EcssTcReceiverCore, EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, PusServiceHelper, + TmAsVecSenderWithId, TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithId, }; use satrs::tmtc::tm_helper::SharedTmPool; @@ -55,20 +56,29 @@ impl TcReleaser for mpsc::Sender> { } pub struct Pus11Wrapper< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - pub pus_11_handler: - PusService11SchedHandler, + pub pus_11_handler: PusService11SchedHandler< + TcReceiver, + TmSender, + TcInMemConverter, + VerificationReporter, + PusScheduler, + >, pub sched_tc_pool: StaticMemoryPool, pub releaser_buf: [u8; 4096], pub tc_releaser: Box, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > Pus11Wrapper + > Pus11Wrapper { pub fn release_tcs(&mut self) { let releaser = |enabled: bool, info: &TcInfo, tc: &[u8]| -> bool { @@ -125,8 +135,12 @@ pub fn create_scheduler_service_static( tc_releaser: PusTcSourceProviderSharedPool, pus_sched_rx: mpsc::Receiver, sched_tc_pool: StaticMemoryPool, -) -> Pus11Wrapper -{ +) -> Pus11Wrapper< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscBoundedSender, +> { let sched_srv_tm_sender = TmInSharedPoolSenderWithId::new( TmSenderId::PusSched as ChannelId, "PUS_11_TM_SENDER", @@ -142,8 +156,8 @@ pub fn create_scheduler_service_static( .expect("Creating PUS Scheduler failed"); let pus_11_handler = PusService11SchedHandler::new( PusServiceHelper::new( - Box::new(sched_srv_receiver), - Box::new(sched_srv_tm_sender), + sched_srv_receiver, + sched_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInSharedStoreConverter::new(tc_releaser.clone_backing_pool(), 2048), @@ -164,7 +178,12 @@ pub fn create_scheduler_service_dynamic( tc_source_sender: mpsc::Sender>, pus_sched_rx: mpsc::Receiver, sched_tc_pool: StaticMemoryPool, -) -> Pus11Wrapper { +) -> Pus11Wrapper< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, +> { let sched_srv_tm_sender = TmAsVecSenderWithId::new( TmSenderId::PusSched as ChannelId, "PUS_11_TM_SENDER", @@ -179,8 +198,8 @@ pub fn create_scheduler_service_dynamic( .expect("Creating PUS Scheduler failed"); let pus_11_handler = PusService11SchedHandler::new( PusServiceHelper::new( - Box::new(sched_srv_receiver), - Box::new(sched_srv_tm_sender), + sched_srv_receiver, + sched_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInVecConverter::default(), diff --git a/satrs-example/src/pus/stack.rs b/satrs-example/src/pus/stack.rs index 23061f7..ed06e08 100644 --- a/satrs-example/src/pus/stack.rs +++ b/satrs-example/src/pus/stack.rs @@ -1,4 +1,7 @@ -use satrs::pus::{verification::VerificationReportingProvider, EcssTcInMemConverter}; +use satrs::pus::{ + verification::VerificationReportingProvider, EcssTcInMemConverter, EcssTcReceiverCore, + EcssTmSenderCore, +}; use super::{ action::Pus8Wrapper, event::Pus5Wrapper, hk::Pus3Wrapper, scheduler::Pus11Wrapper, @@ -6,27 +9,36 @@ use super::{ }; pub struct PusStack< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - event_srv: Pus5Wrapper, - hk_srv: Pus3Wrapper, - action_srv: Pus8Wrapper, - schedule_srv: Pus11Wrapper, - test_srv: Service17CustomWrapper, + event_srv: Pus5Wrapper, + hk_srv: Pus3Wrapper, + action_srv: Pus8Wrapper, + schedule_srv: Pus11Wrapper, + test_srv: Service17CustomWrapper, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > PusStack + > PusStack { pub fn new( - hk_srv: Pus3Wrapper, - event_srv: Pus5Wrapper, - action_srv: Pus8Wrapper, - schedule_srv: Pus11Wrapper, - test_srv: Service17CustomWrapper, + hk_srv: Pus3Wrapper, + event_srv: Pus5Wrapper, + action_srv: Pus8Wrapper, + schedule_srv: Pus11Wrapper, + test_srv: Service17CustomWrapper< + TcReceiver, + TmSender, + TcInMemConverter, + VerificationReporter, + >, ) -> Self { Self { event_srv, diff --git a/satrs-example/src/pus/test.rs b/satrs-example/src/pus/test.rs index 696cfdc..17822a3 100644 --- a/satrs-example/src/pus/test.rs +++ b/satrs-example/src/pus/test.rs @@ -7,8 +7,10 @@ use satrs::pus::verification::{ VerificationReporterWithSharedPoolMpscBoundedSender, VerificationReporterWithVecMpscSender, }; use satrs::pus::{ - EcssTcAndToken, EcssTcInMemConverter, EcssTcInVecConverter, MpscTcReceiver, - PusPacketHandlerResult, PusServiceHelper, TmAsVecSenderWithId, TmInSharedPoolSenderWithId, + EcssTcAndToken, EcssTcInMemConverter, EcssTcInVecConverter, EcssTcReceiverCore, + EcssTmSenderCore, MpscTcReceiver, PusPacketHandlerResult, PusServiceHelper, + TmAsVecSenderWithId, TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc, + TmInSharedPoolSenderWithId, }; use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::PusPacket; @@ -28,6 +30,8 @@ pub fn create_test_service_static( event_sender: mpsc::Sender<(EventU32, Option)>, pus_test_rx: mpsc::Receiver, ) -> Service17CustomWrapper< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, EcssTcInSharedStoreConverter, VerificationReporterWithSharedPoolMpscBoundedSender, > { @@ -43,8 +47,8 @@ pub fn create_test_service_static( pus_test_rx, ); let pus17_handler = PusService17TestHandler::new(PusServiceHelper::new( - Box::new(test_srv_receiver), - Box::new(test_srv_tm_sender), + test_srv_receiver, + test_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInSharedStoreConverter::new(tc_pool, 2048), @@ -60,7 +64,12 @@ pub fn create_test_service_dynamic( verif_reporter: VerificationReporterWithVecMpscSender, event_sender: mpsc::Sender<(EventU32, Option)>, pus_test_rx: mpsc::Receiver, -) -> Service17CustomWrapper { +) -> Service17CustomWrapper< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, +> { let test_srv_tm_sender = TmAsVecSenderWithId::new( TmSenderId::PusTest as ChannelId, "PUS_17_TM_SENDER", @@ -72,8 +81,8 @@ pub fn create_test_service_dynamic( pus_test_rx, ); let pus17_handler = PusService17TestHandler::new(PusServiceHelper::new( - Box::new(test_srv_receiver), - Box::new(test_srv_tm_sender), + test_srv_receiver, + test_srv_tm_sender, PUS_APID, verif_reporter.clone(), EcssTcInVecConverter::default(), @@ -85,17 +94,22 @@ pub fn create_test_service_dynamic( } pub struct Service17CustomWrapper< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - pub pus17_handler: PusService17TestHandler, + pub pus17_handler: + PusService17TestHandler, pub test_srv_event_sender: Sender<(EventU32, Option)>, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > Service17CustomWrapper + > Service17CustomWrapper { pub fn handle_next_packet(&mut self) -> bool { let res = self.pus17_handler.handle_one_tc(); diff --git a/satrs/src/action.rs b/satrs/src/action.rs index e073fea..7caeaa6 100644 --- a/satrs/src/action.rs +++ b/satrs/src/action.rs @@ -40,3 +40,24 @@ impl TargetedActionRequest { } } } + +/// A reply to an action request. +#[non_exhaustive] +#[derive(Clone, Eq, PartialEq, Debug)] +pub enum ActionReply { + CompletionFailed(ActionId), + StepFailed { + id: ActionId, + step: u32, + }, + Completed(ActionId), + #[cfg(feature = "alloc")] + CompletedStringId(alloc::string::String), + #[cfg(feature = "alloc")] + CompletionFailedStringId(alloc::string::String), + #[cfg(feature = "alloc")] + StepFailedStringId { + id: alloc::string::String, + step: u32, + }, +} diff --git a/satrs/src/pus/action.rs b/satrs/src/pus/action.rs index 6fc7629..2ee4815 100644 --- a/satrs/src/pus/action.rs +++ b/satrs/src/pus/action.rs @@ -62,9 +62,9 @@ pub mod alloc_mod { #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] pub mod std_mod { use crate::pus::{ - verification::VerificationReportingProvider, EcssTcInMemConverter, GenericRoutingError, - PusPacketHandlerResult, PusPacketHandlingError, PusRoutingErrorHandler, PusServiceBase, - PusServiceHelper, + get_current_cds_short_timestamp, verification::VerificationReportingProvider, + EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, GenericRoutingError, + PusPacketHandlerResult, PusPacketHandlingError, PusRoutingErrorHandler, PusServiceHelper, }; use super::*; @@ -81,6 +81,8 @@ pub mod std_mod { /// 3. Route the action request using the provided [PusActionRequestRouter]. /// 4. Handle all routing errors using the provided [PusRoutingErrorHandler]. pub struct PusService8ActionHandler< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, RequestConverter: PusActionToRequestConverter, @@ -88,13 +90,16 @@ pub mod std_mod { RoutingErrorHandler: PusRoutingErrorHandler, RoutingError = GenericRoutingError, > { - service_helper: PusServiceHelper, + service_helper: + PusServiceHelper, pub request_converter: RequestConverter, pub request_router: RequestRouter, pub routing_error_handler: RoutingErrorHandler, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, RequestConverter: PusActionToRequestConverter, @@ -103,6 +108,8 @@ pub mod std_mod { RoutingError: Clone, > PusService8ActionHandler< + TcReceiver, + TmSender, TcInMemConverter, VerificationReporter, RequestConverter, @@ -114,7 +121,12 @@ pub mod std_mod { PusPacketHandlingError: From, { pub fn new( - service_helper: PusServiceHelper, + service_helper: PusServiceHelper< + TcReceiver, + TmSender, + TcInMemConverter, + VerificationReporter, + >, request_converter: RequestConverter, request_router: RequestRouter, routing_error_handler: RoutingErrorHandler, @@ -139,10 +151,7 @@ pub mod std_mod { .tc_in_mem_converter .convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?; let mut partial_error = None; - let time_stamp = - PusServiceBase::::get_current_cds_short_timestamp( - &mut partial_error, - ); + let time_stamp = get_current_cds_short_timestamp(&mut partial_error); let (target_id, action_request) = self.request_converter.convert( ecss_tc_and_token.token, &tc, @@ -189,7 +198,8 @@ mod tests { verification::{ tests::TestVerificationReporter, FailParams, RequestId, VerificationReportingProvider, }, - EcssTcInVecConverter, GenericRoutingError, PusPacketHandlerResult, PusPacketHandlingError, + EcssTcInVecConverter, GenericRoutingError, MpscTcReceiver, PusPacketHandlerResult, + PusPacketHandlingError, TmAsVecSenderWithMpsc, }; use super::*; @@ -259,6 +269,8 @@ mod tests { struct Pus8HandlerWithVecTester { common: PusServiceHandlerWithVecCommon, handler: PusService8ActionHandler< + MpscTcReceiver, + TmAsVecSenderWithMpsc, EcssTcInVecConverter, TestVerificationReporter, TestConverter<8>, diff --git a/satrs/src/pus/event_srv.rs b/satrs/src/pus/event_srv.rs index 5e9b053..64c1ba0 100644 --- a/satrs/src/pus/event_srv.rs +++ b/satrs/src/pus/event_srv.rs @@ -7,23 +7,36 @@ use spacepackets::ecss::PusPacket; use std::sync::mpsc::Sender; use super::verification::VerificationReportingProvider; -use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; +use super::{ + get_current_cds_short_timestamp, EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, + PusServiceHelper, +}; pub struct PusService5EventHandler< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - pub service_helper: PusServiceHelper, + pub service_helper: + PusServiceHelper, event_request_tx: Sender, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > PusService5EventHandler + > PusService5EventHandler { pub fn new( - service_helper: PusServiceHelper, + service_helper: PusServiceHelper< + TcReceiver, + TmSender, + TcInMemConverter, + VerificationReporter, + >, event_request_tx: Sender, ) -> Self { Self { @@ -94,9 +107,7 @@ impl< Ok(PusPacketHandlerResult::RequestHandled) }; let mut partial_error = None; - let time_stamp = PusServiceBase::::get_current_cds_short_timestamp( - &mut partial_error, - ); + let time_stamp = get_current_cds_short_timestamp(&mut partial_error); match srv.unwrap() { Subservice::TmInfoReport | Subservice::TmLowSeverityReport @@ -141,6 +152,7 @@ mod tests { use crate::pus::verification::{ RequestId, VerificationReporterWithSharedPoolMpscBoundedSender, }; + use crate::pus::{MpscTcReceiver, TmInSharedPoolSenderWithBoundedMpsc}; use crate::{ events::EventU32, pus::{ @@ -158,6 +170,8 @@ mod tests { struct Pus5HandlerWithStoreTester { common: PusServiceHandlerWithSharedStoreCommon, handler: PusService5EventHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, EcssTcInSharedStoreConverter, VerificationReporterWithSharedPoolMpscBoundedSender, >, diff --git a/satrs/src/pus/hk.rs b/satrs/src/pus/hk.rs index b371f03..852e8f7 100644 --- a/satrs/src/pus/hk.rs +++ b/satrs/src/pus/hk.rs @@ -64,9 +64,9 @@ pub mod alloc_mod { #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] pub mod std_mod { use crate::pus::{ - verification::VerificationReportingProvider, EcssTcInMemConverter, GenericRoutingError, - PusPacketHandlerResult, PusPacketHandlingError, PusRoutingErrorHandler, PusServiceBase, - PusServiceHelper, + get_current_cds_short_timestamp, verification::VerificationReportingProvider, + EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, GenericRoutingError, + PusPacketHandlerResult, PusPacketHandlingError, PusRoutingErrorHandler, PusServiceHelper, }; use super::*; @@ -85,6 +85,8 @@ pub mod std_mod { /// 4. Handle all routing errors using the provided [PusRoutingErrorHandler]. The generic error /// type is constrained to the [GenericRoutingError] for the concrete implementation. pub struct PusService3HkHandler< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, RequestConverter: PusHkToRequestConverter, @@ -92,13 +94,16 @@ pub mod std_mod { RoutingErrorHandler: PusRoutingErrorHandler, RoutingError = GenericRoutingError, > { - service_helper: PusServiceHelper, + service_helper: + PusServiceHelper, pub request_converter: RequestConverter, pub request_router: RequestRouter, pub routing_error_handler: RoutingErrorHandler, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, RequestConverter: PusHkToRequestConverter, @@ -107,6 +112,8 @@ pub mod std_mod { RoutingError: Clone, > PusService3HkHandler< + TcReceiver, + TmSender, TcInMemConverter, VerificationReporter, RequestConverter, @@ -118,7 +125,12 @@ pub mod std_mod { PusPacketHandlingError: From, { pub fn new( - service_helper: PusServiceHelper, + service_helper: PusServiceHelper< + TcReceiver, + TmSender, + TcInMemConverter, + VerificationReporter, + >, request_converter: RequestConverter, request_router: RequestRouter, routing_error_handler: RoutingErrorHandler, @@ -142,10 +154,7 @@ pub mod std_mod { .tc_in_mem_converter .convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?; let mut partial_error = None; - let time_stamp = - PusServiceBase::::get_current_cds_short_timestamp( - &mut partial_error, - ); + let time_stamp = get_current_cds_short_timestamp(&mut partial_error); let (target_id, hk_request) = self.request_converter.convert( ecss_tc_and_token.token, &tc, @@ -185,6 +194,7 @@ mod tests { CcsdsPacket, SequenceFlags, SpHeader, }; + use crate::pus::{MpscTcReceiver, TmAsVecSenderWithMpsc}; use crate::{ hk::HkRequest, pus::{ @@ -268,6 +278,8 @@ mod tests { struct Pus3HandlerWithVecTester { common: PusServiceHandlerWithVecCommon, handler: PusService3HkHandler< + MpscTcReceiver, + TmAsVecSenderWithMpsc, EcssTcInVecConverter, TestVerificationReporter, TestConverter<3>, diff --git a/satrs/src/pus/mod.rs b/satrs/src/pus/mod.rs index 282833b..ba0ff1d 100644 --- a/satrs/src/pus/mod.rs +++ b/satrs/src/pus/mod.rs @@ -371,13 +371,11 @@ pub mod std_mod { use crate::pool::{PoolProvider, PoolProviderWithGuards, SharedStaticMemoryPool, StoreAddr}; use crate::pus::verification::{TcStateAccepted, VerificationToken}; use crate::pus::{ - EcssChannel, EcssTcAndToken, EcssTcReceiver, EcssTcReceiverCore, EcssTmSender, - EcssTmSenderCore, EcssTmtcError, GenericRecvError, GenericSendError, PusTmWrapper, - TryRecvTmtcError, + EcssChannel, EcssTcAndToken, EcssTcReceiverCore, EcssTmSenderCore, EcssTmtcError, + GenericRecvError, GenericSendError, PusTmWrapper, TryRecvTmtcError, }; use crate::tmtc::tm_helper::SharedTmPool; use crate::{ChannelId, TargetId}; - use alloc::boxed::Box; use alloc::vec::Vec; use spacepackets::ecss::tc::PusTcReader; use spacepackets::ecss::tm::PusTmCreator; @@ -847,34 +845,35 @@ pub mod std_mod { } } - pub struct PusServiceBase { - pub tc_receiver: Box, - pub tm_sender: Box, + pub struct PusServiceBase< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, + VerificationReporter: VerificationReportingProvider, + > { + pub tc_receiver: TcReceiver, + pub tm_sender: TmSender, pub tm_apid: u16, pub verification_handler: VerificationReporter, } - - impl PusServiceBase { - #[cfg(feature = "std")] - pub fn get_current_cds_short_timestamp( - 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); - 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(); - } else { - *partial_error = Some(time_provider.unwrap_err()); - } - time_stamp - } - #[cfg(feature = "std")] - pub fn get_current_timestamp_ignore_error() -> [u8; 7] { - let mut dummy = None; - Self::get_current_cds_short_timestamp(&mut dummy) + #[cfg(feature = "std")] + pub fn get_current_cds_short_timestamp( + 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); + 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(); + } else { + *partial_error = Some(time_provider.unwrap_err()); } + time_stamp + } + #[cfg(feature = "std")] + pub fn get_current_timestamp_ignore_error() -> [u8; 7] { + let mut dummy = None; + get_current_cds_short_timestamp(&mut dummy) } /// This is a high-level PUS packet handler helper. @@ -887,21 +886,25 @@ pub mod std_mod { /// by using the [EcssTcInMemConverter] abstraction. This object provides some convenience /// methods to make the generic parts of TC handling easier. pub struct PusServiceHelper< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - pub common: PusServiceBase, + pub common: PusServiceBase, pub tc_in_mem_converter: TcInMemConverter, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > PusServiceHelper + > PusServiceHelper { pub fn new( - tc_receiver: Box, - tm_sender: Box, + tc_receiver: TcReceiver, + tm_sender: TmSender, tm_apid: u16, verification_handler: VerificationReporter, tc_in_mem_converter: TcInMemConverter, @@ -948,6 +951,34 @@ pub mod std_mod { } } } + + pub type PusServiceHelperDynWithMpsc = PusServiceHelper< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + TcInMemConverter, + VerificationReporter, + >; + pub type PusServiceHelperDynWithBoundedMpsc = + PusServiceHelper< + MpscTcReceiver, + TmAsVecSenderWithBoundedMpsc, + TcInMemConverter, + VerificationReporter, + >; + pub type PusServiceHelperStaticWithMpsc = + PusServiceHelper< + MpscTcReceiver, + TmInSharedPoolSenderWithMpsc, + TcInMemConverter, + VerificationReporter, + >; + pub type PusServiceHelperStaticWithBoundedMpsc = + PusServiceHelper< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + TcInMemConverter, + VerificationReporter, + >; } pub(crate) fn source_buffer_large_enough(cap: usize, len: usize) -> Result<(), EcssTmtcError> { @@ -969,7 +1000,6 @@ pub mod tests { use std::sync::mpsc::TryRecvError; use std::sync::{mpsc, RwLock}; - use alloc::boxed::Box; use alloc::collections::VecDeque; use alloc::vec::Vec; use satrs_shared::res_code::ResultU16; @@ -996,8 +1026,8 @@ pub mod tests { use super::{ EcssTcAndToken, EcssTcInSharedStoreConverter, EcssTcInVecConverter, GenericRoutingError, MpscTcReceiver, PusPacketHandlerResult, PusPacketHandlingError, PusRoutingErrorHandler, - PusServiceHelper, TcInMemory, TmAsVecSenderWithId, TmInSharedPoolSenderWithBoundedMpsc, - TmInSharedPoolSenderWithId, + PusServiceHelper, TcInMemory, TmAsVecSenderWithId, TmAsVecSenderWithMpsc, + TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithId, }; pub const TEST_APID: u16 = 0x101; @@ -1047,18 +1077,19 @@ pub mod tests { verification_handler: VerificationReporterWithSharedPoolMpscBoundedSender, } + pub type PusServiceHelperStatic = PusServiceHelper< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscBoundedSender, + >; + impl PusServiceHandlerWithSharedStoreCommon { /// This function generates the structure in addition to the PUS service handler /// [PusServiceHandler] which might be required for a specific PUS service handler. /// /// The PUS service handler is instantiated with a [EcssTcInStoreConverter]. - pub fn new() -> ( - Self, - PusServiceHelper< - EcssTcInSharedStoreConverter, - VerificationReporterWithSharedPoolMpscBoundedSender, - >, - ) { + pub fn new() -> (Self, PusServiceHelperStatic) { let pool_cfg = StaticPoolConfig::new(alloc::vec![(16, 16), (8, 32), (4, 64)], false); let tc_pool = StaticMemoryPool::new(pool_cfg.clone()); let tm_pool = StaticMemoryPool::new(pool_cfg); @@ -1092,8 +1123,8 @@ pub mod tests { verification_handler: verification_handler.clone(), }, PusServiceHelper::new( - Box::new(test_srv_tc_receiver), - Box::new(test_srv_tm_sender), + test_srv_tc_receiver, + test_srv_tm_sender, TEST_APID, verification_handler, in_store_converter, @@ -1157,12 +1188,15 @@ pub mod tests { tm_receiver: mpsc::Receiver>, pub verification_handler: VerificationReporter, } + pub type PusServiceHelperDynamic = PusServiceHelper< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, + >; impl PusServiceHandlerWithVecCommon { - pub fn new_with_standard_verif_reporter() -> ( - Self, - PusServiceHelper, - ) { + pub fn new_with_standard_verif_reporter() -> (Self, PusServiceHelperDynamic) { let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel(); let (tm_tx, tm_rx) = mpsc::channel(); @@ -1182,8 +1216,8 @@ pub mod tests { verification_handler: verification_handler.clone(), }, PusServiceHelper::new( - Box::new(test_srv_tc_receiver), - Box::new(test_srv_tm_sender), + test_srv_tc_receiver, + test_srv_tm_sender, TEST_APID, verification_handler, in_store_converter, @@ -1195,7 +1229,12 @@ pub mod tests { impl PusServiceHandlerWithVecCommon { pub fn new_with_test_verif_sender() -> ( Self, - PusServiceHelper, + PusServiceHelper< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + TestVerificationReporter, + >, ) { let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel(); let (tm_tx, tm_rx) = mpsc::channel(); @@ -1213,8 +1252,8 @@ pub mod tests { verification_handler: verification_handler.clone(), }, PusServiceHelper::new( - Box::new(test_srv_tc_receiver), - Box::new(test_srv_tm_sender), + test_srv_tc_receiver, + test_srv_tm_sender, TEST_APID, verification_handler, in_store_converter, diff --git a/satrs/src/pus/scheduler_srv.rs b/satrs/src/pus/scheduler_srv.rs index 22958ed..dbe3ae6 100644 --- a/satrs/src/pus/scheduler_srv.rs +++ b/satrs/src/pus/scheduler_srv.rs @@ -1,6 +1,9 @@ use super::scheduler::PusSchedulerProvider; use super::verification::VerificationReportingProvider; -use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; +use super::{ + get_current_cds_short_timestamp, EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, + PusServiceHelper, +}; use crate::pool::PoolProvider; use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError}; use alloc::string::ToString; @@ -16,22 +19,39 @@ use spacepackets::time::cds::TimeProvider; /// [Self::scheduler] and [Self::scheduler_mut] function and then use the scheduler API to release /// telecommands when applicable. pub struct PusService11SchedHandler< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, PusScheduler: PusSchedulerProvider, > { - pub service_helper: PusServiceHelper, + pub service_helper: + PusServiceHelper, scheduler: PusScheduler, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, Scheduler: PusSchedulerProvider, - > PusService11SchedHandler + > + PusService11SchedHandler< + TcReceiver, + TmSender, + TcInMemConverter, + VerificationReporter, + Scheduler, + > { pub fn new( - service_helper: PusServiceHelper, + service_helper: PusServiceHelper< + TcReceiver, + TmSender, + TcInMemConverter, + VerificationReporter, + >, scheduler: Scheduler, ) -> Self { Self { @@ -70,9 +90,7 @@ impl< )); } let mut partial_error = None; - let time_stamp = PusServiceBase::::get_current_cds_short_timestamp( - &mut partial_error, - ); + let time_stamp = get_current_cds_short_timestamp(&mut partial_error); match standard_subservice.unwrap() { scheduling::Subservice::TcEnableScheduling => { let start_token = self @@ -181,6 +199,7 @@ mod tests { verification::{RequestId, TcStateAccepted, VerificationToken}, EcssTcInSharedStoreConverter, }; + use crate::pus::{MpscTcReceiver, TmInSharedPoolSenderWithBoundedMpsc}; use alloc::collections::VecDeque; use delegate::delegate; use spacepackets::ecss::scheduling::Subservice; @@ -198,6 +217,8 @@ mod tests { struct Pus11HandlerWithStoreTester { common: PusServiceHandlerWithSharedStoreCommon, handler: PusService11SchedHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, EcssTcInSharedStoreConverter, VerificationReporterWithSharedPoolMpscBoundedSender, TestScheduler, diff --git a/satrs/src/pus/test.rs b/satrs/src/pus/test.rs index 0eef92b..4ad023c 100644 --- a/satrs/src/pus/test.rs +++ b/satrs/src/pus/test.rs @@ -6,23 +6,39 @@ use spacepackets::ecss::PusPacket; use spacepackets::SpHeader; use super::verification::VerificationReportingProvider; -use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; +use super::{ + get_current_cds_short_timestamp, EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, + MpscTcReceiver, PusServiceHelper, TmAsVecSenderWithBoundedMpsc, TmAsVecSenderWithMpsc, + TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithMpsc, +}; /// This is a helper class for [std] environments to handle generic PUS 17 (test service) packets. /// This handler only processes ping requests and generates a ping reply for them accordingly. pub struct PusService17TestHandler< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - pub service_helper: PusServiceHelper, + pub service_helper: + PusServiceHelper, } impl< + TcReceiver: EcssTcReceiverCore, + TmSender: EcssTmSenderCore, TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, - > PusService17TestHandler + > PusService17TestHandler { - pub fn new(service_helper: PusServiceHelper) -> Self { + pub fn new( + service_helper: PusServiceHelper< + TcReceiver, + TmSender, + TcInMemConverter, + VerificationReporter, + >, + ) -> Self { Self { service_helper } } @@ -41,10 +57,7 @@ impl< } if tc.subservice() == 1 { let mut partial_error = None; - let time_stamp = - PusServiceBase::::get_current_cds_short_timestamp( - &mut partial_error, - ); + let time_stamp = get_current_cds_short_timestamp(&mut partial_error); let result = self .service_helper .common @@ -98,6 +111,35 @@ impl< } } +pub type PusService17TestHandlerDynWithMpsc = + PusService17TestHandler< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + TcInMemConverter, + VerificationReporter, + >; +pub type PusService17TestHandlerDynWithBoundedMpsc = + PusService17TestHandler< + MpscTcReceiver, + TmAsVecSenderWithBoundedMpsc, + TcInMemConverter, + VerificationReporter, + >; +pub type PusService17TestHandlerStaticWithMpsc = + PusService17TestHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithMpsc, + TcInMemConverter, + VerificationReporter, + >; +pub type PusService17TestHandlerStaticWithBoundedMpsc = + PusService17TestHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + TcInMemConverter, + VerificationReporter, + >; + #[cfg(test)] mod tests { use crate::pus::tests::{ @@ -110,8 +152,8 @@ mod tests { use crate::pus::verification::RequestId; use crate::pus::verification::{TcStateAccepted, VerificationToken}; use crate::pus::{ - EcssTcInSharedStoreConverter, EcssTcInVecConverter, PusPacketHandlerResult, - PusPacketHandlingError, + EcssTcInSharedStoreConverter, EcssTcInVecConverter, MpscTcReceiver, PusPacketHandlerResult, + PusPacketHandlingError, TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc, }; use delegate::delegate; use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader}; @@ -124,6 +166,8 @@ mod tests { struct Pus17HandlerWithStoreTester { common: PusServiceHandlerWithSharedStoreCommon, handler: PusService17TestHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, EcssTcInSharedStoreConverter, VerificationReporterWithSharedPoolMpscBoundedSender, >, @@ -164,8 +208,12 @@ mod tests { struct Pus17HandlerWithVecTester { common: PusServiceHandlerWithVecCommon, - handler: - PusService17TestHandler, + handler: PusService17TestHandler< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, + >, } impl Pus17HandlerWithVecTester { -- 2.43.0 From 88793cfa8784dbb05d33c9da7d4c9b25e3141a25 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 26 Feb 2024 15:34:20 +0100 Subject: [PATCH 2/2] add some helper types --- satrs/src/pus/scheduler_srv.rs | 48 ++++++++++++++++++++-- satrs/src/pus/test.rs | 73 +++++++++++++++++++--------------- 2 files changed, 86 insertions(+), 35 deletions(-) diff --git a/satrs/src/pus/scheduler_srv.rs b/satrs/src/pus/scheduler_srv.rs index dbe3ae6..9cfb920 100644 --- a/satrs/src/pus/scheduler_srv.rs +++ b/satrs/src/pus/scheduler_srv.rs @@ -1,8 +1,14 @@ use super::scheduler::PusSchedulerProvider; -use super::verification::VerificationReportingProvider; +use super::verification::{ + VerificationReporterWithSharedPoolMpscBoundedSender, + VerificationReporterWithSharedPoolMpscSender, VerificationReporterWithVecMpscBoundedSender, + VerificationReporterWithVecMpscSender, VerificationReportingProvider, +}; use super::{ - get_current_cds_short_timestamp, EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, - PusServiceHelper, + get_current_cds_short_timestamp, EcssTcInMemConverter, EcssTcInSharedStoreConverter, + EcssTcInVecConverter, EcssTcReceiverCore, EcssTmSenderCore, MpscTcReceiver, PusServiceHelper, + TmAsVecSenderWithBoundedMpsc, TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc, + TmInSharedPoolSenderWithMpsc, }; use crate::pool::PoolProvider; use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError}; @@ -187,6 +193,42 @@ impl< Ok(PusPacketHandlerResult::RequestHandled) } } +/// Helper type definition for a PUS 11 handler with a dynamic TMTC memory backend and regular +/// mpsc queues. +pub type PusService11SchedHandlerDynWithMpsc = PusService11SchedHandler< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, + PusScheduler, +>; +/// Helper type definition for a PUS 11 handler with a dynamic TMTC memory backend and bounded MPSC +/// queues. +pub type PusService11SchedHandlerDynWithBoundedMpsc = PusService11SchedHandler< + MpscTcReceiver, + TmAsVecSenderWithBoundedMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscBoundedSender, + PusScheduler, +>; +/// Helper type definition for a PUS 11 handler with a shared store TMTC memory backend and regular +/// mpsc queues. +pub type PusService11SchedHandlerStaticWithMpsc = PusService11SchedHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscSender, + PusScheduler, +>; +/// Helper type definition for a PUS 11 handler with a shared store TMTC memory backend and bounded +/// mpsc queues. +pub type PusService11SchedHandlerStaticWithBoundedMpsc = PusService11SchedHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscBoundedSender, + PusScheduler, +>; #[cfg(test)] mod tests { diff --git a/satrs/src/pus/test.rs b/satrs/src/pus/test.rs index 4ad023c..ea5a720 100644 --- a/satrs/src/pus/test.rs +++ b/satrs/src/pus/test.rs @@ -5,11 +5,16 @@ use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; use spacepackets::ecss::PusPacket; use spacepackets::SpHeader; -use super::verification::VerificationReportingProvider; +use super::verification::{ + VerificationReporterWithSharedPoolMpscBoundedSender, + VerificationReporterWithSharedPoolMpscSender, VerificationReporterWithVecMpscBoundedSender, + VerificationReporterWithVecMpscSender, VerificationReportingProvider, +}; use super::{ - get_current_cds_short_timestamp, EcssTcInMemConverter, EcssTcReceiverCore, EcssTmSenderCore, - MpscTcReceiver, PusServiceHelper, TmAsVecSenderWithBoundedMpsc, TmAsVecSenderWithMpsc, - TmInSharedPoolSenderWithBoundedMpsc, TmInSharedPoolSenderWithMpsc, + get_current_cds_short_timestamp, EcssTcInMemConverter, EcssTcInSharedStoreConverter, + EcssTcInVecConverter, EcssTcReceiverCore, EcssTmSenderCore, MpscTcReceiver, PusServiceHelper, + TmAsVecSenderWithBoundedMpsc, TmAsVecSenderWithMpsc, TmInSharedPoolSenderWithBoundedMpsc, + TmInSharedPoolSenderWithMpsc, }; /// This is a helper class for [std] environments to handle generic PUS 17 (test service) packets. @@ -111,34 +116,38 @@ impl< } } -pub type PusService17TestHandlerDynWithMpsc = - PusService17TestHandler< - MpscTcReceiver, - TmAsVecSenderWithMpsc, - TcInMemConverter, - VerificationReporter, - >; -pub type PusService17TestHandlerDynWithBoundedMpsc = - PusService17TestHandler< - MpscTcReceiver, - TmAsVecSenderWithBoundedMpsc, - TcInMemConverter, - VerificationReporter, - >; -pub type PusService17TestHandlerStaticWithMpsc = - PusService17TestHandler< - MpscTcReceiver, - TmInSharedPoolSenderWithMpsc, - TcInMemConverter, - VerificationReporter, - >; -pub type PusService17TestHandlerStaticWithBoundedMpsc = - PusService17TestHandler< - MpscTcReceiver, - TmInSharedPoolSenderWithBoundedMpsc, - TcInMemConverter, - VerificationReporter, - >; +/// Helper type definition for a PUS 17 handler with a dynamic TMTC memory backend and regular +/// mpsc queues. +pub type PusService17TestHandlerDynWithMpsc = PusService17TestHandler< + MpscTcReceiver, + TmAsVecSenderWithMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscSender, +>; +/// Helper type definition for a PUS 17 handler with a dynamic TMTC memory backend and bounded MPSC +/// queues. +pub type PusService17TestHandlerDynWithBoundedMpsc = PusService17TestHandler< + MpscTcReceiver, + TmAsVecSenderWithBoundedMpsc, + EcssTcInVecConverter, + VerificationReporterWithVecMpscBoundedSender, +>; +/// Helper type definition for a PUS 17 handler with a shared store TMTC memory backend and regular +/// mpsc queues. +pub type PusService17TestHandlerStaticWithMpsc = PusService17TestHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscSender, +>; +/// Helper type definition for a PUS 17 handler with a shared store TMTC memory backend and bounded +/// mpsc queues. +pub type PusService17TestHandlerStaticWithBoundedMpsc = PusService17TestHandler< + MpscTcReceiver, + TmInSharedPoolSenderWithBoundedMpsc, + EcssTcInSharedStoreConverter, + VerificationReporterWithSharedPoolMpscBoundedSender, +>; #[cfg(test)] mod tests { -- 2.43.0