当前位置:网站首页>状态机程序框架
状态机程序框架
2022-06-28 08:36:00 【DingUXiu】
state.h
#ifndef __STATE_H
#define __STATE_H
//定义状态机函数指针
typedef void (*state_func_p)(void);
#endif
state.c
#include "state.h"
//记录当前状态,实现状态循环
static state_func_p g_state_cur = NULL;
//func:即将跳转的状态
void main_setState(state_func_p func){
g_state_cur = func;
}
// 获取当前状态
state_func_p main_getState(void){
return g_state_funcCur;
}
封装成get、set函数供上层调用
main.c
#include "state.h"
//空闲状态
void main_stateIdle(void){
//功能实现
if(开始运行){
main_setState(main_stateRun);
}
if(发生错误){
main_setState(main_stateError);
}
}
//运行状态
void main_stateRun(void){
//功能实现
if(停止运行){
main_setState(main_stateIdle);
}
if(发生错误){
main_setState(main_stateError);
}
}
//错误状态
void main_stateError(void){
//功能实现
if(错误消除){
main_setState(main_stateIdle);
}
}
int main(void){
//设置初始为空闲状态
main_setState(main_stateIdle);
while(1){
(*(main_getState()))();
}
}
边栏推荐
猜你喜欢
Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
广州:金融新活水 文企新机遇
Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support
爱分析发布《2022爱分析 · IT运维厂商全景报告》 安超云强势入选!
Comment supprimer le crosstalk SiC MOSFET?
探讨gis三维系统在矿山行业中的应用
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service
[untitled]
VMware Workstation related issues
AWS saves data on the cloud (3)
随机推荐
Chenglian premium products donated love materials for flood fighting and disaster relief to Yingde
Avframe Memory Management API
Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!
Little artist huangxinyang was invited to participate in the Wuhan station of children's unit of Paris Fashion Week
广州:金融新活水 文企新机遇
Sword finger offer 03 Duplicate number in array
yaml json
Webrtc advantages and module splitting
Map. ToCharArray( ),Map. getOrDefault(). Map. charAt()
Usage record of Xintang nuc980: self made development board (based on nuc980dk61yc)
[untitled]
Children's unit of 2022 Paris fashion week ended successfully at Wuhan station on June 19
抖音服務器帶寬有多大,才能供上億人同時刷?
Not so Mobile
What is the bandwidth of the Tiktok server that can be used by hundreds of millions of people at the same time?
Basic twelve style classes for duilib
微内核Zephyr获众多厂家支持!
Robot Rapping Results Report
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...
Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu