| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #include "CONFIG.h"
- #if BC260Y
- #include "stm32f10x.h"
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include <stdlib.h>
- #include "bc260y.h"
- #include "PumpBusiness.h"
- #include "Log_Module.h"
- #include "Initialize.h"
- // 流程
- enum PowerStep{
- STEP_START, // 开始
- STEP_EXIT_SLEEP, // 退出睡眠
- STEP_ENTER_SLEEP, // 进入睡眠
- STEP_SET_SLEEP ,// 设置休眠模式
- STEP_SET_CFUN_1, // 设置全功能模式
- STEP_WAIT_SET_CFUN_1, // 等待设置全功能模式结果
- STEP_WAIT, // 等待
- STEP_SET_QISDE_0,
- STEP_SET_CGREG_2, // 设置ps域允许上报网络注册和位置信息
- STEP_QUERY_CGREG, // 查询网络注册状态
- STEP_SUCCESS, // 成功
- STEP_FAILURE, // 失败
- };
- // 当前
- static enum PowerStep powerstep = STEP_START;
- // 下一步
- static enum PowerStep next_step = STEP_START;
- static enum Initialize_Result InitializeResult;
- static struct TIMER_Struct timer;
- // 计时相关的变量
- static uint32_t Power_wait_time = 10;
- static uint8_t set_mincfun_flag=0;//0代表正在初始化,1代表空闲
- static uint8_t cgreg_n;
- static uint8_t cgreg_stat;
- static uint16_t cgreg_lac;
- static uint32_t cgreg_ci;
- static uint8_t query_cgreg_times = 0; // 查询网络状态的次数
- //// 声明函数。步骤跳转
- void pownext_step(enum PowerStep ns);
- // 发送流程
- void Power_Handle(void);
- // 等待
- static void powerwait(void)
- {
- if(time_get_delay(&timer) > Power_wait_time)
- {
- pownext_step(next_step); // 进入下一步
- time_clear(&timer);
- }
- }
- // 失败
- static void power_failure(char * info)
- {
- Log_Printf_Debug("STEP: 数据发送失败,%s\r\n", info);
- // UDP_Client5.status = Client_Status_Failure;
- // strcpy(UDP_Client5.info, info);
- networkTest_Flag=1;
- pownext_step(STEP_FAILURE);
- }
- // 成功
- static void power_success(char * info)
- {
- Log_Printf_Debug("STEP: 数据发送成功,%s\r\n", info);
- // UDP_Client5.status = Client_Status_Success;
- // strcpy(UDP_Client5.info, info);
- networkTest_Flag=2;
- pownext_step(STEP_SUCCESS);
- }
- //直接跳转到下一步
- static void pownext_step(enum PowerStep ns)
- {
- // 重置ec800m状态
- bc260y.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;
- //获取初始化状态
- enum Initialize_Result get_initialize_status(void){
-
- if(set_mincfun_flag==0)
- {
- InitializeResult=Initialize_Result_Busy;
- }
- else
- {
- InitializeResult=Initialize_Result_free;
- }
- return InitializeResult;
- }
- void Initialize_Handle(void)
- {
- result =bc260y.ready();
- if(result==Result_Success)
- {
- set_mincfun_flag=0;
- pownext_wait_step(STEP_START,2000);
- Log_Printf_Debug("完成准备%d\r\n");
- }
- if(set_mincfun_flag==1)
- {
- return ;
- }
- // 流程
- switch(powerstep)
- {
- case STEP_START: // 开始
- pownext_step(STEP_EXIT_SLEEP);
-
- query_cgreg_times = 0; // 查询网络状态的次数
- break;
- case STEP_EXIT_SLEEP: // 退出休眠
- bc260y.exit_sleep();
- pownext_wait_step(STEP_SET_SLEEP, 10);
- break;
- case STEP_SET_SLEEP: // 设置休眠模式
- result = bc260y.set_sleep(1);
- // power_times++;
- if(result == Result_Success)
- {
- Log_Printf_Debug("设置休眠模式成功\r\n");
- pownext_wait_step(STEP_SET_CFUN_1,3);
- }
- else if(result == Result_Failed)
- {
- Log_Printf_Debug("设置休眠模式失败\r\n");
- pownext_step(STEP_FAILURE);
- }
- break;
- case STEP_SET_CFUN_1:
- result = bc260y.set_cfun(1);
-
- if(result == Result_Success)
- {
- pownext_wait_step(STEP_SET_CGREG_2,3);
- }
- else if(result == Result_Failed)
- {
- power_failure("设置全功能模式失败");
- }
- break;
- case STEP_SET_CGREG_2: // 设置ps域
- result = bc260y.set_cgreg(2);
- if(result == Result_Success)
- {
- pownext_wait_step(STEP_SET_QISDE_0,5);
- }
- else if(result == Result_Failed)
- {
- power_failure("设置ps域失败");
- }
- break;
- case STEP_SET_QISDE_0:
- result = bc260y.set_qisde(0);
- if(result == Result_Success)
- {
- pownext_step(STEP_QUERY_CGREG);
- }
- else if(result == Result_Failed)
- {
- power_failure("关闭回显失败");
- }
- break;
- case STEP_QUERY_CGREG: // 查询ps域
- result = bc260y.query_cgreg(&cgreg_n, &cgreg_stat, &cgreg_lac, &cgreg_ci);
- if(result == Result_Success)
- {
- if(cgreg_stat == 1)
- {
-
- // 下一步
- power_success("查询PS域成功");
-
- }
- else if(query_cgreg_times > 20) // 最多查询20次
- {
- power_failure("查询ps域次数过多");
- }
- else
- {
- pownext_wait_step(STEP_QUERY_CGREG,400);
- query_cgreg_times++;
- }
- }
- else if(result == Result_Failed)
- {
- power_failure("查询ps域失败");
- }
- break;
- case STEP_WAIT: // 等待
- powerwait();
- break;
- case STEP_SUCCESS: // 成功
- // bc260y.enter_sleep();
- pownext_wait_step(STEP_START, 50);
- set_mincfun_flag=1;
- Log_Printf_Debug("初始化成功\r\n");
- break;
- case STEP_FAILURE: // 失败
- // bc260y.enter_sleep();
- pownext_wait_step(STEP_START, 500);
- break;
- default:
- break;
- }
-
- }
- #endif
|