FSM/FSM_OOP/childtest/childFSM_private.h

122 lines
1.6 KiB
C

#ifndef __CHILD_PRIVATE_FSM_H_
#define __CHILD_PRIVATE_FSM_H_
#include "FSM_protected.h"
#include "childFSM.h"
#include <stdio.h>
/*
继承基类
*/
typedef struct _ChildFSM
{
// 继承父类
FSM base;
}ChildFSM;
/*
状态和对应的 action, exit, during 函数
*/
typedef enum _State
{
Idle,
D,
E,
Count_State,
} State;
#define DEFAULT_STATE E
void actionFcn(enter, D)()
{
printf(" enterD ");
}
void actionFcn(during, D)()
{
printf(" duringD ");
}
void actionFcn(exit, D)()
{
printf(" exitD ");
}
void actionFcn(enter, E)()
{
printf(" enterE ");
}
void actionFcn(during, E)()
{
printf(" duringE ");
}
void actionFcn(exit, E)()
{
printf(" exitE ");
}
/*
事件和对应的转移函数
*/
typedef enum _Event{
Idle_Event,
Idle2D,
Idle2E,
D2E,
E2D,
Count_Event,
}Event;
State transitionHandler(Idle2D)()
{
printf(" Idle2D ");
return D;
}
State transitionHandler(Idle2E)()
{
printf(" Idle2E ");
return E;
}
State transitionHandler(D2E)()
{
printf(" D2E ");
return E;
}
State transitionHandler(E2D)()
{
printf(" E2D ");
return D;
}
/*
用户自定义事件选择逻辑—————————————————begin
*/
const static char *stateStr[] = {
"Idle",
"D",
"E",
};
const static char *eventStr[] = {
"Idle",
"Idle2D",
"Idle2E",
"D2E",
"E2D",
};
static void printFSM(ChildFSM* pFSM){
printf(" \t\tChildFSM: ");
printf("当前状态:%s, 当前事件:%s, 动作:", stateStr[getFSMCurState((FSM_Ptr)pFSM)], eventStr[getFSMCurEvent((FSM_Ptr)pFSM)]);
}
#endif