From 09594e17615abd5d65986ee6c964b36f08ea1a1c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 Dec 2024 17:37:17 +0100 Subject: [PATCH] continue subsystem helper --- satrs/src/subsystem.rs | 27 ++++++++++++++++++--------- satrs/tests/mode_tree.rs | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/satrs/src/subsystem.rs b/satrs/src/subsystem.rs index aecc579..fac02b6 100644 --- a/satrs/src/subsystem.rs +++ b/satrs/src/subsystem.rs @@ -21,6 +21,16 @@ pub struct SequenceExecutionHelper { current_sequence_index: Option, } +impl Default for SequenceExecutionHelper { + fn default() -> Self { + Self { + target_mode: 0, + state: SequenceExecutionHelperStates::Idle, + request_id: 0, + current_sequence_index: todo!(), + } + } +} pub trait CheckSuccessProvider { fn mode_request_requires_success_check( &mut self, @@ -37,20 +47,19 @@ pub enum SequenceHandlerResult { } impl SequenceExecutionHelper { - pub fn new( + pub fn load( + &mut self, mode: Mode, request_id: RequestId, sequence_tables: &SequenceModeTables, - ) -> Option { + ) -> Result<(), ()> { if !sequence_tables.0.contains_key(&mode) { - return None; + return Err(()); } - Some(Self { - target_mode: mode, - state: SequenceExecutionHelperStates::Idle, - request_id, - current_sequence_index: None, - }) + self.target_mode = mode; + self.request_id = request_id; + self.current_sequence_index = None; + Ok(()) } pub fn confirm_sequence_done(&mut self) { diff --git a/satrs/tests/mode_tree.rs b/satrs/tests/mode_tree.rs index 00412ed..5134c47 100644 --- a/satrs/tests/mode_tree.rs +++ b/satrs/tests/mode_tree.rs @@ -13,6 +13,7 @@ use satrs::mode_tree::{ TargetTablesMapValue, }; use satrs::request::MessageMetadata; +use satrs::subsystem::SequenceExecutionHelper; use satrs::{ mode::{ModeAndSubmode, ModeReply, ModeRequest}, queue::GenericTargetedMessagingError, @@ -62,8 +63,22 @@ pub struct SubsystemHelper { pub children_mode_store: ModeStoreVec, pub target_tables: TargetModeTables, pub sequence_tables: SequenceModeTables, + pub helper: SequenceExecutionHelper, } impl SubsystemHelper { + pub fn new( + children_mode_store: ModeStoreVec, + target_tables: TargetModeTables, + sequence_tables: SequenceModeTables, + ) -> Self{ + Self { + children_mode_store, + target_tables, + sequence_tables, + helper: Default::default(), + } + } + pub fn add_target_and_sequence_table( &mut self, mode: Mode,