#include "stm32f10x.h" #include #include #include #include #include "LowPower.h" #include "ec800m.h" #include "PumpBusiness.h" #if NBFLAG #else // 流程 enum PowerStep{ STEP_START, // 开始 STEP_EXIT_SLEEP, // 退出睡眠 STEP_ENTER_SLEEP, // 进入睡眠 STEP_SET_SLEEP ,// 设置休眠模式 STEP_SET_CFUN_0, // 设置最小功能模式 STEP_WAIT, // 等待 STEP_SUCCESS, // 成功 STEP_FAILURE, // 失败 }; // 当前 static enum PowerStep powerstep = STEP_START; // 下一步 static enum PowerStep next_step = STEP_START; extern struct AT_Struct AT; extern uint8_t send_data_switch; // 计时相关的变量 uint8_t Power_time_flag = 0; uint32_t Power_timer_ms = 0; uint32_t Power_wait_time = 10; uint8_t set_mincfun_flag=1; //// 声明函数。步骤跳转 void pownext_step(enum PowerStep ns); // 发送流程 void Power_Handle_Handle(void); // 等待 static void powerwait(void) { if(Power_time_flag == 0) { Power_timer_ms = 0; Power_time_flag = 1; } else if(Power_timer_ms >Power_wait_time) { pownext_step(next_step); // 进入下一步 Power_time_flag = 0; } } //直接跳转到下一步 static void pownext_step(enum PowerStep ns) { // 重置ec800m状态 ec800m.reset(); powerstep = ns; } // 先等待再跳转到下一步 static void pownext_wait_step(enum PowerStep ns, uint32_t t) { pownext_step(STEP_WAIT); // 等待 Power_wait_time = t; next_step = ns; // 等待之后跳转 } // 发送数据的逻辑 static enum Result result = Result_None; void Power_Handle(void) { result =ec800m.ready(); if(result==Result_Success) { set_mincfun_flag=0; pownext_step(STEP_START); Log_Printf_Debug("完成准备\r\n"); } if(set_mincfun_flag==1) { return ; } // 流程 switch(powerstep) { case STEP_START: // 开始 pownext_step(STEP_EXIT_SLEEP); break; case STEP_EXIT_SLEEP: // 退出休眠 ec800m.exit_sleep(); pownext_wait_step(STEP_SET_SLEEP, 5); break; case STEP_SET_SLEEP: // 设置休眠模式 result = ec800m.set_sleep(1); if(result == Result_Success) { Log_Printf_Debug("设置休眠模式成功\r\n"); pownext_step(STEP_SET_CFUN_0); } else if(result == Result_Failed) { Log_Printf_Debug("设置休眠模式失败\r\n"); pownext_step(STEP_FAILURE); } break; case STEP_SET_CFUN_0: // 设置最小功能模式 result = ec800m.set_cfun(0); if(result == Result_Success) { pownext_step(STEP_SUCCESS); Log_Printf_Debug("设置最小功能模式成功\r\n"); } else if(result == Result_Failed) { Log_Printf_Debug("设置最小功能模式失败\r\n"); pownext_step(STEP_FAILURE); } break; case STEP_WAIT: // 等待 powerwait(); break; case STEP_SUCCESS: // 成功 ec800m.enter_sleep(); pownext_wait_step(STEP_START, 5); set_mincfun_flag=1; break; case STEP_FAILURE: // 失败 ec800m.enter_sleep(); pownext_wait_step(STEP_START, 5); break; default: break; } } #endif