diff --git a/satrs-example/src/pus/event.rs b/satrs-example/src/pus/event.rs index 8ef19af..388cc3c 100644 --- a/satrs-example/src/pus/event.rs +++ b/satrs-example/src/pus/event.rs @@ -52,7 +52,9 @@ pub fn create_event_service_static( ), event_request_tx, ); - Pus5Wrapper { pus_5_handler } + Pus5Wrapper { + handler: pus_5_handler, + } } pub fn create_event_service_dynamic( @@ -86,7 +88,9 @@ pub fn create_event_service_dynamic( ), event_request_tx, ); - Pus5Wrapper { pus_5_handler } + Pus5Wrapper { + handler: pus_5_handler, + } } pub struct Pus5Wrapper< @@ -95,7 +99,7 @@ pub struct Pus5Wrapper< TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - pub pus_5_handler: + pub handler: PusService5EventHandler, } @@ -106,8 +110,8 @@ impl< VerificationReporter: VerificationReportingProvider, > Pus5Wrapper { - pub fn handle_next_packet(&mut self, time_stamp: &[u8]) -> bool { - match self.pus_5_handler.handle_one_tc(time_stamp) { + pub fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> bool { + match self.handler.poll_and_handle_next_tc(time_stamp) { Ok(result) => match result { PusPacketHandlerResult::RequestHandled => {} PusPacketHandlerResult::RequestHandledPartialSuccess(e) => { diff --git a/satrs-example/src/pus/mod.rs b/satrs-example/src/pus/mod.rs index 7e99ac4..1649bf5 100644 --- a/satrs-example/src/pus/mod.rs +++ b/satrs-example/src/pus/mod.rs @@ -27,6 +27,7 @@ pub mod scheduler; pub mod stack; pub mod test; +/// Simple router structure which forwards PUS telecommands to dedicated handlers. pub struct PusTcMpscRouter { pub test_service_receiver: Sender, pub event_service_receiver: Sender, diff --git a/satrs-example/src/pus/scheduler.rs b/satrs-example/src/pus/scheduler.rs index 1c99a83..4af9167 100644 --- a/satrs-example/src/pus/scheduler.rs +++ b/satrs-example/src/pus/scheduler.rs @@ -103,10 +103,10 @@ impl< } } - pub fn handle_next_packet(&mut self, time_stamp: &[u8]) -> bool { + pub fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> bool { match self .pus_11_handler - .handle_one_tc(time_stamp, &mut self.sched_tc_pool) + .poll_and_handle_next_tc(time_stamp, &mut self.sched_tc_pool) { Ok(result) => match result { PusPacketHandlerResult::RequestHandled => {} diff --git a/satrs-example/src/pus/stack.rs b/satrs-example/src/pus/stack.rs index 6376def..f8269d1 100644 --- a/satrs-example/src/pus/stack.rs +++ b/satrs-example/src/pus/stack.rs @@ -53,6 +53,8 @@ impl< } pub fn periodic_operation(&mut self) { + // Release all telecommands which reached their release time before calling the service + // handlers. self.schedule_srv.release_tcs(); let time_stamp = cds::TimeProvider::from_now_with_u16_days() .expect("time stamp generation error") @@ -68,9 +70,9 @@ impl< nothing_to_do = false; } }; - is_srv_finished(self.test_srv.handle_next_packet(&time_stamp), None); - is_srv_finished(self.schedule_srv.handle_next_packet(&time_stamp), None); - is_srv_finished(self.event_srv.handle_next_packet(&time_stamp), None); + is_srv_finished(self.test_srv.poll_and_handle_next_packet(&time_stamp), None); + is_srv_finished(self.schedule_srv.poll_and_handle_next_tc(&time_stamp), None); + is_srv_finished(self.event_srv.poll_and_handle_next_tc(&time_stamp), None); is_srv_finished( self.action_srv_wrapper.poll_and_handle_next_tc(&time_stamp), Some( diff --git a/satrs-example/src/pus/test.rs b/satrs-example/src/pus/test.rs index 7fb49a5..7c9e7aa 100644 --- a/satrs-example/src/pus/test.rs +++ b/satrs-example/src/pus/test.rs @@ -54,7 +54,7 @@ pub fn create_test_service_static( EcssTcInSharedStoreConverter::new(tc_pool, 2048), )); Service17CustomWrapper { - pus17_handler, + handler: pus17_handler, test_srv_event_sender: event_sender, } } @@ -88,7 +88,7 @@ pub fn create_test_service_dynamic( EcssTcInVecConverter::default(), )); Service17CustomWrapper { - pus17_handler, + handler: pus17_handler, test_srv_event_sender: event_sender, } } @@ -99,7 +99,7 @@ pub struct Service17CustomWrapper< TcInMemConverter: EcssTcInMemConverter, VerificationReporter: VerificationReportingProvider, > { - pub pus17_handler: + pub handler: PusService17TestHandler, pub test_srv_event_sender: Sender<(EventU32, Option)>, } @@ -111,8 +111,8 @@ impl< VerificationReporter: VerificationReportingProvider, > Service17CustomWrapper { - pub fn handle_next_packet(&mut self, time_stamp: &[u8]) -> bool { - let res = self.pus17_handler.handle_one_tc(time_stamp); + pub fn poll_and_handle_next_packet(&mut self, time_stamp: &[u8]) -> bool { + let res = self.handler.poll_and_handle_next_tc(time_stamp); if res.is_err() { warn!("PUS17 handler failed with error {:?}", res.unwrap_err()); return true; @@ -133,7 +133,7 @@ impl< } PusPacketHandlerResult::CustomSubservice(subservice, token) => { let (tc, _) = PusTcReader::new( - self.pus17_handler + self.handler .service_helper .tc_in_mem_converter .tc_slice_raw(), @@ -148,19 +148,19 @@ impl< .send((TEST_EVENT.into(), None)) .expect("Sending test event failed"); let start_token = self - .pus17_handler + .handler .service_helper .verif_reporter() .start_success(token, &stamp_buf) .expect("Error sending start success"); - self.pus17_handler + self.handler .service_helper .verif_reporter() .completion_success(start_token, &stamp_buf) .expect("Error sending completion success"); } else { let fail_data = [tc.subservice()]; - self.pus17_handler + self.handler .service_helper .verif_reporter() .start_failure( diff --git a/satrs/src/pus/event_srv.rs b/satrs/src/pus/event_srv.rs index edb88f5..bb66151 100644 --- a/satrs/src/pus/event_srv.rs +++ b/satrs/src/pus/event_srv.rs @@ -46,7 +46,7 @@ impl< } } - pub fn handle_one_tc( + pub fn poll_and_handle_next_tc( &mut self, time_stamp: &[u8], ) -> Result { @@ -213,7 +213,7 @@ mod tests { impl SimplePusPacketHandler for Pus5HandlerWithStoreTester { fn handle_one_tc(&mut self) -> Result { let time_stamp = cds::TimeProvider::new_with_u16_days(0, 0).to_vec().unwrap(); - self.handler.handle_one_tc(&time_stamp) + self.handler.poll_and_handle_next_tc(&time_stamp) } } diff --git a/satrs/src/pus/scheduler_srv.rs b/satrs/src/pus/scheduler_srv.rs index 1774382..0677573 100644 --- a/satrs/src/pus/scheduler_srv.rs +++ b/satrs/src/pus/scheduler_srv.rs @@ -73,7 +73,7 @@ impl< &self.scheduler } - pub fn handle_one_tc( + pub fn poll_and_handle_next_tc( &mut self, time_stamp: &[u8], sched_tc_pool: &mut (impl PoolProvider + ?Sized), @@ -279,7 +279,7 @@ mod tests { pub fn handle_one_tc(&mut self) -> Result { let time_stamp = cds::TimeProvider::new_with_u16_days(0, 0).to_vec().unwrap(); self.handler - .handle_one_tc(&time_stamp, &mut self.sched_tc_pool) + .poll_and_handle_next_tc(&time_stamp, &mut self.sched_tc_pool) } } @@ -351,7 +351,7 @@ mod tests { let time_stamp = cds::TimeProvider::new_with_u16_days(0, 0).to_vec().unwrap(); test_harness .handler - .handle_one_tc(&time_stamp, &mut test_harness.sched_tc_pool) + .poll_and_handle_next_tc(&time_stamp, &mut test_harness.sched_tc_pool) .unwrap(); test_harness.check_next_verification_tm(1, request_id); test_harness.check_next_verification_tm(3, request_id); diff --git a/satrs/src/pus/test.rs b/satrs/src/pus/test.rs index cd02243..f85a566 100644 --- a/satrs/src/pus/test.rs +++ b/satrs/src/pus/test.rs @@ -47,7 +47,7 @@ impl< Self { service_helper } } - pub fn handle_one_tc( + pub fn poll_and_handle_next_tc( &mut self, time_stamp: &[u8], ) -> Result { @@ -212,7 +212,7 @@ mod tests { impl SimplePusPacketHandler for Pus17HandlerWithStoreTester { fn handle_one_tc(&mut self) -> Result { let time_stamp = cds::TimeProvider::new_with_u16_days(0, 0).to_vec().unwrap(); - self.handler.handle_one_tc(&time_stamp) + self.handler.poll_and_handle_next_tc(&time_stamp) } } @@ -254,7 +254,7 @@ mod tests { impl SimplePusPacketHandler for Pus17HandlerWithVecTester { fn handle_one_tc(&mut self) -> Result { let time_stamp = cds::TimeProvider::new_with_u16_days(0, 0).to_vec().unwrap(); - self.handler.handle_one_tc(&time_stamp) + self.handler.poll_and_handle_next_tc(&time_stamp) } }