代码拉取完成,页面将自动刷新
/***************config.h**********************/
#define STATE_LEN 3
typedef enum {
state_1 =0,
state_2 =1,
state_3 = 3
} state;
/****************statamachine.h*****************************/
typedef state (*state_handle)(void *);
struct _statemachine;
typedef struct _statemachine{
state_handle state_handle_list[STATE_LEN];
unsigned int end_state_liste[STATE_LEN];
state start_state;
unsigned int (*add_state_handle)(struct _statemachine*,state,state_handle,unsigned int);
unsigned int (*set_startstate_handle)(struct _statemachine*,state);
unsigned int (*run_statemachine)(struct _statemachine*,void *);
} statemachine;
unsigned int _add_state_handle(statemachine* ,state ,state_handle ,unsigned int);
unsigned int _set_startstate_handle(statemachine*,state);
unsigned int _run_statemachine(statemachine* ,void *);
/*******************************statemachine.c***************************************************/
unsigned int _add_state_handle(statemachine* sta_m,state _state,state_handle handler,unsigned int end_sta){
if((_state > STATE_LEN) | (handler == NULL)){
return 0;
}
else{
if (end_sta ==1){
sta_m -> end_state_liste[_state] = 1;
}
else{
sta_m -> end_state_liste[_state] = 0;
}
sta_m -> state_handle_list[_state] = handler;
return 1;
}
}
unsigned int _set_startstate_handle(statemachine* sta_m,state _state){
if((_state > STATE_LEN) | (sta_m -> state_handle_list[_state] == NULL)){
return 0;
}
else{
sta_m -> start_state = _state;
return 1;
}
}
unsigned int _run_statemachine(statemachine* sta_m,void *buf){
state _state = sta_m -> start_state;
state_handle _state_handler = sta_m -> state_handle_list[_state];
while(true){
_state = _state_handler(buf);
if(sta_m->end_state_liste[_state]==1){
_state_handler = sta_m -> state_handle_list[_state];
_state_handler(buf);
break;
}
_state_handler = sta_m -> state_handle_list[_state];
}
return 1;
}
unsigned int _init_statemachine(statemachine*);
unsigned int statemachine_process(statemachine*,void*);
unsigned int _init_statemachine(statemachine* sta_m){
sta_m -> add_state_handle = _add_state_handle;
sta_m -> set_startstate_handle = _set_startstate_handle;
sta_m -> run_statemachine = _run_statemachine;
return 1;
}
unsigned int statemachine_process(statemachine* sta_m,void* buf){
return sta_m -> run_statemachine(sta_m,buf);
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。