hmi.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-26 Administrator the first version
  9. */
  10. #include <rtthread.h>
  11. #include "hmi.h"
  12. #include <board.h>
  13. #include <control.h>
  14. #include <rtdevice.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "stdarg.h"
  19. #include "string.h"
  20. #include "sht30_collect.h"
  21. #include "beep.h"
  22. #include "easyflash.h"
  23. #include "sound.h"
  24. #include "ymodem.h"
  25. #include <shell.h>
  26. #include "dtu_uart2.h"
  27. #include <fal.h>
  28. #include "selfcheck.h"
  29. #include <user_mb_app.h>
  30. #define DBG_ENABLE
  31. #define DBG_COLOR
  32. #define DBG_TAG "hmi"
  33. #define DBG_LEVEL DBG_LOG
  34. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  35. #define HMI_THREAD_PRIORITY 5 //线程优先级
  36. #define HMI_THREAD_STACK_SIZE 2048 //线程栈空间大小
  37. #define HMI_THREAD_TIMESLICE 10 //时间片
  38. #define CONTROL_MOTOR_PRIORITY 18
  39. #define CONTROL_MOTOR_STACK_SIZE 2048
  40. #define CONTROL_MOTOR_TIMESLICE 5
  41. static char msg_pool[512];
  42. static char rx_buffer[HMI_UART_RXBUFFER_SIZE + 1];
  43. void list_mem(void);
  44. int mb_master_samlpe();
  45. /**/
  46. Device_Status_typedef device_status;
  47. extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
  48. time_t time(time_t *t);
  49. /* 串口接收消息结构*/
  50. struct rx_msg
  51. {
  52. rt_device_t dev;
  53. rt_size_t size;
  54. };
  55. struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
  56. ////
  57. static rt_thread_t hmi1 = RT_NULL;
  58. static rt_thread_t ctr_motor = RT_NULL;
  59. rt_device_t serial; /*串口设备句柄*/
  60. rt_timer_t timer_uart2 = RT_NULL;
  61. /* 消息队列控制块 */
  62. static struct rt_messagequeue rx_mq;//接收数据消息队列
  63. static void HMI_Decode(void);
  64. static rt_err_t uart_input(rt_device_t dev, rt_size_t size);
  65. static int HMI_uart4_init(void)
  66. {
  67. serial = rt_device_find(UART_NAME);
  68. /*修改串口配置参数*/
  69. config.baud_rate = BAUD_RATE_115200; //修改波特率9600
  70. config.data_bits = DATA_BITS_8; //数据位8
  71. config.stop_bits = STOP_BITS_1; //停止位1
  72. #ifdef RT_USING_SERIAL_V2
  73. config.rx_bufsz = 512;
  74. config.tx_bufsz = 1024;
  75. #else
  76. config.bufsz = 512; //缓冲区128字节
  77. #endif
  78. config.parity = PARITY_NONE; //无奇偶校验
  79. /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
  80. rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
  81. // /* step4:打开串口设备。以中断接收及轮询发送模式打开串口设备 */
  82. //rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
  83. /* 以 DMA 接收及轮询发送模式打开串口设备 */
  84. #ifdef RT_USING_SERIAL_V2
  85. rt_err_t uart_res = rt_device_open(serial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
  86. #else
  87. rt_err_t uart_res = rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX); //RT_DEVICE_FLAG_DMA_RX
  88. #endif
  89. if(uart_res!=RT_EOK)
  90. {
  91. LOG_E("%s打开失败!",UART_NAME);
  92. }else{
  93. LOG_I("%s Open Success!",UART_NAME);
  94. }
  95. return RT_EOK;
  96. }
  97. /*串口屏写数据*/
  98. void HMI_WRITE(char *fmt, ...)
  99. {
  100. va_list ap;
  101. //末尾需要拼接的3个ff
  102. static const char hmi_hex[3]={0xff,0xff,0xff};
  103. static char str[MAX_SIZE];
  104. //memset(str,'\0',sizeof(str));
  105. rt_size_t str_length;
  106. va_start(ap,fmt);
  107. // 预留3字节空间给 hmi_hex
  108. str_length = rt_vsnprintf(str, sizeof(str) - 3, fmt, ap);
  109. va_end(ap);
  110. if (str_length > MAX_SIZE - 3)
  111. str_length = MAX_SIZE - 3;
  112. // 追加三个 0xff
  113. memcpy(str + str_length, hmi_hex, sizeof(hmi_hex));
  114. rt_device_write(serial, 0, str, str_length + sizeof(hmi_hex));
  115. rt_thread_mdelay(5); //2025-0308
  116. }
  117. /* 接收数据回调函数 */
  118. static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
  119. {
  120. struct rx_msg msg;
  121. rt_err_t result;
  122. msg.dev = dev;
  123. msg.size = size;
  124. result = rt_mq_send(&rx_mq, &msg, sizeof(msg));
  125. if ( result == -RT_EFULL)
  126. {
  127. /* 消息队列满 */
  128. LOG_E("hmi message queue full!\n");
  129. rt_mq_control(&rx_mq, RT_IPC_CMD_RESET, RT_NULL); // 清空队列
  130. }
  131. return result;
  132. }
  133. /*入口函数*/
  134. static void Hmi_thread_entry(void *parameter)
  135. {
  136. struct rx_msg msg;
  137. rt_err_t result;
  138. rt_uint32_t rx_length;
  139. if(device_status.dtype==3){
  140. device_status.collt_box_sta = 0;
  141. device_status.run_sta = 0;
  142. }
  143. device_status.camsta = 1;
  144. while(1)
  145. {
  146. rt_memset(&msg, 0, sizeof(msg));
  147. /* 从消息队列中读取消息*/
  148. result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), 50);
  149. if (result == RT_EOK)
  150. {
  151. rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
  152. rx_buffer[rx_length] = '\0';
  153. //LOG_I("%s",rx_buffer);
  154. //\r 对应的hex为0x0d,0x0a,占两个字节,屏幕发送的数据都以\r结尾
  155. HMI_Decode();
  156. }
  157. /*********************************************************************************************************************/
  158. //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);
  159. //rt_kprintf("workSta.vbat.txt=%c%d.%02d%c\n",hmi_str,voltage/100,voltage%100,hmi_str);
  160. }
  161. }
  162. /*******************************************************************************************/
  163. static void t_uart2_callback(void *parameter)
  164. {
  165. HMI_WRITE("sysSet.va0.txt=\"指令超时,请重试...\"");
  166. LOG_E("t_uart2_callback");
  167. }
  168. void Start_timer_Uart2(void)
  169. {
  170. if(timer_uart2!=RT_NULL)
  171. {
  172. rt_timer_start(timer_uart2);
  173. }
  174. else
  175. {
  176. LOG_E("timer_uart2 start Failed!");
  177. }
  178. }
  179. /***************************** 解析从屏幕收到的数据 begin **********************************/
  180. static void HMI_Decode(void)
  181. {
  182. time_t now = time(RT_NULL);
  183. static struct tm tm;
  184. gmtime_r(&now, &tm);
  185. static char *json_temp;
  186. static char *var;
  187. if(device_status.refresh_num==0) device_status.refresh_num = 10;
  188. if(strstr(rx_buffer,"getFullData") != NULL){
  189. char *readinfo = makeJson_ReadInfo();
  190. if(device_status.refresh_num==5)
  191. {
  192. device_status.refresh_num = 15;
  193. DTU_Write("%s",readinfo);
  194. //list_mem();
  195. device_status.hmi_fresh = 1;
  196. rt_thread_delay(100);
  197. }
  198. //在解析getinfo中清除超时
  199. if(device_status.refresh_timeout==30)
  200. {
  201. rt_sprintf(device_status.sim,"1");
  202. rt_sprintf(device_status.net,"1");
  203. rt_sprintf(device_status.csq,"0");
  204. device_status.camsta = 1;
  205. device_status.link_sta=0;
  206. device_status.refresh_timeout=0;
  207. }
  208. rt_free(readinfo);
  209. device_status.refresh_num--;
  210. device_status.refresh_timeout++;
  211. if(1)
  212. {
  213. HMI_WRITE("uploadSet.iccid.txt=\"%s\"",device_status.iccid);
  214. HMI_WRITE("uploadSet.t0.txt=\"%s\"",device_status.mqttcfg1);
  215. //更新固件版本号
  216. HMI_WRITE("debug.t3.txt=\"%s\"",device_status.driver);
  217. //更新固件编译日期
  218. HMI_WRITE("debug.t4.txt=\"%s\"",device_status.driver_compile);
  219. //
  220. HMI_WRITE("debug.t5.txt=\"%s\"",device_status.driver_bl);
  221. HMI_WRITE("debug.t7.txt=\"%s\"",device_status.driver_compile);
  222. //更新dtu/rtu版本
  223. HMI_WRITE("debug.t9.txt=\"%s\"",device_status.driver_4g);
  224. //更新时间
  225. 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);
  226. 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);
  227. HMI_WRITE("set.t0.txt=\"%d\"",tm.tm_hour);
  228. HMI_WRITE("set.t1.txt=\"%d\"",tm.tm_min);
  229. HMI_WRITE("set.t2.txt=\"%d\"",tm.tm_sec);
  230. //更新电压
  231. HMI_WRITE("menu.vbat.txt=\"%s\"",device_status.voltage);
  232. //更新电流
  233. HMI_WRITE("menu.power.txt=\"%s\"",device_status.power);
  234. //更新温湿度数据
  235. HMI_WRITE("menu.envHum.val=%d",atoi(device_status.humidity));
  236. HMI_WRITE("menu.envTem.val=%d",atoi(device_status.tempture));
  237. //更新电池状态
  238. HMI_WRITE("menu.batStatus.val=%d",device_status.bat_status);
  239. //更新上仓门状态
  240. HMI_WRITE("workSta.upStatus.val=%d",device_status.up_status);
  241. //更新下仓门状态
  242. HMI_WRITE("workSta.downStatus.val=%d",device_status.down_status);
  243. HMI_WRITE("menu.eth1_sta.val=%d",!device_status.camera_sta);
  244. //更新工作状态
  245. HMI_WRITE("menu.workStatus.val=%d",device_status.work_status);
  246. //更新温控状态
  247. HMI_WRITE("workSta.tempStatus.val=%d",device_status.temp_status);
  248. //更新雨控状态
  249. HMI_WRITE("workSta.rainStatus.val=%d",device_status.rain_status);
  250. //更新光控状态
  251. HMI_WRITE("workSta.sunStatus.val=%d",device_status.sun_status);
  252. //更新有线连接状态
  253. HMI_WRITE("menu.va_net.val=%d",device_status.link_sta);
  254. //更新CSQ
  255. HMI_WRITE("menu.csq_value.txt=\"%s\"",device_status.csq);
  256. HMI_WRITE("menu.va_csq.val=%d",atoi(device_status.csq));
  257. HMI_WRITE("workSta.csq_value.txt=\"%s\"",device_status.csq);
  258. //更新收集时间
  259. HMI_WRITE("sysSet.stime.val=%d",device_status.cul_time);
  260. //更新加热时间
  261. HMI_WRITE("workSta.heatTime.val=%d",device_status.heattime);
  262. HMI_WRITE("sysSet.jtime.val=%d",device_status.heattime);
  263. //
  264. HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
  265. //更新加热时间和温度
  266. HMI_WRITE("workSta.heatTem.val=%d",device_status.heattem);
  267. HMI_WRITE("sysSet.jheat.val=%d",device_status.heatvalue);
  268. //更新加热状态
  269. HMI_WRITE("workSta.heatStatus.val=%d",device_status.heat_status);
  270. //更新密码
  271. HMI_WRITE("inputPasswd.pwdData.txt=\"8888\"");
  272. //更新时间设置中的参数
  273. //更新定时模式
  274. HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
  275. //更新光控定时时长
  276. HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
  277. //更新时控开始
  278. HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
  279. //更新时控结束
  280. HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
  281. //SIM卡状态
  282. HMI_WRITE("workSta.bt0.val=%d",atoi(device_status.sim));
  283. //ID
  284. HMI_WRITE("menu.equipid.txt=\"%s\"",device_status.imei);
  285. //HMI_WRITE("workSta.equipid.txt=\"%s\"",device_status.imei);
  286. HMI_WRITE("menu.deviceId.txt=\"%s\"",device_status.deviceId);
  287. //数据上传间隔
  288. HMI_WRITE("menu.datt.txt=\"%d\"",device_status.dattim);
  289. HMI_WRITE("menu.next.txt=\"%d\"",device_status.num_updata);
  290. //语音音量
  291. HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
  292. //主板温度
  293. HMI_WRITE("menu.bt.txt=\"%d.%d\"",Get_Temprate()/100,Get_Temprate()%100);
  294. //
  295. HMI_WRITE("menu.t4.txt=\"%d:00-%d:00\"",device_status.startBar,device_status.stopBar);
  296. //
  297. HMI_WRITE("menu.ct.txt=\"%d\"",device_status.all_ycct);
  298. //
  299. HMI_WRITE("menu.version.txt=\"%s\"",device_status.driver);
  300. HMI_WRITE("menu.build.txt=\"%s\"",device_status.driver_compile);
  301. //更新熄屏时间
  302. if(device_status.thsp<60) device_status.thsp = device_status.thsp * 60;
  303. HMI_WRITE("thsp=%d",device_status.thsp);
  304. }
  305. if(atoi(device_status.gps)==1){
  306. HMI_WRITE("menu.gps_state.txt=\"定位成功:(%s)%d/%d\"",device_status.gps_state,device_status.gps_inuse,device_status.gps_view);
  307. }else if(atoi(device_status.gps)==2){
  308. HMI_WRITE("menu.gps_state.txt=\"定位成功:(基站)\"");
  309. }
  310. //更新联网状态
  311. if(atoi(device_status.net)==1)
  312. {
  313. HMI_WRITE("menu.net.val=1");
  314. HMI_WRITE("workSta.net.val=1");
  315. }
  316. else {
  317. HMI_WRITE("workSta.net.val=0");
  318. HMI_WRITE("menu.net.val=0");
  319. }
  320. if(atoi(device_status.csq)==0&&atoi(device_status.net)==1)
  321. {
  322. HMI_WRITE("menu.net.val=1");
  323. HMI_WRITE("workSta.net.val=2");
  324. }
  325. /**********************************************************************/
  326. }
  327. else if (strstr(rx_buffer,"getClockData")!=NULL) {
  328. //更新定时模式
  329. HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
  330. //更新光控定时时长
  331. HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
  332. //更新时控开始
  333. HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
  334. //更新时控结束
  335. HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
  336. }
  337. else if (strstr(rx_buffer,"button")!=NULL) {
  338. LOG_D("button!");
  339. DTU_Write("button");
  340. }
  341. //拍照
  342. else if(strstr(rx_buffer,"putTest.switchPhoto=1")!=NULL) {
  343. #if MATCH_DEVICE == 1
  344. ctr_led(ON);
  345. //发送拍照指令
  346. char *takephotojson = makeJson_takephoto();
  347. DTU_Write("%s",takephotojson);
  348. rt_free(takephotojson);
  349. HMI_WRITE("sysTest.switchPhoto.val=0");
  350. #else
  351. device_status.photo_ws = 1;
  352. #endif
  353. }
  354. else if (strstr(rx_buffer,"putTest.switchPic=1")!=NULL) {
  355. #if MATCH_DEVICE == 1
  356. ctr_led(ON);
  357. //发送拍照指令
  358. char *takephotojson = makeJson_takephoto();
  359. DTU_Write("%s",takephotojson);
  360. rt_free(takephotojson);
  361. HMI_WRITE("sysTest.switchPhoto.val=0");
  362. #else
  363. device_status.photo_ws = 1;
  364. #endif
  365. }
  366. //打开补光
  367. else if (strstr(rx_buffer,"putTest.switchLed=1")!=NULL) {
  368. LOG_I("打开补光!!");
  369. ctr_led(ON);
  370. }
  371. //关闭补光
  372. else if (strstr(rx_buffer,"putTest.switchLed=0")!=NULL) {
  373. LOG_I("关闭补光!!!");
  374. ctr_led(OFF);
  375. }
  376. //关闭加热
  377. else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
  378. device_status.heat_status = 0;
  379. ctr_Heat(OFF);
  380. LOG_I("Close Heat!");
  381. }
  382. //打开加热
  383. else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
  384. device_status.heat_status = 1;
  385. ctr_Heat(ON);
  386. LOG_I("Open Heat!");
  387. }
  388. //清扫
  389. else if (strstr(rx_buffer,"clear")!=NULL) {
  390. LOG_I("翻板!");
  391. device_status.clear_status = 10;
  392. }
  393. //打开补光
  394. else if (strstr(rx_buffer,"putTest.switchFill=1")!=NULL) {
  395. rt_kprintf("\n打开补光!!!\n");
  396. ctr_led(ON);
  397. }
  398. //关闭补光
  399. else if (strstr(rx_buffer,"putTest.switchFill=0")!=NULL) {
  400. rt_kprintf("\n关闭补光!!!\n");
  401. ctr_led(OFF);
  402. }
  403. //打开灯管
  404. else if (strstr(rx_buffer,"putTest.switchLamp=1")!=NULL)
  405. {
  406. device_status.test_flag=1;
  407. rt_kprintf("Open Lamp!\n");
  408. ctr_lamp(ON,1);
  409. #if LAMP_EN == 1
  410. ctr_lamp(ON,2);
  411. ctr_lamp(ON,3);
  412. #endif
  413. DTU_Write("{\"cmd\":\"workstart\"}");
  414. USHORT dkdg[] = {0xb4f2,0xbfaa,0xb5c6,0xb9dc};
  415. _485_play(dkdg,4);
  416. }
  417. //关闭灯管
  418. else if (strstr(rx_buffer,"putTest.switchLamp=0")!=NULL)
  419. {
  420. device_status.test_flag=0;
  421. rt_kprintf("Close Lamp1!\n");
  422. ctr_lamp(OFF,1);
  423. #if LAMP_EN == 1
  424. ctr_lamp(OFF,2);
  425. ctr_lamp(OFF,3);
  426. #endif
  427. DTU_Write("{\"cmd\":\"workdone\"}");
  428. USHORT gbdg[] = {0xb9d8,0xb1d5,0xb5c6,0xb9dc};
  429. _485_play(gbdg,4);
  430. }
  431. //关闭加热
  432. else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
  433. device_status.heat_status = 0;
  434. ctr_Heat(OFF);
  435. rt_kprintf("Close Heat!\n");
  436. }
  437. //打开加热
  438. else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
  439. device_status.heat_status = 1;
  440. ctr_Heat(ON);
  441. rt_kprintf("Open Heat!\n");
  442. }
  443. //设置设备时间
  444. else if (strstr(rx_buffer,"stamp=")!=NULL)
  445. {
  446. var = strstr(rx_buffer,"=");
  447. var ++;
  448. LOG_I("设置时间:%s",var);
  449. static char year_s[5],month_s[3],day_s[3],hour_s[3],min_s[3],sec_s[3];
  450. strncpy(year_s, var, 4);
  451. strncpy(month_s,var+4,2);
  452. strncpy(day_s,var+6,2);
  453. strncpy(hour_s,var+8,2);
  454. strncpy(min_s,var+10,2);
  455. strncpy(sec_s,var+12,2);
  456. if(atoi(year_s)>=2024&&atoi(year_s)<3000&&atoi(month_s)>0&&atoi(month_s)<13&&atoi(day_s)>0&&atoi(day_s)<32)
  457. {
  458. if(set_date(atoi(year_s),atoi(month_s),atoi(day_s))==RT_EOK)
  459. {
  460. LOG_I("设置日期:%d年%d月%d日",atoi(year_s),atoi(month_s),atoi(day_s));
  461. if(atoi(hour_s)>0&&atoi(hour_s)<=24&&atoi(min_s)>=0&&atoi(min_s)<=59&&atoi(sec_s)>=0&&atoi(sec_s)<=59)
  462. {
  463. LOG_I("设置时间:%d时%d分%d秒",atoi(hour_s),atoi(min_s),atoi(sec_s));
  464. set_time(atoi(hour_s),atoi(min_s),atoi(sec_s));
  465. MA_save();
  466. }
  467. //上传最新数据
  468. device_status.num_updata = 2; //2秒后上报数据更新RTU的时间
  469. }
  470. else {
  471. LOG_E("set_date failed!");
  472. }
  473. }
  474. }
  475. //设备编码设置
  476. else if (strstr(rx_buffer,"deviceId=")!=NULL)
  477. {
  478. char value_str[20];
  479. memset(value_str,0,sizeof(value_str));
  480. LOG_I("设备编码 长度:%d",strlen(rx_buffer));
  481. if(strlen(rx_buffer)!=19){
  482. LOG_E("编码长度错误!");
  483. return;
  484. }
  485. var = strstr(rx_buffer,"=");
  486. var ++;
  487. strncpy(value_str,var,8); //设备编码为16位
  488. if(strstr(value_str,"00000000")!=RT_NULL){
  489. char *config_reset = makeJson_Config_Reset();
  490. //发送json到RTU
  491. DTU_Write("%s",config_reset);
  492. rt_free(config_reset);
  493. //恢复RTU的默认配置参数
  494. }else{
  495. rt_sprintf(device_status.deviceId,"10300101%s",value_str); //设备大类编码103-虫情 设备小类编码 001 生产商代码01
  496. ef_set_env_blob("deviceId", &device_status.deviceId, sizeof(device_status.deviceId));
  497. LOG_I("解析到设备编码:%s",device_status.deviceId);
  498. char *device_id = makeJson_Config_BDH(device_status.deviceId);
  499. //发送json到RTU
  500. DTU_Write("%s",device_id);
  501. rt_free(device_id);
  502. }
  503. }
  504. //定时设置
  505. else if (strstr(rx_buffer,"saveClockSet=")!=NULL) {
  506. char value_str[10];
  507. memset(value_str,0,sizeof(value_str));
  508. LOG_I("时间设置!");
  509. var=strstr(rx_buffer,"=");
  510. var++;
  511. strncpy(value_str,var,2);
  512. if(atoi(value_str) > 0 && atoi(value_str) <60)
  513. {
  514. if(device_status.version_type!=6)
  515. {
  516. device_status.sunBar=atoi(value_str);
  517. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  518. }
  519. else {
  520. device_status.shake_sec = atoi(value_str);
  521. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
  522. }
  523. }
  524. else {
  525. LOG_E("参数设置异常(光控时长):%d!!!",atoi(value_str));
  526. }
  527. memset(value_str,0,sizeof(value_str));
  528. //时控开始时间
  529. strncpy(value_str,var+2,2);
  530. if(atoi(value_str) >= 0 && atoi(value_str) < 24)
  531. {
  532. #if 1
  533. device_status.startBar=atoi(value_str);
  534. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  535. #endif
  536. }
  537. else {
  538. LOG_E("参数设置异常(开始):%d!!!",atoi(value_str));
  539. }
  540. memset(value_str,0,sizeof(value_str));
  541. //
  542. strncpy(value_str,var+4,2);
  543. if(atoi(value_str) >= 0&& atoi(value_str) < 24)
  544. {
  545. #if 1
  546. device_status.stopBar=atoi(value_str);
  547. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  548. #endif
  549. }
  550. else {
  551. LOG_E("参数设置异常(结束):%d!!!",atoi(value_str));
  552. }
  553. memset(value_str,0,sizeof(value_str));
  554. //
  555. strncpy(value_str,var+6,2);
  556. if(atoi(value_str) >= 0 && atoi(value_str) <= 1)
  557. {
  558. device_status.timeSwitch=atoi(value_str);
  559. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  560. }
  561. else {
  562. if(device_status.version_type==6)
  563. {
  564. device_status.timeSwitch=1;
  565. device_status.dattim=atoi(value_str);
  566. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
  567. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  568. }
  569. else {
  570. LOG_E("参数设置异常(模式):%d!!!",atoi(value_str));
  571. }
  572. }
  573. //2022/06/23,add:
  574. rt_sprintf(device_status.json_w_clock,"屏幕操作:修改工作时间:开始-%d,结束-%d,模式-%d(0-光控,1-时控)操作时间:%s",device_status.startBar,device_status.stopBar,device_status.timeSwitch,device_status.stamp);
  575. json_temp = makeJson_Warn(device_status.json_w_clock, "修改工作时间");
  576. ef_set_env_blob("json_w_clock", &device_status.json_w_clock, sizeof(device_status.json_w_clock)); //将修改屏幕参数操作记录保存到Flash中
  577. if(atoi(device_status.net)==0)
  578. DTU_Write("%s",json_temp);
  579. rt_free(json_temp);
  580. rt_thread_delay(2000);
  581. MA_save();
  582. rt_kprintf("工作时间参数已保存:模式-%d,光控时间-%d,时控开始时间-%d,时控结束时间-%d\n",device_status.timeSwitch,device_status.sunBar,device_status.startBar,device_status.stopBar);
  583. }
  584. else if (strstr(rx_buffer,"saveSystemSet")!=NULL) {
  585. static char clt_time_str[3],heattime_str[3],heatvale_str[4],vol_str[4],thsp_str[5];
  586. LOG_I("系统设置!");
  587. var = strstr(rx_buffer,"=");
  588. var ++;
  589. strncpy(clt_time_str,var,2);
  590. if(atoi(clt_time_str)>0 && atoi(clt_time_str) <= 240)
  591. {
  592. device_status.cul_time = atoi(clt_time_str); //收集时间
  593. ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
  594. }
  595. strncpy(heattime_str,var+2,2);
  596. if(atoi(heattime_str)>0 && atoi(heattime_str) <= 30)
  597. {
  598. device_status.heattime = atoi(heattime_str); //加热时间
  599. LOG_I("设置加热时间:%d",atoi(heattime_str));
  600. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  601. }
  602. strncpy(heatvale_str,var+4,3);
  603. if(atoi(heatvale_str) > 0 && atoi(heatvale_str) <= 130)
  604. {
  605. device_status.heatvalue=atoi(heatvale_str);
  606. LOG_I("设置加热温度:%d",device_status.heatvalue);
  607. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  608. }
  609. strncpy(vol_str,var+7,3);
  610. if(atoi(vol_str)>0&&atoi(vol_str)<8)
  611. {
  612. device_status.vol = atoi(vol_str); //音量
  613. LOG_I("设置音量:%d",device_status.vol);
  614. //DTU_Write("volume=");
  615. }
  616. strncpy(thsp_str,var+10,4);
  617. if(atoi(thsp_str)>0&&atoi(thsp_str)<3600)
  618. {
  619. device_status.thsp = atoi(thsp_str); //熄屏时间
  620. LOG_I("设置熄屏时间:%d",device_status.thsp);
  621. }
  622. else {
  623. LOG_E("参数设置失败!!!");
  624. }
  625. rt_thread_delay(1000);
  626. MA_save();
  627. //rt_kprintf("系统设置已保存:收集时间-%d,加热时间-%d,加热温度-%d,音量-%d,自动关屏-%d\n",device_status.clt_time,device_status.heattime,device_status.heatvalue,device_status.vol,device_status.thsp);
  628. }
  629. else if (strstr(rx_buffer,"rtc_h=")!=NULL) {
  630. char rtc_h[2];
  631. var = strstr(rx_buffer,"=");
  632. var++;
  633. strncpy(rtc_h,var,2);
  634. if(atoi(rtc_h)>=0 && atoi(rtc_h) <= 24)
  635. {
  636. set_time(atoi(rtc_h), 99, 99);
  637. }
  638. }
  639. else if (strstr(rx_buffer,"rtc_m=")!=NULL) {
  640. char rtc_m[2];
  641. var = strstr(rx_buffer,"=");
  642. var++;
  643. strncpy(rtc_m,var,2);
  644. if(atoi(rtc_m)>=0 && atoi(rtc_m) <= 24)
  645. {
  646. set_time(99, atoi(rtc_m), 99);
  647. }
  648. }
  649. else if (strstr(rx_buffer,"rtc_s=")!=NULL) {
  650. char rtc_s[2];
  651. var = strstr(rx_buffer,"=");
  652. var++;
  653. strncpy(rtc_s,var,2);
  654. if(atoi(rtc_s)>=0 && atoi(rtc_s) <= 24)
  655. {
  656. set_time(99, 99, atoi(rtc_s));
  657. }
  658. }
  659. else if(strstr(rx_buffer,"saveUploadSet=")!=NULL)
  660. {
  661. static char dattim_str[3];
  662. rt_kprintf("上传间隔设置!\n");
  663. var = strstr(rx_buffer,"=");
  664. var ++;
  665. strncpy(dattim_str,var,2);
  666. if(atoi(dattim_str)>=1&&atoi(dattim_str)<=120)
  667. {
  668. device_status.dattim =atoi(dattim_str); //数据上传间隔
  669. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
  670. MA_save();
  671. }
  672. else {
  673. rt_kprintf("设置失败!!!\n");
  674. }
  675. rt_kprintf("数据上传设置:%d\n",device_status.dattim);
  676. }
  677. else if(strstr(rx_buffer,"saveXYtype=")!=NULL)
  678. {
  679. static char xy_str[3];
  680. LOG_I("修改诱芯!");
  681. var = strstr(rx_buffer,"=");
  682. var ++;
  683. strncpy(xy_str,var,2);
  684. if(atoi(xy_str)>=0&&atoi(xy_str)<=100){
  685. LOG_I("修改诱芯:%d",atoi(xy_str));
  686. device_status.InsectSpecies =atoi(xy_str); //昆虫种类
  687. ef_set_env_blob("InsectSpecies", &device_status.InsectSpecies, sizeof(device_status.InsectSpecies));
  688. MA_save();
  689. }else{
  690. LOG_E("诱芯设置失败!");
  691. }
  692. }
  693. //恢复出厂设置电池
  694. else if (strstr(rx_buffer,"resetdcDefault")!=NULL)
  695. {
  696. ResetParamDefault_DC();
  697. rt_thread_delay(1000);
  698. //2022/06/23,add:
  699. rt_sprintf(device_status.json_w_reset,"屏幕操作:系统重置:电池供电,操作时间:%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);
  700. json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
  701. ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
  702. if(atoi(device_status.net)==0)
  703. DTU_Write("%s",json_temp);
  704. rt_free(json_temp);
  705. }
  706. //恢复出厂设置-交流
  707. else if (strstr(rx_buffer,"resetDefault")!=NULL)
  708. {
  709. ResetParamDefault();
  710. rt_thread_delay(1000);
  711. //2022/06/23,add:
  712. rt_sprintf(device_status.json_w_reset,"屏幕操作:系统重置:交流供电,操作时间:%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);
  713. json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
  714. ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
  715. if(atoi(device_status.net)==0)
  716. DTU_Write("%s",json_temp);
  717. rt_free(json_temp);
  718. }
  719. else if (strstr(rx_buffer,"DebugEnable")!=NULL) {
  720. Debug_log_ON();
  721. }
  722. else if (strstr(rx_buffer,"DebugDisable")!=NULL) {
  723. Debug_log_OFF();
  724. }
  725. else if((strstr(rx_buffer,"SwversionV8")!=NULL)) {
  726. if(device_status.dtype!=8)
  727. {
  728. LOG_D("设置版本类型:8");
  729. device_status.dtype = 8;
  730. device_status.version_type = 8;
  731. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //设备类型
  732. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  733. DTU_Write("SwversionV8");
  734. MA_save();
  735. }
  736. }
  737. else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
  738. {
  739. HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
  740. HMI_WRITE("sysTest.heat_txt.txt=\"%s\"",device_status.heat_power);
  741. // HMI_WRITE("sysTest.switchHeat.val=%d",device_status.heat_status);
  742. }
  743. //立即上传
  744. else if(strstr(rx_buffer,"uploaddata")!=RT_NULL)
  745. {
  746. UpLoad_Data();
  747. }
  748. else if (strstr(rx_buffer,"checkupdate")!=NULL)
  749. {
  750. time_t now = time(RT_NULL);
  751. static struct tm tm;
  752. gmtime_r(&now, &tm);
  753. 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);
  754. HMI_WRITE("hardcheck.p0.pic=%d",70);
  755. //RTC时间判断,如果当前年份小于2020,提示需要设置时间
  756. if(tm.tm_year+1900<2020)
  757. {
  758. 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);
  759. 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);
  760. }
  761. }
  762. //进入bootloader模式
  763. else if (strstr(rx_buffer,"bootloader")!=NULL) {
  764. device_status.stop_in_bootloader = 1;
  765. ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
  766. rt_hw_cpu_reset();
  767. }
  768. //软件重启
  769. else if (strstr(rx_buffer,"reboot")!=NULL) {
  770. rt_hw_cpu_reset();
  771. }
  772. //屏幕上触发远程升级
  773. else if (strstr(rx_buffer,"hmi_update")!=NULL) {
  774. DTU_Write("hmi_update");
  775. device_status.update_flag = 1;
  776. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  777. rt_thread_delay(2000);
  778. rt_hw_cpu_reset();
  779. }else if (strstr(rx_buffer,"checkcamera")!=NULL){
  780. DTU_Write("{\"ctr_cam\":\"checkcamera\"}");
  781. //校准屏幕的RTC
  782. HMI_WRITE("rtc0=%d",tm.tm_year+1900);
  783. HMI_WRITE("rtc1=%d",tm.tm_mon+1);
  784. HMI_WRITE("rtc2=%d",tm.tm_mday);
  785. HMI_WRITE("rtc3=%d",tm.tm_hour);
  786. HMI_WRITE("rtc4=%d",tm.tm_min);
  787. HMI_WRITE("rtc5=%d",tm.tm_sec);
  788. //开启超时定时器
  789. Start_timer_Uart2();
  790. }else if (strstr(rx_buffer,"ReadCamParam")!=NULL){
  791. DTU_Write("{\"ctr_cam\":\"ReadParam\"}");
  792. //开启超时定时器
  793. Start_timer_Uart2();
  794. }//SaveCamParam:2070.00000-0.7-144-30-0-0-5472*5472
  795. else if (strstr(rx_buffer,"SaveCamParam")!=NULL){
  796. const char *prefix ="SaveCamParam:";
  797. size_t prefix_len = strlen(prefix);
  798. const char *start_pos = strstr(rx_buffer, prefix);
  799. if(start_pos!=NULL)
  800. {
  801. // 移动到前缀之后的位置
  802. start_pos += prefix_len;
  803. DTU_Write("%s",makeJson_Cam("SaveParam",start_pos));
  804. }
  805. //开启超时定时器
  806. Start_timer_Uart2();
  807. }else if (strstr(rx_buffer,"GrabOn")!=NULL){
  808. DTU_Write("{\"ctr_cam\":\"GrabOn\"}");
  809. //开启超时定时器
  810. Start_timer_Uart2();
  811. }else if (strstr(rx_buffer,"GrabOff")!=NULL){
  812. DTU_Write("{\"ctr_cam\":\"GrabOff\"}");
  813. //开启超时定时器
  814. Start_timer_Uart2();
  815. }
  816. }
  817. //入口函数-电机控制及
  818. static void Ctr_Mortor_entry(void* parameter)
  819. {
  820. rt_int16_t photo_led_sec = 900; //55S
  821. rt_int16_t off_router_sec = 600; //60S
  822. struct timeval tv;
  823. while(1)
  824. {
  825. #if 0
  826. time_t time_reset12V;
  827. time(&time_reset12V);
  828. static struct tm alarm_reset12V;
  829. alarm_reset12V =*localtime(&time_reset12V);
  830. if((alarm_reset12V.tm_hour)==8&&(alarm_reset12V.tm_min==19)&&(alarm_reset12V.tm_sec==50))
  831. {
  832. ctr_RTU_DTU(OFF);
  833. rt_thread_delay(1000*10);
  834. ctr_RTU_DTU(ON);
  835. }
  836. #endif
  837. //拍照
  838. if(device_status.photo_ws==1)
  839. {
  840. photo_led_sec--;
  841. ctr_led(ON);
  842. //打开补光灯
  843. if(photo_led_sec==890)
  844. {
  845. gettimeofday(&tv, NULL);
  846. device_status.photo_stamp = tv.tv_sec;
  847. DTU_Write("takephoto.mp3");
  848. //延时
  849. rt_thread_delay(1000);
  850. LOG_I("测试拍照!");
  851. Hk_Take_io();
  852. char *takephotojson = makeJson_takephoto();
  853. DTU_Write("%s",takephotojson);
  854. rt_free(takephotojson);
  855. }
  856. if(photo_led_sec==500) //4800W相机
  857. {
  858. ctr_led(OFF);
  859. photo_led_sec = 900;
  860. device_status.photo_ws = 0;
  861. HMI_WRITE("sysTest.switchPhoto.val=0");
  862. HMI_WRITE("sysTest.switchFill.val=0");
  863. }
  864. }else if(device_status.photo_ws ==2){
  865. ctr_led(ON);
  866. photo_led_sec--;
  867. if(photo_led_sec==890){
  868. gettimeofday(&tv, NULL);
  869. device_status.photo_stamp = tv.tv_sec;
  870. DTU_Write("takephoto.mp3");
  871. rt_thread_delay(2000);
  872. DTU_Write(makeJson_ParsePhoto());
  873. }else if(photo_led_sec==500){
  874. photo_led_sec = 900;
  875. ctr_led(OFF);
  876. device_status.photo_ws = 0;
  877. device_status.clear_status = 10; //翻板
  878. }
  879. }
  880. if(device_status.C01==10)
  881. {
  882. off_router_sec--;
  883. if(off_router_sec==0)
  884. {
  885. off_router_sec = 600;
  886. device_status.C01=0;
  887. ctr_router(OFF);
  888. ctr_RTU_DTU(OFF);
  889. }
  890. }
  891. rt_thread_delay(100);
  892. }
  893. }
  894. /*屏幕写数据*/
  895. int Hmi_Fresh(void)
  896. {
  897. //初始化串口4
  898. //HMI_uart4_init();
  899. rt_err_t ret = RT_EOK;
  900. /* 初始化消息队列 */
  901. rt_mq_init(&rx_mq, "rx_mq",
  902. msg_pool, /* 存放消息的缓冲区 */
  903. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  904. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  905. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  906. /* 设置接收回调函数 */
  907. rt_device_set_rx_indicate(serial, uart_input);
  908. /* 创建线程*/
  909. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  910. Hmi_thread_entry,
  911. RT_NULL,
  912. HMI_THREAD_STACK_SIZE,
  913. HMI_THREAD_PRIORITY,
  914. HMI_THREAD_TIMESLICE);
  915. /*部分控制的线程*/
  916. ctr_motor = rt_thread_create("Ctr motor",
  917. Ctr_Mortor_entry,
  918. RT_NULL,
  919. CONTROL_MOTOR_STACK_SIZE,
  920. CONTROL_MOTOR_PRIORITY,
  921. CONTROL_MOTOR_TIMESLICE);
  922. if(ctr_motor != RT_NULL)
  923. {
  924. rt_thread_startup(ctr_motor);
  925. }
  926. /* 如果获得线程控制块,启动这个线程 */
  927. if (hmi1 != RT_NULL)
  928. {
  929. rt_thread_startup(hmi1);
  930. }
  931. else
  932. {
  933. ret = RT_ERROR;
  934. }
  935. //定时器,串口通信超时监测20S
  936. timer_uart2 = rt_timer_create("t_uart2",t_uart2_callback,RT_NULL, 20000, RT_TIMER_FLAG_ONE_SHOT);
  937. if(timer_uart2==RT_NULL)
  938. {
  939. LOG_E("rt_timer_create timer_uart2 failed!");
  940. }
  941. return ret;
  942. }
  943. void Check_ParamConfig(void)
  944. {
  945. time_t now = time(RT_NULL);
  946. static struct tm tm;
  947. gmtime_r(&now, &tm);
  948. if(easyflash_init()==EF_NO_ERR) //初始化成功
  949. {
  950. ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
  951. ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
  952. ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
  953. device_status.rebootcnt++;
  954. ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
  955. LOG_I("REBOOT_TIME:%d-%d-%d",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
  956. }
  957. else {
  958. LOG_E("easyflash init ERRPR!!!");
  959. }
  960. //保存默认配置
  961. if(device_status.iSave!=FLASH_FLAG)
  962. {
  963. device_status.iSave=FLASH_FLAG;
  964. /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
  965. device_status.dtype = 8;
  966. device_status.version_type = 8; //4.0
  967. device_status.clt_time = 10; //收集时间
  968. device_status.heattime = 10; //加热时间
  969. device_status.heatvalue=100;//加热温度
  970. device_status.thsp = 300; //默认熄屏时间5分钟
  971. device_status.sunBar = 9; //光控定时时长
  972. device_status.startBar = 20; //定时开始时间
  973. device_status.stopBar = 0; //定时结束时间
  974. device_status.tph = 70; //高温保护阈值
  975. device_status.tpl = 5; //低温保护阈值
  976. device_status.shake_ws = 1; //震动开关,默认开
  977. device_status.shake_sec = 1; //震动时间,s
  978. device_status.vol = 7; //音量
  979. device_status.timeSwitch = 1; //工作模式:时控
  980. device_status.passWord = 8888; //屏幕密码
  981. device_status.dattim = 20; //数据上传间隔
  982. device_status.ds = 1; //设备状态
  983. device_status.update_flag = 0;
  984. device_status.sleep_mode = 0;
  985. /*孢子仪*/
  986. /*孢子仪*/
  987. device_status.collecting_sh1 = 9;
  988. device_status.collecting_eh1 = 10;
  989. device_status.collecting_sh2 = 14;
  990. device_status.collecting_eh2 = 16;
  991. device_status.cold_sw = 0;
  992. device_status.heat_sw =0;
  993. device_status.cul_time = 60;
  994. device_status.run_sta = 0;
  995. device_status.InsectSpecies = 0;
  996. device_status.Power_Type = 0;
  997. sprintf(device_status.deviceId,"0");
  998. sprintf(device_status.driver, "%s",VERSION);
  999. rt_sprintf(device_status.tempture, "-15");
  1000. rt_sprintf(device_status.humidity, "31");
  1001. rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
  1002. ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
  1003. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1004. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  1005. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1006. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1007. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1008. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1009. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1010. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1011. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1012. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1013. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1014. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1015. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1016. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1017. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  1018. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1019. ef_set_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture)); //温度
  1020. ef_set_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity)); //湿度
  1021. ef_set_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1)); //上传平台
  1022. ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  1023. ef_set_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw)); //制冷开关
  1024. ef_set_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw)); //加热开关
  1025. ef_set_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1)); //风机开关
  1026. ef_set_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1)); //采集时间
  1027. ef_set_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2)); //采集时间
  1028. ef_set_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2)); //采集时间
  1029. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta)); //
  1030. ef_set_env_blob("InsectSpecies", &device_status.InsectSpecies, sizeof(device_status.InsectSpecies)); //昆虫种类
  1031. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type)); //供电类型
  1032. ef_set_env_blob("deviceId", &device_status.deviceId, sizeof(device_status.deviceId)); //设备编码
  1033. ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode)); //设备编码
  1034. LOG_I("SOFTWARE VERSION:%s",device_status.driver);
  1035. LOG_I("Default paramconf is:");
  1036. LOG_I("clt_time:%d",device_status.iSave);
  1037. LOG_I("cul_time:%d",device_status.cul_time);
  1038. LOG_I("startBar:%d",device_status.startBar);
  1039. LOG_I("stopBar:%d",device_status.stopBar);
  1040. LOG_I("timeSwitch:%d",device_status.timeSwitch);
  1041. LOG_I("sunBar:%d",device_status.sunBar);
  1042. LOG_I("jtime:%d",device_status.heattime);
  1043. LOG_I("jheat:%d",device_status.heatvalue);
  1044. LOG_I("thsp:%d", device_status.thsp);
  1045. LOG_I("passwd:%d",device_status.passWord);
  1046. LOG_I("InsectSpecies:%d",device_status.InsectSpecies);
  1047. LOG_I("Power_Type:%d",device_status.Power_Type);
  1048. }//从easyflash读取参数配置
  1049. else if (device_status.iSave==FLASH_FLAG) {
  1050. ef_get_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype),NULL); //设备类型
  1051. ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
  1052. ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
  1053. ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
  1054. ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
  1055. ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
  1056. ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
  1057. ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
  1058. ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
  1059. ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
  1060. ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
  1061. ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
  1062. ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
  1063. ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
  1064. ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
  1065. ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
  1066. ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
  1067. ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
  1068. ef_get_env_blob("lat",&device_status.lat,sizeof(device_status.lat),NULL);
  1069. ef_get_env_blob("lng",&device_status.lng,sizeof(device_status.lng),NULL);
  1070. ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL); //开关机状态
  1071. ef_get_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture),NULL); //环境温度
  1072. ef_get_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity),NULL); //环境湿度
  1073. ef_get_env_blob("json_w_clock",&device_status.json_w_clock,sizeof(device_status.json_w_clock),NULL); //时间
  1074. ef_get_env_blob("json_w_reset",&device_status.json_w_reset,sizeof(device_status.json_w_reset),NULL); //重置
  1075. ef_get_env_blob("json_w_platform",&device_status.json_w_platform,sizeof(device_status.json_w_platform),NULL);//平台
  1076. ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
  1077. ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
  1078. ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL); //平台地址
  1079. /*孢子仪*/
  1080. ef_get_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time),NULL); //培养时间
  1081. ef_get_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw),NULL); //制冷开关
  1082. ef_get_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw),NULL); //加热开关
  1083. ef_get_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1),NULL); //采集开始1
  1084. ef_get_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1),NULL); //采集结束1
  1085. ef_get_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2),NULL); //采集开始2
  1086. ef_get_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2),NULL); //采集结束2
  1087. ef_get_env_blob("run_sta",&device_status.run_sta,sizeof(device_status.run_sta),NULL); //运行状态
  1088. ef_get_env_blob("InsectSpecies",&device_status.InsectSpecies,sizeof(device_status.InsectSpecies),NULL); //昆虫种类
  1089. ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL); //昆虫种类
  1090. ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL); //昆虫种类
  1091. ef_get_env_blob("sleep_mode",&device_status.sleep_mode,sizeof(device_status.sleep_mode),NULL); //休眠开关
  1092. device_status.light_over_tim = device_status.sunBar * 3600; //光控计数
  1093. device_status.work_done = 0;
  1094. //工作完成标志位
  1095. if(device_status.dattim==0)
  1096. {
  1097. device_status.dattim = 10;
  1098. }
  1099. device_status.dtype = 8;
  1100. device_status.version_type = 8;
  1101. rt_sprintf(device_status.driver, "%s",VERSION);
  1102. if(device_status.Power_Type>1) device_status.Power_Type = 0;
  1103. LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
  1104. LOG_I("read flash paramconfis:%d-%s-%s",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
  1105. LOG_I("开机次数:%d",device_status.rebootcnt);
  1106. LOG_I("定时开始时间:%d",device_status.startBar);
  1107. LOG_I("定时结束时间:%d",device_status.stopBar);
  1108. LOG_I("timeSwitch:%d",device_status.timeSwitch);
  1109. LOG_I("光控定时时长:%d",device_status.sunBar);
  1110. LOG_I("诱虫时间:%d",device_status.cul_time);
  1111. LOG_I("加热温度:%d",device_status.heatvalue);
  1112. LOG_I("震动开关:%d",device_status.shake_ws);
  1113. LOG_I("震动时间:%d",device_status.shake_sec);
  1114. LOG_I("高温保护:%d",device_status.tph);
  1115. LOG_I("低温保护:%d",device_status.tpl);
  1116. LOG_I("thsp:%d", device_status.thsp);
  1117. LOG_I("密码:%d",device_status.passWord);
  1118. LOG_I("数据上传间隔:%d",device_status.dattim);
  1119. LOG_I("温湿度数据:%d-%d",atoi(device_status.tempture),atoi(device_status.humidity));
  1120. LOG_I("上传平台:%s",device_status.mqttcfg1);
  1121. LOG_I("PowerType:%d",device_status.Power_Type);
  1122. LOG_I("deviceId:%s",device_status.deviceId);
  1123. LOG_I("sleep_mode:%d",device_status.sleep_mode);
  1124. }
  1125. //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
  1126. if(device_status.update_flag==1)
  1127. {
  1128. device_status.update_flag = 0;
  1129. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  1130. ymodem_ota(1,0);
  1131. }
  1132. else {
  1133. device_status.update_flag = 0;
  1134. //初始化联网状态
  1135. rt_sprintf(device_status.net,"1");
  1136. rt_sprintf(device_status.csq,"0");
  1137. rt_sprintf(device_status.sim,"1");
  1138. ctr_router(ON);
  1139. Hmi_Fresh();
  1140. Control_clear();
  1141. Control_heat();
  1142. dtu_data_play();
  1143. sht30_collect();
  1144. #if SENSOR_EN==1
  1145. mb_master_samlpe();
  1146. #endif
  1147. uint16_t connect_num=0;
  1148. //等待联网,
  1149. while(atoi(device_status.net)==1)
  1150. {
  1151. device_status.num_updata = 0;
  1152. if(Read_Real_Voltage()/100>5&&device_status.power_status==0)
  1153. ctr_RTU_DTU(ON);
  1154. char *readinfo = makeJson_ReadInfo();
  1155. DTU_Write("%s",readinfo);
  1156. rt_free(readinfo);
  1157. rt_thread_delay(1000);
  1158. connect_num++;
  1159. LOG_I("联网中......%d",connect_num);
  1160. //超时时间为3分钟
  1161. if(connect_num==180) //180
  1162. {
  1163. device_status.timeSwitch = 1;
  1164. LOG_W("Time not set:%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);
  1165. break;
  1166. }
  1167. if(tm.tm_year>=2021)
  1168. break;
  1169. }
  1170. connect_num = 0;
  1171. while(atoi(device_status.net)==0)
  1172. {
  1173. char *readinfo = makeJson_ReadInfo();
  1174. DTU_Write("%s",readinfo);
  1175. rt_free(readinfo);
  1176. rt_thread_delay(2000);
  1177. connect_num++;
  1178. if(connect_num>5) break;
  1179. }
  1180. device_status.timeSwitch = 1;
  1181. DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
  1182. rt_thread_delay(1000);
  1183. dtu_send_data_start();
  1184. Workstatus_check();
  1185. Work_Loop_Task();
  1186. }
  1187. }
  1188. void ResetParamDefault(void)
  1189. {
  1190. ctr_router(ON);
  1191. ctr_RTU_DTU(ON);
  1192. device_status.dtype = 8;
  1193. device_status.version_type = 8;
  1194. ef_set_env_blob("dtype", &device_status.dtype, sizeof(device_status.dtype));
  1195. device_status.InsectSpecies = 0;
  1196. ef_set_env_blob("InsectSpecies", &device_status.InsectSpecies, sizeof(device_status.InsectSpecies));
  1197. rt_sprintf(device_status.tempture,"%d",-15);
  1198. device_status.ds = 1; //设备状态开机
  1199. device_status.thsp = 300;
  1200. device_status.passWord = 8888;
  1201. device_status.dattim = 30;
  1202. device_status.collecting_sh1 = 9;
  1203. device_status.collecting_eh1 = 10;
  1204. device_status.collecting_sh2 = 14;
  1205. device_status.collecting_eh2 = 16;
  1206. device_status.Power_Type = 0;
  1207. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1208. if(device_status.dtype==8)
  1209. {
  1210. device_status.cul_time = 60; //收集时间
  1211. ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
  1212. device_status.dattim = 30; //数据上传间隔
  1213. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim)); //数据上传间隔
  1214. device_status.startBar = 9; //定时开始时间
  1215. device_status.stopBar = 18; //定时结束时间
  1216. device_status.heattime = 10; //加热时间
  1217. device_status.shake_ws = 1; //针对开关
  1218. device_status.shake_sec = 1; //震动时间1-100ms
  1219. device_status.sunBar = 8;
  1220. device_status.tph = 70; //高温保护阈值
  1221. device_status.tpl = -5; //低温保护阈值
  1222. device_status.timeSwitch = 1; //定时模式:时控
  1223. device_status.heatvalue=100; //加热温度
  1224. device_status.sleep_mode = 0;
  1225. ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));
  1226. ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
  1227. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1228. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1229. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1230. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1231. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1232. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1233. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1234. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1235. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1236. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1237. }
  1238. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1239. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1240. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1241. HMI_WRITE("play %d,%d,%d",1,5,0);
  1242. DTU_Write("reset.mp3");
  1243. rt_thread_delay(1000);
  1244. }
  1245. void ResetParamDefault_DC(void)
  1246. {
  1247. ctr_router(ON);
  1248. ctr_RTU_DTU(ON);
  1249. device_status.dtype = 8;
  1250. device_status.version_type = 8;
  1251. ef_set_env_blob("dtype", &device_status.dtype, sizeof(device_status.dtype));
  1252. device_status.InsectSpecies = 0;
  1253. ef_set_env_blob("InsectSpecies", &device_status.InsectSpecies, sizeof(device_status.InsectSpecies));
  1254. //将温度数据设置为-15摄氏度,以便上传的数据中包含温控数据
  1255. rt_sprintf(device_status.tempture,"%d",-15);
  1256. device_status.cul_time = 60; //收集时间
  1257. ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
  1258. device_status.dattim = 30; //数据上传间隔
  1259. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim)); //数据上传间隔
  1260. device_status.startBar = 9; //定时开始时间
  1261. device_status.stopBar = 18; //定时结束时间
  1262. device_status.heattime = 10; //加热时间
  1263. device_status.shake_ws = 1; //针对开关
  1264. device_status.shake_sec = 1; //震动时间1-100ms
  1265. #if LAMP_EN == 1
  1266. device_status.sunBar = 3; //光控定时时长
  1267. #else
  1268. device_status.sunBar = 4;
  1269. #endif
  1270. device_status.Power_Type = 1;
  1271. device_status.tph = 70; //高温保护阈值
  1272. device_status.tpl = -5; //低温保护阈值
  1273. device_status.timeSwitch = 1; //定时模式
  1274. device_status.heatvalue=100;
  1275. device_status.ds = 1; //设备状态开机
  1276. device_status.thsp = 300;
  1277. device_status.passWord = 8888;
  1278. device_status.Power_Type = 0;
  1279. device_status.sleep_mode = 0;
  1280. ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));
  1281. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1282. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1283. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  1284. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1285. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1286. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1287. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1288. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1289. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1290. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1291. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1292. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1293. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1294. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1295. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1296. ef_set_env_blob("Power_Type", &device_status.passWord,sizeof(device_status.Power_Type));
  1297. DTU_Write("reset.mp3");
  1298. rt_thread_delay(1000);
  1299. }
  1300. void Debug_log_ON(void)
  1301. {
  1302. rt_console_set_device("uart4");
  1303. finsh_set_device("uart4");
  1304. }
  1305. void Debug_log_OFF(void)
  1306. {
  1307. rt_console_set_device("uart1");
  1308. finsh_set_device("uart1");
  1309. rt_mq_init(&rx_mq, "rx_mq",
  1310. msg_pool, /* 存放消息的缓冲区 */
  1311. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  1312. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  1313. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  1314. rt_device_set_rx_indicate(serial, uart_input);
  1315. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  1316. Hmi_thread_entry,
  1317. RT_NULL,
  1318. HMI_THREAD_STACK_SIZE,
  1319. HMI_THREAD_PRIORITY,
  1320. HMI_THREAD_TIMESLICE);
  1321. if (hmi1 != RT_NULL)
  1322. {
  1323. rt_thread_startup(hmi1);
  1324. }
  1325. }
  1326. MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
  1327. MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
  1328. //
  1329. INIT_BOARD_EXPORT(HMI_uart4_init);