EC800M_UDP_Client5.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. #include "stm32f10x.h"
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "EC800M_UDP_Client5.h"
  7. #include "CoAP.h"
  8. #include "mbedtls_util.h"
  9. #include "cJSON.h"
  10. #include "sys.h"
  11. #include "ec800m.h"
  12. #include "pump_dicts.h"
  13. #include "INflash.h"
  14. #include "PumpBusiness.h"
  15. #if _4GFLAG
  16. // 流程
  17. enum Step{
  18. STEP_NONE, // 空闲状态,无操作
  19. STEP_START, // 开始
  20. STEP_EXIT_SLEEP, // 退出睡眠
  21. STEP_ENTER_SLEEP, // 进入睡眠
  22. STEP_WAIT, // 等待
  23. STEP_STATE, // 查询状态
  24. STEP_OPEN, // 打开
  25. STEP_OPEN_WAIT_RESULT, // 等待打开结果
  26. STEP_JUDGE_AUTH_OR_DATA, // 判断认证还是发送
  27. STEP_JOIN_AUTH_MESSAGE, // 拼接认证报文
  28. STEP_JOIN_DATA_MESSAGE, // 拼接数据报文
  29. STEP_QUERY_SLEEP, // 查询休眠
  30. STEP_SET_SLEEP, // 开启休眠
  31. STEP_QUERY_QENG_SERVINGCELL, // 查询信号质量
  32. STEP_SET_QISDE_0, // 关闭发送回显
  33. STEP_SEND, // 发送
  34. STEP_RECV, // 等待发送结果
  35. STEP_SET_CFUN_0, // 设置最小功能模式
  36. STEP_WAIT_SET_CFUN_0, // 等待设置最小功能模式
  37. STEP_SET_CFUN_1, // 设置全功能模式
  38. STEP_WAIT_SET_CFUN_1, // 等待设置全功能模式结果
  39. STEP_SET_CGREG_2, // 设置ps域允许上报网络注册和位置信息
  40. STEP_QUERY_CGREG, // 查询网络注册状态
  41. STEP_CLOSE, // 关闭
  42. STEP_SUCCESS, // 成功
  43. STEP_FAILURE, // 失败
  44. STEP_FINISH, // 流程结束
  45. };
  46. // 当前
  47. static enum Step step = STEP_NONE;
  48. // 下一步
  49. static enum Step next_step = STEP_NONE;
  50. // 客户端5
  51. struct EC800M_Client_Struct UDP_Client5 = {
  52. .status = Client_Status_None,
  53. };
  54. // 注册后的参数
  55. extern Coefficient_Data flashdata;
  56. // socket ID
  57. static uint8_t connectID = 5;
  58. /** 阿里云连接参数 **/
  59. static char ProductKey[20] = "a1t3qlUNDcP";
  60. static char DeviceName[20] = "LTEcat1ceshi001";
  61. static char DeviceSecret[40] = "4929a78860f663ec72e2c313a4eee7ac";
  62. static char ClientID[60];
  63. static char Seq[10] = "666";
  64. static uint16_t Port = 5682;
  65. static char Host[60];
  66. static uint32_t SeqOffset;
  67. static char Random[20];
  68. static char Token[50];
  69. // payload缓存
  70. //static uint8_t payload[256];
  71. //static uint16_t payload_length;
  72. // coap报文
  73. static uint8_t coap_message[512];
  74. static uint16_t coap_message_length = 0;
  75. // aes cbc
  76. static uint8_t aes_key[16] = {0};
  77. static char iv[] = "543yhjy97ae7fyfg";
  78. // 泵参数
  79. static struct Pump_Params pump_params;
  80. // 待发送数据的地址和长度
  81. static uint8_t data[128];
  82. static uint16_t data_length;
  83. static uint8_t test_flag=0;
  84. // 计时相关的变量
  85. uint8_t Client5_time_flag = 0;
  86. uint32_t Client5_timer_ms = 0;
  87. uint32_t Client5_wait_time = 10;
  88. // 信号值
  89. static struct Signal
  90. {
  91. int RSRP;
  92. int RSRQ;
  93. int RSSI;
  94. int SINR;
  95. } signal = {
  96. .RSRP = 99,
  97. .RSRQ = 99,
  98. .RSSI = 99,
  99. .SINR = 99,
  100. };
  101. void Query_Signal(int * RSRP, int * RSRQ, int * RSSI, int * SINR)
  102. {
  103. *RSRP = signal.RSRP;
  104. *RSRQ = signal.RSRQ;
  105. *RSSI = signal.RSSI;
  106. *SINR = signal.SINR;
  107. }
  108. // 初始化
  109. void UDP_Client5_Init(void)
  110. {
  111. // 赋值三元组
  112. strcpy(ProductKey, flashdata.productKey);
  113. strcpy(DeviceName, flashdata.deviceName);
  114. strcpy(DeviceSecret, flashdata.deviceSecret);
  115. // 设置host
  116. memset(Host, '\0', sizeof(Host));
  117. strcat(Host, ProductKey);
  118. strcat(Host, ".coap.cn-shanghai.link.aliyuncs.com");
  119. // 设置clientid
  120. memset(ClientID, '\0', sizeof(ClientID));
  121. strcat(ClientID, ProductKey);
  122. strcat(ClientID, "&");
  123. strcat(ClientID, DeviceName);
  124. }
  125. // 声明函数。步骤跳转
  126. void goto_step(enum Step ns);
  127. // 发送流程
  128. void UDP_Client5_Handle(void);
  129. // 发送数据
  130. void UDP_Client5_Send(struct Pump_Params params,uint8_t test_switch)
  131. {
  132. test_flag=test_switch;
  133. if(step == STEP_NONE)
  134. {
  135. // 待发送数据的地址和长度
  136. pump_params = params;
  137. // 初始化
  138. UDP_Client5_Init();
  139. // 正在发送
  140. UDP_Client5.status = Client_Status_Sending;
  141. // 流程开始
  142. goto_step(STEP_START);
  143. }
  144. }
  145. // 获取状态
  146. enum Client_Status UDP_Client5_Status(void)
  147. {
  148. if(UDP_Client5.status == Client_Status_None)
  149. {
  150. return UDP_Client5.status;
  151. }
  152. else if(step == STEP_FINISH)
  153. {
  154. return UDP_Client5.status;
  155. }
  156. else
  157. {
  158. return Client_Status_Sending;
  159. }
  160. }
  161. // 清除
  162. void UDP_Client5_Clear(void)
  163. {
  164. // 流程置空
  165. goto_step(STEP_NONE);
  166. // 空闲
  167. UDP_Client5.status = Client_Status_None;
  168. }
  169. // 直接跳转到下一步
  170. static void goto_step(enum Step ns)
  171. {
  172. // 重置ec800m状态
  173. ec800m.reset();
  174. step = ns;
  175. }
  176. // 先等待再跳转到下一步
  177. static void goto_step_wait(enum Step ns, uint32_t t)
  178. {
  179. goto_step(STEP_WAIT); // 等待
  180. Client5_wait_time = t;
  181. next_step = ns; // 等待之后跳转
  182. }
  183. // 只等待,等待之后返回原来的步骤
  184. static void goto_wait(uint32_t t)
  185. {
  186. goto_step_wait(step, t);
  187. }
  188. // 失败
  189. static void goto_failure(char * info)
  190. {
  191. Log_Printf_Debug("STEP: 数据发送失败,%s\r\n", info);
  192. UDP_Client5.status = Client_Status_Failure;
  193. strcpy(UDP_Client5.info, info);
  194. goto_step(STEP_FAILURE);
  195. }
  196. // 成功
  197. static void goto_success(char * info)
  198. {
  199. Log_Printf_Debug("STEP: 数据发送成功,%s\r\n", info);
  200. UDP_Client5.status = Client_Status_Success;
  201. strcpy(UDP_Client5.info, info);
  202. goto_step(STEP_SUCCESS);
  203. }
  204. // 等待
  205. static void wait(void)
  206. {
  207. if(Client5_time_flag == 0)
  208. {
  209. Client5_timer_ms = 0;
  210. Client5_time_flag = 1;
  211. }
  212. else if(Client5_timer_ms > Client5_wait_time)
  213. {
  214. goto_step(next_step); // 进入下一步
  215. Client5_time_flag = 0;
  216. }
  217. }
  218. // 判断认证还是发送
  219. static uint8_t judge_auth_or_data(void)
  220. {
  221. if(strlen(Token) > 0) // 已认证
  222. {
  223. return 1;
  224. }
  225. else
  226. {
  227. return 0;
  228. }
  229. }
  230. // 拼接认证报文
  231. static void join_auth_message(uint8_t * coap_message, uint16_t * coap_message_length)
  232. {
  233. SeqOffset=65535;
  234. Log_Printf_Debug("STEP: 拼接认证报文,seqOffset=%d\r\n", SeqOffset);
  235. // 先清除
  236. // memset(coap_message, 0, sizeof(coap_message));
  237. // coap_message_length = 0;
  238. // CoAP协议
  239. CoAP_Init();
  240. CoAP_Set_T(0);
  241. CoAP_Set_Code(2);
  242. CoAP_Set_MessageID(SeqOffset);
  243. // option
  244. // host
  245. CoAP_Set_Option_Str(3, Host);
  246. // port
  247. CoAP_Set_Option_Short(7, Port);
  248. // path
  249. CoAP_Set_Option_Str(11, "auth");
  250. // content-format
  251. CoAP_Set_Option_Short(12, 50);
  252. // accept
  253. CoAP_Set_Option_Short(17, 50);
  254. // 待签名数据
  255. // 签名相关
  256. static char StrForSignature[100];
  257. static char sign[50];
  258. memset(StrForSignature, '\0', sizeof(StrForSignature));
  259. sprintf((char * )StrForSignature, "clientId%sdeviceName%sproductKey%sseq%s", ClientID, DeviceName, ProductKey, Seq);
  260. // 签名
  261. memset(sign, '\0', sizeof(sign));
  262. utils_hmac_sha1_str(StrForSignature, strlen((char * )StrForSignature), sign, DeviceSecret, strlen(DeviceSecret));
  263. // payload
  264. // memset(payload, '\0', sizeof(payload));
  265. char payload[256] = {0};
  266. sprintf((char * )payload, "{\"clientId\":\"%s\",\"signmethod\":\"hmacsha1\",\"sign\":\"%s\",\"productKey\":\"%s\",\"deviceName\":\"%s\",\"seq\":\"%s\"}", ClientID, sign, ProductKey, DeviceName, Seq);
  267. // 设置payload
  268. CoAP_Set_Payload_Str(payload);
  269. // 生成报文
  270. * coap_message_length = CoAP_Get_Length();
  271. memcpy(coap_message, CoAP_Get_Message(), * coap_message_length);
  272. }
  273. // 拼接数据报文
  274. static void join_data_message(uint8_t * data, uint8_t data_length, uint8_t * coap_message, uint16_t * coap_message_length)
  275. {
  276. SeqOffset++;
  277. Log_Printf_Debug("STEP: 拼接数据报文,seqOffset=%d\r\n", SeqOffset);
  278. // 先清除
  279. // memset(coap_message, 0, sizeof(coap_message));
  280. // coap_message_length = 0;
  281. char out[80]={0};
  282. char sha256_source[100] = {0};
  283. snprintf(sha256_source, sizeof(sha256_source), "%s,%s" ,DeviceSecret ,Random);
  284. Log_Printf_Debug("sha256_source: %s\r\n", sha256_source);
  285. utils_sha256(sha256_source, strlen(sha256_source), out);
  286. memset(aes_key, 0, sizeof(aes_key));
  287. memcpy(aes_key, out+8, 16); //获取key
  288. // CoAP协议
  289. CoAP_Init();
  290. CoAP_Set_T(0);
  291. CoAP_Set_Code(2);
  292. CoAP_Set_MessageID(SeqOffset);
  293. // option
  294. // host
  295. CoAP_Set_Option_Str(3, Host);
  296. // port
  297. CoAP_Set_Option_Short(7, Port);
  298. // path
  299. CoAP_Set_Option_Str(11, "topic");
  300. CoAP_Set_Option_Str(11, "sys");
  301. CoAP_Set_Option_Str(11, ProductKey);
  302. CoAP_Set_Option_Str(11, DeviceName);
  303. CoAP_Set_Option_Str(11, "thing");
  304. CoAP_Set_Option_Str(11, "model");
  305. CoAP_Set_Option_Str(11, "up_raw");
  306. // content-format
  307. CoAP_Set_Option_Short(12, 50);
  308. // accept
  309. CoAP_Set_Option_Short(17, 50);
  310. // 2088
  311. CoAP_Set_Option_Str(2088, Token);
  312. // 2089
  313. char Rand2089[10] = {'\0'};
  314. char Opt2089[20] = {'\0'};
  315. my_itoa(SeqOffset, Rand2089, 10);
  316. int Opt2089_Length = utils_aes128_cbc_enc((char * )aes_key, iv, Rand2089, Opt2089);
  317. CoAP_Set_Option_Str(2089, Opt2089);
  318. // payload
  319. // memset(payload, '\0', sizeof(payload));
  320. uint8_t payload[256] = {0};
  321. //
  322. int payload_length = utils_aes128_cbc_enc_with_length((char * )aes_key, iv, data, data_length, payload);
  323. // payload_length = utils_aes128_cbc_enc((char * )aes_key, iv, (char * )Data_Buffer, (char * )payload);
  324. Log_Printf_Debug("payload_length: %d\r\n", payload_length);
  325. CoAP_Set_Payload(payload, payload_length);
  326. // 生成报文
  327. * coap_message_length = CoAP_Get_Length();
  328. memcpy(coap_message, CoAP_Get_Message(), * coap_message_length);
  329. }
  330. // 等待数据返回
  331. static uint8_t recv_data_handle(uint8_t * coap_message, uint16_t coap_message_length)
  332. {
  333. uint16_t payload_length = CoAP_Get_Payload_Length(coap_message, coap_message_length);
  334. uint8_t payload[256] = {0};
  335. CoAP_Get_Payload(coap_message, coap_message_length, payload);
  336. Log_Printf_Debug("payload长度: %d\r\n", payload_length);
  337. // 判断是认证返回,还是数据发送返回
  338. if(payload_length == 0) // 无返回
  339. {
  340. // 清空Token,重新认证
  341. memset(Token, '\0', sizeof(Token));
  342. return 0;
  343. }
  344. else if(payload[0] == '{' && payload[payload_length-1] == '}') // 认证返回
  345. {
  346. // 解析json
  347. cJSON * cjson = cJSON_Parse((char * )payload);
  348. Log_Printf_Debug("plaintext(%d): %s\r\n",payload_length, payload);
  349. memset(Random, '\0', sizeof(Random));
  350. memset(Token, '\0', sizeof(Token));
  351. if(cJSON_HasObjectItem(cjson, "random"))
  352. {
  353. char * random = cJSON_GetObjectItem(cjson, "random")->valuestring;
  354. strcpy(Random, random);
  355. }
  356. if(cJSON_HasObjectItem(cjson, "seqOffset"))
  357. {
  358. uint16_t seqOffset = cJSON_GetObjectItem(cjson, "seqOffset")->valueint;
  359. SeqOffset = seqOffset;
  360. }
  361. if(cJSON_HasObjectItem(cjson, "token"))
  362. {
  363. char * token = cJSON_GetObjectItem(cjson, "token")->valuestring;
  364. strcpy(Token, token);
  365. }
  366. Log_Printf_Debug("\r\n(%s, %s, %d)\r\n", Random, Token, SeqOffset);
  367. cJSON_Delete(cjson);//清除结构体
  368. return 1;
  369. }
  370. else
  371. {
  372. // 数据发送成功返回
  373. uint8_t plaintext[256] = {0}; // 明文
  374. uint16_t plaintext_length = utils_aes128_cbc_dec((char * )aes_key, iv, (char * )payload, payload_length, (char * )plaintext);
  375. Log_Printf_Debug("\r\nplaintext(%d): %s\r\n",plaintext_length, (char *)plaintext);
  376. return 2;
  377. }
  378. }
  379. // 发送数据的逻辑
  380. static enum Result result = Result_None;
  381. static uint8_t cgreg_n;
  382. static uint8_t cgreg_stat;
  383. static uint16_t cgreg_lac;
  384. static uint32_t cgreg_ci;
  385. static uint8_t query_cgreg_times = 0; // 查询网络状态的次数
  386. static uint8_t auth_times = 0; // 认证次数
  387. static uint16_t socket_err = 0;
  388. static uint8_t auth_or_data = 0;
  389. void UDP_Client5_Handle(void)
  390. {
  391. // 流程
  392. switch(step)
  393. {
  394. case STEP_NONE: // 空闲
  395. break;
  396. case STEP_START: // 开始
  397. query_cgreg_times = 0; // 查询网络状态的次数
  398. auth_times = 0; // 认证次数
  399. goto_step(STEP_EXIT_SLEEP);
  400. break;
  401. case STEP_EXIT_SLEEP: // 退出休眠
  402. ec800m.exit_sleep();
  403. goto_step_wait(STEP_SET_CFUN_1, 3);
  404. break;
  405. case STEP_SET_CFUN_1: // 设置全功能模式
  406. result = ec800m.set_cfun(1);
  407. if(result == Result_Success)
  408. {
  409. goto_step(STEP_SET_CGREG_2);
  410. }
  411. else if(result == Result_Failed)
  412. {
  413. goto_failure("设置全功能模式失败");
  414. }
  415. break;
  416. case STEP_SET_CGREG_2: // 设置ps域
  417. result = ec800m.set_cgreg(2);
  418. if(result == Result_Success)
  419. {
  420. goto_step(STEP_QUERY_CGREG);
  421. }
  422. else if(result == Result_Failed)
  423. {
  424. goto_failure("设置ps域失败");
  425. }
  426. break;
  427. case STEP_QUERY_CGREG: // 查询ps域
  428. result = ec800m.query_cgreg(&cgreg_n, &cgreg_stat, &cgreg_lac, &cgreg_ci);
  429. if(result == Result_Success)
  430. {
  431. if(cgreg_stat == 1)
  432. {
  433. // 下一步
  434. if(test_flag == 0)
  435. {
  436. goto_step(STEP_CLOSE);
  437. }
  438. else
  439. {
  440. goto_step(STEP_QUERY_QENG_SERVINGCELL);
  441. }
  442. }
  443. else if(query_cgreg_times > 20) // 最多查询20次
  444. {
  445. goto_failure("查询ps域次数过多");
  446. }
  447. else
  448. {
  449. goto_wait(400);
  450. query_cgreg_times++;
  451. }
  452. }
  453. else if(result == Result_Failed)
  454. {
  455. goto_failure("查询ps域失败");
  456. }
  457. break;
  458. case STEP_QUERY_QENG_SERVINGCELL: // 查询信号质量
  459. result = ec800m.qeng_servingcell(&signal.RSRP, &signal.RSRQ, &signal.RSSI, &signal.SINR);
  460. if(result == Result_Success)
  461. {
  462. goto_step(STEP_CLOSE);
  463. }
  464. else if(result == Result_Failed)
  465. {
  466. goto_failure("查询信号质量失败");
  467. }
  468. break;
  469. case STEP_CLOSE: // 关闭连接
  470. result = ec800m.close_socket(connectID);
  471. if(result == Result_Success)
  472. {
  473. goto_step(STEP_OPEN);
  474. }
  475. else if(result == Result_Failed)
  476. {
  477. goto_failure("关闭连接失败");
  478. }
  479. break;
  480. case STEP_OPEN: // 打开客户端
  481. result = ec800m.open_socket(connectID, "UDP", Host, Port, 1, &socket_err);
  482. if(result == Result_Success)
  483. {
  484. if(socket_err == 0)
  485. {
  486. goto_step(STEP_JUDGE_AUTH_OR_DATA);
  487. }
  488. else
  489. {
  490. goto_failure("客户端打开错误");
  491. }
  492. }
  493. else if(result == Result_Failed)
  494. {
  495. goto_failure("打开客户端失败");
  496. }
  497. break;
  498. case STEP_JUDGE_AUTH_OR_DATA: // 判断认证还是发送
  499. auth_or_data = judge_auth_or_data();
  500. if(auth_or_data == 1) // 已认证
  501. {
  502. goto_step(STEP_JOIN_DATA_MESSAGE);
  503. }
  504. else
  505. {
  506. goto_step(STEP_JOIN_AUTH_MESSAGE);
  507. }
  508. break;
  509. case STEP_JOIN_AUTH_MESSAGE: // 拼接认证报文
  510. if(auth_times > 0) // 最多重新认证一次
  511. {
  512. goto_failure("认证次数过多");
  513. }
  514. else
  515. {
  516. join_auth_message(coap_message, &coap_message_length);
  517. goto_step(STEP_SET_QISDE_0);
  518. auth_times++;
  519. }
  520. break;
  521. case STEP_JOIN_DATA_MESSAGE: // 拼接数据报文
  522. pump_params.lac = cgreg_lac;
  523. pump_params.ci = cgreg_ci;
  524. Pump_Params_Refresh();
  525. // 编码
  526. business_protocol_encode(pump_params, data, &data_length);
  527. join_data_message(data, data_length, coap_message, &coap_message_length);
  528. goto_step(STEP_SET_QISDE_0);
  529. break;
  530. case STEP_SET_QISDE_0: // 关闭发送回显
  531. result = ec800m.set_qisde(0);
  532. if(result == Result_Success)
  533. {
  534. goto_step(STEP_SEND);
  535. }
  536. else if(result == Result_Failed)
  537. {
  538. goto_failure("关闭发送回显失败");
  539. }
  540. break;
  541. case STEP_SEND: // 发送send
  542. result = ec800m.send(connectID, coap_message, coap_message_length);
  543. if(result == Result_Success)
  544. {
  545. goto_step(STEP_RECV);
  546. }
  547. else if(result == Result_Failed)
  548. {
  549. goto_failure("发送send失败");
  550. }
  551. break;
  552. case STEP_RECV: // 等待结果
  553. result = ec800m.recv_with_time(connectID, coap_message, &coap_message_length, 10000);
  554. if(result == Result_Success)
  555. {
  556. uint8_t res = recv_data_handle(coap_message, coap_message_length);
  557. if(res == 0) // 发送失败
  558. {
  559. goto_step(STEP_JUDGE_AUTH_OR_DATA); // 重新认证
  560. }
  561. else if(res == 1) // 认证成功
  562. {
  563. goto_step(STEP_JOIN_DATA_MESSAGE);
  564. }
  565. else if(res == 2) // 发送成功
  566. {
  567. goto_success("发送成功");
  568. }
  569. }
  570. else if(result == Result_Failed)
  571. {
  572. goto_failure("等待结果失败");
  573. }
  574. break;
  575. case STEP_WAIT: // 等待
  576. wait();
  577. break;
  578. case STEP_SUCCESS: // 成功
  579. goto_step(STEP_SET_SLEEP);
  580. break;
  581. case STEP_FAILURE: // 失败
  582. goto_step(STEP_SET_SLEEP);
  583. break;
  584. case STEP_SET_SLEEP: // 设置休眠模式
  585. result = ec800m.set_sleep(1);
  586. if(result != Result_None)
  587. {
  588. goto_step(STEP_SET_CFUN_0);
  589. }
  590. break;
  591. case STEP_SET_CFUN_0: // 设置最小功能模式
  592. result = ec800m.set_cfun(0);
  593. if(result != Result_None)
  594. {
  595. goto_step(STEP_ENTER_SLEEP);
  596. }
  597. break;
  598. case STEP_ENTER_SLEEP: // 进入睡眠
  599. ec800m.enter_sleep();
  600. goto_step(STEP_FINISH);
  601. break;
  602. case STEP_FINISH: // 结束流程
  603. break;
  604. default:
  605. break;
  606. }
  607. }
  608. #endif