BC260Y_UDP_Client5.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. #include "CONFIG.h"
  2. #if BC260Y
  3. /**
  4. ******************************************************************************
  5. * 版 本 :V1.0.0
  6. * 作 者 :liuyanbin,helomgxiang
  7. * 版权所有,盗版必究。
  8. * Copyright(C) All rights reserved
  9. ******************************************************************************
  10. * 历史记录
  11. * 序号 版本 变更内容 作者 日期
  12. * 1 V0.0.1 实现数据发送功能 何龙翔 2023/12/10
  13. * 2 V0.0.2 实现NB数据发送功能 刘艳斌 2024/1/10
  14. * 3 V0.0.3 整合4g和nb 刘艳斌 2024/1/24
  15. *
  16. ******************************************************************************
  17. */
  18. #include "stm32f10x.h"
  19. #include <stdio.h>
  20. #include <stdarg.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include "UDP_Client.h"
  24. #include "Timer_Module.h"
  25. #include "Log_Module.h"
  26. #include "mbedtls_util.h"
  27. #include "cJSON.h"
  28. #include "bc260y.h"
  29. #include "Pump_Dicts_Util.h"
  30. #include "Regist.h"
  31. #include "PumpBusiness.h"
  32. #include "aliyuniot.h"
  33. #include "Initialize.h"
  34. // 流程
  35. enum Step{
  36. STEP_NONE, // 空闲状态,无操作
  37. STEP_START, // 开始
  38. STEP_EXIT_SLEEP, // 退出睡眠
  39. STEP_ENTER_SLEEP, // 进入睡眠
  40. STEP_WAIT, // 等待
  41. STEP_STATE, // 查询状态
  42. STEP_OPEN, // 打开
  43. STEP_OPEN_WAIT_RESULT, // 等待打开结果
  44. STEP_JUDGE_AUTH_OR_DATA, // 判断认证还是发送
  45. STEP_JOIN_AUTH_MESSAGE, // 拼接认证报文
  46. STEP_JOIN_DATA_MESSAGE, // 拼接数据报文
  47. STEP_QUERY_SLEEP, // 查询休眠
  48. STEP_SET_SLEEP, // 开启休眠
  49. STEP_QUERY_QENG_SERVINGCELL, // 查询信号质量
  50. STEP_SET_QISDE_0, // 关闭发送回显
  51. STEP_SET_QISDE_1,
  52. STEP_SEND, // 发送
  53. STEP_RECV, // 等待发送结果
  54. STEP_QUERY_CFUN,
  55. STEP_SET_CFUN_0, // 设置最小功能模式
  56. STEP_WAIT_SET_CFUN_0, // 等待设置最小功能模式
  57. STEP_SET_CFUN_1, // 设置全功能模式
  58. STEP_WAIT_SET_CFUN_1, // 等待设置全功能模式结果
  59. STEP_SET_CGREG_2, // 设置ps域允许上报网络注册和位置信息
  60. STEP_QUERY_CGREG, // 查询网络注册状态
  61. STEP_DATAFORMAT,//配置发送格式
  62. STEP_CLOSE, // 关闭
  63. STEP_SUCCESS, // 成功
  64. STEP_FAILURE, // 失败
  65. STEP_FINISH, // 流程结束
  66. STEP_VERIFY_REGIST,//验证注册
  67. STEP_VERIFY_INITIALIZE, // 验证初始化
  68. STEP_QUERY_SOCKET, // 查询连接
  69. STEP_QUERY_DNS, // 查询DNS
  70. STEP_SET_DNS, // 设置DNS
  71. STEP_QUERY_CFUN_DNS, // 设置完dns后,查询功能模式
  72. STEP_SET_CFUN_0_DNS, // 设置完dns后,设置最小功能模式
  73. };
  74. // 当前
  75. static enum Step step = STEP_NONE;
  76. // 下一步
  77. static enum Step next_step = STEP_NONE;
  78. // 客户端5
  79. struct UDP_Client_Struct client = {
  80. .status = Client_Status_None,
  81. };
  82. // socket ID
  83. static uint8_t connectID = 1;
  84. // coap报文
  85. static uint8_t coap_message[512];
  86. static uint16_t coap_message_length = 0;
  87. // 泵参数
  88. extern struct Pump_Params pump_params;
  89. // 待发送数据的地址和长度
  90. static uint8_t databuff[128];
  91. static uint16_t data_length;
  92. static uint8_t test_flag=0;
  93. // 计时相关的变量
  94. static struct TIMER_Struct timer;
  95. uint32_t wait_time = 10;
  96. // 信号值
  97. static struct Signal
  98. {
  99. int RSRP;
  100. int RSRQ;
  101. int RSSI;
  102. int SINR;
  103. } signal = {
  104. .RSRP = 99,
  105. .RSRQ = 99,
  106. .RSSI = 99,
  107. .SINR = 99,
  108. };
  109. void Query_Signal(int * RSRP, int * RSRQ, int * RSSI, int * SINR)
  110. {
  111. *RSRP = signal.RSRP;
  112. *RSRQ = signal.RSRQ;
  113. *RSSI = signal.RSSI;
  114. *SINR = signal.SINR;
  115. }
  116. // 初始化
  117. void UDP_Client_Init(void)
  118. {
  119. // aliyuniot_set_device_params("he1fAihB9M9", "123456", "76ef28342ee0760d781af138095b8fe4");
  120. aliyuniot_set_device_params(regist_get_aliyun_productKey(),regist_get_aliyun_deviceName(),regist_get_aliyun_deviceSecret());
  121. // aliyuniot_set_device_params(flashdata.productKey,flashdata.deviceName,flashdata.deviceSecret);
  122. // 设置host
  123. }
  124. // 声明函数。步骤跳转
  125. void goto_step(enum Step ns);
  126. // 发送流程
  127. void UDP_Client_Handle(void);
  128. // 发送数据
  129. void UDP_Client_Send(uint8_t test_switch)
  130. {
  131. test_flag=test_switch;
  132. if(step == STEP_NONE)
  133. {
  134. // 初始化
  135. UDP_Client_Init();
  136. // 正在发送
  137. client.status = Client_Status_Sending;
  138. // 流程开始
  139. goto_step(STEP_START);
  140. }
  141. }
  142. // 获取状态
  143. enum Client_Status UDP_Client_Status(void)
  144. {
  145. if(client.status == Client_Status_None)
  146. {
  147. return client.status;
  148. }
  149. else if(step == STEP_FINISH)
  150. {
  151. return client.status;
  152. }
  153. else
  154. {
  155. return Client_Status_Sending;
  156. }
  157. }
  158. // 获取备注
  159. char * UDP_Client_Get_Info(void)
  160. {
  161. return client.info;
  162. }
  163. // 清除
  164. void UDP_Client_Clear(void)
  165. {
  166. // 流程置空
  167. goto_step(STEP_NONE);
  168. // 空闲
  169. client.status = Client_Status_None;
  170. }
  171. // 直接跳转到下一步
  172. static void goto_step(enum Step ns)
  173. {
  174. // 重置bc260y状态
  175. bc260y.reset();
  176. step = ns;
  177. }
  178. // 先等待再跳转到下一步
  179. static void goto_step_wait(enum Step ns, uint32_t t)
  180. {
  181. goto_step(STEP_WAIT); // 等待
  182. wait_time = t;
  183. next_step = ns; // 等待之后跳转
  184. }
  185. // 只等待,等待之后返回原来的步骤
  186. static void goto_wait(uint32_t t)
  187. {
  188. goto_step_wait(step, t);
  189. }
  190. // 失败
  191. static void goto_failure(char * info)
  192. {
  193. Log_Printf_Debug("STEP: 数据发送失败,%s\r\n", info);
  194. client.status = Client_Status_Failure;
  195. strcpy(client.info, info);
  196. goto_step(STEP_FAILURE);
  197. }
  198. // 成功
  199. static void goto_success(char * info)
  200. {
  201. Log_Printf_Debug("STEP: 数据发送成功,%s\r\n", info);
  202. client.status = Client_Status_Success;
  203. strcpy(client.info, info);
  204. goto_step(STEP_SUCCESS);
  205. }
  206. // 等待
  207. static void wait(void)
  208. {
  209. if(time_get_delay(&timer) > wait_time)
  210. {
  211. goto_step(next_step); // 进入下一步
  212. time_clear(&timer);
  213. }
  214. }
  215. //// 发送数据的逻辑
  216. static enum Result result = Result_None;
  217. static uint8_t cgreg_n;
  218. static uint8_t cgreg_stat;
  219. static uint16_t cgreg_lac;
  220. static uint32_t cgreg_ci;
  221. //static uint8_t query_cgreg_times = 0; // 查询网络状态的次数
  222. static uint8_t auth_times = 0; // 认证次数
  223. static uint16_t socket_err = 0;
  224. static uint8_t auth_or_data = 0;
  225. static enum Initialize_Result InitializeResult;
  226. // dns
  227. static char pridnsaddr[20];
  228. static uint8_t resend_counter = 0;//nb失败重发标志
  229. static uint8_t cfun_mode = 0;
  230. static uint8_t connectstate = 0;
  231. void UDP_Client_Handle(void)
  232. {
  233. // 如果模块正在初始化,直接返回发送失败
  234. InitializeResult = get_initialize_status();
  235. if(InitializeResult==Initialize_Result_Busy)
  236. {
  237. goto_failure("模块正在初始化");
  238. goto_step(STEP_FINISH);
  239. }
  240. // 流程
  241. switch(step)
  242. {
  243. case STEP_NONE: // 空闲
  244. break;
  245. case STEP_START: // 开始
  246. Log_Printf_Debug("\r\n>>发送流程开始\r\n");
  247. auth_times = 0; // 认证次数
  248. goto_step(STEP_EXIT_SLEEP);
  249. Log_Printf_Debug("\r\n>>退出休眠\r\n");
  250. break;
  251. case STEP_EXIT_SLEEP: // 退出休眠
  252. result = bc260y.exit_sleep_2();
  253. if(result == Result_Success)
  254. {
  255. goto_step(STEP_SET_QISDE_1);
  256. Log_Printf_Debug("\r\n>>开启回显\r\n");
  257. }
  258. else if(result == Result_Failed)
  259. {
  260. goto_failure("退出休眠失败");
  261. }
  262. break;
  263. case STEP_SET_QISDE_1: // 开启回显
  264. result = bc260y.set_qisde(1);
  265. if(result == Result_Success)
  266. {
  267. goto_step(STEP_SET_SLEEP);
  268. Log_Printf_Debug("\r\n>>设置休眠模式\r\n");
  269. }
  270. else if(result == Result_Failed)
  271. {
  272. goto_failure("开启回显失败");
  273. }
  274. break;
  275. case STEP_SET_SLEEP: // 设置休眠模式
  276. result = bc260y.set_sleep(2);
  277. if(result == Result_Success)
  278. {
  279. goto_step(STEP_DATAFORMAT);
  280. Log_Printf_Debug("\r\n>>配置发送格式\r\n");
  281. }
  282. else if(result == Result_Failed)
  283. {
  284. goto_failure("设置休眠模式失败");
  285. }
  286. break;
  287. case STEP_DATAFORMAT: // 配置发送格式
  288. result = bc260y.dataformat(1);
  289. if(result == Result_Success)
  290. {
  291. goto_step(STEP_QUERY_DNS);
  292. Log_Printf_Debug("\r\n>>查询DNS\r\n");
  293. memset(pridnsaddr, 0, sizeof(pridnsaddr));
  294. }
  295. else if(result == Result_Failed)
  296. {
  297. goto_failure("配置发送格式失败");
  298. }
  299. break;
  300. case STEP_QUERY_DNS: // 查询DNS
  301. result = bc260y.query_dns(pridnsaddr);
  302. if(result == Result_Success)
  303. {
  304. if(strlen(pridnsaddr) <= 1)
  305. {
  306. goto_step(STEP_SET_DNS);
  307. Log_Printf_Debug("\r\n>>设置DNS\r\n");
  308. }
  309. else
  310. {
  311. goto_step(STEP_QUERY_CFUN);
  312. Log_Printf_Debug("\r\n>>查询功能模式\r\n");
  313. }
  314. }
  315. else if(result == Result_Failed)
  316. {
  317. goto_failure("查询DNS失败");
  318. }
  319. break;
  320. case STEP_SET_DNS:
  321. result = bc260y.set_dns("114.114.114.114", "8.8.8.8"); // 设置DNS
  322. if(result == Result_Success)
  323. {
  324. goto_step(STEP_QUERY_CFUN_DNS);
  325. Log_Printf_Debug("\r\n>>设置完dns,查询功能模式\r\n");
  326. }
  327. else if(result == Result_Failed)
  328. {
  329. goto_failure("查询功能模式失败");
  330. }
  331. break;
  332. case STEP_QUERY_CFUN_DNS: // 设置完dns,查询功能模式
  333. result = bc260y.query_cfun(&cfun_mode);
  334. if(result == Result_Success)
  335. {
  336. if(cfun_mode == 1)
  337. {
  338. goto_step(STEP_SET_CFUN_0_DNS);
  339. Log_Printf_Debug("\r\n>>设置完dns,先设置最小功能模式\r\n");
  340. }
  341. else
  342. {
  343. goto_step(STEP_SET_CFUN_1);
  344. Log_Printf_Debug("\r\n>>设置完dns,设置全功能模式\r\n");
  345. }
  346. }
  347. else if(result == Result_Failed)
  348. {
  349. goto_failure("查询功能模式失败");
  350. }
  351. break;
  352. case STEP_SET_CFUN_0_DNS: // 设置完dns,设置最小功能模式
  353. result = bc260y.set_cfun(0);
  354. if(result == Result_Success)
  355. {
  356. goto_step(STEP_SET_CFUN_1);
  357. Log_Printf_Debug("\r\n>>设置完dns,设置全功能模式\r\n");
  358. }
  359. else if(result == Result_Failed)
  360. {
  361. goto_failure("设置完dns,设置最小模式失败");
  362. }
  363. break;
  364. case STEP_QUERY_CFUN: // 查询功能模式
  365. result = bc260y.query_cfun(&cfun_mode);
  366. if(result == Result_Success)
  367. {
  368. if(cfun_mode == 0)
  369. {
  370. goto_step(STEP_SET_CFUN_1);
  371. Log_Printf_Debug("\r\n>>设置全功能模式\r\n");
  372. }
  373. else
  374. {
  375. goto_step(STEP_SET_CGREG_2);
  376. Log_Printf_Debug("\r\n>>设置ps域\r\n");
  377. }
  378. }
  379. else if(result == Result_Failed)
  380. {
  381. goto_failure("查询功能模式失败");
  382. }
  383. break;
  384. case STEP_SET_CFUN_1: // 设置全功能模式
  385. result = bc260y.set_cfun(1);
  386. if(result == Result_Success)
  387. {
  388. resend_counter++;
  389. goto_step(STEP_SET_CGREG_2);
  390. Log_Printf_Debug("\r\n>>设置ps域\r\n");
  391. }
  392. else if(result == Result_Failed)
  393. {
  394. resend_counter++;
  395. goto_failure("设置全功能模式失败");
  396. }
  397. break;
  398. case STEP_SET_CGREG_2: // 设置ps域
  399. result = bc260y.set_cereg(2);
  400. if(result == Result_Success)
  401. {
  402. // goto_step_wait(STEP_QUERY_CGREG, 400);
  403. goto_step(STEP_QUERY_CGREG);
  404. Log_Printf_Debug("\r\n>>查询ps域\r\n");
  405. }
  406. else if(result == Result_Failed)
  407. {
  408. goto_failure("设置ps域失败");
  409. }
  410. break;
  411. case STEP_QUERY_CGREG: // 查询ps域
  412. result = bc260y.query_cereg(&cgreg_n, &cgreg_stat, &cgreg_lac, &cgreg_ci);
  413. if(result == Result_Success)
  414. {
  415. if(cgreg_stat == 1)
  416. {
  417. // 参数赋值
  418. pump_params.lac = cgreg_lac;
  419. pump_params.ci = cgreg_ci;
  420. // 编码
  421. // 下一步
  422. if(test_flag == 0)
  423. {
  424. goto_step(STEP_QUERY_SOCKET);
  425. Log_Printf_Debug("\r\n>>查询连接\r\n");
  426. }
  427. else
  428. {
  429. goto_step(STEP_QUERY_QENG_SERVINGCELL);
  430. Log_Printf_Debug("\r\n>>查询信号质量\r\n");
  431. }
  432. }
  433. else
  434. {
  435. goto_failure("网络注册失败");
  436. }
  437. }
  438. else if(result == Result_Failed)
  439. {
  440. goto_failure("查询ps域失败");
  441. }
  442. break;
  443. case STEP_QUERY_QENG_SERVINGCELL: // 查询信号质量
  444. result = bc260y.qeng_servingcell(&signal.RSRP, &signal.RSRQ, &signal.RSSI, &signal.SINR);
  445. if(result == Result_Success)
  446. {
  447. goto_step(STEP_QUERY_SOCKET);
  448. Log_Printf_Debug("\r\n>>查询连接\r\n");
  449. }
  450. else if(result == Result_Failed)
  451. {
  452. goto_failure("查询信号质量失败");
  453. }
  454. break;
  455. case STEP_QUERY_SOCKET: // 查询连接
  456. result =bc260y.query_socket_state(connectID,&connectstate);
  457. if(result == Result_Success)
  458. {
  459. if(connectstate==2)
  460. {
  461. goto_step(STEP_JUDGE_AUTH_OR_DATA);
  462. Log_Printf_Debug("\r\n>>判断认证还是发送\r\n");
  463. }
  464. else
  465. {
  466. goto_step(STEP_CLOSE);
  467. Log_Printf_Debug("\r\n>>关闭连接\r\n");
  468. }
  469. }
  470. else if(result == Result_Failed)
  471. {
  472. goto_failure("查询UDP连接失败");
  473. }
  474. break;
  475. case STEP_CLOSE: // 关闭连接
  476. result = bc260y.close_socket(connectID);
  477. if(result == Result_Success)
  478. {
  479. goto_step(STEP_OPEN);
  480. Log_Printf_Debug("\r\n>>打开客户端\r\n");
  481. }
  482. else if(result == Result_Failed)
  483. {
  484. goto_failure("关闭连接失败");
  485. }
  486. break;
  487. case STEP_OPEN: // 打开客户端
  488. result = bc260y.open_socket(connectID, "UDP",aliyuniot_get_host(), aliyuniot_get_port(), 1, &socket_err);
  489. if(result == Result_Success)
  490. {
  491. if(socket_err == 0)
  492. {
  493. goto_step(STEP_JUDGE_AUTH_OR_DATA);
  494. Log_Printf_Debug("\r\n>>判断认证还是发送\r\n");
  495. }
  496. else
  497. {
  498. goto_failure("客户端打开错误");
  499. }
  500. }
  501. else if(result == Result_Failed)
  502. {
  503. goto_failure("打开客户端失败");
  504. }
  505. break;
  506. case STEP_JUDGE_AUTH_OR_DATA: // 判断认证还是发送
  507. auth_or_data = aliyuniot_is_authentication();
  508. if(auth_or_data == 1) // 已认证
  509. {
  510. goto_step(STEP_JOIN_DATA_MESSAGE);
  511. Log_Printf_Debug("\r\n>>拼接数据报文\r\n");
  512. }
  513. else
  514. {
  515. goto_step(STEP_JOIN_AUTH_MESSAGE);
  516. Log_Printf_Debug("\r\n>>拼接认证报文\r\n");
  517. }
  518. break;
  519. case STEP_JOIN_AUTH_MESSAGE: // 拼接认证报文
  520. if(auth_times > 0) // 最多重新认证一次
  521. {
  522. goto_failure("认证次数过多");
  523. }
  524. else
  525. {
  526. memset(coap_message, 0, sizeof(coap_message));
  527. aliyuniot_get_auth_message(coap_message, &coap_message_length);
  528. // Log_Printf_Debug("认证报文:%d\r\n", coap_message_length);
  529. // Log_SendHex(coap_message, coap_message_length);
  530. // Log_Printf_Debug("\r\n");
  531. goto_step(STEP_SEND);
  532. Log_Printf_Debug("\r\n>>发送认证报文\r\n");
  533. auth_times++;
  534. }
  535. break;
  536. case STEP_JOIN_DATA_MESSAGE: // 拼接数据报文
  537. pump_params.lac = cgreg_lac;
  538. pump_params.ci = cgreg_ci;
  539. Pump_Params_Refresh();
  540. // 编码
  541. memset(databuff, 0, sizeof(databuff));
  542. business_protocol_encode(pump_params, databuff, &data_length);
  543. memset(coap_message, 0, sizeof(coap_message));
  544. aliyuniot_get_data_message(databuff, data_length, coap_message, &coap_message_length);
  545. // Log_Printf_Debug("数据报文:%d\r\n", coap_message_length);
  546. // Log_SendHex(coap_message, coap_message_length);
  547. // Log_Printf_Debug("\r\n");
  548. goto_step(STEP_SEND);
  549. Log_Printf_Debug("\r\n>>发送数据报文\r\n");
  550. break;
  551. case STEP_SEND: // 发送send
  552. result = bc260y.send_rai(connectID, coap_message, coap_message_length, 2);
  553. if(result == Result_Success)
  554. {
  555. memset(coap_message, 0, sizeof(coap_message));
  556. goto_step(STEP_RECV);
  557. Log_Printf_Debug("\r\n>>等待接收数据\r\n");
  558. }
  559. else if(result == Result_Failed)
  560. {
  561. goto_failure("发送send失败");
  562. }
  563. break;
  564. case STEP_RECV: // 等待结果
  565. result = bc260y.recv_with_time(connectID, coap_message, &coap_message_length, 4000);
  566. if(result == Result_Success)
  567. {
  568. uint8_t res = aliyuniot_recv_data_handle(coap_message, coap_message_length);
  569. if(res == 0) // 发送失败
  570. {
  571. goto_step(STEP_JUDGE_AUTH_OR_DATA); // 重新认证
  572. Log_Printf_Debug("\r\n>>重新认证\r\n");
  573. }
  574. else if(res == 1) // 认证成功
  575. {
  576. goto_step(STEP_JOIN_DATA_MESSAGE);
  577. Log_Printf_Debug("\r\n>>拼接数据报文\r\n");
  578. }
  579. else if(res == 2) // 发送成功
  580. {
  581. goto_success("发送成功");
  582. }
  583. }
  584. else if(result == Result_Failed)
  585. {
  586. goto_failure("等待结果失败");
  587. }
  588. break;
  589. case STEP_WAIT: // 等待
  590. wait();
  591. break;
  592. case STEP_SUCCESS: // 成功
  593. goto_step(STEP_ENTER_SLEEP);
  594. Log_Printf_Debug("\r\n>>成功,进入睡眠\r\n");
  595. break;
  596. case STEP_FAILURE: // 失败
  597. resend_counter++;
  598. goto_step(STEP_SET_CFUN_0);
  599. Log_Printf_Debug("\r\n>>失败,设置最小功能模式\r\n");
  600. break;
  601. case STEP_SET_CFUN_0: // 设置最小功能模式
  602. result = bc260y.set_cfun(0);
  603. if(result == Result_Success)
  604. {
  605. if(resend_counter > 1) // 重发次数
  606. {
  607. goto_step(STEP_ENTER_SLEEP);
  608. Log_Printf_Debug("\r\n>>重发次数%d > 1,结束发送,进入睡眠\r\n", resend_counter);
  609. }
  610. else
  611. {
  612. goto_step(STEP_START);
  613. Log_Printf_Debug("\r\n>>重发次数%d <= 1,重新发送\r\n", resend_counter);
  614. }
  615. }
  616. else if(result == Result_Failed)
  617. {
  618. goto_step(STEP_ENTER_SLEEP);
  619. Log_Printf_Debug("\r\n>>进入睡眠\r\n");
  620. }
  621. break;
  622. case STEP_ENTER_SLEEP: // 进入睡眠
  623. resend_counter=0;//失败重发置0
  624. goto_step(STEP_FINISH);
  625. Log_Printf_Debug("\r\n>>发送流程结束\r\n");
  626. break;
  627. case STEP_FINISH: // 结束流程
  628. break;
  629. default:
  630. break;
  631. }
  632. }
  633. #endif