Process_Control.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "Process_Control.h"
  6. #include "Log_Module.h"
  7. // 直接跳转到下一步
  8. // 不带日志
  9. void PCTRL_GotoStepNoLog(struct PCTRL_Struct * pctrl, uint16_t ns)
  10. {
  11. if(pctrl->goto_step_listener)
  12. {
  13. pctrl->current_step = pctrl->goto_step_listener(ns);
  14. }
  15. else
  16. {
  17. pctrl->current_step = ns;
  18. }
  19. }
  20. // 带日志
  21. void PCTRL_GotoStep(struct PCTRL_Struct * pctrl, uint16_t ns, char * msg)
  22. {
  23. PCTRL_GotoStepNoLog(pctrl, ns);
  24. // 预存一下
  25. memset(pctrl->current_step_msg, 0, sizeof(pctrl->current_step_msg));
  26. strcpy(pctrl->current_step_msg, msg);
  27. Log_Printf_Debug("\r\n步骤%d:%s\r\n", pctrl->current_step, pctrl->current_step_msg);
  28. }
  29. // 先等待再跳转到下一步
  30. void PCTRL_GotoStepWait(struct PCTRL_Struct * pctrl, uint16_t ns, uint32_t t, char * msg)
  31. {
  32. PCTRL_GotoStepNoLog(pctrl, pctrl->step_wait); // 等待
  33. pctrl->wait_time = t;
  34. pctrl->next_step = ns; // 等待之后跳转
  35. // 预存一下
  36. memset(pctrl->next_step_msg, 0, sizeof(pctrl->next_step_msg));
  37. strcpy(pctrl->next_step_msg, msg);
  38. Log_Printf_Debug("%dms后跳转到步骤%d:%s", t, pctrl->next_step, pctrl->next_step_msg);
  39. }
  40. // 只等待,等待之后返回原来的步骤
  41. void PCTRL_GotoWait(struct PCTRL_Struct * pctrl, uint32_t t)
  42. {
  43. PCTRL_GotoStepWait(pctrl, pctrl->current_step, t, pctrl->current_step_msg);
  44. }
  45. // 等待
  46. void PCTRL_Wait(struct PCTRL_Struct * pctrl)
  47. {
  48. if(time_get_delay(&pctrl->timer) > pctrl->wait_time)
  49. {
  50. PCTRL_GotoStep(pctrl, pctrl->next_step, pctrl->next_step_msg); // 进入下一步
  51. time_clear(&pctrl->timer);
  52. }
  53. }