开源hsm代码学习笔记---数据结构的定义

状态id

/*!
  \typedef StateID
  Unique identifier of the statemachine
*/
typedef  unsigned int StateID;


/*!
  \def STATEID_NULL
  Initial State of the system once the HSM is created
*/
#define STATEID_NULL  0


/*!
  \def STATE_START
  Macro indicating user stateID start
*/
#define STATE_START  STATEID_NULL+1 


enum statelist_SampleHSM
{
  ROOT_STATE = STATE_START,
  STATE_1,
  STATE1_1,
  STATE1_2,
  STATE_2,
  STATE2_1,
  STATE2_1_1,
  STATE_3,
  State4,
  MAX_STATEID
};


事件id

/*! \enum EventID
 * ID of the minimum required Events.
 */
 typedef enum  
{
EV_NULL,
EV_DEFAULT,
EV_BASE_MAX // Always keep this as the last value in the base class
}EventID;


enum EventIDList_SampleHSM
{
  EV2 = EV_BASE_MAX,
  EV_1,
  EV5,
  EV3,
  EV4,
  MAX_EVENTS
};


无动作定义

/*!
  \def noAction
  no Action in the transition
*/
#define noAction 0


无条件定义
/*!
  \def noCondition
  no condition in the transition
*/
#define noCondition 0


/*!
  \def NULL_TRANSTION
  no Transition
*/
#define NULL_TRANSITION 0,0



1、跳转表

hsm中状态之间转换条件包含状态转换的触发事件id、跳转条件、跳转动作、初始状态id、目的状态id。

每个状态都有与之相应的一个 state Transition table

 /*! \struct Transition
 * state Transition elements
 */
typedef struct Transition
{
EventID triggerID;//Event creating  the transition
int (*condition)();//condition for the transition
void (*action)();//Transition action
StateID fromState;//Source StateID
StateID toState;//Destination StateID


}Transition;
 /*! \struct TransitionTable
 * state Transition table for each state
 */
typedef struct TransitionTable
{
Transition* transition;
unsigned int transitionCount;  //表示该状态跳转到其他状态的次数

}TransitionTable;





2、状态

state的结构体成员信息当前状态id、parent状态id、对应的状态转换表(1中介绍的state Transition table)、状态入口动作/出口动作、行为动作

 /*! \struct State
 * Elements of a state
 */
typedef struct State
{
StateID stateID;/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值