| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include <stdlib.h>
- #include "Process_Control.h"
- #include "Log_Module.h"
- // 直接跳转到下一步
- // 不带日志
- void PCTRL_GotoStepNoLog(struct PCTRL_Struct * pctrl, uint16_t ns)
- {
- if(pctrl->goto_step_listener)
- {
- pctrl->current_step = pctrl->goto_step_listener(ns);
- }
- else
- {
- pctrl->current_step = ns;
- }
- }
- // 带日志
- void PCTRL_GotoStep(struct PCTRL_Struct * pctrl, uint16_t ns, char * msg)
- {
- PCTRL_GotoStepNoLog(pctrl, ns);
- // 预存一下
- memset(pctrl->current_step_msg, 0, sizeof(pctrl->current_step_msg));
- strcpy(pctrl->current_step_msg, msg);
- Log_Printf_Debug("\r\n步骤%d:%s\r\n", pctrl->current_step, pctrl->current_step_msg);
- }
- // 先等待再跳转到下一步
- void PCTRL_GotoStepWait(struct PCTRL_Struct * pctrl, uint16_t ns, uint32_t t, char * msg)
- {
- PCTRL_GotoStepNoLog(pctrl, pctrl->step_wait); // 等待
- pctrl->wait_time = t;
- pctrl->next_step = ns; // 等待之后跳转
- // 预存一下
- memset(pctrl->next_step_msg, 0, sizeof(pctrl->next_step_msg));
- strcpy(pctrl->next_step_msg, msg);
- Log_Printf_Debug("%dms后跳转到步骤%d:%s", t, pctrl->next_step, pctrl->next_step_msg);
- }
- // 只等待,等待之后返回原来的步骤
- void PCTRL_GotoWait(struct PCTRL_Struct * pctrl, uint32_t t)
- {
- PCTRL_GotoStepWait(pctrl, pctrl->current_step, t, pctrl->current_step_msg);
- }
- // 等待
- void PCTRL_Wait(struct PCTRL_Struct * pctrl)
- {
- if(time_get_delay(&pctrl->timer) > pctrl->wait_time)
- {
- PCTRL_GotoStep(pctrl, pctrl->next_step, pctrl->next_step_msg); // 进入下一步
- time_clear(&pctrl->timer);
- }
- }
|