From 23327a77864db6a58aee8dc999454fe71f297f09 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 May 2024 12:01:24 +0200 Subject: [PATCH] bounded the PUS stack hot loop --- satrs-example/src/pus/stack.rs | 57 +++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/satrs-example/src/pus/stack.rs b/satrs-example/src/pus/stack.rs index 073406f..3594bd6 100644 --- a/satrs-example/src/pus/stack.rs +++ b/satrs-example/src/pus/stack.rs @@ -26,31 +26,6 @@ pub struct PusStack PusStack { - pub fn direct_service_checker( - service: &mut S, - timestamp: &[u8], - nothing_to_do: &mut bool, - ) { - let handling_status = service.poll_and_handle_next_tc(timestamp); - if handling_status == HandlingStatus::HandledOne { - *nothing_to_do = false; - } - } - - pub fn targeted_service_checker( - service: &mut S, - timestamp: &[u8], - nothing_to_do: &mut bool, - ) { - let request_handling = service.poll_and_handle_next_tc_default_handler(timestamp); - let reply_handling = service.poll_and_handle_next_reply_default_handler(timestamp); - if request_handling == HandlingStatus::HandledOne - || reply_handling == HandlingStatus::HandledOne - { - *nothing_to_do = false; - } - } - pub fn periodic_operation(&mut self) { // Release all telecommands which reached their release time before calling the service // handlers. @@ -59,6 +34,7 @@ impl .expect("time stamp generation error") .to_vec() .unwrap(); + let mut loop_count = 0_u32; // Hot loop which will run continuously until all request and reply handling is done. loop { let mut nothing_to_do = true; @@ -83,6 +59,37 @@ impl self.mode_srv.check_for_request_timeouts(); break; } + // Safety mechanism to avoid infinite loops. + loop_count += 1; + if loop_count >= 500 { + log::warn!("reached PUS stack loop count 500, breaking"); + break; + } + } + } + + pub fn direct_service_checker( + service: &mut S, + timestamp: &[u8], + nothing_to_do: &mut bool, + ) { + let handling_status = service.poll_and_handle_next_tc(timestamp); + if handling_status == HandlingStatus::HandledOne { + *nothing_to_do = false; + } + } + + pub fn targeted_service_checker( + service: &mut S, + timestamp: &[u8], + nothing_to_do: &mut bool, + ) { + let request_handling = service.poll_and_handle_next_tc_default_handler(timestamp); + let reply_handling = service.poll_and_handle_next_reply_default_handler(timestamp); + if request_handling == HandlingStatus::HandledOne + || reply_handling == HandlingStatus::HandledOne + { + *nothing_to_do = false; } } } -- 2.43.0