diff --git a/FSM_OOP/baseFSM/FSM.c b/FSM_OOP/baseFSM/FSM.c index d2d4911..b4e8c2e 100644 --- a/FSM_OOP/baseFSM/FSM.c +++ b/FSM_OOP/baseFSM/FSM.c @@ -47,21 +47,23 @@ void stepBaseFSM(FSM *pFSM) preload(pFSM); setEvent(pFSM); - int index = pFSM->privateVars.curState * pFSM->privateVars.numEvent + pFSM->privateVars.curEvent; - int curState = pFSM->privateVars.curState; - FSM **childFSM = pFSM->privateVars.childFSM; - int nextState; - void *data = pFSM->data; FSMHandler *fcns = &pFSM->privateVars.fcns; + int curState = pFSM->privateVars.curState; + void *data = pFSM->data; - if(fcns->isDelayActionActivated[curState] && fcns->delayActionTable[curState] != NULL ){ + if(!fcns->isDelayActionExcuted[curState] && fcns->delayActionTable[curState] != NULL ){ fcns->delayActionTable[curState](data, NULL); - fcns->isDelayActionActivated[curState] = 0; + fcns->isDelayActionExcuted[curState] = 1; } + + FSM **childFSM = pFSM->privateVars.childFSM; + int index = pFSM->privateVars.curState * pFSM->privateVars.numEvent + pFSM->privateVars.curEvent; + int nextState; + if (fcns->transitionTable[index] != NULL) { - fcns->isDelayActionActivated[curState] = 1; + fcns->isDelayActionExcuted[curState] = 0; if (fcns->exitActionTable[curState] != NULL) fcns->exitActionTable[curState](data, childFSM); @@ -100,7 +102,8 @@ FSM* newBaseFSM(int numState, int numEvent, int defaultState){ pFSM->privateVars.preloader.isReady = 0; pFSM->privateVars.fcns.duringActionTable = calloc(numState, sizeof(StateFuncPtr)); - pFSM->privateVars.fcns.isDelayActionActivated = calloc(numState, sizeof(int)); + pFSM->privateVars.fcns.isDelayActionExcuted = calloc(numState, sizeof(int)); + pFSM->privateVars.fcns.delayActionTable = calloc(numState, sizeof(StateFuncPtr)); pFSM->privateVars.fcns.enterActionTable = calloc(numState, sizeof(StateFuncPtr)); pFSM->privateVars.fcns.exitActionTable = calloc(numState, sizeof(StateFuncPtr)); diff --git a/FSM_OOP/baseFSM/FSM_protected.h b/FSM_OOP/baseFSM/FSM_protected.h index d10005d..893c1f1 100644 --- a/FSM_OOP/baseFSM/FSM_protected.h +++ b/FSM_OOP/baseFSM/FSM_protected.h @@ -46,7 +46,7 @@ typedef struct _FSMHandler{ void (**duringActionTable)(void *data, FSM **cFSM); void (**exitActionTable)(void *data, FSM **cFSM); - int *isDelayActionActivated; + int *isDelayActionExcuted; void (**delayActionTable)(void *data, FSM **childFSM); void (**childFSMStepTable)(FSM **cFSM);