Вы находитесь на странице: 1из 4

MasterSM

PublicFunctions:StartMasterSM,PostMasterSM,RunMasterSM
ModuleFunctions:DuringIdle,DuringSending,DuringPlayingGame
ModuleVariables:CurrentMasterState,FifthByte,MyPriority,GameCounter

InitMasterSM
InitializeThisEvent
Savepriority
Initializedigitali/o
InitializePWM
InitializeSSI
Initializewiresensinginterrupt
Initializehalleffectinterrupt
Initializebeaconinterrupt
Initializeflywheelinterrupt
Turnred/blueLEDontoshowaffiliation(RED=hi,BLUE=low)
SetThisEventasES_ENTRYevent
CallstartfunctionfortheMasterSM
ReturnTrue
EndInitMasterSM

PostMasterSM
Postpriorityandeventtoservice
EndPostMasterSM

RunMasterSM
LocalVariables:MakeTransition,NextState,EntryEventKind,ReturnEvent

SwitchCurrentMasterState

CaseIdle:
SetCurrentEventtoDuringIdle

IfCurrentEvent.EventTypeisnotES_NO_EVENT
SwitchCurrentEvent.EventType
Case:ES_TIMEOUTEvent
IfCurrentEvent.EventParamisQUERY_TIMER
QuerythePACtoseeifgameisready
NextStateisSending
MakeTransitionisTrue
EntryEventKindisnothistoryentry
EndIf
EndBlock
EndSwitch
EndIf
EndBlock

CaseSending:
SetCurrentEventtoDuringSending

IfCurrentEvent.EventTypeisnotES_NO_EVENT
SwitchCurrentEvent.EventType
Case:GAME_STARTEvent
NextStateisPlayingGame

MakeTransitionisTrue
EntryEventKindisnothistoryentry
EndBlock
Case:WAITINGEvent
NextStateisIdle
MakeTransitionisTrue
EntryEventKindisnothistoryentry
EndBlock
EndSwitch
EndIf
EndBlock

CasePlayingGame:
SetCurrentEventtoDuringPlayingGame

IfCurrentEvent.EventTypeisnotES_NO_EVENT
SwitchCurrentEvent.EventType
Case:ES_TIMEOUTEvent
IfCurrentEvent.EventParamisGAME_TIMER
IfGameCounteris0
IncrementGameCounter
InitializeGAME_TIMERwithGAME_TIME
ElseifGameCounteris1
IncrementGameCounter
InitializeGAME_TIMEwithGAME_TIME
ElseifGameCounteris2
NextStateisGameOver
MakeTransitionisTrue
EntryEventKindisnothistoryentry
GameCounteris0
EndIf
EndIf
EndBlock
EndSwitch
EndIf
EndBlock

CaseGameOver:
Stopeverything
Disablewiresensinginterrupt
EndBlock
EndSwitch

IfMakeTransitionistrue
Executeexitfunctionforcurrentstate
CallRunMasterSMfunctionwithCurrentEvent
CurrentStateequalsNextState
Executeentryfunctionforcurrentstate
CallRunMasterSMfunctionwithEntryEventKind
EndIf

ReturnReturnEvent
EndRunMasterSM

StartMasterSM
InitializeCurrentMasterStatevariable
CallRunMasterSMwithCurrentEvent
Callreturn
EndStartMasterSM

DuringIdle
DefineReturnEvent

IfES_ENTRYevent
InitializeQueryTimer
Stopmotors
Disablewiresensinginterrupt
ElseifES_EXITevent
QueryPAC
Else

EndIf

ReturnReturnEvent
EndDuringIdle

DuringSending
DefineReturnEvent

IfES_ENTRYevent
FifthByteequalsGetFifthByte()fromPACservice
IfFifthByteandBIT0HIisBIT0HI
ReturnEventisGAME_START
Else
ReturnEventisWAITING
EndIf

ElseifES_EXITevent
QueryPAC
Else

EndIf

ReturnReturnEvent
EndDuringSending

DuringPlayingGame
DefineReturnEvent

IfES_ENTRYevent
LightgameindicatorLED
LightaffiliationLEDs
InitializeGAME_TIMER
StartPlayingGamestatemachine
ElseifES_EXITevent
RunPlayingGamestatemachine
TurnoffgameindicatorLED
TurnoffaffiliationLEDs
Else

ReturnEventequalsRunPlayingGame
EndIf

ReturnReturnEvent
EndDuringPlayingGame

EndMasterSM

Вам также может понравиться