master_sm Module
Files:
Interface
Function: StartMasterSM
Arguments: None.
Returns: None.
Does any required initialization for the goalfinding state machine.
Function: RunMasterSM
Arguments: Event_t: the event to process.
Returns: Event_t: an event to return.
Runs the tasks for the master state machine.
Function: QueryMasterSM
Arguments: None.
Returns: MasterState_t The current state of the master state machine.
Runs the tasks for the master state machine.
Pseudo-Code
StartMasterSM Initialize module variable CurrentState to WAITING_FOR_FLASH Call RunMasterSM(EV_ENTRY)
RunMasterSM(Takes an Event_t and returns new Event_t)
  Initialize MakeTransition to FALSE
  Set NextState to CurrentState
  Switch between values of CurrentState:
    If value is WAITING_FOR_FLASH:
      Call DuringWaitingForFlash(CurrentEvent) and store the return in CurrentEvent
      Switch between values of CurrentEvent:
        if value is EV_FLASH:
          Set NextState to PLAYING_GAME
          Set MakeTransition to TRUE
        Endif
      Endswitch
    Endif
    If value is PLAYING_GAME:
      Call DuringPlayingGame(CurrentEvent) and store the return in CurrentEvent
      Switch between values of CurrentEvent:
        if value is EV_GAME_TIMER_DONE:
          Set NextState to GAME_DONE
          Set MakeTransition to TRUE
        Endif
      Endswitch
    Endif
    If value is GAME_DONE:
      Call DuringGameDone(CurrentEvent) and store the return in CurrentEvent
    Endif
  Endswitch
  If MakeTransition is TRUE:
    Call RunMasterSM(EV_EXIT)
    Set CurrentState to NextState
    Call RunMasterSM(EV_ENTRY)
  Endif
  return CurrentEvent
QueryMasterSM(Returns current MasterState_t) return module variable CurrentState
DuringWaitingForFlash(Takes current event Event_t, returns new event Event_t)
  If the event is not EV_ENTRY or EV_EXIT:
    Do not move
  Endif
  Return same event
DuringPlayingGame(Takes current event Event_t, returns new event Event_t)
  If the event is EV_ENTRY:
    Start the game timer with 2 minutes
    Start the warning timer with 1.5 minutes
    Call StartPlayingSM()
  Else if the event is EV_EXIT:
    Call RunPlayingSM(event)
  Else:
    Call RunPlayingSM(event) and store result as new event
  Endif
  Return new eventevent
DuringGameDone(Takes current event Event_t, returns new event Event_t)
  If the event is EV_ENTRY:
    Do not move
  Endif
  Return same event