Skip to content

[Question] How to get current State of Sub-FSM? #660

@innerand

Description

@innerand

Hi,

how can I get the current state of an orthogonal sub-FSM within a guard or action?

A minimal example would be a module that contains multiple components. If one or more components are in an error state, the module also should go to error state.

Thanks!

// pseudo code
struct CompAErrEvent{};
struct CompAOkEvent{};
struct CompBErrEvent{};
struct CompBOkEvent{};


struct CompAFsm {
 struct OkState{}; 
 struct ErrState{};

  auto operator()() noexcept {
  using namespace boost::sml

  return make_transition_table(
    *state<OkState> +  event<CompAErrEvent> = state<ErrState>,
     state<ErrState> + event<CompAOkEvent> = state<OkState>
  );
  }
}

struct CompBFsm {
 struct OkState{}; 
 struct ErrState{};

  auto operator()() noexcept {
  using namespace boost::sml

  return make_transition_table(
    *state<OkState> +  event<CompBErrEvent> = state<ErrState>,
     state<ErrState> + event<CompBOkEvent> = state<OkState>
  );
  }
}


struct ModuleFsm {
 struct OkState{}; 
 struct ErrState{};
  
  auto operator()() noexcept {
  using namespace boost::sml

  auto errGuard = [](){
    // State of CompAFsm and CompBFsm required here 
    // return (!CmpAFsm::ErrState && !CmpBFsm::ErrState)
    return false; 
  }

  return make_transition_table(
    *state<CompAFsm> + on_entry<_> / [](){},
    *state<CompBFsm> + on_entry<_> / [](){},

    *state<OkState> +  event<CompAErrEvent> = state<ErrState>,
     state<OkState> +  event<CompBErrEvent> = state<ErrState>,

     state<ErrState> + event<CompAOkEvent> [ errGuard ] = state<OkState>,
     state<ErrState> + event<CompBOkEvent> [ errGuard ] = state<OkState>
  );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions