90 lines
2.6 KiB
C
90 lines
2.6 KiB
C
/**
|
||
* @file FSM_private.h
|
||
* @author 天神 (dalaoshi@stu.xjtu.edu.cn)
|
||
* @brief 状态机框架的私有变量,只能在状态机框架内使用。
|
||
* @version 2.1
|
||
* @date 2024-05-07
|
||
*
|
||
* @copyright 天神创意无限公司 2024
|
||
*
|
||
*/
|
||
|
||
|
||
#ifndef __FSM_PRIVATE_H_
|
||
#define __FSM_PRIVATE_H_
|
||
|
||
#include <string.h>
|
||
#include "FSM_protected.h"
|
||
|
||
typedef struct FSMHandler FSMHandler;
|
||
typedef struct FSM FSM;
|
||
typedef struct FSMSignals FSMSignals;
|
||
|
||
/* -------------------------------------------------------------------------- */
|
||
/* private数据类型 */
|
||
/* -------------------------------------------------------------------------- */
|
||
/**
|
||
* @brief
|
||
* @deprecated 预装载器弃用
|
||
*
|
||
*/
|
||
typedef struct FSMDataLoader
|
||
{
|
||
void *shadowData;
|
||
int isReady;
|
||
int isOverflow;
|
||
size_t size;
|
||
}FSMDataLoader;
|
||
|
||
|
||
/**
|
||
* @brief 基类状态机的私有变量和函数,子类不可直接访问
|
||
*
|
||
*/
|
||
typedef struct FSMPrivateVars
|
||
{
|
||
int numState;
|
||
int defaultState; /**< Idle状态不能停留,必须指定一个初始状态 */
|
||
|
||
int curState;
|
||
int nextState; /**< nextState为Idle代表状态机不发生变化 */
|
||
int index; /**< 状态转移函数表对应的标号 */
|
||
|
||
FSMHandler fcns;
|
||
|
||
int numChild;
|
||
FSM **childFSM;
|
||
|
||
FSMDataLoader preloader; /**< @deprecated 弃用 */
|
||
|
||
}FSMPrivateVars;
|
||
|
||
FSMPrivateVars* newFMSPrivateVars(int numState, int defaultState){
|
||
typedef void (*StateFuncPtr)(void *);
|
||
typedef void (*ChildFSMStepFuncPtr)(FSM **);
|
||
typedef int (*TransitionFuncPtr)(void *, int *);
|
||
typedef int (*SelectNextStateFcnPtr)(void *, FSMSignals *);
|
||
|
||
FSMPrivateVars *privateVars = calloc(1, sizeof(FSMPrivateVars));
|
||
privateVars->numState = numState;
|
||
privateVars->defaultState = defaultState;
|
||
privateVars->curState = 0;
|
||
privateVars->nextState = 0;
|
||
privateVars->numChild = 0;
|
||
|
||
privateVars->preloader.isReady = 0;
|
||
|
||
privateVars->fcns.duringActionTable = calloc(numState, sizeof(StateFuncPtr));
|
||
privateVars->fcns.enterActionTable = calloc(numState, sizeof(StateFuncPtr));
|
||
privateVars->fcns.exitActionTable = calloc(numState, sizeof(StateFuncPtr));
|
||
|
||
privateVars->fcns.selectNextState = calloc(numState, sizeof(SelectNextStateFcnPtr));
|
||
privateVars->fcns.transitionTable = calloc(numState * numState, sizeof(TransitionFuncPtr));
|
||
privateVars->fcns.transitionGeneralAction = calloc(1, sizeof(StateFuncPtr));
|
||
|
||
privateVars->fcns.childFSMStepTable = calloc(numState * numState, sizeof(ChildFSMStepFuncPtr));
|
||
|
||
return privateVars;
|
||
}
|
||
|
||
#endif |