hmi.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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)
  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. if(device_status.ctr_up_motor==1)
  571. {
  572. //打开上仓门
  573. ctr_cangmen_up(OPEN);
  574. num_up_open--;
  575. //如果未工作且上仓门电机电流大于1A,立即停止,记录到Flash,上报预警
  576. if(atoi(device_status.power)>limit_current)
  577. {
  578. ctr_cangmen_up(OFF);
  579. num_up_open = 200;
  580. rt_kprintf("*************************上仓门电机打开堵转!!!**********************%d\n",atoi(device_status.power));
  581. }
  582. if (num_up_open == 0)
  583. {
  584. ctr_cangmen_up(OFF);
  585. num_up_open = 200;
  586. }
  587. }
  588. else if(device_status.ctr_up_motor==2)
  589. {
  590. ctr_cangmen_up(CLOSE);
  591. num_up_close --;
  592. if(atoi(device_status.power)>limit_current)
  593. {
  594. ctr_cangmen_up(OFF);
  595. num_up_close = 200;
  596. rt_kprintf("************************上仓门电机关闭堵转!!!**********************%d\n",atoi(device_status.power));
  597. }
  598. if (num_up_close == 0)
  599. {
  600. ctr_cangmen_up(OFF);
  601. num_up_close= 200;
  602. }
  603. }
  604. if (device_status.ctr_down_motor == 1)
  605. {
  606. ctr_cangmen_down(OPEN);
  607. num_down_open--;
  608. if(atoi(device_status.power)>limit_current)
  609. {
  610. ctr_cangmen_down(OFF);
  611. num_down_open = 200;
  612. rt_kprintf("*************************下仓门电机打开堵转!!!**********************%d\n",atoi(device_status.power));
  613. }
  614. if (num_down_open == 0)
  615. {
  616. ctr_cangmen_down(OFF);
  617. num_down_open = 200;
  618. }
  619. }
  620. else if (device_status.ctr_down_motor == 2)
  621. {
  622. ctr_cangmen_down(CLOSE);
  623. num_down_close--;
  624. if(atoi(device_status.power)>limit_current)
  625. {
  626. ctr_cangmen_down(OFF);
  627. num_down_close = 200;
  628. rt_kprintf("*************************下仓门电机关闭堵转!!!**********************%d\n",atoi(device_status.power));
  629. }
  630. if (num_down_close == 0)
  631. {
  632. ctr_cangmen_down(OFF);
  633. num_down_close = 200;
  634. }
  635. }
  636. if(device_status.clear_status==1)
  637. {
  638. device_status.clear_status = 0;
  639. if(ctr_clear(650)==0)
  640. ctr_TG_Clear(250);
  641. }
  642. if(device_status.sun_test==1)
  643. {
  644. SunTest();
  645. }
  646. if(device_status.photo_ws==1)
  647. {
  648. //打开补光灯
  649. if(photo_led_sec==100)
  650. {
  651. ctr_led(ON);
  652. DTU_Write("takephoto.mp3");
  653. //延时
  654. rt_thread_delay(1000);
  655. rt_kprintf("\n测试拍照!\n");
  656. Hk_Take_io();
  657. }
  658. photo_led_sec--;
  659. if(photo_led_sec==0)
  660. {
  661. ctr_led(OFF);
  662. photo_led_sec = 100;
  663. device_status.photo_ws = 0;
  664. HMI_WRITE("sysTest.switchPhoto.val=0");
  665. HMI_WRITE("sysTest.switchFill.val=0");
  666. }
  667. }
  668. rt_thread_delay(100);
  669. //rt_kprintf("action num is:%d%d%d",num_up_open,num_up_close,num_down_open,num_down_close,num_clear);
  670. }
  671. }
  672. /*屏幕写数据*/
  673. int Hmi_Fresh(void)
  674. {
  675. //初始化串口4
  676. rt_err_t ret = RT_EOK;
  677. /* 初始化消息队列 */
  678. rt_mq_init(&rx_mq, "rx_mq",
  679. msg_pool, /* 存放消息的缓冲区 */
  680. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  681. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  682. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  683. /* 设置接收回调函数 */
  684. rt_device_set_rx_indicate(serial, uart_input);
  685. /* 创建线程*/
  686. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  687. Hmi_thread_entry,
  688. RT_NULL,
  689. HMI_THREAD_STACK_SIZE,
  690. HMI_THREAD_PRIORITY,
  691. HMI_THREAD_TIMESLICE);
  692. /*打开上仓门的线程*/
  693. ctr_motor = rt_thread_create("Ctr motor",
  694. Ctr_Mortor_entry,
  695. RT_NULL,
  696. CONTROL_MOTOR_STACK_SIZE,
  697. CONTROL_MOTOR_PRIORITY,
  698. CONTROL_MOTOR_TIMESLICE);
  699. if(ctr_motor != RT_NULL)
  700. {
  701. rt_thread_startup(ctr_motor);
  702. }
  703. /* 如果获得线程控制块,启动这个线程 */
  704. if (hmi1 != RT_NULL)
  705. {
  706. rt_thread_startup(hmi1);
  707. }
  708. else
  709. {
  710. ret = RT_ERROR;
  711. }
  712. return ret;
  713. }
  714. void Check_ParamConfig(void)
  715. {
  716. time_t now = time(RT_NULL);
  717. static struct tm tm;
  718. gmtime_r(&now, &tm);
  719. if(easyflash_init()==EF_NO_ERR) //初始化成功
  720. {
  721. ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
  722. ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
  723. ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
  724. device_status.rebootcnt++;
  725. ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
  726. rt_kprintf("REBOOT_TIME:%d-%d-%d\n",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
  727. }
  728. else {
  729. rt_kprintf("easyflash init ERRPR!!!\n");
  730. }
  731. //保存默认屏幕配置
  732. if(device_status.iSave!=FLASH_FLAG)
  733. {
  734. device_status.iSave=FLASH_FLAG;
  735. device_status.clt_time = 20; //收集时间
  736. device_status.heattime = 20; //加热时间
  737. device_status.heatvalue=100;//加热温度
  738. device_status.thsp = 300; //默认熄屏时间5分钟
  739. device_status.sunBar = 8; //光控定时时长
  740. device_status.startBar = 20; //定时开始时间
  741. device_status.stopBar = 5; //定时结束时间
  742. device_status.tph = 70; //高温保护阈值
  743. device_status.tpl = 5; //低温保护阈值
  744. device_status.shake_ws = 1; //震动开关,默认开
  745. device_status.shake_sec = 1; //震动时间,s
  746. device_status.vol = 7; //音量
  747. device_status.timeSwitch = 1; //工作模式
  748. device_status.passWord = 8888; //屏幕密码
  749. device_status.work_done = 0; //工作完成标志位
  750. device_status.dattim = 20; //数据上传间隔
  751. device_status.ds = 1; //设备状态
  752. device_status.version_type = 0; //版本类型
  753. ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
  754. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  755. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  756. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  757. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  758. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  759. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  760. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  761. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  762. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  763. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  764. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  765. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  766. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  767. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  768. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  769. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  770. if(device_status.version_type==1)
  771. {
  772. sprintf(device_status.driver, "%s",VERSION_ZP);
  773. }
  774. else if (device_status.version_type==4) {
  775. sprintf(device_status.driver, "%s",VERSION_HK);
  776. }
  777. rt_kprintf("SOFTWARE VERSION:%s\n",device_status.driver);
  778. rt_kprintf("set flash paramconfis:\n");
  779. rt_kprintf("stime:%d\n",device_status.iSave);
  780. rt_kprintf("stime:%d\n",device_status.clt_time);
  781. rt_kprintf("startBar:%d\n",device_status.startBar);
  782. rt_kprintf("stopBar:%d\n",device_status.stopBar);
  783. rt_kprintf("timeSwitch:%d\n",device_status.timeSwitch);
  784. rt_kprintf("sunBar:%d\n",device_status.sunBar);
  785. rt_kprintf("jtime:%d\n",device_status.heattime);
  786. rt_kprintf("jheat:%d\n",device_status.heatvalue);
  787. rt_kprintf("thsp:%d\n", device_status.thsp);
  788. rt_kprintf("密码:%d\n",device_status.passWord);
  789. }//从easyflash读取参数配置
  790. else if (device_status.iSave==FLASH_FLAG) {
  791. ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
  792. ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
  793. ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
  794. ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
  795. ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
  796. ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
  797. ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
  798. ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
  799. ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
  800. ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
  801. ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
  802. ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
  803. ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
  804. ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
  805. ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
  806. ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
  807. ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
  808. ef_get_env_blob("ds",&device_status.ds,
  809. sizeof(device_status.ds),NULL); //开关机状态
  810. ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
  811. ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
  812. ef_get_env_blob("driver_compile",&device_status.driver_compile,sizeof(device_status.driver_compile),NULL); //BL版本号 进BL的时候存储到FLASH
  813. device_status.light_over_tim = device_status.sunBar * 3600; //光控计数
  814. device_status.work_done = 0;
  815. //工作完成标志位
  816. if(device_status.dattim==0)
  817. {
  818. device_status.dattim = 20;
  819. }
  820. if(device_status.version_type==0)
  821. {
  822. app_partion_backup(); //固件备份至df_area
  823. device_status.version_type = 4;
  824. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
  825. }
  826. if(device_status.version_type==1)
  827. {
  828. rt_sprintf(device_status.driver, "%s",VERSION_ZP);
  829. }
  830. else if (device_status.version_type==4) {
  831. rt_sprintf(device_status.driver, "%s",VERSION_HK);
  832. }
  833. rt_kprintf("SOFTWARE VERSION:%s-imei:%s--iccid:%s\n",device_status.driver,device_status.imei,device_status.iccid);
  834. rt_kprintf("read flash paramconfis:%d-%s-%s\r\n",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
  835. rt_kprintf("开机次数:%d\n",device_status.rebootcnt);
  836. rt_kprintf("收集时间:%d\n",device_status.clt_time);
  837. rt_kprintf("定时开始时间:%d\n",device_status.startBar);
  838. rt_kprintf("定时结束时间:%d\n",device_status.stopBar);
  839. rt_kprintf("timeSwitch:%d\n",device_status.timeSwitch);
  840. rt_kprintf("光控定时时长:%d\n",device_status.sunBar);
  841. rt_kprintf("收集时间:%d\n",device_status.heattime);
  842. rt_kprintf("加热温度:%d\n",device_status.heatvalue);
  843. rt_kprintf("震动开关:%d\n",device_status.shake_ws);
  844. rt_kprintf("震动时间:%d\n",device_status.shake_sec);
  845. rt_kprintf("高温保护:%d\n",device_status.tph);
  846. rt_kprintf("低温保护:%d\n",device_status.tpl);
  847. rt_kprintf("thsp:%d\n", device_status.thsp);
  848. rt_kprintf("密码:%d\n",device_status.passWord);
  849. rt_kprintf("数据上传间隔:%d\n",device_status.dattim);
  850. }
  851. 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);
  852. //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
  853. if(device_status.update_flag==1)
  854. {
  855. device_status.update_flag = 0;
  856. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  857. ymodem_ota(1,0);
  858. }
  859. else {
  860. //初始化联网状态
  861. rt_sprintf(device_status.net,"1");
  862. rt_sprintf(device_status.csq,"0");
  863. rt_sprintf(device_status.sim,"1");
  864. Hmi_Fresh();
  865. dtu_data_play();
  866. sht30_collect();
  867. mb_master_samlpe();
  868. uint16_t connect_num=0;
  869. //等待联网,
  870. while(atoi(device_status.net)==1)
  871. {
  872. char *readinfo = makeJson_ReadInfo();
  873. DTU_Write("%s",readinfo);
  874. rt_free(readinfo);
  875. rt_thread_delay(1000);
  876. connect_num++;
  877. rt_kprintf("联网中......%d\n",connect_num);
  878. //超时时间为3分钟
  879. if(connect_num==180)
  880. {
  881. device_status.timeSwitch = 0;
  882. //保存光控变量
  883. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  884. 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);
  885. set_date(2020, 1, 1);
  886. set_time(0, 0, 0);
  887. break;
  888. }
  889. if(tm.tm_year>=2021)
  890. break;
  891. }
  892. DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
  893. }
  894. }
  895. void ResetParamDefault(void)
  896. {
  897. device_status.clt_time = 20; //收集时间
  898. device_status.dattim = 20; //数据上传间隔
  899. device_status.startBar = 20; //定时开始时间
  900. device_status.stopBar = 5; //定时结束时间
  901. device_status.heattime = 20; //加热时间
  902. device_status.shake_ws = 1; //针对开关
  903. device_status.shake_sec = 1; //震动时间1-100ms
  904. device_status.sunBar = 8; //光控定时时长
  905. device_status.tph = 70; //高温保护阈值
  906. device_status.tpl = 5; //低温保护阈值
  907. device_status.timeSwitch = 0; //定时模式
  908. device_status.heatvalue=110;//加热温度
  909. device_status.ds = 1; //设备状态开机
  910. device_status.thsp = 300;
  911. device_status.passWord = 8888;
  912. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  913. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  914. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  915. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  916. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  917. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  918. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  919. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  920. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  921. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  922. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  923. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  924. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  925. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  926. DTU_Write("reset.mp3");
  927. }
  928. void ResetParamDefault_DC(void)
  929. {
  930. device_status.clt_time = 20; //收集时间
  931. device_status.dattim = 20; //数据上传间隔
  932. device_status.startBar = 20; //定时开始时间
  933. device_status.stopBar = 0; //定时结束时间
  934. device_status.heattime = 20; //加热时间
  935. device_status.shake_ws = 1; //针对开关
  936. device_status.shake_sec = 1; //震动时间1-100ms
  937. device_status.sunBar = 4; //光控定时时长
  938. device_status.tph = 70; //高温保护阈值
  939. device_status.tpl = 5; //低温保护阈值
  940. device_status.timeSwitch = 0; //定时模式
  941. device_status.heatvalue=110;
  942. device_status.ds = 1; //设备状态开机
  943. device_status.thsp = 300;
  944. device_status.passWord = 8888;
  945. device_status.timeSwitch = 0;
  946. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  947. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  948. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  949. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  950. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  951. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  952. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  953. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  954. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  955. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  956. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  957. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  958. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  959. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  960. DTU_Write("reset.mp3");
  961. }
  962. //固件备份
  963. void app_partion_backup(void)
  964. {
  965. rt_kprintf("固件恢复!!!\n");
  966. const char *dst_part_name = "df_area";
  967. const char *src_part_name = "app";
  968. const struct fal_partition *dst_part;
  969. const struct fal_partition *src_part;
  970. dst_part = fal_partition_find(dst_part_name);
  971. src_part = fal_partition_find(src_part_name);
  972. if (dst_part == RT_NULL || src_part == RT_NULL)
  973. {
  974. if (dst_part == RT_NULL)
  975. rt_kprintf("%s partition is not exist!\n", dst_part_name);
  976. if (src_part == RT_NULL)
  977. rt_kprintf("%s partition is not exist!\n", src_part_name);
  978. }
  979. else
  980. {
  981. rt_kprintf("Clone %s partition to %s partition:\n", src_part_name, dst_part_name);
  982. if (fal_partition_erase(dst_part, 0, dst_part->len) >= 0)
  983. {
  984. int clone_pos = 0;
  985. int clone_len = 0, clone_tol_len;
  986. rt_uint8_t *buf = rt_malloc(4096);
  987. if (dst_part->len < src_part->len)
  988. clone_tol_len = dst_part->len;
  989. else
  990. clone_tol_len = src_part->len;
  991. while ((clone_pos < clone_tol_len) && (buf != RT_NULL))
  992. {
  993. clone_len = fal_partition_read(src_part, clone_pos, buf, 4096);
  994. if (clone_len < 0)
  995. {
  996. rt_kprintf("\nread %s partition failed, clone stop!\n", src_part_name);
  997. break;
  998. }
  999. if (fal_partition_write(dst_part, clone_pos, buf, clone_len) < 0)
  1000. {
  1001. rt_kprintf("\nwrite %s partition failed, clone stop!\n", dst_part_name);
  1002. break;
  1003. }
  1004. HMI_WRITE("#");
  1005. rt_kprintf("#");
  1006. clone_pos += clone_len;
  1007. }
  1008. if (clone_pos >= clone_tol_len)
  1009. {
  1010. rt_kprintf("\nClone partition success, total %d bytes!\n", clone_tol_len);
  1011. }
  1012. else
  1013. {
  1014. rt_kprintf("Clone partition failed!");
  1015. }
  1016. if (buf)
  1017. rt_free(buf);
  1018. }
  1019. }
  1020. }
  1021. void Debug_log_ON(void)
  1022. {
  1023. rt_console_set_device("uart4");
  1024. finsh_set_device("uart4");
  1025. }
  1026. void Debug_log_OFF(void)
  1027. {
  1028. rt_console_set_device("uart1");
  1029. finsh_set_device("uart1");
  1030. rt_mq_init(&rx_mq, "rx_mq",
  1031. msg_pool, /* 存放消息的缓冲区 */
  1032. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  1033. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  1034. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  1035. rt_device_set_rx_indicate(serial, uart_input);
  1036. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  1037. Hmi_thread_entry,
  1038. RT_NULL,
  1039. HMI_THREAD_STACK_SIZE,
  1040. HMI_THREAD_PRIORITY,
  1041. HMI_THREAD_TIMESLICE);
  1042. if (hmi1 != RT_NULL)
  1043. {
  1044. rt_thread_startup(hmi1);
  1045. }
  1046. }
  1047. MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
  1048. MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
  1049. //
  1050. INIT_BOARD_EXPORT(HMI_uart4_init);