diff --git a/satrs-core/src/pus/event_srv.rs b/satrs-core/src/pus/event_srv.rs index 86f6b80..c467c30 100644 --- a/satrs-core/src/pus/event_srv.rs +++ b/satrs-core/src/pus/event_srv.rs @@ -150,10 +150,9 @@ mod tests { impl Pus5HandlerWithStoreTester { pub fn new(event_request_tx: Sender) -> Self { let (common, srv_handler) = PusServiceHandlerWithStoreCommon::new(); - let pus_17_handler = PusService5EventHandler::new(srv_handler, event_request_tx); Self { common, - handler: pus_17_handler, + handler: PusService5EventHandler::new(srv_handler, event_request_tx) } } } diff --git a/satrs-core/src/pus/scheduler_srv.rs b/satrs-core/src/pus/scheduler_srv.rs index 77bd7c1..b5a7d13 100644 --- a/satrs-core/src/pus/scheduler_srv.rs +++ b/satrs-core/src/pus/scheduler_srv.rs @@ -1,12 +1,9 @@ +use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; use crate::pool::SharedPool; use crate::pus::scheduler::PusScheduler; -use crate::pus::{EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError}; +use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError}; use spacepackets::ecss::{scheduling, PusPacket}; use spacepackets::time::cds::TimeProvider; -use std::boxed::Box; - -use super::verification::VerificationReporterWithSender; -use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; /// This is a helper class for [std] environments to handle generic PUS 11 (scheduling service) /// packets. This handler is constrained to using the [PusScheduler], but is able to process @@ -17,29 +14,19 @@ use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper}; /// [Self::scheduler] and [Self::scheduler_mut] function and then use the scheduler API to release /// telecommands when applicable. pub struct PusService11SchedHandler { - pub psb: PusServiceHelper, + pub service_helper: PusServiceHelper, shared_tc_store: SharedPool, scheduler: PusScheduler, } impl PusService11SchedHandler { pub fn new( - tc_receiver: Box, - tm_sender: Box, - tm_apid: u16, - verification_handler: VerificationReporterWithSender, - tc_in_mem_converter: TcInMemConverter, + service_helper: PusServiceHelper, shared_tc_store: SharedPool, scheduler: PusScheduler, ) -> Self { Self { - psb: PusServiceHelper::new( - tc_receiver, - tm_sender, - tm_apid, - verification_handler, - tc_in_mem_converter, - ), + service_helper, shared_tc_store, scheduler, } @@ -54,13 +41,13 @@ impl PusService11SchedHandler Result { - let possible_packet = self.psb.retrieve_and_accept_next_packet()?; + let possible_packet = self.service_helper.retrieve_and_accept_next_packet()?; if possible_packet.is_none() { return Ok(PusPacketHandlerResult::Empty); } let ecss_tc_and_token = possible_packet.unwrap(); let tc = self - .psb + .service_helper .tc_in_mem_converter .convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?; let subservice = tc.subservice(); @@ -76,7 +63,7 @@ impl PusService11SchedHandler { let start_token = self - .psb + .service_helper .common .verification_handler .get_mut() @@ -85,7 +72,7 @@ impl PusService11SchedHandler PusService11SchedHandler { let start_token = self - .psb + .service_helper .common .verification_handler .get_mut() @@ -106,7 +93,7 @@ impl PusService11SchedHandler PusService11SchedHandler { let start_token = self - .psb + .service_helper .common .verification_handler .get_mut() @@ -131,7 +118,7 @@ impl PusService11SchedHandler PusService11SchedHandler { let start_token = self - .psb + .service_helper .common .verification_handler .get_mut() @@ -152,7 +139,7 @@ impl PusService11SchedHandler(&tc, pool.as_mut()) .expect("insertion of activity into pool failed"); - self.psb + self.service_helper .common .verification_handler .get_mut() @@ -177,4 +164,51 @@ impl PusService11SchedHandler, + } + + impl Pus11HandlerWithStoreTester { + pub fn new(shared_tc_store: SharedPool, scheduler: PusScheduler) -> Self { + let (common, srv_handler) = PusServiceHandlerWithStoreCommon::new(); + Self { + common, + handler: PusService11SchedHandler::new(srv_handler, shared_tc_store, scheduler), + } + } + } + + impl PusTestHarness for Pus11HandlerWithStoreTester { + delegate! { + to self.common { + fn send_tc(&mut self, tc: &PusTcCreator) -> VerificationToken; + fn read_next_tm(&mut self) -> PusTmReader<'_>; + fn check_no_tm_available(&self) -> bool; + fn check_next_verification_tm(&self, subservice: u8, expected_request_id: RequestId); + } + + to self.handler { + fn handle_one_tc(&mut self) -> Result; + } + } + } +} diff --git a/satrs-core/src/pus/test.rs b/satrs-core/src/pus/test.rs index cb38051..fb548db 100644 --- a/satrs-core/src/pus/test.rs +++ b/satrs-core/src/pus/test.rs @@ -151,10 +151,9 @@ mod tests { impl Pus17HandlerWithVecTester { pub fn new() -> Self { let (common, srv_handler) = PusServiceHandlerWithVecCommon::new(); - let pus_17_handler = PusService17TestHandler::new(srv_handler); Self { common, - handler: pus_17_handler, + handler: PusService17TestHandler::new(srv_handler) } } } diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 8336fd5..569a46d 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -205,11 +205,13 @@ fn main() { let scheduler = PusScheduler::new_with_current_init_time(Duration::from_secs(5)) .expect("Creating PUS Scheduler failed"); let pus_11_handler = PusService11SchedHandler::new( - Box::new(sched_srv_receiver), - Box::new(sched_srv_tm_sender), - PUS_APID, - verif_reporter.clone(), - EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048), + PusServiceHelper::new( + Box::new(sched_srv_receiver), + Box::new(sched_srv_tm_sender), + PUS_APID, + verif_reporter.clone(), + EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048), + ), tc_store.pool.clone(), scheduler, );