hmi.c 46 KB

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