hmi.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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.heat_time_min);
  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. ctr_cangmen_up(OFF);
  326. device_status.ctr_up_motor = 1;
  327. }
  328. //关闭上仓门
  329. else if(strstr(rx_buffer,"putTest.switchUp=0")!=NULL){
  330. rt_kprintf("CLOSE UP!\n");
  331. ctr_cangmen_up(OFF);
  332. device_status.ctr_up_motor = 2;
  333. }
  334. //打开下仓门
  335. else if(strstr(rx_buffer,"putTest.switchDown=1")!=NULL){
  336. ctr_cangmen_down(OFF);
  337. device_status.ctr_down_motor = 1;
  338. rt_kprintf("Open down!\n");
  339. }
  340. //关闭下仓门
  341. else if(strstr(rx_buffer,"putTest.switchDown=0")!=NULL){
  342. ctr_cangmen_down(OFF);
  343. device_status.ctr_down_motor = 2;
  344. rt_kprintf("CLOSE down!\n");
  345. }
  346. //定时设置
  347. else if (strstr(rx_buffer,"saveClockSet=")!=NULL) {
  348. char sun_str[3],start_str[3],stop_str[3],timeswitch_str[3];
  349. rt_kprintf("时间设置!\n");
  350. var=strstr(rx_buffer,"=");
  351. var++;
  352. strncpy(sun_str,var,2);
  353. if(atoi(sun_str) > 0 && atoi(sun_str) <12)
  354. {
  355. device_status.sunBar=atoi(sun_str);
  356. time_t now;
  357. time(&now);
  358. static struct tm nowstamp;
  359. nowstamp =*localtime(&now);
  360. nowstamp.tm_hour = nowstamp.tm_hour - 8;
  361. static rt_uint32_t nowstamp_num = 0;
  362. nowstamp_num = mktime(&nowstamp);
  363. device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
  364. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  365. }
  366. else {
  367. rt_kprintf("参数设置异常!!!");
  368. }
  369. //时控开始时间
  370. strncpy(start_str,var+2,2);
  371. if(atoi(start_str) >= 0 && atoi(start_str) < 24)
  372. {
  373. device_status.startBar=atoi(start_str);
  374. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  375. }
  376. else {
  377. rt_kprintf("参数设置异常!!!");
  378. }
  379. //
  380. strncpy(stop_str,var+4,2);
  381. if(atoi(stop_str) >= 0&& atoi(stop_str) < 24)
  382. {
  383. device_status.stopBar=atoi(stop_str);
  384. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  385. }
  386. else {
  387. rt_kprintf("参数设置异常!!!");
  388. }
  389. //
  390. strncpy(timeswitch_str,var+6,2);
  391. if(atoi(timeswitch_str) >= 0 && atoi(timeswitch_str) <= 1)
  392. {
  393. device_status.timeSwitch=atoi(timeswitch_str);
  394. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  395. }
  396. else {
  397. rt_kprintf("参数设置异常!!!");
  398. }
  399. MA_save();
  400. rt_kprintf("工作时间参数已保存:模式-%d,光控时间-%d,时控开始时间-%d,时控结束时间-%d\n",device_status.timeSwitch,device_status.sunBar,device_status.startBar,device_status.stopBar);
  401. }
  402. else if (strstr(rx_buffer,"saveSystemSet")!=NULL) {
  403. char clt_time_str[3],heattime_str[3],heatvale_str[4],vol_str[4],thsp_str[5];
  404. rt_kprintf("系统设置!\n");
  405. var = strstr(rx_buffer,"=");
  406. var ++;
  407. strncpy(clt_time_str,var,2);
  408. if(atoi(clt_time_str)>0 && atoi(clt_time_str) <= 30)
  409. {
  410. device_status.clt_time = atoi(clt_time_str); //收集时间
  411. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  412. }
  413. strncpy(heattime_str,var+2,2);
  414. if(atoi(heattime_str)>0 && atoi(heattime_str) <= 30)
  415. {
  416. rt_kprintf("加热时间:%d\n",atoi(heattime_str));
  417. device_status.heattime = atoi(heattime_str); //加热时间
  418. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  419. }
  420. strncpy(heatvale_str,var+4,3);
  421. if(atoi(heatvale_str) > 0 && atoi(heatvale_str) <= 130)
  422. {
  423. device_status.heatvalue=atoi(heatvale_str);
  424. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  425. }
  426. strncpy(vol_str,var+7,3);
  427. if(atoi(vol_str)>0&&atoi(vol_str)<8)
  428. {
  429. device_status.vol = atoi(vol_str); //音量
  430. DTU_Write("volume=");
  431. }
  432. strncpy(thsp_str,var+10,4);
  433. if(atoi(thsp_str)>0&&atoi(thsp_str)<3600)
  434. {
  435. device_status.thsp = atoi(thsp_str); //熄屏时间
  436. }
  437. else {
  438. rt_kprintf("参数设置失败!!!\n");
  439. }
  440. MA_save();
  441. rt_kprintf("系统设置已保存:收集时间-%d,加热时间-%d,加热温度-%d,音量-%d,自动关屏-%d\n",device_status.clt_time,device_status.heattime,device_status.heatvalue,device_status.vol,device_status.thsp);
  442. }
  443. else if (strstr(rx_buffer,"rtc_h=")!=NULL) {
  444. char rtc_h[2];
  445. var = strstr(rx_buffer,"=");
  446. var++;
  447. strncpy(rtc_h,var,2);
  448. if(atoi(rtc_h)>=0 && atoi(rtc_h) <= 24)
  449. {
  450. set_time(atoi(rtc_h), 99, 99);
  451. }
  452. }
  453. else if (strstr(rx_buffer,"rtc_m=")!=NULL) {
  454. char rtc_m[2];
  455. var = strstr(rx_buffer,"=");
  456. var++;
  457. strncpy(rtc_m,var,2);
  458. if(atoi(rtc_m)>=0 && atoi(rtc_m) <= 24)
  459. {
  460. set_time(99, atoi(rtc_m), 99);
  461. }
  462. }
  463. else if (strstr(rx_buffer,"rtc_s=")!=NULL) {
  464. char rtc_s[2];
  465. var = strstr(rx_buffer,"=");
  466. var++;
  467. strncpy(rtc_s,var,2);
  468. if(atoi(rtc_s)>=0 && atoi(rtc_s) <= 24)
  469. {
  470. set_time(99, 99, atoi(rtc_s));
  471. }
  472. }
  473. else if(strstr(rx_buffer,"saveUploadSet=")!=NULL)
  474. {
  475. static char dattim_str[3];
  476. rt_kprintf("上传间隔设置!\n");
  477. var = strstr(rx_buffer,"=");
  478. var ++;
  479. strncpy(dattim_str,var,2);
  480. if(atoi(dattim_str)>=1&&atoi(dattim_str)<=120)
  481. {
  482. device_status.dattim =atoi(dattim_str); //数据上传间隔
  483. MA_save();
  484. }
  485. else {
  486. rt_kprintf("设置失败!!!\n");
  487. }
  488. rt_kprintf("数据上传设置:%d\n",device_status.dattim);
  489. }
  490. //光控测试
  491. else if(strstr(rx_buffer,"putTest.switchSun=1")!=NULL)
  492. {
  493. rt_kprintf("光控测试!!!");
  494. ctr_lamp(ON);
  495. device_status.sun_test = 1;
  496. }
  497. //恢复出厂设置电池
  498. else if (strstr(rx_buffer,"resetdcDefault")!=NULL)
  499. {
  500. ResetParamDefault_DC();
  501. MA_save();
  502. }
  503. //恢复出厂设置-交流
  504. else if (strstr(rx_buffer,"resetDefault")!=NULL)
  505. {
  506. ResetParamDefault();
  507. MA_save();
  508. }
  509. //获取SIM卡信息
  510. else if(strstr(rx_buffer,"getSim")!=NULL)
  511. {
  512. //http://sim.openluat.com/api/wechat/openapidoc
  513. DTU_Write("getsiminfo");
  514. }
  515. else if (strstr(rx_buffer,"DebugEnable")!=NULL) {
  516. Debug_log_ON();
  517. }
  518. else if (strstr(rx_buffer,"DebugDisable")!=NULL) {
  519. Debug_log_OFF();
  520. }
  521. else if (strstr(rx_buffer,"SwversionV1")!=NULL)
  522. {
  523. device_status.version_type = 1;
  524. sprintf(device_status.driver, "%s",VERSION_ZP);
  525. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  526. MA_save();
  527. }
  528. else if (strstr(rx_buffer,"SwversionV1")!=NULL) {
  529. device_status.version_type = 4;
  530. sprintf(device_status.driver, "%s",VERSION_HK);
  531. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  532. MA_save();
  533. }
  534. else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
  535. {
  536. HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
  537. }
  538. else if (strstr(rx_buffer,"checkupdate")!=NULL)
  539. {
  540. time_t now = time(RT_NULL);
  541. static struct tm tm;
  542. gmtime_r(&now, &tm);
  543. 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);
  544. HMI_WRITE("hardcheck.p0.pic=%d",70);
  545. //RTC时间判断,如果当前年份小于2020,提示需要设置时间
  546. if(tm.tm_year+1900<2020)
  547. {
  548. 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);
  549. 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);
  550. }
  551. }
  552. //进入bootloader模式
  553. else if (strstr(rx_buffer,"bootloader")!=NULL) {
  554. device_status.stop_in_bootloader = 1;
  555. ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
  556. rt_hw_cpu_reset();
  557. }
  558. //软件重启
  559. else if (strstr(rx_buffer,"reboot")!=NULL) {
  560. rt_hw_cpu_reset();
  561. }
  562. }
  563. //入口函数-电机控制及
  564. static void Ctr_Mortor_entry(void* parameter)
  565. {
  566. rt_uint32_t limit_current = 3000; //推杆电击限制电流1A
  567. static rt_uint16_t num_up_open = 200; //20s
  568. static rt_uint16_t num_up_close = 200; //
  569. static rt_uint16_t num_down_open = 200; //
  570. static rt_uint16_t num_down_close = 200; //
  571. static rt_uint16_t photo_led_sec = 450; //45S
  572. while(1)
  573. {
  574. time_t time_reset12V;
  575. time(&time_reset12V);
  576. static struct tm alarm_reset12V;
  577. alarm_reset12V =*localtime(&time_reset12V);
  578. if((alarm_reset12V.tm_hour)==5&&(alarm_reset12V.tm_min==59)&&(alarm_reset12V.tm_sec==55))
  579. {
  580. ctr_RTU_DTU(OFF);
  581. rt_thread_delay(1000*10);
  582. ctr_RTU_DTU(ON);
  583. }
  584. if(device_status.ctr_up_motor==1)
  585. {
  586. //打开上仓门
  587. ctr_cangmen_up(OPEN);
  588. num_up_open--;
  589. //如果未工作且上仓门电机电流大于1A,立即停止,记录到Flash,上报预警
  590. if(atoi(device_status.power)>limit_current)
  591. {
  592. ctr_cangmen_up(OFF);
  593. num_up_open = 200;
  594. rt_kprintf("*************************上仓门电机打开堵转!!!**********************%d\n",atoi(device_status.power));
  595. }
  596. if (num_up_open == 0)
  597. {
  598. ctr_cangmen_up(OFF);
  599. num_up_open = 200;
  600. }
  601. }
  602. else if(device_status.ctr_up_motor==2)
  603. {
  604. ctr_cangmen_up(CLOSE);
  605. num_up_close --;
  606. if(atoi(device_status.power)>limit_current)
  607. {
  608. ctr_cangmen_up(OFF);
  609. num_up_close = 200;
  610. rt_kprintf("************************上仓门电机关闭堵转!!!**********************%d\n",atoi(device_status.power));
  611. }
  612. if (num_up_close == 0)
  613. {
  614. ctr_cangmen_up(OFF);
  615. num_up_close= 200;
  616. }
  617. }
  618. if (device_status.ctr_down_motor == 1)
  619. {
  620. ctr_cangmen_down(OPEN);
  621. num_down_open--;
  622. if(atoi(device_status.power)>limit_current)
  623. {
  624. ctr_cangmen_down(OFF);
  625. num_down_open = 200;
  626. rt_kprintf("*************************下仓门电机打开堵转!!!**********************%d\n",atoi(device_status.power));
  627. }
  628. if (num_down_open == 0)
  629. {
  630. ctr_cangmen_down(OFF);
  631. num_down_open = 200;
  632. }
  633. }
  634. else if (device_status.ctr_down_motor == 2)
  635. {
  636. ctr_cangmen_down(CLOSE);
  637. num_down_close--;
  638. if(atoi(device_status.power)>limit_current)
  639. {
  640. ctr_cangmen_down(OFF);
  641. num_down_close = 200;
  642. rt_kprintf("*************************下仓门电机关闭堵转!!!**********************%d\n",atoi(device_status.power));
  643. }
  644. if (num_down_close == 0)
  645. {
  646. ctr_cangmen_down(OFF);
  647. num_down_close = 200;
  648. }
  649. }
  650. if(device_status.clear_status==1)
  651. {
  652. device_status.clear_status = 0;
  653. if(ctr_clear(650)==0)
  654. ctr_TG_Clear(350);
  655. }
  656. if(device_status.sun_test==1)
  657. {
  658. SunTest();
  659. }
  660. if(device_status.photo_ws==1)
  661. {
  662. //打开补光灯
  663. if(photo_led_sec==100)
  664. {
  665. ctr_led(ON);
  666. DTU_Write("takephoto.mp3");
  667. //延时
  668. rt_thread_delay(1000);
  669. rt_kprintf("\n测试拍照!\n");
  670. Hk_Take_io();
  671. }
  672. photo_led_sec--;
  673. if(photo_led_sec==0)
  674. {
  675. ctr_led(OFF);
  676. photo_led_sec = 100;
  677. device_status.photo_ws = 0;
  678. HMI_WRITE("sysTest.switchPhoto.val=0");
  679. HMI_WRITE("sysTest.switchFill.val=0");
  680. }
  681. }
  682. rt_thread_delay(100);
  683. //rt_kprintf("action num is:%d%d%d",num_up_open,num_up_close,num_down_open,num_down_close,num_clear);
  684. }
  685. }
  686. /*屏幕写数据*/
  687. int Hmi_Fresh(void)
  688. {
  689. //初始化串口4
  690. rt_err_t ret = RT_EOK;
  691. /* 初始化消息队列 */
  692. rt_mq_init(&rx_mq, "rx_mq",
  693. msg_pool, /* 存放消息的缓冲区 */
  694. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  695. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  696. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  697. /* 设置接收回调函数 */
  698. rt_device_set_rx_indicate(serial, uart_input);
  699. /* 创建线程*/
  700. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  701. Hmi_thread_entry,
  702. RT_NULL,
  703. HMI_THREAD_STACK_SIZE,
  704. HMI_THREAD_PRIORITY,
  705. HMI_THREAD_TIMESLICE);
  706. /*打开上仓门的线程*/
  707. ctr_motor = rt_thread_create("Ctr motor",
  708. Ctr_Mortor_entry,
  709. RT_NULL,
  710. CONTROL_MOTOR_STACK_SIZE,
  711. CONTROL_MOTOR_PRIORITY,
  712. CONTROL_MOTOR_TIMESLICE);
  713. if(ctr_motor != RT_NULL)
  714. {
  715. rt_thread_startup(ctr_motor);
  716. }
  717. /* 如果获得线程控制块,启动这个线程 */
  718. if (hmi1 != RT_NULL)
  719. {
  720. rt_thread_startup(hmi1);
  721. }
  722. else
  723. {
  724. ret = RT_ERROR;
  725. }
  726. return ret;
  727. }
  728. void Check_ParamConfig(void)
  729. {
  730. time_t now = time(RT_NULL);
  731. static struct tm tm;
  732. gmtime_r(&now, &tm);
  733. if(easyflash_init()==EF_NO_ERR) //初始化成功
  734. {
  735. ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
  736. ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
  737. ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
  738. device_status.rebootcnt++;
  739. ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
  740. rt_kprintf("REBOOT_TIME:%d-%d-%d\n",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
  741. }
  742. else {
  743. rt_kprintf("easyflash init ERRPR!!!\n");
  744. }
  745. //保存默认屏幕配置
  746. if(device_status.iSave!=FLASH_FLAG)
  747. {
  748. device_status.iSave=FLASH_FLAG;
  749. device_status.clt_time = 10; //收集时间
  750. device_status.heattime = 10; //加热时间
  751. device_status.heatvalue=100;//加热温度
  752. device_status.thsp = 300; //默认熄屏时间5分钟
  753. device_status.sunBar = 8; //光控定时时长
  754. device_status.startBar = 20; //定时开始时间
  755. device_status.stopBar = 0; //定时结束时间
  756. device_status.tph = 70; //高温保护阈值
  757. device_status.tpl = 5; //低温保护阈值
  758. device_status.shake_ws = 1; //震动开关,默认开
  759. device_status.shake_sec = 1; //震动时间,s
  760. device_status.vol = 7; //音量
  761. device_status.timeSwitch = 1; //工作模式
  762. device_status.passWord = 8888; //屏幕密码
  763. device_status.dattim = 20; //数据上传间隔
  764. device_status.ds = 1; //设备状态
  765. device_status.version_type = 4; //版本类型
  766. device_status.update_flag = 0;
  767. ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
  768. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  769. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  770. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  771. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  772. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  773. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  774. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  775. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  776. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  777. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  778. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  779. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  780. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  781. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  782. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  783. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  784. if(device_status.version_type==1)
  785. {
  786. sprintf(device_status.driver, "%s",VERSION_ZP);
  787. }
  788. else if (device_status.version_type==4) {
  789. sprintf(device_status.driver, "%s",VERSION_HK);
  790. }
  791. rt_kprintf("SOFTWARE VERSION:%s\n",device_status.driver);
  792. rt_kprintf("set flash paramconfis:\n");
  793. rt_kprintf("stime:%d\n",device_status.iSave);
  794. rt_kprintf("stime:%d\n",device_status.clt_time);
  795. rt_kprintf("startBar:%d\n",device_status.startBar);
  796. rt_kprintf("stopBar:%d\n",device_status.stopBar);
  797. rt_kprintf("timeSwitch:%d\n",device_status.timeSwitch);
  798. rt_kprintf("sunBar:%d\n",device_status.sunBar);
  799. rt_kprintf("jtime:%d\n",device_status.heattime);
  800. rt_kprintf("jheat:%d\n",device_status.heatvalue);
  801. rt_kprintf("thsp:%d\n", device_status.thsp);
  802. rt_kprintf("密码:%d\n",device_status.passWord);
  803. }//从easyflash读取参数配置
  804. else if (device_status.iSave==FLASH_FLAG) {
  805. ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
  806. ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
  807. ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
  808. ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
  809. ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
  810. ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
  811. ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
  812. ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
  813. ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
  814. ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
  815. ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
  816. ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
  817. ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
  818. ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
  819. ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
  820. ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
  821. ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
  822. ef_get_env_blob("ds",&device_status.ds,
  823. sizeof(device_status.ds),NULL); //开关机状态
  824. ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
  825. ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
  826. ef_get_env_blob("driver_compile",&device_status.driver_compile,sizeof(device_status.driver_compile),NULL); //BL版本号 进BL的时候存储到FLASH
  827. device_status.light_over_tim = device_status.sunBar * 3600; //光控计数
  828. device_status.work_done = 0;
  829. //工作完成标志位
  830. if(device_status.dattim==0)
  831. {
  832. device_status.dattim = 20;
  833. }
  834. if(device_status.version_type==0)
  835. {
  836. app_partion_backup(); //固件备份至df_area
  837. device_status.version_type = 4;
  838. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
  839. }
  840. if(device_status.version_type==1)
  841. {
  842. rt_sprintf(device_status.driver, "%s",VERSION_ZP);
  843. }
  844. else if (device_status.version_type==4) {
  845. rt_sprintf(device_status.driver, "%s",VERSION_HK);
  846. }
  847. rt_kprintf("SOFTWARE VERSION:%s-imei:%s--iccid:%s\n",device_status.driver,device_status.imei,device_status.iccid);
  848. rt_kprintf("read flash paramconfis:%d-%s-%s\r\n",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
  849. rt_kprintf("开机次数:%d\n",device_status.rebootcnt);
  850. rt_kprintf("收集时间:%d\n",device_status.clt_time);
  851. rt_kprintf("定时开始时间:%d\n",device_status.startBar);
  852. rt_kprintf("定时结束时间:%d\n",device_status.stopBar);
  853. rt_kprintf("timeSwitch:%d\n",device_status.timeSwitch);
  854. rt_kprintf("光控定时时长:%d\n",device_status.sunBar);
  855. rt_kprintf("收集时间:%d\n",device_status.heattime);
  856. rt_kprintf("加热温度:%d\n",device_status.heatvalue);
  857. rt_kprintf("震动开关:%d\n",device_status.shake_ws);
  858. rt_kprintf("震动时间:%d\n",device_status.shake_sec);
  859. rt_kprintf("高温保护:%d\n",device_status.tph);
  860. rt_kprintf("低温保护:%d\n",device_status.tpl);
  861. rt_kprintf("thsp:%d\n", device_status.thsp);
  862. rt_kprintf("密码:%d\n",device_status.passWord);
  863. rt_kprintf("数据上传间隔:%d\n",device_status.dattim);
  864. }
  865. 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);
  866. //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
  867. if(device_status.update_flag==1)
  868. {
  869. device_status.update_flag = 0;
  870. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  871. ymodem_ota(1,0);
  872. }
  873. else {
  874. device_status.update_flag = 0;
  875. //初始化联网状态
  876. rt_sprintf(device_status.net,"1");
  877. rt_sprintf(device_status.csq,"0");
  878. rt_sprintf(device_status.sim,"1");
  879. ctr_router(ON);
  880. Hmi_Fresh();
  881. dtu_data_play();
  882. sht30_collect();
  883. mb_master_samlpe();
  884. uint16_t connect_num=0;
  885. //等待联网,
  886. while(atoi(device_status.net)==1)
  887. {
  888. char *readinfo = makeJson_ReadInfo();
  889. DTU_Write("%s",readinfo);
  890. rt_free(readinfo);
  891. rt_thread_delay(1000);
  892. connect_num++;
  893. rt_kprintf("联网中......%d\n",connect_num);
  894. //超时时间为3分钟
  895. if(connect_num==30)
  896. {
  897. device_status.timeSwitch = 0;
  898. //保存光控变量
  899. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  900. 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);
  901. set_date(2020, 1, 1);
  902. set_time(0, 0, 0);
  903. break;
  904. }
  905. if(tm.tm_year>=2021)
  906. break;
  907. }
  908. DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
  909. }
  910. }
  911. void ResetParamDefault(void)
  912. {
  913. device_status.clt_time = 20; //收集时间
  914. device_status.dattim = 20; //数据上传间隔
  915. device_status.startBar = 20; //定时开始时间
  916. device_status.stopBar = 5; //定时结束时间
  917. device_status.heattime = 20; //加热时间
  918. device_status.shake_ws = 1; //针对开关
  919. device_status.shake_sec = 1; //震动时间1-100ms
  920. device_status.sunBar = 8; //光控定时时长
  921. device_status.tph = 70; //高温保护阈值
  922. device_status.tpl = 5; //低温保护阈值
  923. device_status.timeSwitch = 0; //定时模式
  924. device_status.heatvalue=110;//加热温度
  925. device_status.ds = 1; //设备状态开机
  926. device_status.thsp = 300;
  927. device_status.passWord = 8888;
  928. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  929. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  930. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  931. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  932. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  933. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  934. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  935. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  936. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  937. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  938. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  939. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  940. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  941. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  942. DTU_Write("reset.mp3");
  943. }
  944. void ResetParamDefault_DC(void)
  945. {
  946. device_status.clt_time = 20; //收集时间
  947. device_status.dattim = 20; //数据上传间隔
  948. device_status.startBar = 20; //定时开始时间
  949. device_status.stopBar = 0; //定时结束时间
  950. device_status.heattime = 20; //加热时间
  951. device_status.shake_ws = 1; //针对开关
  952. device_status.shake_sec = 1; //震动时间1-100ms
  953. device_status.sunBar = 4; //光控定时时长
  954. device_status.tph = 70; //高温保护阈值
  955. device_status.tpl = 5; //低温保护阈值
  956. device_status.timeSwitch = 0; //定时模式
  957. device_status.heatvalue=110;
  958. device_status.ds = 1; //设备状态开机
  959. device_status.thsp = 300;
  960. device_status.passWord = 8888;
  961. device_status.timeSwitch = 0;
  962. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  963. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  964. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  965. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  966. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  967. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  968. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  969. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  970. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  971. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  972. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  973. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  974. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  975. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  976. DTU_Write("reset.mp3");
  977. }
  978. //固件备份
  979. void app_partion_backup(void)
  980. {
  981. rt_kprintf("固件恢复!!!\n");
  982. const char *dst_part_name = "df_area";
  983. const char *src_part_name = "app";
  984. const struct fal_partition *dst_part;
  985. const struct fal_partition *src_part;
  986. dst_part = fal_partition_find(dst_part_name);
  987. src_part = fal_partition_find(src_part_name);
  988. if (dst_part == RT_NULL || src_part == RT_NULL)
  989. {
  990. if (dst_part == RT_NULL)
  991. rt_kprintf("%s partition is not exist!\n", dst_part_name);
  992. if (src_part == RT_NULL)
  993. rt_kprintf("%s partition is not exist!\n", src_part_name);
  994. }
  995. else
  996. {
  997. rt_kprintf("Clone %s partition to %s partition:\n", src_part_name, dst_part_name);
  998. if (fal_partition_erase(dst_part, 0, dst_part->len) >= 0)
  999. {
  1000. int clone_pos = 0;
  1001. int clone_len = 0, clone_tol_len;
  1002. rt_uint8_t *buf = rt_malloc(4096);
  1003. if (dst_part->len < src_part->len)
  1004. clone_tol_len = dst_part->len;
  1005. else
  1006. clone_tol_len = src_part->len;
  1007. while ((clone_pos < clone_tol_len) && (buf != RT_NULL))
  1008. {
  1009. clone_len = fal_partition_read(src_part, clone_pos, buf, 4096);
  1010. if (clone_len < 0)
  1011. {
  1012. rt_kprintf("\nread %s partition failed, clone stop!\n", src_part_name);
  1013. break;
  1014. }
  1015. if (fal_partition_write(dst_part, clone_pos, buf, clone_len) < 0)
  1016. {
  1017. rt_kprintf("\nwrite %s partition failed, clone stop!\n", dst_part_name);
  1018. break;
  1019. }
  1020. HMI_WRITE("#");
  1021. rt_kprintf("#");
  1022. clone_pos += clone_len;
  1023. }
  1024. if (clone_pos >= clone_tol_len)
  1025. {
  1026. rt_kprintf("\nClone partition success, total %d bytes!\n", clone_tol_len);
  1027. }
  1028. else
  1029. {
  1030. rt_kprintf("Clone partition failed!");
  1031. }
  1032. if (buf)
  1033. rt_free(buf);
  1034. }
  1035. }
  1036. }
  1037. void Debug_log_ON(void)
  1038. {
  1039. rt_console_set_device("uart4");
  1040. finsh_set_device("uart4");
  1041. }
  1042. void Debug_log_OFF(void)
  1043. {
  1044. rt_console_set_device("uart1");
  1045. finsh_set_device("uart1");
  1046. rt_mq_init(&rx_mq, "rx_mq",
  1047. msg_pool, /* 存放消息的缓冲区 */
  1048. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  1049. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  1050. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  1051. rt_device_set_rx_indicate(serial, uart_input);
  1052. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  1053. Hmi_thread_entry,
  1054. RT_NULL,
  1055. HMI_THREAD_STACK_SIZE,
  1056. HMI_THREAD_PRIORITY,
  1057. HMI_THREAD_TIMESLICE);
  1058. if (hmi1 != RT_NULL)
  1059. {
  1060. rt_thread_startup(hmi1);
  1061. }
  1062. }
  1063. MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
  1064. MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
  1065. //
  1066. INIT_BOARD_EXPORT(HMI_uart4_init);