hmi.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-26 Administrator the first version
  9. */
  10. #include <rtthread.h>
  11. #include "hmi.h"
  12. #include <board.h>
  13. #include <control.h>
  14. #include <rtdevice.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "stdarg.h"
  19. #include "string.h"
  20. #include "sht30_collect.h"
  21. #include "beep.h"
  22. #include "easyflash.h"
  23. #include "sound.h"
  24. #include "ymodem.h"
  25. #include <shell.h>
  26. #include "dtu_uart2.h"
  27. #include <fal.h>
  28. #include "selfcheck.h"
  29. #include <user_mb_app.h>
  30. #define DBG_ENABLE
  31. #define DBG_COLOR
  32. #define DBG_TAG "hmi"
  33. #define DBG_LEVEL DBG_LOG
  34. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  35. #include <cJSON.h>
  36. #define HMI_THREAD_PRIORITY 5 //线程优先级
  37. #define HMI_THREAD_STACK_SIZE 2048 //线程栈空间大小
  38. #define HMI_THREAD_TIMESLICE 10 //时间片
  39. #define CONTROL_MOTOR_PRIORITY 18
  40. #define CONTROL_MOTOR_STACK_SIZE 2048
  41. #define CONTROL_MOTOR_TIMESLICE 5
  42. static char msg_pool[512];
  43. void list_mem(void);
  44. int mb_master_samlpe();
  45. /**/
  46. Device_Status_typedef device_status;
  47. CheckResult check_results;
  48. extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
  49. time_t time(time_t *t);
  50. /* 串口接收消息结构*/
  51. struct rx_msg
  52. {
  53. rt_device_t dev;
  54. rt_size_t size;
  55. };
  56. struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
  57. ////
  58. static rt_thread_t hmi1 = RT_NULL;
  59. static rt_thread_t ctr_motor = RT_NULL;
  60. rt_device_t serial; /*串口设备句柄*/
  61. rt_timer_t timer_uart2 = RT_NULL;
  62. /* 消息队列控制块 */
  63. static struct rt_messagequeue rx_mq;//接收数据消息队列
  64. static void HMI_Decode(void);
  65. static rt_err_t uart_input(rt_device_t dev, rt_size_t size);
  66. #ifdef RT_USING_SERIAL_V2
  67. static int HMI_uart4_init(void)
  68. {
  69. serial = rt_device_find(UART_NAME);
  70. /*修改串口配置参数*/
  71. config.baud_rate = BAUD_RATE_115200; //修改波特率9600
  72. config.data_bits = DATA_BITS_8; //数据位8
  73. config.stop_bits = STOP_BITS_1; //停止位1
  74. #ifdef RT_USING_SERIAL_V2
  75. config.rx_bufsz = 512;
  76. config.tx_bufsz = 1024;
  77. #else
  78. config.bufsz = 512; //缓冲区128字节
  79. #endif
  80. config.parity = PARITY_NONE; //无奇偶校验
  81. /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
  82. rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
  83. // /* step4:打开串口设备。以中断接收及轮询发送模式打开串口设备 */
  84. //rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
  85. /* 以 DMA 接收及轮询发送模式打开串口设备 */
  86. #ifdef RT_USING_SERIAL_V2
  87. rt_err_t uart_res = rt_device_open(serial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_NON_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
  88. #else
  89. rt_err_t uart_res = rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX); //RT_DEVICE_FLAG_DMA_RX
  90. #endif
  91. if(uart_res!=RT_EOK)
  92. {
  93. LOG_E("%s打开失败!",UART_NAME);
  94. }else{
  95. LOG_I("%s Open Success!",UART_NAME);
  96. }
  97. return RT_EOK;
  98. }
  99. #endif
  100. /*串口屏写数据*/
  101. void HMI_WRITE(char *fmt, ...)
  102. {
  103. va_list ap;
  104. //末尾需要拼接的3个ff
  105. static const char hmi_hex[3]={0xff,0xff,0xff};
  106. static char str[MAX_SIZE];
  107. //memset(str,'\0',sizeof(str));
  108. rt_size_t str_length;
  109. va_start(ap,fmt);
  110. // 预留3字节空间给 hmi_hex
  111. str_length = rt_vsnprintf(str, sizeof(str) - 3, fmt, ap);
  112. va_end(ap);
  113. if (str_length > MAX_SIZE - 3)
  114. str_length = MAX_SIZE - 3;
  115. // 追加三个 0xff
  116. //memcpy(str + str_length, hmi_hex, sizeof(hmi_hex));
  117. rt_device_write(serial, 0, str, str_length);
  118. rt_thread_mdelay(1); //2025-0308
  119. }
  120. /* 接收数据回调函数 */
  121. static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
  122. {
  123. struct rx_msg msg;
  124. rt_err_t result;
  125. msg.dev = dev;
  126. msg.size = size;
  127. result = rt_mq_send(&rx_mq, &msg, sizeof(msg));
  128. if ( result == -RT_EFULL)
  129. {
  130. /* 消息队列满 */
  131. LOG_E("hmi message queue full!\n");
  132. rt_mq_control(&rx_mq, RT_IPC_CMD_RESET, RT_NULL); // 清空队列
  133. }
  134. return result;
  135. }
  136. //JSON数据解析
  137. int parsehmi(char *json_string)
  138. {
  139. cJSON *root = cJSON_Parse(json_string);
  140. if(!root)
  141. {
  142. cJSON_Delete(root);
  143. LOG_E("parse json err:%s",json_string);
  144. return -1;
  145. }
  146. else
  147. {
  148. LOG_I("解析JSON:%s",json_string);
  149. cJSON *item2 = cJSON_GetObjectItem(root,"write");
  150. cJSON *item3 = cJSON_GetObjectItem(root,"message");
  151. cJSON *item4 = cJSON_GetObjectItem(root,"status");
  152. cJSON *item5 = cJSON_GetObjectItem(root,"UART2");
  153. if(item5!=RT_NULL&&
  154. item2!=RT_NULL&&
  155. item3!=RT_NULL&&
  156. item4!=RT_NULL)
  157. {
  158. check_results.UATR_2_TX_STA = 0;
  159. check_results.UATR_4_RX_STA = 0;
  160. }else {
  161. check_results.UATR_2_TX_STA = 1;
  162. check_results.UATR_4_RX_STA = 1;
  163. }
  164. cJSON_Delete(root);
  165. }
  166. return 0;
  167. }
  168. /*入口函数*/
  169. static void Hmi_thread_entry(void *parameter)
  170. {
  171. struct rx_msg msg;
  172. rt_err_t result;
  173. rt_uint32_t rx_length;
  174. static char str_check[2]={'{','}'};
  175. static char rx_buffer[512];
  176. static char rx_buffer_tmp[512];
  177. static char rx_buffer_tmp2[512];
  178. while(1)
  179. {
  180. rt_memset(&msg, 0, sizeof(msg));
  181. /* 从消息队列中读取消息*/
  182. result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), 50);
  183. if (result == RT_EOK)
  184. {
  185. rx_length =(sizeof(rx_buffer) - 1) > msg.size ?
  186. msg.size : sizeof(rx_buffer) - 1;
  187. rx_length = rt_device_read(msg.dev, 0, &rx_buffer[0], rx_length);
  188. rx_buffer[rx_length] = '\0';
  189. LOG_D("UART4 RECV:%s",rx_buffer);
  190. char str_check_head[2];
  191. char str_check_end[2];
  192. rt_sprintf(str_check_head, "%c",rx_buffer[0]);
  193. rt_sprintf(str_check_end, "%c",rx_buffer[rx_length-1]);
  194. if(str_check_end[0]==str_check[1]&&str_check_head[0]==str_check[0])
  195. {
  196. parsehmi(rx_buffer);
  197. rt_memset(rx_buffer,0,sizeof(rx_buffer));
  198. rt_memset(rx_buffer_tmp,0,sizeof(rx_buffer_tmp));
  199. rt_memset(rx_buffer_tmp2,0,sizeof(rx_buffer_tmp2));
  200. }
  201. else {
  202. if(rx_buffer[rx_length-1]!='}')
  203. {
  204. rt_sprintf(rx_buffer_tmp, "%s",rx_buffer);
  205. }
  206. else {
  207. rt_sprintf(rx_buffer_tmp2,"%s",rx_buffer);
  208. rt_sprintf(rx_buffer, "%s%s",rx_buffer_tmp,rx_buffer_tmp2);
  209. parsehmi(rx_buffer);
  210. rt_memset(rx_buffer,0,sizeof(rx_buffer));
  211. rt_memset(rx_buffer_tmp,0,sizeof(rx_buffer_tmp));
  212. rt_memset(rx_buffer_tmp2,0,sizeof(rx_buffer_tmp2));
  213. }
  214. }
  215. }
  216. }
  217. }
  218. /*******************************************************************************************/
  219. static void t_uart2_callback(void *parameter)
  220. {
  221. HMI_WRITE("sysSet.va0.txt=\"指令超时,请重试...\"");
  222. LOG_E("t_uart2_callback");
  223. }
  224. void Start_timer_Uart2(void)
  225. {
  226. if(timer_uart2!=RT_NULL)
  227. {
  228. rt_timer_start(timer_uart2);
  229. }
  230. else
  231. {
  232. LOG_E("timer_uart2 start Failed!");
  233. }
  234. }
  235. /*屏幕写数据*/
  236. int Hmi_Fresh(void)
  237. {
  238. //初始化串口4
  239. HMI_uart4_init();
  240. rt_err_t ret = RT_EOK;
  241. /* 初始化消息队列 */
  242. rt_mq_init(&rx_mq, "rx_mq",
  243. msg_pool, /* 存放消息的缓冲区 */
  244. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  245. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  246. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  247. /* 设置接收回调函数 */
  248. rt_device_set_rx_indicate(serial, uart_input);
  249. /* 创建线程*/
  250. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  251. Hmi_thread_entry,
  252. RT_NULL,
  253. HMI_THREAD_STACK_SIZE,
  254. HMI_THREAD_PRIORITY,
  255. HMI_THREAD_TIMESLICE);
  256. /* 如果获得线程控制块,启动这个线程 */
  257. if (hmi1 != RT_NULL)
  258. {
  259. rt_thread_startup(hmi1);
  260. }
  261. else
  262. {
  263. ret = RT_ERROR;
  264. }
  265. return ret;
  266. }
  267. void callback_IN1(void *args)
  268. {
  269. LOG_W("callback_IN1!");
  270. check_results.IN_1_STA = 0;
  271. }
  272. void callback_IN2(void *args)
  273. {
  274. LOG_W("callback_IN2!");
  275. check_results.IN_2_STA = 0;
  276. }
  277. void callback_IN3(void *args)
  278. {
  279. LOG_W("callback_IN3!");
  280. check_results.IN_3_STA = 0;
  281. }
  282. void callback_IN4(void *args)
  283. {
  284. LOG_W("callback_IN4!");
  285. check_results.IN_4_STA = 0;
  286. }
  287. void Check_ParamConfig(void)
  288. {
  289. rt_tick_t start, end;
  290. start = rt_tick_get(); // 获取当前tick值
  291. check_results.IN_1_STA = 1;
  292. check_results.IN_2_STA = 1;
  293. check_results.IN_3_STA = 1;
  294. check_results.IN_4_STA = 1;
  295. /* PC14引脚为输入模式 */
  296. rt_pin_mode(IO_IN1, PIN_MODE_INPUT);
  297. /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
  298. rt_pin_attach_irq(IO_IN1, PIN_IRQ_MODE_RISING, callback_IN1, RT_NULL);
  299. /* 使能中断 */
  300. rt_pin_irq_enable(IO_IN1, PIN_IRQ_ENABLE);
  301. rt_pin_mode(IO_IN2, PIN_MODE_INPUT);
  302. /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
  303. rt_pin_attach_irq(IO_IN2, PIN_IRQ_MODE_RISING, callback_IN2, RT_NULL);
  304. /* 使能中断 */
  305. rt_pin_irq_enable(IO_IN2, PIN_IRQ_ENABLE);
  306. rt_pin_mode(IO_IN3, PIN_MODE_INPUT);
  307. /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
  308. rt_pin_attach_irq(IO_IN3, PIN_IRQ_MODE_RISING, callback_IN3, RT_NULL);
  309. /* 使能中断 */
  310. rt_pin_irq_enable(IO_IN3, PIN_IRQ_ENABLE);
  311. rt_pin_mode(IO_IN4, PIN_MODE_INPUT);
  312. /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
  313. rt_pin_attach_irq(IO_IN4, PIN_IRQ_MODE_RISING, callback_IN4, RT_NULL);
  314. /* 使能中断 */
  315. rt_pin_irq_enable(IO_IN4, PIN_IRQ_ENABLE);
  316. EfErrCode ec_ef= 0;
  317. uint16_t current_1 = 0;
  318. ctr_photo(OFF);
  319. sht30_collect();
  320. time_t now = time(RT_NULL);
  321. static struct tm tm;
  322. gmtime_r(&now, &tm);
  323. if(easyflash_init()==EF_NO_ERR) //初始化成功
  324. {
  325. LOG_I("Flash 初始化成功!");
  326. }
  327. else {
  328. LOG_E("Flash初始化失败!");
  329. }
  330. LOG_I("Flash写测试...");
  331. /* 设置一个名为 ‘test_key’ 的变量,值为 ‘20250826’ */
  332. ec_ef = ef_set_and_save_env("testkey", "20250826");
  333. if(ec_ef==EF_NO_ERR){
  334. check_results.FLASH_WRITE_STA = 0;
  335. LOG_I("Flash写完成...");
  336. }else {
  337. check_results.FLASH_WRITE_STA = 1;
  338. LOG_I("Flash写失败...%d",ec_ef);
  339. }
  340. LOG_I("Flash读测试...");
  341. /* 读取字符串 */
  342. size_t len;
  343. char *value;
  344. value = ef_get_env("testkey");
  345. if (value) {
  346. if(strstr(value,"20250826")!=RT_NULL) {
  347. check_results.FLASH_READ_STA = 0;
  348. }else {
  349. check_results.FLASH_READ_STA = 1;
  350. }
  351. LOG_I("test_key value: %s (len=%d)\n", value, sizeof(value));
  352. } else {
  353. check_results.FLASH_READ_STA = 1;
  354. LOG_E("test_key not found!\n");
  355. }
  356. LOG_I("串口通信测试...");
  357. HMI_WRITE("{\"UART4\": 1, \"write\": 5, \"message\": \"自检\", \"status\": \"OK\" }");
  358. rt_thread_delay(1000);
  359. DTU_Write("{\"UART2\": 1, \"write\": 5, \"message\": \"自检\", \"status\": \"OK\" }");
  360. rt_thread_delay(3000);
  361. uint16_t current = atoi(device_status.power);
  362. uint16_t voltage_ = atoi(device_status.voltage);
  363. current_1 = atoi(device_status.heat_power);
  364. if(current>100)
  365. {
  366. check_results.CURRENT_24V_STA = 1;
  367. LOG_E("负载电流异常!");
  368. Beep_Tip(2000);
  369. return;
  370. }
  371. LOG_I("负载电流:%d",current);
  372. if(voltage_<=23)
  373. {
  374. check_results.VOLTAGE_24V_STA = 1;
  375. LOG_E("电压异常!");
  376. Beep_Tip(2000);
  377. return;
  378. }
  379. if(current_1>0)
  380. {
  381. check_results.CURRENT_24V_STA = 1;
  382. LOG_E("负载电流1异常!");
  383. Beep_Tip(2000);
  384. return;
  385. }
  386. check_results.VOLTAGE_24V_STA = 0;
  387. check_results.CURRENT_24V_STA = 0;
  388. LOG_I("打开24V输出通道1!");
  389. ctr_lamp(ON, 1);
  390. rt_thread_delay(5000);
  391. uint16_t current_ = atoi(device_status.power);
  392. rt_sprintf(check_results.OP_24V_1,"%s",device_status.power);
  393. LOG_I("24V输出通道1负载电流:[%d]mA",current_);
  394. LOG_I("关闭24V输出通道1!");
  395. ctr_lamp(OFF, 1);
  396. if(current_-current>800)
  397. {
  398. LOG_W("24V输出通道1正常!");
  399. check_results.OP_24V_1_STA = 0;
  400. }else {
  401. LOG_W("24V输出通道1负载电流异常!");
  402. check_results.OP_24V_1_STA = 1;
  403. }
  404. rt_thread_delay(5000);
  405. LOG_I("打开24V输出通道2!");
  406. ctr_Collect_Fan(ON);
  407. rt_thread_delay(5000);
  408. current_1 = atoi(device_status.heat_power);
  409. rt_sprintf(check_results.OP_24V_2,"%s",device_status.heat_power);
  410. LOG_I("24V输出通道2负载电流:[%d]mA",current_1);
  411. LOG_I("关闭24V输出通道2!");
  412. ctr_Collect_Fan(OFF);
  413. if(current_1>800)
  414. {
  415. LOG_W("24V输出通道2正常!");
  416. check_results.OP_24V_2_STA = 0;
  417. }else {
  418. LOG_E("24V输出通道2负载电流异常!");
  419. check_results.OP_24V_2_STA = 1;
  420. }
  421. rt_thread_delay(5000);
  422. LOG_I("打开24V输出通道3!");
  423. ctr_Cold(ON);
  424. rt_thread_delay(5000);
  425. current_1 = atoi(device_status.heat_power);
  426. rt_sprintf(check_results.OP_24V_3,"%s",device_status.heat_power);
  427. LOG_I("24V输出通道3负载电流:[%d]mA",current_1);
  428. LOG_I("关闭24V输出通道3!");
  429. ctr_Cold(OFF);
  430. if(current_1>800)
  431. {
  432. LOG_W("24V输出通道3正常!");
  433. check_results.OP_24V_3_STA = 0;
  434. }else {
  435. LOG_E("24V输出通道3负载电流异常!");
  436. check_results.OP_24V_3_STA = 1;
  437. }
  438. rt_thread_delay(5000);
  439. LOG_I("打开24V输出通道4!");
  440. ctr_Heat(ON);
  441. rt_thread_delay(5000);
  442. current_1 = atoi(device_status.heat_power);
  443. rt_sprintf(check_results.OP_24V_4,"%s",device_status.heat_power);
  444. LOG_I("24V输出通道4负载电流:[%d]mA",current_1);
  445. LOG_I("关闭24V输出通道4!");
  446. ctr_Heat(OFF);
  447. if(current_1>800)
  448. {
  449. LOG_W("24V输出通道4正常!");
  450. check_results.OP_24V_4_STA = 0;
  451. }else {
  452. LOG_W("24V输出通道4负载电流异常!");
  453. check_results.OP_24V_4_STA = 1;
  454. }
  455. rt_thread_delay(5000);
  456. LOG_I("打开电机驱动通道1...");
  457. ctr_cangmen_down(CLOSE);
  458. rt_thread_delay(5000);
  459. current_ = atoi(device_status.power);
  460. rt_sprintf(check_results.OP_MOTOR_1,"%s",device_status.power);
  461. LOG_I("电机驱动通道1负载电流:[%d]mA",current_);
  462. LOG_I("关闭电机驱动通道1...");
  463. ctr_cangmen_down(OFF);
  464. if(current_-current>800)
  465. {
  466. LOG_W("电机驱动通道1正常!");
  467. check_results.OP_MOTOR_1_STA = 0;
  468. }else {
  469. LOG_W("电机驱动通道1负载电流异常!");
  470. check_results.OP_MOTOR_1_STA = 1;
  471. }
  472. rt_thread_delay(5000);
  473. LOG_I("打开电机驱动通道2...");
  474. ctr_cangmen_up(OPEN);
  475. rt_thread_delay(5000);
  476. current_ = atoi(device_status.power);
  477. rt_sprintf(check_results.OP_MOTOR_2,"%s",device_status.power);
  478. LOG_I("电机驱动通道2负载电流:[%d]mA",current_);
  479. LOG_I("关闭电机驱动通道2...");
  480. ctr_cangmen_up(OFF);
  481. if(current_-current>800)
  482. {
  483. LOG_W("电机驱动通道2正常!");
  484. check_results.OP_MOTOR_2_STA = 0;
  485. }else {
  486. LOG_W("电机驱动通道2负载电流异常!");
  487. check_results.OP_MOTOR_2_STA = 1;
  488. }
  489. rt_thread_delay(5000);
  490. LOG_I("打开电机驱动通道3...");
  491. ctr_Motor_OP_3(ON);
  492. rt_thread_delay(5000);
  493. current_ = atoi(device_status.power);
  494. rt_sprintf(check_results.OP_MOTOR_3,"%s",device_status.power);
  495. LOG_I("电机驱动通道3负载电流:[%d]mA",current_);
  496. LOG_I("关闭电机驱动通道3...");
  497. ctr_Motor_OP_3(OFF);
  498. if(current_-current>800)
  499. {
  500. LOG_W("电机驱动通道3正常!");
  501. check_results.OP_MOTOR_3_STA = 0;
  502. }else {
  503. LOG_W("电机驱动通道3负载电流异常!");
  504. check_results.OP_MOTOR_3_STA = 1;
  505. }
  506. rt_thread_delay(5000);
  507. LOG_I("打开12V输出通道1...");
  508. ctr_router(ON);
  509. rt_thread_delay(5000);
  510. current_ = atoi(device_status.power);
  511. rt_sprintf(check_results.OP_12V_1,"%s",device_status.power);
  512. LOG_I("12V输出通道1负载电流:[%d]mA",current_);
  513. LOG_I("关闭12V输出通道1...");
  514. ctr_router(OFF);
  515. if(current_-current>800)
  516. {
  517. LOG_W("12V输出通道1正常!");
  518. check_results.OP_12V_1_STA = 0;
  519. }else {
  520. LOG_E("12V输出通道1负载电流异常!");
  521. check_results.OP_12V_1_STA = 1;
  522. }
  523. rt_thread_delay(5000);
  524. LOG_I("打开12V输出通道2...");
  525. ctr_photo(ON);
  526. rt_thread_delay(5000);
  527. current_ = atoi(device_status.power);
  528. rt_sprintf(check_results.OP_12V_2,"%s",device_status.power);
  529. LOG_I("12V输出通道2负载电流:[%d]mA",current_);
  530. LOG_I("关闭12V输出通道2...");
  531. ctr_photo(OFF);
  532. if(current_-current>500)
  533. {
  534. LOG_W("12V输出通道2正常!");
  535. check_results.OP_12V_2_STA = 0;
  536. }else {
  537. LOG_E("12V输出通道2负载电流异常!");
  538. check_results.OP_12V_2_STA = 1;
  539. }
  540. rt_thread_delay(5000);
  541. LOG_I("打开5V输出通道1...");
  542. ctr_led(ON);
  543. rt_thread_delay(5000);
  544. current_ = atoi(device_status.power);
  545. rt_sprintf(check_results.OP_5V_1,"%s",device_status.power);
  546. LOG_I("5V输出通道1负载电流:[%d]mA",current_);
  547. LOG_I("关闭5V输出通道1...");
  548. ctr_led(OFF);
  549. if(current_-current>100)
  550. {
  551. LOG_W("5V输出通道1正常!");
  552. check_results.OP_5V_1_STA = 0;
  553. }else {
  554. LOG_W("5V输出通道1负载电流异常!");
  555. check_results.OP_5V_1_STA = 1;
  556. }
  557. LOG_W("********自检结果:");
  558. LOG_W("********电压:%s %s",
  559. device_status.voltage,
  560. check_results.VOLTAGE_24V_STA ? "异常" : "正常");
  561. LOG_W("********电流:%s %s",
  562. device_status.power,
  563. check_results.CURRENT_24V_STA ? "异常" : "正常");
  564. LOG_W("********Flash写入:%s",
  565. check_results.FLASH_WRITE_STA ? "异常" : "正常");
  566. LOG_W("********Flash读取:%s",
  567. check_results.FLASH_READ_STA ? "异常" : "正常");
  568. LOG_W("********ADC_1:%d %s",
  569. check_results.ADC_1,
  570. check_results.ADC1_STA ? "异常" : "正常");
  571. LOG_W("********ADC_2:%d %s",
  572. check_results.ADC_2,
  573. check_results.ADC2_STA ? "异常" : "正常");
  574. LOG_W("********ADC_3:%d %s",
  575. check_results.ADC_3,
  576. check_results.ADC3_STA ? "异常" : "正常");
  577. LOG_W("********UART2RX:%s",
  578. check_results.UATR_2_RX_STA ? "异常" : "正常");
  579. LOG_W("********UART2TX:%s",
  580. check_results.UATR_2_TX_STA ? "异常" : "正常");
  581. LOG_W("********UART4RX:%s",
  582. check_results.UATR_4_RX_STA ? "异常" : "正常");
  583. LOG_W("********UART4TX:%s",
  584. check_results.UATR_4_TX_STA ? "异常" : "正常");
  585. LOG_W("********UART 485:%s",
  586. check_results.UART_485_STA ? "异常" : "正常");
  587. LOG_W("********24V通道1负载电流:%s %s",
  588. check_results.OP_24V_1,
  589. check_results.OP_24V_1_STA ? "异常" : "正常");
  590. LOG_W("********24V通道2负载电流:%s %s",
  591. check_results.OP_24V_2,
  592. check_results.OP_24V_2_STA ? "异常" : "正常");
  593. LOG_W("********24V通道3负载电流:%s %s",
  594. check_results.OP_24V_3,
  595. check_results.OP_24V_3_STA ? "异常" : "正常");
  596. LOG_W("********24V通道4负载电流:%s %s",
  597. check_results.OP_24V_4,
  598. check_results.OP_24V_4_STA ? "异常" : "正常");
  599. LOG_W("********12V通道1负载电流:%s %s",
  600. check_results.OP_12V_1,
  601. check_results.OP_12V_1_STA ? "异常" : "正常");
  602. LOG_W("********12V通道2负载负载电流:%s %s",
  603. check_results.OP_12V_2,
  604. check_results.OP_12V_2_STA ? "异常" : "正常");
  605. LOG_W("********5V通道1负载电流:%s %s",
  606. check_results.OP_5V_1,
  607. check_results.OP_5V_1_STA ? "异常" : "正常");
  608. LOG_W("********电机驱动通道1负载电流:%s %s",
  609. check_results.OP_MOTOR_1,
  610. check_results.OP_MOTOR_1_STA ? "异常" : "正常");
  611. LOG_W("********电机驱动通道2负载电流:%s %s",
  612. check_results.OP_MOTOR_2,
  613. check_results.OP_MOTOR_2_STA ? "异常" : "正常");
  614. LOG_W("********电机驱动通道3负载电流:%s %s",
  615. check_results.OP_MOTOR_3,
  616. check_results.OP_MOTOR_3_STA ? "异常" : "正常");
  617. LOG_W("********IO输入检测通道1:%s",
  618. check_results.IN_1_STA ? "异常" : "正常");
  619. LOG_W("********IO输入检测通道2:%s",
  620. check_results.IN_2_STA ? "异常" : "正常");
  621. LOG_W("********IO输入检测通道3:%s",
  622. check_results.IN_3_STA ? "异常" : "正常");
  623. LOG_W("********IO输入检测通道4:%s",
  624. check_results.IN_4_STA ? "异常" : "正常");
  625. LOG_W("********12V电压检测:%f %s",
  626. check_results.VOLTAGE_12V,
  627. check_results.VOLTAGE_12V_STA ? "异常" : "正常");
  628. LOG_W("********5V电压检测:%f %s",
  629. check_results.VOLTAGE_5V,
  630. check_results.VOLTAGE_3V3_STA ? "异常" : "正常");
  631. LOG_W("********3.3V电压检测:%f %s",
  632. check_results.VOLTAGE_3_3V,
  633. check_results.VOLTAGE_3V3_STA ? "异常" : "正常");
  634. if(check_results.ADC1_STA ||
  635. check_results.ADC2_STA ||
  636. check_results.ADC3_STA ||
  637. check_results.CURRENT_24V_STA ||
  638. check_results.FLASH_READ_STA ||
  639. check_results.FLASH_WRITE_STA ||
  640. check_results.IN_1_STA ||
  641. check_results.IN_2_STA ||
  642. check_results.IN_3_STA ||
  643. check_results.IN_4_STA ||
  644. check_results.MCU_TEMPTURE_STA ||
  645. check_results.OP_12V_1_STA ||
  646. check_results.OP_12V_2_STA ||
  647. check_results.OP_24V_1_STA ||
  648. check_results.OP_24V_2_STA ||
  649. check_results.OP_24V_3_STA ||
  650. check_results.OP_24V_4_STA ||
  651. check_results.OP_5V_1_STA ||
  652. check_results.OP_MOTOR_1_STA ||
  653. check_results.OP_MOTOR_2_STA ||
  654. check_results.OP_MOTOR_3_STA ||
  655. check_results.UART_485_STA ||
  656. check_results.UATR_2_RX_STA ||
  657. check_results.UATR_2_TX_STA ||
  658. check_results.UATR_4_RX_STA ||
  659. check_results.UATR_4_TX_STA ||
  660. check_results.VOLTAGE_12V_STA ||
  661. check_results.VOLTAGE_24V_STA ||
  662. check_results.VOLTAGE_3V3_STA ||
  663. check_results.VOLTAGE_5V_STA)
  664. {
  665. check_results.RESULT = 1;
  666. LOG_E("********检测结果:%s",
  667. check_results.RESULT ? "不通过" : "通过");
  668. ef_set_and_save_env("RESULT", "不通过");
  669. }else {
  670. check_results.RESULT = 0;
  671. LOG_I("********检测结果:%s",
  672. check_results.RESULT ? "不通过" : "通过");
  673. ef_set_and_save_env("RESULT", "通过");
  674. }
  675. ctr_Motor_Driver(1,1,0,0);
  676. end = rt_tick_get();
  677. rt_uint32_t elapsed = end - start; // 计算消耗的tick数
  678. LOG_W("耗时 %d ms %d s.\n", elapsed * (1000 / RT_TICK_PER_SECOND),elapsed * (1000 / RT_TICK_PER_SECOND)/1000);
  679. }
  680. //
  681. INIT_APP_EXPORT(Hmi_Fresh);