当前位置:网站首页>状态机程序框架
状态机程序框架
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()))();
}
}
边栏推荐
- 抖音服務器帶寬有多大,才能供上億人同時刷?
- Kali Notes(1)
- Modifying the SSH default port when installing Oracle RAC makes CRS unable to install
- Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
- Solve NPM err! Unexpected end of JSON input while parsing near
- Goldbach`s Conjecture
- Not so Mobile
- Resolution of Rac grid failure to start after server restart
- TCP那点事
- About RAC modifying scan IP
猜你喜欢

Kubernetes notes and the latest k3s installation introduction

Operating principle of Rogowski coil

AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0

广州:金融新活水 文企新机遇

B_ QuRT_ User_ Guide(27)

Large current and frequency range that can be measured by Rogowski coil

Kali Notes(1)

Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
![Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...](/img/90/425965ca4b3df3656ce2a5f4230c4b.jpg)
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...

Superimposed ladder diagram and line diagram and merged line diagram and needle diagram
随机推荐
Unity gets the coordinate point in front of the current object at a certain angle and distance
887. egg drop
【云原生 | Kubernetes篇】深入了解Pod(六)
Set<String>
JS rounding tips
Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!
The micro kernel zephyr is supported by many manufacturers!
About using font icons in placeholder
Usage record of Xintang nuc980: self made development board (based on nuc980dk61yc)
[learning notes] matroid
VMware Workstation related issues
Infinite penetration test
用Pytorch搭建第一个神经网络且进行优化
After installing NRM, the internal/validators js:124 throw new ERR_ INVALID_ ARG_ TYPE(name, ‘string‘, value)
为什么函数模板没有偏特化?
Build an integrated kubernetes in Fedora
Unity - use of API related to Pico development input system ---c
Solve NPM err! Unexpected end of JSON input while parsing near
Kubernetes notes and the latest k3s installation introduction
探讨gis三维系统在矿山行业中的应用