| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- #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 Step{
- STEP_START, // 开始
- STEP_EXIT_SLEEP, // 退出睡眠
- STEP_ENTER_SLEEP, // 进入睡眠
- STEP_SET_SLEEP ,// 设置休眠模式
- STEP_QUERY_CFUN,
- STEP_SET_CFUN_0,
- STEP_SET_CFUN_1, // 设置全功能模式
- STEP_WAIT_SET_CFUN_1, // 等待设置全功能模式结果
- STEP_WAIT, // 等待
- STEP_SET_QISDE_0,
- STEP_SET_QISDE_1,
- STEP_SET_CGREG_2, // 设置ps域允许上报网络注册和位置信息
- STEP_QUERY_CGREG, // 查询网络注册状态
- STEP_SUCCESS, // 成功
- STEP_FAILURE, // 失败
- STEP_FINISH,
- };
- // 当前
- static enum Step step = STEP_START;
- // 下一步
- static enum Step next_step = STEP_START;
- static enum Initialize_Result InitializeResult;
- static struct TIMER_Struct timer;
- // 计时相关的变量
- static uint32_t wait_time = 10;
- static uint8_t set_mincfun_flag=1;//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; // 查询网络状态的次数
- static uint8_t set_func_0_times = 0; // 设置最小功能模式的次数
- //// 声明函数。步骤跳转
- void goto_step(enum Step ns);
- // 发送流程
- // 等待
- static void wait(void)
- {
- if(time_get_delay(&timer) > wait_time)
- {
- goto_step(next_step); // 进入下一步
- time_clear(&timer);
- }
- }
- // 失败
- static void goto_failure(char * info)
- {
- Log_Printf_Debug("STEP: 初始化失败,%s\r\n", info);
- networkTest_Flag=1;
- goto_step(STEP_FAILURE);
- }
- // 成功
- static void goto_success(char * info)
- {
- Log_Printf_Debug("STEP: 初始化成功,%s\r\n", info);
- networkTest_Flag=2;
- goto_step(STEP_SUCCESS);
- }
- //直接跳转到下一步
- static void goto_step(enum Step ns)
- {
- // 重置ec800m状态
- bc260y.reset();
- step = ns;
- }
- // 先等待再跳转到下一步
- static void goto_step_wait(enum Step ns, uint32_t t)
- {
- goto_step(STEP_WAIT); // 等待
- wait_time = t;
- next_step = ns; // 等待之后跳转
- }
- // 只等待,等待之后返回原来的步骤
- static void goto_wait(uint32_t t)
- {
- goto_step_wait(step, t);
- }
- // 发送数据的逻辑
- static enum Result result = Result_None;
- static uint8_t cfun_mode = 0;
- //获取初始化状态
- 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;
- goto_step(STEP_START);
- }
- if(set_mincfun_flag==1)
- {
- return ;
- }
- // 流程
- switch(step)
- {
- case STEP_START: // 开始
- query_cgreg_times = 0; // 查询网络状态的次数
- set_func_0_times = 0;
- goto_step(STEP_EXIT_SLEEP);
- break;
- case STEP_EXIT_SLEEP: // 退出休眠
- result = bc260y.exit_sleep_2();
- if(result == Result_Success)
- {
- Log_Printf_Debug("退出休眠成功\r\n");
- goto_step_wait(STEP_SET_QISDE_1, 10);
- }
- else if(result == Result_Failed)
- {
- Log_Printf_Debug("退出休眠失败\r\n");
- goto_failure("退出休眠失败");
- }
- break;
- case STEP_SET_QISDE_1: // 开启回显
- result = bc260y.set_qisde(1);
- if(result == Result_Success)
- {
- goto_step(STEP_SET_CFUN_0);
- }
- else if(result == Result_Failed)
- {
- goto_failure("开启回显失败");
- }
- break;
- case STEP_SET_SLEEP: // 设置休眠模式
- result = bc260y.set_sleep(2);
- if(result == Result_Success)
- {
- Log_Printf_Debug("设置休眠模式成功\r\n");
- goto_step(STEP_QUERY_CFUN);
- }
- else if(result == Result_Failed)
- {
- Log_Printf_Debug("设置休眠模式失败\r\n");
- goto_failure("设置休眠模式失败");
- }
- break;
- case STEP_QUERY_CFUN: // 查询功能模式
- result = bc260y.query_cfun(&cfun_mode);
- if(result == Result_Success)
- {
- if(cfun_mode == 0)
- {
- goto_step(STEP_SET_CFUN_1);
- }
- else
- {
- goto_step(STEP_SET_CGREG_2);
- }
- }
- else if(result == Result_Failed)
- {
- goto_failure("查询功能模式失败");
- }
- break;
- case STEP_SET_CFUN_1:
- result = bc260y.set_cfun(1);
- if(result == Result_Success)
- {
- goto_step(STEP_SET_CGREG_2);
- }
- else if(result == Result_Failed)
- {
- goto_failure("设置全功能模式失败");
- }
- break;
- case STEP_SET_CGREG_2: // 设置ps域
- result = bc260y.set_cereg(2);
- if(result == Result_Success)
- {
- goto_step(STEP_QUERY_CGREG);
- }
- else if(result == Result_Failed)
- {
- goto_failure("设置ps域失败");
- }
- break;
- case STEP_QUERY_CGREG: // 查询ps域
- result = bc260y.query_cereg(&cgreg_n, &cgreg_stat, &cgreg_lac, &cgreg_ci);
- if(result == Result_Success)
- {
- if(cgreg_stat == 1)
- {
- // 下一步
- goto_success("查询PS域成功");
- }
- else
- {
- goto_failure("网络注册失败");
- }
- }
- else if(result == Result_Failed)
- {
- goto_failure("网络注册失败");
- }
- break;
- case STEP_WAIT: // 等待
- wait();
- break;
- case STEP_SUCCESS: // 成功
- Log_Printf_Debug("初始化成功\r\n");
- goto_step(STEP_FINISH);
- break;
- case STEP_FAILURE: // 失败
- goto_step(STEP_SET_CFUN_0);
- break;
- case STEP_SET_CFUN_0: // 设置最小功能模式
- result = bc260y.set_cfun(0);
- if(result == Result_Success)
- {
- if(set_func_0_times < 1)
- {
- set_func_0_times++;
- goto_step(STEP_SET_SLEEP);
- }
- else
- {
- goto_step(STEP_FINISH);
- }
- }
- else if(result == Result_Failed)
- {
- goto_step(STEP_FINISH);
- }
- break;
- case STEP_FINISH: // 结束流程
- set_mincfun_flag=1;
- break;
- default:
- break;
- }
-
- }
- #endif
|