Skip to content

Commit

Permalink
continue subsystem helper
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Dec 3, 2024
1 parent ba5c7d4 commit 09594e1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
27 changes: 18 additions & 9 deletions satrs/src/subsystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ pub struct SequenceExecutionHelper {
current_sequence_index: Option<usize>,
}

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,
Expand All @@ -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<Self> {
) -> 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) {
Expand Down
15 changes: 15 additions & 0 deletions satrs/tests/mode_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 09594e1

Please sign in to comment.