hmi.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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. #define DBG_TAG "hmi.c"
  26. #define DBG_LVL LOG_LVL_INFO
  27. #include <shell.h>
  28. #include "dtu_uart2.h"
  29. #include <fal.h>
  30. #define HMI_THREAD_PRIORITY 24 //线程优先级
  31. #define HMI_THREAD_STACK_SIZE 2048 //线程栈空间大小
  32. #define HMI_THREAD_TIMESLICE 10 //时间片
  33. #define CONTROL_MOTOR_PRIORITY 18
  34. #define CONTROL_MOTOR_STACK_SIZE 2048
  35. #define CONTROL_MOTOR_TIMESLICE 5
  36. static char msg_pool[256];
  37. static char rx_buffer[HMI_UART_RXBUFFER_SIZE + 1];
  38. void list_mem(void);
  39. /**/
  40. Device_Status_typedef device_status;
  41. time_t time(time_t *t);
  42. /* 串口接收消息结构*/
  43. struct rx_msg
  44. {
  45. rt_device_t dev;
  46. rt_size_t size;
  47. };
  48. struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
  49. static rt_thread_t hmi1 = RT_NULL;
  50. static rt_thread_t ctr_motor = RT_NULL;
  51. rt_device_t serial; /*串口设备句柄*/
  52. /* 消息队列控制块 */
  53. static struct rt_messagequeue rx_mq;//接收数据消息队列
  54. static void HMI_Decode(char *cmd,uint8_t cmd_len);
  55. static rt_err_t uart_input(rt_device_t dev, rt_size_t size);
  56. static int HMI_uart4_init(void)
  57. {
  58. serial = rt_device_find(UART_NAME);
  59. /*修改串口配置参数*/
  60. config.baud_rate = BAUD_RATE_115200; //修改波特率9600
  61. config.data_bits = DATA_BITS_8; //数据位8
  62. config.stop_bits = STOP_BITS_1; //停止位1
  63. config.bufsz = 512; //缓冲区128字节
  64. config.parity = PARITY_NONE; //无奇偶校验
  65. /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
  66. rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
  67. // /* step4:打开串口设备。以中断接收及轮询发送模式打开串口设备 */
  68. //rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
  69. /* 以 DMA 接收及轮询发送模式打开串口设备 */
  70. rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX);
  71. return RT_EOK;
  72. }
  73. /*串口屏写数据*/
  74. void HMI_WRITE(char *fmt, ...)
  75. {
  76. va_list ap;
  77. //末尾需要拼接的3个ff
  78. const char hmi_hex[3]={0xff,0xff,0xff};
  79. static char str[MAX_SIZE];
  80. memset(str,'\0',sizeof(str));
  81. rt_size_t str_length;
  82. va_start(ap,fmt);
  83. str_length = rt_vsnprintf(str, sizeof(str) - 1, fmt, ap);
  84. if (str_length > MAX_SIZE - 1)
  85. str_length = MAX_SIZE - 1;
  86. rt_device_write(serial, 0, str, str_length);
  87. va_end(ap);
  88. rt_device_write(serial, 0,hmi_hex,3);
  89. }
  90. /* 接收数据回调函数 */
  91. static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
  92. {
  93. struct rx_msg msg;
  94. rt_err_t result;
  95. msg.dev = dev;
  96. msg.size = size;
  97. result = rt_mq_send(&rx_mq, &msg, sizeof(msg));
  98. if ( result == -RT_EFULL)
  99. {
  100. /* 消息队列满 */
  101. rt_kprintf("message queue full!\n");
  102. }
  103. return result;
  104. }
  105. /*入口函数*/
  106. static void Hmi_thread_entry(void *parameter)
  107. {
  108. struct rx_msg msg;
  109. rt_err_t result;
  110. rt_uint32_t rx_length;
  111. while(1)
  112. {
  113. rt_memset(&msg, 0, sizeof(msg));
  114. /* 从消息队列中读取消息*/
  115. result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), 50);
  116. if (result == RT_EOK)
  117. {
  118. rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
  119. rx_buffer[rx_length] = '\0';
  120. rt_kprintf("%s\n",rx_buffer);
  121. //\r 对应的hex为0x0d,0x0a,占两个字节,屏幕发送的数据都以\r结尾
  122. HMI_Decode(rx_buffer,rx_length);
  123. }
  124. /*********************************************************************************************************************/
  125. //rt_kprintf("%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  126. //rt_kprintf("workSta.vbat.txt=%c%d.%02d%c\n",hmi_str,voltage/100,voltage%100,hmi_str);
  127. }
  128. }
  129. /*******************************************************************************************/
  130. /***************************** 解析从屏幕收到的数据 begin **********************************/
  131. static void HMI_Decode(char *cmd,uint8_t cmd_len)
  132. {
  133. char *var;
  134. if(device_status.refresh_num==0) device_status.refresh_num = 10;
  135. if(strstr(rx_buffer,"getFullData") != NULL){
  136. time_t now = time(RT_NULL);
  137. static struct tm tm;
  138. gmtime_r(&now, &tm);
  139. char *readinfo = makeJson_ReadInfo();
  140. if(device_status.refresh_num==5)
  141. {
  142. device_status.refresh_num = 15;
  143. DTU_Write("%s",readinfo);
  144. list_mem();
  145. device_status.hmi_fresh = 1;
  146. rt_thread_delay(100);
  147. }
  148. //在解析getinfo中清除超时
  149. if(device_status.refresh_timeout==30)
  150. {
  151. rt_sprintf(device_status.sim,"1");
  152. rt_sprintf(device_status.net,"1");
  153. rt_sprintf(device_status.csq,"0");
  154. device_status.refresh_timeout=0;
  155. }
  156. rt_free(readinfo);
  157. device_status.refresh_num--;
  158. device_status.refresh_timeout++;
  159. HMI_WRITE("uploadSet.iccid.txt=\"%s\"",device_status.iccid);
  160. //HMI_WRITE("mqttcfg.mqtt1Message.txt=\"%s\"",device_status.mqttcfg1);
  161. HMI_WRITE("uploadSet.t0.txt=\"%s\"",device_status.mqttcfg2);
  162. //更新固件版本号
  163. HMI_WRITE("debug.t3.txt=\"%s\"",device_status.driver);
  164. //更新固件编译日期
  165. HMI_WRITE("debug.t4.txt=\"%s\"",CompileTime);
  166. //
  167. HMI_WRITE("debug.t5.txt=\"%s\"",device_status.driver_bl);
  168. HMI_WRITE("debug.t7.txt=\"%s\"",device_status.driver_compile);
  169. //更新dtu/rtu版本
  170. HMI_WRITE("debug.t9.txt=\"%s\"",device_status.driver_4g);
  171. //更新时间
  172. HMI_WRITE("menu.rtc.txt=\"%04d-%02d-%02d %02d:%02d:%02d\"",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  173. HMI_WRITE("workSta.rtc.txt=\"%04d-%02d-%02d %02d:%02d:%02d\"",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  174. HMI_WRITE("set.t0.txt=\"%d\"",tm.tm_hour);
  175. HMI_WRITE("set.t1.txt=\"%d\"",tm.tm_min);
  176. HMI_WRITE("set.t2.txt=\"%d\"",tm.tm_sec);
  177. //更新电压
  178. HMI_WRITE("workSta.vbat.txt=\"%s\"",device_status.voltage);
  179. //更新电流
  180. HMI_WRITE("workSta.power.txt=\"%s\"",device_status.power);
  181. //更新温湿度数据
  182. HMI_WRITE("workSta.envHum.val=%d",atoi(device_status.humidity));
  183. HMI_WRITE("workSta.envTem.val=%d",atoi(device_status.tempture));
  184. //更新电池状态
  185. HMI_WRITE("workSta.batStatus.val=%d",device_status.bat_status);
  186. //更新上仓门状态
  187. HMI_WRITE("workSta.upStatus.val=%d",device_status.up_status);
  188. //更新下仓门状态
  189. HMI_WRITE("workSta.downStatus.val=%d",device_status.down_status);
  190. //更新工作状态
  191. HMI_WRITE("workSta.workStatus.val=%d",device_status.work_status);
  192. //更新温控状态
  193. HMI_WRITE("workSta.tempStatus.val=%d",device_status.temp_status);
  194. //更新雨控状态
  195. HMI_WRITE("workSta.rainStatus.val=%d",device_status.rain_status);
  196. //更新光控状态
  197. HMI_WRITE("workSta.sunStatus.val=%d",device_status.sun_status);
  198. //更新CSQ
  199. HMI_WRITE("menu.csq_value.txt=\"%s\"",device_status.csq);
  200. HMI_WRITE("workSta.csq_value.txt=\"%s\"",device_status.csq);
  201. //更新收集时间
  202. HMI_WRITE("sysSet.stime.val=%d",device_status.clt_time);
  203. //更新加热时间
  204. HMI_WRITE("workSta.heatTime.val=%d",device_status.heattime);
  205. HMI_WRITE("sysSet.jtime.val=%d",device_status.heattime);
  206. //
  207. HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
  208. //更新加热温度
  209. HMI_WRITE("workSta.heatTem.val=%d",device_status.heattem);
  210. HMI_WRITE("sysSet.jheat.val=%d",device_status.heatvalue);
  211. //更新加热状态
  212. HMI_WRITE("workSta.heatStatus.val=%d",device_status.heat_status);
  213. //更新熄屏时间
  214. HMI_WRITE("thsp=%d",device_status.thsp);
  215. //更新密码
  216. static char pwd_char[10];
  217. //整型转字符串
  218. itoa(device_status.passWord,pwd_char,10);
  219. HMI_WRITE("inputPasswd.pwdData.txt=\"%s\"",pwd_char);
  220. //更新时间设置中的参数
  221. //更新定时模式
  222. HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
  223. //更新光控定时时长
  224. HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
  225. //更新时控开始
  226. HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
  227. //更新时控结束
  228. HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
  229. //SIM卡状态
  230. HMI_WRITE("workSta.bt0.val=%d",atoi(device_status.sim));
  231. //ID
  232. HMI_WRITE("menu.equipid.txt=\"%s\"",device_status.imei);
  233. HMI_WRITE("workSta.equipid.txt=\"%s\"",device_status.imei);
  234. //数据上传间隔
  235. HMI_WRITE("uploadSet.datt.val=%d",device_status.dattim);
  236. //语音音量
  237. HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
  238. //更新联网状态
  239. if(atoi(device_status.net)==1)
  240. {
  241. HMI_WRITE("menu.net.val=1");
  242. HMI_WRITE("workSta.net.val=1");
  243. }
  244. else {
  245. HMI_WRITE("workSta.net.val=0");
  246. HMI_WRITE("menu.net.val=0");
  247. }
  248. if(atoi(device_status.csq)==0&&atoi(device_status.net)==1)
  249. {
  250. HMI_WRITE("menu.net.val=1");
  251. HMI_WRITE("workSta.net.val=2");
  252. }
  253. }
  254. else if (strstr(rx_buffer,"getClockData")!=NULL) {
  255. //更新定时模式
  256. HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
  257. //更新光控定时时长
  258. HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
  259. //更新时控开始
  260. HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
  261. //更新时控结束
  262. HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
  263. }
  264. else if (strstr(rx_buffer,"button")!=NULL) {
  265. rt_kprintf("按键!\n");
  266. DTU_Write("button");
  267. }
  268. //拍照
  269. else if(strstr(rx_buffer,"putTest.switchPhoto=1")!=NULL) {
  270. device_status.photo_ws = 1;
  271. }
  272. //清扫
  273. else if (strstr(rx_buffer,"clear")!=NULL) {
  274. rt_kprintf("\n清扫!\n");
  275. if(device_status.version_type==4)
  276. {
  277. device_status.clear_status=1;
  278. }
  279. else if (device_status.version_type==1) {
  280. turnzp();
  281. }
  282. }
  283. //震动
  284. else if (strstr(rx_buffer,"putTest.switchShake=1")!=NULL) {
  285. rt_kprintf("\n震动!\n");
  286. ctr_shake(ON,device_status.shake_sec);
  287. }
  288. //打开补光
  289. else if (strstr(rx_buffer,"putTest.switchFill=1")!=NULL) {
  290. rt_kprintf("\n打开补光!!!\n");
  291. ctr_led(ON);
  292. }
  293. //关闭补光
  294. else if (strstr(rx_buffer,"putTest.switchFill=0")!=NULL) {
  295. rt_kprintf("\n关闭补光!!!\n");
  296. ctr_led(OFF);
  297. }
  298. //打开灯管
  299. else if (strstr(rx_buffer,"putTest.switchLamp=1")!=NULL)
  300. {
  301. rt_kprintf("Open Lamp!\n");
  302. ctr_lamp(ON);
  303. }
  304. //关闭灯管
  305. else if (strstr(rx_buffer,"putTest.switchLamp=0")!=NULL)
  306. {
  307. rt_kprintf("Close Lamp!\n");
  308. ctr_lamp(OFF);
  309. }
  310. //关闭加热
  311. else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
  312. device_status.heat_status = 0;
  313. ctr_Heat(OFF);
  314. rt_kprintf("Close Heat!\n");
  315. }
  316. //打开加热
  317. else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
  318. device_status.heat_status = 1;
  319. ctr_Heat(ON);
  320. rt_kprintf("Open Heat!\n");
  321. }
  322. //打开上仓门
  323. else if(strstr(rx_buffer,"putTest.switchUp=1")!=NULL){
  324. rt_kprintf("Open UP!\n");
  325. device_status.ctr_up_motor = 1;
  326. }
  327. //关闭上仓门
  328. else if(strstr(rx_buffer,"putTest.switchUp=0")!=NULL){
  329. rt_kprintf("CLOSE UP!\n");
  330. device_status.ctr_up_motor = 2;
  331. }
  332. //打开下仓门
  333. else if(strstr(rx_buffer,"putTest.switchDown=1")!=NULL){
  334. device_status.ctr_down_motor = 1;
  335. rt_kprintf("Open down!\n");
  336. }
  337. //关闭下仓门
  338. else if(strstr(rx_buffer,"putTest.switchDown=0")!=NULL){
  339. device_status.ctr_down_motor = 2;
  340. rt_kprintf("CLOSE down!\n");
  341. }
  342. //定时设置
  343. else if (strstr(rx_buffer,"saveClockSet=")!=NULL) {
  344. char sun_str[3],start_str[3],stop_str[3],timeswitch_str[3];
  345. rt_kprintf("时间设置!\n");
  346. var=strstr(rx_buffer,"=");
  347. var++;
  348. strncpy(sun_str,var,2);
  349. if(atoi(sun_str) > 0 && atoi(sun_str) <12)
  350. {
  351. device_status.sunBar=atoi(sun_str);
  352. time_t now;
  353. time(&now);
  354. static struct tm nowstamp;
  355. nowstamp =*localtime(&now);
  356. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  357. static rt_uint32_t nowstamp_num = 0;
  358. nowstamp_num = mktime(&nowstamp);
  359. device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
  360. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  361. }
  362. else {
  363. rt_kprintf("参数设置异常!!!");
  364. }
  365. //时控开始时间
  366. strncpy(start_str,var+2,2);
  367. if(atoi(start_str) >= 0 && atoi(start_str) < 24)
  368. {
  369. device_status.startBar=atoi(start_str);
  370. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  371. }
  372. else {
  373. rt_kprintf("参数设置异常!!!");
  374. }
  375. //
  376. strncpy(stop_str,var+4,2);
  377. if(atoi(stop_str) >= 0&& atoi(stop_str) < 24)
  378. {
  379. device_status.stopBar=atoi(stop_str);
  380. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  381. }
  382. else {
  383. rt_kprintf("参数设置异常!!!");
  384. }
  385. //
  386. strncpy(timeswitch_str,var+6,2);
  387. if(atoi(timeswitch_str) >= 0 && atoi(timeswitch_str) <= 1)
  388. {
  389. device_status.timeSwitch=atoi(timeswitch_str);
  390. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  391. }
  392. else {
  393. rt_kprintf("参数设置异常!!!");
  394. }
  395. MA_save();
  396. rt_kprintf("工作时间参数已保存:模式-%d,光控时间-%d,时控开始时间-%d,时控结束时间-%d\n",device_status.timeSwitch,device_status.sunBar,device_status.startBar,device_status.stopBar);
  397. }
  398. else if (strstr(rx_buffer,"saveSystemSet")!=NULL) {
  399. char clt_time_str[3],heattime_str[3],heatvale_str[4],vol_str[4],thsp_str[5];
  400. rt_kprintf("系统设置!\n");
  401. var = strstr(rx_buffer,"=");
  402. var ++;
  403. strncpy(clt_time_str,var,2);
  404. if(atoi(clt_time_str)>0 && atoi(clt_time_str) <= 30)
  405. {
  406. device_status.clt_time = atoi(clt_time_str); //收集时间
  407. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  408. }
  409. strncpy(heattime_str,var+2,2);
  410. if(atoi(heattime_str)>0 && atoi(heattime_str) <= 30)
  411. {
  412. rt_kprintf("加热时间:%d\n",atoi(heattime_str));
  413. device_status.heattime = atoi(heattime_str); //加热时间
  414. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  415. }
  416. strncpy(heatvale_str,var+4,3);
  417. if(atoi(heatvale_str) > 0 && atoi(heatvale_str) <= 130)
  418. {
  419. device_status.heatvalue=atoi(heatvale_str);
  420. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  421. }
  422. strncpy(vol_str,var+7,3);
  423. if(atoi(vol_str)>0&&atoi(vol_str)<8)
  424. {
  425. device_status.vol = atoi(vol_str); //音量
  426. DTU_Write("volume=");
  427. }
  428. strncpy(thsp_str,var+10,4);
  429. if(atoi(thsp_str)>0&&atoi(thsp_str)<3600)
  430. {
  431. device_status.thsp = atoi(thsp_str); //熄屏时间
  432. }
  433. else {
  434. rt_kprintf("参数设置失败!!!\n");
  435. }
  436. //MA_save();
  437. rt_kprintf("系统设置已保存:收集时间-%d,加热时间-%d,加热温度-%d,音量-%d,自动关屏-%d\n",device_status.clt_time,device_status.heattime,device_status.heatvalue,device_status.vol,device_status.thsp);
  438. }
  439. else if (strstr(rx_buffer,"rtc_h=")!=NULL) {
  440. char rtc_h[2];
  441. var = strstr(rx_buffer,"=");
  442. var++;
  443. strncpy(rtc_h,var,2);
  444. if(atoi(rtc_h)>=0 && atoi(rtc_h) <= 24)
  445. {
  446. set_time(atoi(rtc_h), 99, 99);
  447. }
  448. }
  449. else if (strstr(rx_buffer,"rtc_m=")!=NULL) {
  450. char rtc_m[2];
  451. var = strstr(rx_buffer,"=");
  452. var++;
  453. strncpy(rtc_m,var,2);
  454. if(atoi(rtc_m)>=0 && atoi(rtc_m) <= 24)
  455. {
  456. set_time(99, atoi(rtc_m), 99);
  457. }
  458. }
  459. else if (strstr(rx_buffer,"rtc_s=")!=NULL) {
  460. char rtc_s[2];
  461. var = strstr(rx_buffer,"=");
  462. var++;
  463. strncpy(rtc_s,var,2);
  464. if(atoi(rtc_s)>=0 && atoi(rtc_s) <= 24)
  465. {
  466. set_time(99, 99, atoi(rtc_s));
  467. }
  468. }
  469. else if(strstr(rx_buffer,"saveUploadSet=")!=NULL)
  470. {
  471. static char dattim_str[3];
  472. rt_kprintf("上传间隔设置!\n");
  473. var = strstr(rx_buffer,"=");
  474. var ++;
  475. strncpy(dattim_str,var,2);
  476. if(atoi(dattim_str)>=1&&atoi(dattim_str)<=120)
  477. {
  478. device_status.dattim =atoi(dattim_str); //数据上传间隔
  479. MA_save();
  480. }
  481. else {
  482. rt_kprintf("设置失败!!!\n");
  483. }
  484. rt_kprintf("数据上传设置:%d\n",device_status.dattim);
  485. }
  486. //光控测试
  487. else if(strstr(rx_buffer,"putTest.switchSun=1")!=NULL)
  488. {
  489. rt_kprintf("光控测试!!!");
  490. ctr_lamp(ON);
  491. device_status.sun_test = 1;
  492. }
  493. //恢复出厂设置电池
  494. else if (strstr(rx_buffer,"resetdcDefault")!=NULL)
  495. {
  496. ResetParamDefault_DC();
  497. MA_save();
  498. }
  499. //恢复出厂设置-交流
  500. else if (strstr(rx_buffer,"resetDefault")!=NULL)
  501. {
  502. ResetParamDefault();
  503. MA_save();
  504. }
  505. //获取SIM卡信息
  506. else if(strstr(rx_buffer,"getSim")!=NULL)
  507. {
  508. //http://sim.openluat.com/api/wechat/openapidoc
  509. DTU_Write("getsiminfo");
  510. }
  511. else if (strstr(rx_buffer,"DebugEnable")!=NULL) {
  512. Debug_log_ON();
  513. }
  514. else if (strstr(rx_buffer,"DebugDisable")!=NULL) {
  515. Debug_log_OFF();
  516. }
  517. else if (strstr(rx_buffer,"SwversionV1")!=NULL)
  518. {
  519. device_status.version_type = 1;
  520. sprintf(device_status.driver, "%s",VERSION_ZP);
  521. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  522. MA_save();
  523. }
  524. else if (strstr(rx_buffer,"SwversionV1")!=NULL) {
  525. device_status.version_type = 4;
  526. sprintf(device_status.driver, "%s",VERSION_HK);
  527. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  528. MA_save();
  529. }
  530. else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
  531. {
  532. HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
  533. }
  534. else if (strstr(rx_buffer,"checkupdate")!=NULL)
  535. {
  536. time_t now = time(RT_NULL);
  537. static struct tm tm;
  538. gmtime_r(&now, &tm);
  539. HMI_WRITE("hardcheck.tip_rtc.txt=\"%04d-%02d-%02d %02d:%02d:%02d\"",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  540. HMI_WRITE("hardcheck.p0.pic=%d",70);
  541. //RTC时间判断,如果当前年份小于2020,提示需要设置时间
  542. if(tm.tm_year+1900<2020)
  543. {
  544. rt_kprintf("时间未设置:%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  545. HMI_WRITE("hardcheck.tip_rtc.txt=%04d-%02d-%02d %02d:%02d:%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  546. }
  547. }
  548. //进入bootloader模式
  549. else if (strstr(rx_buffer,"bootloader")!=NULL) {
  550. device_status.stop_in_bootloader = 1;
  551. ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
  552. rt_hw_cpu_reset();
  553. }
  554. //软件重启
  555. else if (strstr(rx_buffer,"reboot")!=NULL) {
  556. rt_hw_cpu_reset();
  557. }
  558. }
  559. //入口函数-电机控制及
  560. static void Ctr_Mortor_entry(void* parameter)
  561. {
  562. rt_uint32_t limit_current = 3000; //推杆电击限制电流1A
  563. static rt_uint16_t num_up_open = 200; //20s
  564. static rt_uint16_t num_up_close = 200; //
  565. static rt_uint16_t num_down_open = 200; //
  566. static rt_uint16_t num_down_close = 200; //
  567. static rt_uint16_t photo_led_sec = 450; //45S
  568. while(1)
  569. {
  570. time_t time_reset12V;
  571. time(&time_reset12V);
  572. static struct tm alarm_reset12V;
  573. alarm_reset12V =*localtime(&time_reset12V);
  574. if((alarm_reset12V.tm_hour)==5&&(alarm_reset12V.tm_min==59)&&(alarm_reset12V.tm_sec==55))
  575. {
  576. ctr_RTU_DTU(OFF);
  577. rt_thread_delay(1000*10);
  578. ctr_RTU_DTU(ON);
  579. }
  580. if(device_status.ctr_up_motor==1)
  581. {
  582. //打开上仓门
  583. ctr_cangmen_up(OPEN);
  584. num_up_open--;
  585. //如果未工作且上仓门电机电流大于1A,立即停止,记录到Flash,上报预警
  586. if(atoi(device_status.power)>limit_current)
  587. {
  588. ctr_cangmen_up(OFF);
  589. num_up_open = 200;
  590. rt_kprintf("*************************上仓门电机打开堵转!!!**********************%d\n",atoi(device_status.power));
  591. }
  592. if (num_up_open == 0)
  593. {
  594. ctr_cangmen_up(OFF);
  595. num_up_open = 200;
  596. }
  597. }
  598. else if(device_status.ctr_up_motor==2)
  599. {
  600. ctr_cangmen_up(CLOSE);
  601. num_up_close --;
  602. if(atoi(device_status.power)>limit_current)
  603. {
  604. ctr_cangmen_up(OFF);
  605. num_up_close = 200;
  606. rt_kprintf("************************上仓门电机关闭堵转!!!**********************%d\n",atoi(device_status.power));
  607. }
  608. if (num_up_close == 0)
  609. {
  610. ctr_cangmen_up(OFF);
  611. num_up_close= 200;
  612. }
  613. }
  614. if (device_status.ctr_down_motor == 1)
  615. {
  616. ctr_cangmen_down(OPEN);
  617. num_down_open--;
  618. if(atoi(device_status.power)>limit_current)
  619. {
  620. ctr_cangmen_down(OFF);
  621. num_down_open = 200;
  622. rt_kprintf("*************************下仓门电机打开堵转!!!**********************%d\n",atoi(device_status.power));
  623. }
  624. if (num_down_open == 0)
  625. {
  626. ctr_cangmen_down(OFF);
  627. num_down_open = 200;
  628. }
  629. }
  630. else if (device_status.ctr_down_motor == 2)
  631. {
  632. ctr_cangmen_down(CLOSE);
  633. num_down_close--;
  634. if(atoi(device_status.power)>limit_current)
  635. {
  636. ctr_cangmen_down(OFF);
  637. num_down_close = 200;
  638. rt_kprintf("*************************下仓门电机关闭堵转!!!**********************%d\n",atoi(device_status.power));
  639. }
  640. if (num_down_close == 0)
  641. {
  642. ctr_cangmen_down(OFF);
  643. num_down_close = 200;
  644. }
  645. }
  646. if(device_status.clear_status==1)
  647. {
  648. device_status.clear_status = 0;
  649. if(ctr_clear(650)==0)
  650. ctr_TG_Clear(250);
  651. }
  652. if(device_status.sun_test==1)
  653. {
  654. SunTest();
  655. }
  656. if(device_status.photo_ws==1)
  657. {
  658. //打开补光灯
  659. if(photo_led_sec==100)
  660. {
  661. ctr_led(ON);
  662. DTU_Write("takephoto.mp3");
  663. //延时
  664. rt_thread_delay(1000);
  665. rt_kprintf("\n测试拍照!\n");
  666. Hk_Take_io();
  667. }
  668. photo_led_sec--;
  669. if(photo_led_sec==0)
  670. {
  671. ctr_led(OFF);
  672. photo_led_sec = 100;
  673. device_status.photo_ws = 0;
  674. HMI_WRITE("sysTest.switchPhoto.val=0");
  675. HMI_WRITE("sysTest.switchFill.val=0");
  676. }
  677. }
  678. rt_thread_delay(100);
  679. //rt_kprintf("action num is:%d%d%d",num_up_open,num_up_close,num_down_open,num_down_close,num_clear);
  680. }
  681. }
  682. /*屏幕写数据*/
  683. int Hmi_Fresh(void)
  684. {
  685. //初始化串口4
  686. rt_err_t ret = RT_EOK;
  687. /* 初始化消息队列 */
  688. rt_mq_init(&rx_mq, "rx_mq",
  689. msg_pool, /* 存放消息的缓冲区 */
  690. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  691. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  692. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  693. /* 设置接收回调函数 */
  694. rt_device_set_rx_indicate(serial, uart_input);
  695. /* 创建线程*/
  696. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  697. Hmi_thread_entry,
  698. RT_NULL,
  699. HMI_THREAD_STACK_SIZE,
  700. HMI_THREAD_PRIORITY,
  701. HMI_THREAD_TIMESLICE);
  702. /*打开上仓门的线程*/
  703. ctr_motor = rt_thread_create("Ctr motor",
  704. Ctr_Mortor_entry,
  705. RT_NULL,
  706. CONTROL_MOTOR_STACK_SIZE,
  707. CONTROL_MOTOR_PRIORITY,
  708. CONTROL_MOTOR_TIMESLICE);
  709. if(ctr_motor != RT_NULL)
  710. {
  711. rt_thread_startup(ctr_motor);
  712. }
  713. /* 如果获得线程控制块,启动这个线程 */
  714. if (hmi1 != RT_NULL)
  715. {
  716. rt_thread_startup(hmi1);
  717. }
  718. else
  719. {
  720. ret = RT_ERROR;
  721. }
  722. return ret;
  723. }
  724. void Check_ParamConfig(void)
  725. {
  726. time_t now = time(RT_NULL);
  727. static struct tm tm;
  728. gmtime_r(&now, &tm);
  729. if(easyflash_init()==EF_NO_ERR) //初始化成功
  730. {
  731. ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
  732. ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
  733. ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
  734. device_status.rebootcnt++;
  735. ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
  736. rt_kprintf("REBOOT_TIME:%d-%d-%d\n",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
  737. }
  738. else {
  739. rt_kprintf("easyflash init ERRPR!!!\n");
  740. }
  741. //保存默认屏幕配置
  742. if(device_status.iSave!=FLASH_FLAG)
  743. {
  744. device_status.iSave=FLASH_FLAG;
  745. device_status.clt_time = 10; //收集时间
  746. device_status.heattime = 10; //加热时间
  747. device_status.heatvalue=100;//加热温度
  748. device_status.thsp = 300; //默认熄屏时间5分钟
  749. device_status.sunBar = 8; //光控定时时长
  750. device_status.startBar = 20; //定时开始时间
  751. device_status.stopBar = 0; //定时结束时间
  752. device_status.tph = 70; //高温保护阈值
  753. device_status.tpl = 5; //低温保护阈值
  754. device_status.shake_ws = 1; //震动开关,默认开
  755. device_status.shake_sec = 1; //震动时间,s
  756. device_status.vol = 7; //音量
  757. device_status.timeSwitch = 1; //工作模式
  758. device_status.passWord = 8888; //屏幕密码
  759. device_status.dattim = 20; //数据上传间隔
  760. device_status.ds = 1; //设备状态
  761. device_status.version_type = 4; //版本类型
  762. ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
  763. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  764. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  765. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  766. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  767. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  768. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  769. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  770. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  771. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  772. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  773. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  774. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  775. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  776. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  777. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  778. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  779. if(device_status.version_type==1)
  780. {
  781. sprintf(device_status.driver, "%s",VERSION_ZP);
  782. }
  783. else if (device_status.version_type==4) {
  784. sprintf(device_status.driver, "%s",VERSION_HK);
  785. }
  786. rt_kprintf("SOFTWARE VERSION:%s\n",device_status.driver);
  787. rt_kprintf("set flash paramconfis:\n");
  788. rt_kprintf("stime:%d\n",device_status.iSave);
  789. rt_kprintf("stime:%d\n",device_status.clt_time);
  790. rt_kprintf("startBar:%d\n",device_status.startBar);
  791. rt_kprintf("stopBar:%d\n",device_status.stopBar);
  792. rt_kprintf("timeSwitch:%d\n",device_status.timeSwitch);
  793. rt_kprintf("sunBar:%d\n",device_status.sunBar);
  794. rt_kprintf("jtime:%d\n",device_status.heattime);
  795. rt_kprintf("jheat:%d\n",device_status.heatvalue);
  796. rt_kprintf("thsp:%d\n", device_status.thsp);
  797. rt_kprintf("密码:%d\n",device_status.passWord);
  798. }//从easyflash读取参数配置
  799. else if (device_status.iSave==FLASH_FLAG) {
  800. ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
  801. ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
  802. ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
  803. ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
  804. ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
  805. ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
  806. ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
  807. ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
  808. ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
  809. ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
  810. ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
  811. ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
  812. ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
  813. ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
  814. ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
  815. ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
  816. ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
  817. ef_get_env_blob("ds",&device_status.ds,
  818. sizeof(device_status.ds),NULL); //开关机状态
  819. ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
  820. ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
  821. ef_get_env_blob("driver_compile",&device_status.driver_compile,sizeof(device_status.driver_compile),NULL); //BL版本号 进BL的时候存储到FLASH
  822. device_status.light_over_tim = device_status.sunBar * 3600; //光控计数
  823. device_status.work_done = 0;
  824. //工作完成标志位
  825. if(device_status.dattim==0)
  826. {
  827. device_status.dattim = 20;
  828. }
  829. if(device_status.version_type==0)
  830. {
  831. app_partion_backup(); //固件备份至df_area
  832. device_status.version_type = 4;
  833. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
  834. }
  835. if(device_status.version_type==1)
  836. {
  837. rt_sprintf(device_status.driver, "%s",VERSION_ZP);
  838. }
  839. else if (device_status.version_type==4) {
  840. rt_sprintf(device_status.driver, "%s",VERSION_HK);
  841. }
  842. rt_kprintf("SOFTWARE VERSION:%s-imei:%s--iccid:%s\n",device_status.driver,device_status.imei,device_status.iccid);
  843. rt_kprintf("read flash paramconfis:%d-%s-%s\r\n",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
  844. rt_kprintf("开机次数:%d\n",device_status.rebootcnt);
  845. rt_kprintf("收集时间:%d\n",device_status.clt_time);
  846. rt_kprintf("定时开始时间:%d\n",device_status.startBar);
  847. rt_kprintf("定时结束时间:%d\n",device_status.stopBar);
  848. rt_kprintf("timeSwitch:%d\n",device_status.timeSwitch);
  849. rt_kprintf("光控定时时长:%d\n",device_status.sunBar);
  850. rt_kprintf("收集时间:%d\n",device_status.heattime);
  851. rt_kprintf("加热温度:%d\n",device_status.heatvalue);
  852. rt_kprintf("震动开关:%d\n",device_status.shake_ws);
  853. rt_kprintf("震动时间:%d\n",device_status.shake_sec);
  854. rt_kprintf("高温保护:%d\n",device_status.tph);
  855. rt_kprintf("低温保护:%d\n",device_status.tpl);
  856. rt_kprintf("thsp:%d\n", device_status.thsp);
  857. rt_kprintf("密码:%d\n",device_status.passWord);
  858. rt_kprintf("数据上传间隔:%d\n",device_status.dattim);
  859. }
  860. rt_kprintf("当前时间:%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  861. //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
  862. if(device_status.update_flag==1)
  863. {
  864. device_status.update_flag = 0;
  865. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  866. ymodem_ota(1,0);
  867. }
  868. else {
  869. //初始化联网状态
  870. rt_sprintf(device_status.net,"1");
  871. rt_sprintf(device_status.csq,"0");
  872. rt_sprintf(device_status.sim,"1");
  873. ctr_router(ON);
  874. Hmi_Fresh();
  875. dtu_data_play();
  876. sht30_collect();
  877. mb_master_samlpe();
  878. uint16_t connect_num=0;
  879. //等待联网,
  880. while(atoi(device_status.net)==1)
  881. {
  882. char *readinfo = makeJson_ReadInfo();
  883. DTU_Write("%s",readinfo);
  884. rt_free(readinfo);
  885. rt_thread_delay(1000);
  886. connect_num++;
  887. rt_kprintf("联网中......%d\n",connect_num);
  888. //超时时间为3分钟
  889. if(connect_num==180)
  890. {
  891. device_status.timeSwitch = 0;
  892. //保存光控变量
  893. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  894. rt_kprintf("Time not set:%04d-%02d-%02d %02d:%02d:%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
  895. set_date(2020, 1, 1);
  896. set_time(0, 0, 0);
  897. break;
  898. }
  899. if(tm.tm_year>=2021)
  900. break;
  901. }
  902. DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
  903. }
  904. }
  905. void ResetParamDefault(void)
  906. {
  907. device_status.clt_time = 20; //收集时间
  908. device_status.dattim = 20; //数据上传间隔
  909. device_status.startBar = 20; //定时开始时间
  910. device_status.stopBar = 5; //定时结束时间
  911. device_status.heattime = 20; //加热时间
  912. device_status.shake_ws = 1; //针对开关
  913. device_status.shake_sec = 1; //震动时间1-100ms
  914. device_status.sunBar = 8; //光控定时时长
  915. device_status.tph = 70; //高温保护阈值
  916. device_status.tpl = 5; //低温保护阈值
  917. device_status.timeSwitch = 0; //定时模式
  918. device_status.heatvalue=110;//加热温度
  919. device_status.ds = 1; //设备状态开机
  920. device_status.thsp = 300;
  921. device_status.passWord = 8888;
  922. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  923. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  924. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  925. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  926. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  927. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  928. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  929. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  930. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  931. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  932. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  933. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  934. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  935. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  936. DTU_Write("reset.mp3");
  937. }
  938. void ResetParamDefault_DC(void)
  939. {
  940. device_status.clt_time = 20; //收集时间
  941. device_status.dattim = 20; //数据上传间隔
  942. device_status.startBar = 20; //定时开始时间
  943. device_status.stopBar = 0; //定时结束时间
  944. device_status.heattime = 20; //加热时间
  945. device_status.shake_ws = 1; //针对开关
  946. device_status.shake_sec = 1; //震动时间1-100ms
  947. device_status.sunBar = 4; //光控定时时长
  948. device_status.tph = 70; //高温保护阈值
  949. device_status.tpl = 5; //低温保护阈值
  950. device_status.timeSwitch = 0; //定时模式
  951. device_status.heatvalue=110;
  952. device_status.ds = 1; //设备状态开机
  953. device_status.thsp = 300;
  954. device_status.passWord = 8888;
  955. device_status.timeSwitch = 0;
  956. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  957. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  958. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  959. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  960. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  961. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  962. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  963. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  964. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  965. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  966. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  967. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  968. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  969. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  970. DTU_Write("reset.mp3");
  971. }
  972. //固件备份
  973. void app_partion_backup(void)
  974. {
  975. rt_kprintf("固件恢复!!!\n");
  976. const char *dst_part_name = "df_area";
  977. const char *src_part_name = "app";
  978. const struct fal_partition *dst_part;
  979. const struct fal_partition *src_part;
  980. dst_part = fal_partition_find(dst_part_name);
  981. src_part = fal_partition_find(src_part_name);
  982. if (dst_part == RT_NULL || src_part == RT_NULL)
  983. {
  984. if (dst_part == RT_NULL)
  985. rt_kprintf("%s partition is not exist!\n", dst_part_name);
  986. if (src_part == RT_NULL)
  987. rt_kprintf("%s partition is not exist!\n", src_part_name);
  988. }
  989. else
  990. {
  991. rt_kprintf("Clone %s partition to %s partition:\n", src_part_name, dst_part_name);
  992. if (fal_partition_erase(dst_part, 0, dst_part->len) >= 0)
  993. {
  994. int clone_pos = 0;
  995. int clone_len = 0, clone_tol_len;
  996. rt_uint8_t *buf = rt_malloc(4096);
  997. if (dst_part->len < src_part->len)
  998. clone_tol_len = dst_part->len;
  999. else
  1000. clone_tol_len = src_part->len;
  1001. while ((clone_pos < clone_tol_len) && (buf != RT_NULL))
  1002. {
  1003. clone_len = fal_partition_read(src_part, clone_pos, buf, 4096);
  1004. if (clone_len < 0)
  1005. {
  1006. rt_kprintf("\nread %s partition failed, clone stop!\n", src_part_name);
  1007. break;
  1008. }
  1009. if (fal_partition_write(dst_part, clone_pos, buf, clone_len) < 0)
  1010. {
  1011. rt_kprintf("\nwrite %s partition failed, clone stop!\n", dst_part_name);
  1012. break;
  1013. }
  1014. HMI_WRITE("#");
  1015. rt_kprintf("#");
  1016. clone_pos += clone_len;
  1017. }
  1018. if (clone_pos >= clone_tol_len)
  1019. {
  1020. rt_kprintf("\nClone partition success, total %d bytes!\n", clone_tol_len);
  1021. }
  1022. else
  1023. {
  1024. rt_kprintf("Clone partition failed!");
  1025. }
  1026. if (buf)
  1027. rt_free(buf);
  1028. }
  1029. }
  1030. }
  1031. void Debug_log_ON(void)
  1032. {
  1033. rt_console_set_device("uart4");
  1034. finsh_set_device("uart4");
  1035. }
  1036. void Debug_log_OFF(void)
  1037. {
  1038. rt_console_set_device("uart1");
  1039. finsh_set_device("uart1");
  1040. rt_mq_init(&rx_mq, "rx_mq",
  1041. msg_pool, /* 存放消息的缓冲区 */
  1042. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  1043. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  1044. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  1045. rt_device_set_rx_indicate(serial, uart_input);
  1046. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  1047. Hmi_thread_entry,
  1048. RT_NULL,
  1049. HMI_THREAD_STACK_SIZE,
  1050. HMI_THREAD_PRIORITY,
  1051. HMI_THREAD_TIMESLICE);
  1052. if (hmi1 != RT_NULL)
  1053. {
  1054. rt_thread_startup(hmi1);
  1055. }
  1056. }
  1057. MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
  1058. MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
  1059. //
  1060. INIT_BOARD_EXPORT(HMI_uart4_init);