From 7f77e8a2141f7f903e68cb91c9d47cf6436ac454 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 2 Apr 2024 20:45:01 +0200 Subject: [PATCH] fixes for example --- satrs-example/src/acs/mgm.rs | 19 +++++++++++++++++-- satrs-example/src/pus/action.rs | 20 +++++++++++++------- satrs-example/src/pus/hk.rs | 32 +++++++++++++++++++++----------- satrs-example/src/pus/mod.rs | 17 +++++++++++++---- satrs-example/src/pus/mode.rs | 30 ++++++++++++++++++++---------- satrs-example/src/pus/stack.rs | 8 +++++--- 6 files changed, 89 insertions(+), 37 deletions(-) diff --git a/satrs-example/src/acs/mgm.rs b/satrs-example/src/acs/mgm.rs index 3505f95..4770b8f 100644 --- a/satrs-example/src/acs/mgm.rs +++ b/satrs-example/src/acs/mgm.rs @@ -71,6 +71,7 @@ impl MgmHandler match &msg.message { CompositeRequest::Hk(hk_req) => match hk_req.variant { @@ -111,8 +112,18 @@ impl MgmHandler {} }, - Err(_) => todo!(), + + Err(e) => { + if e != mpsc::TryRecvError::Empty { + log::warn!( + "{}: failed to receive composite request: {:?}", + self.dev_str, + e + ); + } + } } + // TODO: Put this in loop and only allow one set mode request per cycle? match self.mode_interface.request_rx.try_recv() { Ok(msg) => { let result = self.handle_mode_request(msg); @@ -125,7 +136,11 @@ impl MgmHandler todo!(), + Err(e) => { + if e != mpsc::TryRecvError::Empty { + log::warn!("{}: failed to receive mode request: {:?}", self.dev_str, e); + } + } } } } diff --git a/satrs-example/src/pus/action.rs b/satrs-example/src/pus/action.rs index 04065ae..75a5411 100644 --- a/satrs-example/src/pus/action.rs +++ b/satrs-example/src/pus/action.rs @@ -26,8 +26,8 @@ use std::time::Duration; use crate::requests::GenericRequestRouter; use super::{ - create_verification_reporter, generic_pus_request_timeout_handler, PusTargetedRequestService, - TargetedPusService, + create_verification_reporter, generic_pus_request_timeout_handler, HandlingStatus, + PusTargetedRequestService, TargetedPusService, }; pub struct ActionReplyHandler { @@ -291,12 +291,13 @@ impl Targete false } - fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> bool { + fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> HandlingStatus { + // This only fails if all senders disconnected. Treat it like an empty queue. self.service .poll_and_check_next_reply(time_stamp) .unwrap_or_else(|e| { warn!("PUS 8: Handling reply failed with error {e:?}"); - false + HandlingStatus::Empty }) } @@ -536,7 +537,10 @@ mod tests { #[test] fn converter_action_req_no_data() { - let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.raw(), ActionRequestConverter::default()); + let mut testbench = PusConverterTestbench::new( + TEST_COMPONENT_ID_0.raw(), + ActionRequestConverter::default(), + ); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let sec_header = PusTcSecondaryHeader::new_simple(8, 128); let action_id = 5_u32; @@ -567,7 +571,8 @@ mod tests { #[test] fn converter_action_req_with_data() { - let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ActionRequestConverter::default()); + let mut testbench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ActionRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let sec_header = PusTcSecondaryHeader::new_simple(8, 128); let action_id = 5_u32; @@ -642,7 +647,8 @@ mod tests { #[test] fn reply_handling_step_success() { - let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default()); + let mut testbench = + ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ActionReplyHandler::default()); let action_id = 5_u32; let (req_id, active_req) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_0, &[]); let active_action_req = diff --git a/satrs-example/src/pus/hk.rs b/satrs-example/src/pus/hk.rs index c7d89f7..ab88573 100644 --- a/satrs-example/src/pus/hk.rs +++ b/satrs-example/src/pus/hk.rs @@ -24,7 +24,7 @@ use std::time::Duration; use crate::pus::{create_verification_reporter, generic_pus_request_timeout_handler}; use crate::requests::GenericRequestRouter; -use super::PusTargetedRequestService; +use super::{HandlingStatus, PusTargetedRequestService}; #[derive(Clone, PartialEq, Debug, new)] pub struct HkReply { @@ -324,12 +324,13 @@ impl false } - pub fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> bool { + pub fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> HandlingStatus { + // This only fails if all senders disconnected. Treat it like an empty queue. self.service .poll_and_check_next_reply(time_stamp) .unwrap_or_else(|e| { warn!("PUS 3: Handling reply failed with error {e:?}"); - false + HandlingStatus::Empty }) } @@ -340,7 +341,9 @@ impl #[cfg(test)] mod tests { - use satrs::pus::test_util::{TEST_COMPONENT_ID_0, TEST_COMPONENT_ID_1, TEST_UNIQUE_ID_0, TEST_UNIQUE_ID_1}; + use satrs::pus::test_util::{ + TEST_COMPONENT_ID_0, TEST_COMPONENT_ID_1, TEST_UNIQUE_ID_0, TEST_UNIQUE_ID_1, + }; use satrs::request::MessageMetadata; use satrs::{ hk::HkRequestVariant, @@ -362,7 +365,8 @@ mod tests { #[test] fn hk_converter_one_shot_req() { - let mut hk_bench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default()); + let mut hk_bench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let target_id = TEST_UNIQUE_ID_0; let unique_id = 5_u32; @@ -391,7 +395,8 @@ mod tests { #[test] fn hk_converter_enable_periodic_generation() { - let mut hk_bench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default()); + let mut hk_bench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let target_id = TEST_UNIQUE_ID_0; let unique_id = 5_u32; @@ -429,7 +434,8 @@ mod tests { #[test] fn hk_conversion_disable_periodic_generation() { - let mut hk_bench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default()); + let mut hk_bench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let target_id = TEST_UNIQUE_ID_0; let unique_id = 5_u32; @@ -467,7 +473,8 @@ mod tests { #[test] fn hk_conversion_modify_interval() { - let mut hk_bench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default()); + let mut hk_bench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), HkRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let target_id = TEST_UNIQUE_ID_0; let unique_id = 5_u32; @@ -509,7 +516,8 @@ mod tests { #[test] fn hk_reply_handler() { - let mut reply_testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), HkReplyHandler::default()); + let mut reply_testbench = + ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), HkReplyHandler::default()); let sender_id = 2_u64; let apid_target_id = 3_u32; let unique_id = 5_u32; @@ -528,7 +536,8 @@ mod tests { #[test] fn reply_handling_unrequested_reply() { - let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_1.id(), HkReplyHandler::default()); + let mut testbench = + ReplyHandlerTestbench::new(TEST_COMPONENT_ID_1.id(), HkReplyHandler::default()); let action_reply = HkReply::new(5_u32, HkReplyVariant::Ack); let unrequested_reply = GenericMessage::new(MessageMetadata::new(10_u32, 15_u64), action_reply); @@ -540,7 +549,8 @@ mod tests { #[test] fn reply_handling_reply_timeout() { - let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_1.id(), HkReplyHandler::default()); + let mut testbench = + ReplyHandlerTestbench::new(TEST_COMPONENT_ID_1.id(), HkReplyHandler::default()); let (req_id, active_request) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_1, &[]); let result = testbench.handle_request_timeout(&active_request, &[]); assert!(result.is_ok()); diff --git a/satrs-example/src/pus/mod.rs b/satrs-example/src/pus/mod.rs index bfd69d4..4e67bd2 100644 --- a/satrs-example/src/pus/mod.rs +++ b/satrs-example/src/pus/mod.rs @@ -30,6 +30,12 @@ pub mod scheduler; pub mod stack; pub mod test; +#[derive(Debug, PartialEq, Eq, Copy, Clone)] +pub enum HandlingStatus { + Empty, + HandledOne, +} + pub fn create_verification_reporter(owner_id: ComponentId, apid: Apid) -> VerificationReporter { let verif_cfg = VerificationReporterCfg::new(apid, 1, 2, 8).unwrap(); // Every software component which needs to generate verification telemetry, gets a cloned @@ -150,7 +156,7 @@ impl PusReceiver { pub trait TargetedPusService { /// Returns [true] if the packet handling is finished. fn poll_and_handle_next_tc(&mut self, time_stamp: &[u8]) -> bool; - fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> bool; + fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> HandlingStatus; fn check_for_request_timeouts(&mut self); } @@ -362,14 +368,17 @@ where } } - pub fn poll_and_check_next_reply(&mut self, time_stamp: &[u8]) -> Result { + pub fn poll_and_check_next_reply( + &mut self, + time_stamp: &[u8], + ) -> Result { match self.reply_receiver.try_recv() { Ok(reply) => { self.handle_reply(&reply, time_stamp)?; - Ok(false) + Ok(HandlingStatus::HandledOne) } Err(e) => match e { - mpsc::TryRecvError::Empty => Ok(true), + mpsc::TryRecvError::Empty => Ok(HandlingStatus::Empty), mpsc::TryRecvError::Disconnected => Err(EcssTmtcError::Receive( GenericReceiveError::TxDisconnected(None), )), diff --git a/satrs-example/src/pus/mode.rs b/satrs-example/src/pus/mode.rs index b175603..587604d 100644 --- a/satrs-example/src/pus/mode.rs +++ b/satrs-example/src/pus/mode.rs @@ -38,8 +38,8 @@ use satrs_example::config::components::PUS_MODE_SERVICE; use satrs_example::config::{mode_err, tmtc_err}; use super::{ - create_verification_reporter, generic_pus_request_timeout_handler, PusTargetedRequestService, - TargetedPusService, + create_verification_reporter, generic_pus_request_timeout_handler, HandlingStatus, + PusTargetedRequestService, TargetedPusService, }; #[derive(new)] @@ -302,12 +302,12 @@ impl Targete false } - fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> bool { + fn poll_and_handle_next_reply(&mut self, time_stamp: &[u8]) -> HandlingStatus { self.service .poll_and_check_next_reply(time_stamp) .unwrap_or_else(|e| { warn!("PUS action service: Handling reply failed with error {e:?}"); - false + HandlingStatus::HandledOne }) } @@ -339,7 +339,8 @@ mod tests { #[test] fn mode_converter_read_mode_request() { - let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default()); + let mut testbench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcReadMode as u8); let mut app_data: [u8; 4] = [0; 4]; @@ -354,7 +355,8 @@ mod tests { #[test] fn mode_converter_set_mode_request() { - let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default()); + let mut testbench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcSetMode as u8); let mut app_data: [u8; 4 + ModeAndSubmode::RAW_LEN] = [0; 4 + ModeAndSubmode::RAW_LEN]; @@ -373,7 +375,8 @@ mod tests { #[test] fn mode_converter_announce_mode() { - let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default()); + let mut testbench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcAnnounceMode as u8); let mut app_data: [u8; 4] = [0; 4]; @@ -388,7 +391,8 @@ mod tests { #[test] fn mode_converter_announce_mode_recursively() { - let mut testbench = PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default()); + let mut testbench = + PusConverterTestbench::new(TEST_COMPONENT_ID_0.id(), ModeRequestConverter::default()); let mut sp_header = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap(); let sec_header = PusTcSecondaryHeader::new_simple(200, Subservice::TcAnnounceModeRecursive as u8); @@ -404,7 +408,10 @@ mod tests { #[test] fn reply_handling_unrequested_reply() { - let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ModeReplyHandler::new(TEST_COMPONENT_ID_0.id())); + let mut testbench = ReplyHandlerTestbench::new( + TEST_COMPONENT_ID_0.id(), + ModeReplyHandler::new(TEST_COMPONENT_ID_0.id()), + ); let mode_reply = ModeReply::ModeReply(ModeAndSubmode::new(5, 1)); let unrequested_reply = GenericMessage::new(MessageMetadata::new(10_u32, 15_u64), mode_reply); @@ -416,7 +423,10 @@ mod tests { #[test] fn reply_handling_reply_timeout() { - let mut testbench = ReplyHandlerTestbench::new(TEST_COMPONENT_ID_0.id(), ModeReplyHandler::new(TEST_COMPONENT_ID_0.id())); + let mut testbench = ReplyHandlerTestbench::new( + TEST_COMPONENT_ID_0.id(), + ModeReplyHandler::new(TEST_COMPONENT_ID_0.id()), + ); let (req_id, active_request) = testbench.add_tc(TEST_APID, TEST_UNIQUE_ID_0, &[]); let result = testbench.handle_request_timeout(&active_request, &[]); assert!(result.is_ok()); diff --git a/satrs-example/src/pus/stack.rs b/satrs-example/src/pus/stack.rs index 96ca438..a11463c 100644 --- a/satrs-example/src/pus/stack.rs +++ b/satrs-example/src/pus/stack.rs @@ -7,7 +7,8 @@ use satrs::{ use super::{ action::ActionServiceWrapper, event::EventServiceWrapper, hk::HkServiceWrapper, - scheduler::SchedulingServiceWrapper, test::TestCustomServiceWrapper, TargetedPusService, + scheduler::SchedulingServiceWrapper, test::TestCustomServiceWrapper, HandlingStatus, + TargetedPusService, }; #[derive(new)] @@ -34,9 +35,10 @@ impl loop { let mut nothing_to_do = true; let mut is_srv_finished = - |tc_handling_done: bool, reply_handling_done: Option| { + |tc_handling_done: bool, reply_handling_done: Option| { if !tc_handling_done - || (reply_handling_done.is_some() && !reply_handling_done.unwrap()) + || (reply_handling_done.is_some() + && reply_handling_done.unwrap() == HandlingStatus::Empty) { nothing_to_do = false; }