hmi.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982
  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 <float.h>
  30. #include <math.h>
  31. #define DBG_ENABLE
  32. #define DBG_COLOR
  33. #define DBG_TAG "hmi"
  34. #define DBG_LEVEL DBG_LOG
  35. #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
  36. #define HMI_THREAD_PRIORITY 5 //线程优先级
  37. #define HMI_THREAD_STACK_SIZE 2048 //线程栈空间大小
  38. #define HMI_THREAD_TIMESLICE 10 //时间片
  39. #define CONTROL_MOTOR_PRIORITY 7
  40. #define CONTROL_MOTOR_STACK_SIZE 2048
  41. #define CONTROL_MOTOR_TIMESLICE 5
  42. static char msg_pool[512];
  43. static char rx_buffer[HMI_UART_RXBUFFER_SIZE + 1];
  44. void list_mem(void);
  45. int mb_master_samlpe();
  46. /**/
  47. Device_Status_typedef device_status;
  48. Device_slide_typedef slide_para;
  49. time_t time(time_t *t);
  50. /* 串口接收消息结构*/
  51. struct rx_msg
  52. {
  53. rt_device_t dev;
  54. rt_size_t size;
  55. };
  56. struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
  57. ////
  58. static rt_thread_t hmi1 = RT_NULL;
  59. static rt_thread_t ctr_motor = RT_NULL;
  60. rt_device_t serial; /*串口设备句柄*/
  61. rt_timer_t timer_uart2 = RT_NULL;
  62. /* 消息队列控制块 */
  63. static struct rt_messagequeue rx_mq;//接收数据消息队列
  64. static void HMI_Decode(void);
  65. static rt_err_t uart_input(rt_device_t dev, rt_size_t size);
  66. static int HMI_uart4_init(void)
  67. {
  68. serial = rt_device_find(UART_NAME);
  69. /*修改串口配置参数*/
  70. config.baud_rate = BAUD_RATE_115200; //修改波特率9600
  71. config.data_bits = DATA_BITS_8; //数据位8
  72. config.stop_bits = STOP_BITS_1; //停止位1
  73. #ifdef RT_USING_SERIAL_V2
  74. config.rx_bufsz = 512;
  75. config.tx_bufsz = 128;
  76. #else
  77. config.bufsz = 512; //缓冲区128字节
  78. #endif
  79. config.parity = PARITY_NONE; //无奇偶校验
  80. /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
  81. rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
  82. // /* step4:打开串口设备。以中断接收及轮询发送模式打开串口设备 */
  83. //rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
  84. /* 以 DMA 接收及轮询发送模式打开串口设备 */
  85. #ifdef RT_USING_SERIAL_V2
  86. rt_err_t uart_res = rt_device_open(serial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
  87. #else
  88. rt_err_t uart_res = rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX); //RT_DEVICE_FLAG_DMA_RX
  89. #endif
  90. if(uart_res!=RT_EOK)
  91. {
  92. LOG_E("%s打开失败!",UART_NAME);
  93. }else{
  94. LOG_I("%s Open Success!",UART_NAME);
  95. }
  96. return RT_EOK;
  97. }
  98. /*串口屏写数据*/
  99. void HMI_WRITE(char *fmt, ...)
  100. {
  101. va_list ap;
  102. //末尾需要拼接的3个ff
  103. const char hmi_hex[3]={0xff,0xff,0xff};
  104. static char str[MAX_SIZE];
  105. memset(str,'\0',sizeof(str));
  106. rt_size_t str_length;
  107. va_start(ap,fmt);
  108. str_length = rt_vsnprintf(str, sizeof(str) - 1, fmt, ap);
  109. if (str_length > MAX_SIZE - 1)
  110. str_length = MAX_SIZE - 1;
  111. rt_device_write(serial, 0, str, str_length);
  112. va_end(ap);
  113. rt_device_write(serial, 0,hmi_hex,3);
  114. }
  115. /* 接收数据回调函数 */
  116. static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
  117. {
  118. struct rx_msg msg;
  119. rt_err_t result;
  120. msg.dev = dev;
  121. msg.size = size;
  122. result = rt_mq_send(&rx_mq, &msg, sizeof(msg));
  123. if ( result == -RT_EFULL)
  124. {
  125. /* 消息队列满 */
  126. LOG_I("hmi message queue full!\n");
  127. }
  128. return result;
  129. }
  130. /*入口函数*/
  131. static void Hmi_thread_entry(void *parameter)
  132. {
  133. struct rx_msg msg;
  134. rt_err_t result;
  135. rt_uint32_t rx_length;
  136. if(device_status.dtype==3){
  137. device_status.collt_box_sta = 0;
  138. device_status.run_sta = 0;
  139. }
  140. device_status.camsta = 1;
  141. while(1)
  142. {
  143. rt_memset(&msg, 0, sizeof(msg));
  144. /* 从消息队列中读取消息*/
  145. result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), 50);
  146. if (result == RT_EOK)
  147. {
  148. rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
  149. rx_buffer[rx_length] = '\0';
  150. //LOG_I("%s",rx_buffer);
  151. //\r 对应的hex为0x0d,0x0a,占两个字节,屏幕发送的数据都以\r结尾
  152. HMI_Decode();
  153. }
  154. /*********************************************************************************************************************/
  155. //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);
  156. //rt_kprintf("workSta.vbat.txt=%c%d.%02d%c\n",hmi_str,voltage/100,voltage%100,hmi_str);
  157. }
  158. }
  159. /*******************************************************************************************/
  160. static void t_uart2_callback(void *parameter)
  161. {
  162. HMI_WRITE("sysSet.va0.txt=\"指令超时,请重试...\"");
  163. LOG_E("t_uart2_callback");
  164. }
  165. void Start_timer_Uart2(void)
  166. {
  167. if(timer_uart2!=RT_NULL)
  168. {
  169. rt_timer_start(timer_uart2);
  170. }
  171. else
  172. {
  173. LOG_E("timer_uart2 start Failed!");
  174. }
  175. }
  176. /***************************** 解析从屏幕收到的数据 begin **********************************/
  177. static void HMI_Decode(void)
  178. {
  179. time_t now = time(RT_NULL);
  180. static struct tm tm;
  181. gmtime_r(&now, &tm);
  182. char *json_temp;
  183. char *var=NULL;
  184. rt_free(var);
  185. if(device_status.refresh_num==0) device_status.refresh_num = 10;
  186. if(strstr(rx_buffer,"getFullData") != NULL){
  187. char *readinfo = makeJson_ReadInfo();
  188. if(device_status.refresh_num==5)
  189. {
  190. device_status.refresh_num = 15;
  191. DTU_Write("%s",readinfo);
  192. //list_mem();
  193. device_status.hmi_fresh = 1;
  194. rt_thread_delay(100);
  195. }
  196. //在解析getinfo中清除超时
  197. if(device_status.refresh_timeout==30)
  198. {
  199. rt_sprintf(device_status.sim,"1");
  200. rt_sprintf(device_status.net,"1");
  201. rt_sprintf(device_status.csq,"0");
  202. device_status.camsta = 1;
  203. device_status.link_sta=0;
  204. device_status.refresh_timeout=0;
  205. }
  206. rt_free(readinfo);
  207. device_status.refresh_num--;
  208. device_status.refresh_timeout++;
  209. if(device_status.version_type!=6)
  210. {
  211. HMI_WRITE("uploadSet.iccid.txt=\"%s\"",device_status.iccid);
  212. if(strstr(device_status.mqttcfg1,"8.136.98.49")!=NULL)
  213. {
  214. HMI_WRITE("uploadSet.plt.val=%d",RESET);
  215. }
  216. else if (strstr(device_status.mqttcfg1,"120.27.222.26")!=NULL) {
  217. HMI_WRITE("uploadSet.plt.val=%d",SET);
  218. }
  219. //HMI_WRITE("mqttcfg.mqtt1Message.txt=\"%s\"",device_status.mqttcfg1);
  220. HMI_WRITE("uploadSet.t0.txt=\"%s\"",device_status.mqttcfg1);
  221. //更新固件版本号
  222. HMI_WRITE("debug.t3.txt=\"%s\"",device_status.driver);
  223. //更新固件编译日期
  224. HMI_WRITE("debug.t4.txt=\"%s\"",device_status.driver_compile);
  225. //
  226. HMI_WRITE("debug.t5.txt=\"%s\"",device_status.driver_bl);
  227. HMI_WRITE("debug.t7.txt=\"%s\"",device_status.driver_compile);
  228. //更新dtu/rtu版本
  229. HMI_WRITE("debug.t9.txt=\"%s\"",device_status.driver_4g);
  230. //更新时间
  231. 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);
  232. 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);
  233. HMI_WRITE("set.t0.txt=\"%d\"",tm.tm_hour);
  234. HMI_WRITE("set.t1.txt=\"%d\"",tm.tm_min);
  235. HMI_WRITE("set.t2.txt=\"%d\"",tm.tm_sec);
  236. //更新电压
  237. HMI_WRITE("workSta.vbat.txt=\"%s\"",device_status.voltage);
  238. //更新电流
  239. HMI_WRITE("workSta.power.txt=\"%s\"",device_status.power);
  240. //更新温湿度数据
  241. HMI_WRITE("workSta.envHum.val=%d",atoi(device_status.humidity));
  242. HMI_WRITE("workSta.envTem.val=%d",atoi(device_status.tempture));
  243. //更新电池状态
  244. HMI_WRITE("workSta.batStatus.val=%d",device_status.bat_status);
  245. //更新上仓门状态
  246. HMI_WRITE("workSta.upStatus.val=%d",device_status.up_status);
  247. //更新下仓门状态
  248. HMI_WRITE("workSta.downStatus.val=%d",device_status.down_status);
  249. //更新工作状态
  250. HMI_WRITE("workSta.workStatus.val=%d",device_status.work_status);
  251. //更新温控状态
  252. HMI_WRITE("workSta.tempStatus.val=%d",device_status.temp_status);
  253. //更新雨控状态
  254. HMI_WRITE("workSta.rainStatus.val=%d",device_status.rain_status);
  255. //更新光控状态
  256. HMI_WRITE("workSta.sunStatus.val=%d",device_status.sun_status);
  257. //更新有线连接状态
  258. HMI_WRITE("menu.va_net.val=%d",device_status.link_sta);
  259. //更新CSQ
  260. HMI_WRITE("menu.csq_value.txt=\"%s\"",device_status.csq);
  261. HMI_WRITE("menu.va_csq.val=%d",atoi(device_status.csq));
  262. HMI_WRITE("workSta.csq_value.txt=\"%s\"",device_status.csq);
  263. //更新收集时间
  264. HMI_WRITE("sysSet.stime.val=%d",device_status.clt_time);
  265. //更新加热时间
  266. HMI_WRITE("workSta.heatTime.val=%d",device_status.heattime);
  267. HMI_WRITE("sysSet.jtime.val=%d",device_status.heattime);
  268. //
  269. HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
  270. //更新加热时间和温度
  271. HMI_WRITE("workSta.heatTem.val=%d",device_status.heattem);
  272. HMI_WRITE("sysSet.jheat.val=%d",device_status.heatvalue);
  273. //更新加热状态
  274. HMI_WRITE("workSta.heatStatus.val=%d",device_status.heat_status);
  275. //更新密码
  276. HMI_WRITE("inputPasswd.pwdData.txt=\"8888\"");
  277. //更新时间设置中的参数
  278. //更新定时模式
  279. HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
  280. //更新光控定时时长
  281. HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
  282. //更新时控开始
  283. HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
  284. //更新时控结束
  285. HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
  286. //SIM卡状态
  287. HMI_WRITE("workSta.bt0.val=%d",atoi(device_status.sim));
  288. //ID
  289. HMI_WRITE("menu.equipid.txt=\"%s\"",device_status.imei);
  290. HMI_WRITE("menu.deviceId.txt=\"%s\"",device_status.deviceId);
  291. //HMI_WRITE("workSta.equipid.txt=\"%s\"",device_status.imei);
  292. //数据上传间隔
  293. HMI_WRITE("uploadSet.datt.val=%d",device_status.dattim);
  294. //语音音量
  295. HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
  296. //更新熄屏时间
  297. if(device_status.thsp<60) device_status.thsp = device_status.thsp * 60;
  298. HMI_WRITE("thsp=%d",device_status.thsp);
  299. }
  300. HMI_WRITE("menu.cam_sta.val=%d",device_status.camsta);
  301. #if BOOT_ERR == 1
  302. if(atoi(device_status.gps)==1){
  303. HMI_WRITE("menu.gps_state.txt=\"定位成功:(%s)%d/%d\"",device_status.gps_state,device_status.gps_inuse,device_status.gps_view);
  304. }else if(atoi(device_status.gps)==2){
  305. HMI_WRITE("menu.gps_state.txt=\"定位成功:(基站)\"");
  306. }
  307. #endif
  308. //更新联网状态
  309. if(atoi(device_status.net)==1)
  310. {
  311. HMI_WRITE("menu.net.val=1");
  312. HMI_WRITE("workSta.net.val=1");
  313. }
  314. else {
  315. HMI_WRITE("workSta.net.val=0");
  316. HMI_WRITE("menu.net.val=0");
  317. }
  318. if(atoi(device_status.csq)==0&&atoi(device_status.net)==1)
  319. {
  320. HMI_WRITE("menu.net.val=1");
  321. HMI_WRITE("workSta.net.val=2");
  322. }
  323. if(device_status.dtype==7)
  324. {
  325. //更新温湿度数据
  326. HMI_WRITE("workSta.env_hum.txt=\"%s\"",device_status.humidity);
  327. HMI_WRITE("workSta.env_tem.txt=\"%s\"",device_status.tempture);
  328. HMI_WRITE("workSta.on_off.val=%d",device_status.ds);
  329. HMI_WRITE("workSta.work_sta.val=%d",device_status.work_status);
  330. HMI_WRITE("workSta.collect_fan.val=%d",device_status.collect_fan_status);
  331. //更新电池状态
  332. HMI_WRITE("workSta.bat_sta.val=%d",device_status.bat_status);
  333. //更新散热风机状态
  334. HMI_WRITE("workSta.cool_fan.val=%d",device_status.cool_fan_status);
  335. //更新开关状态
  336. HMI_WRITE("workSta.on_off.val=%d",device_status.ds);
  337. //更新工作状态
  338. HMI_WRITE("workSta.work_sta.val=%d",device_status.work_status);
  339. //箱内温度-外壳
  340. HMI_WRITE("workSta.box_tmp.txt=\"%d\"",device_status.box_temp);
  341. HMI_WRITE("temHum.box_tmp.txt=\"%d\"",device_status.box_temp);
  342. //制冷开关
  343. HMI_WRITE("workSta.cold_sw.val=%d",device_status.cold_sw);
  344. HMI_WRITE("sysSet.cold_sw.val=%d",device_status.cold_sw);
  345. //制冷状态
  346. HMI_WRITE("workSta.cold_sta.val=%d",device_status.cold_status);
  347. HMI_WRITE("sysSet.cold_sw.val=%d",device_status.cold_sw);
  348. //培养温度
  349. HMI_WRITE("workSta.set_temp.val=%d",device_status.heatvalue);
  350. HMI_WRITE("sysSet.keep.val=%d",device_status.heatvalue);
  351. //数据上传间隔
  352. HMI_WRITE("sysSet.datt.val=%d",device_status.dattim);
  353. HMI_WRITE("sysSet.lcd_time.val=%d",device_status.thsp*60);
  354. //当前温度-培养仓
  355. HMI_WRITE("workSta.pre_temp.val=%d",device_status.pre_temp);
  356. //设定培养时间
  357. HMI_WRITE("workSta.cul_time.val=%d",device_status.cul_time);
  358. HMI_WRITE("clockSet.stay.val=%d",device_status.cul_time);
  359. //已培养时间
  360. if(device_status.develop_flag==0)
  361. HMI_WRITE("workSta.staytime.txt=\"0\"");
  362. //滴液时间
  363. HMI_WRITE("clockSet.drop.val=%d",device_status.shake_sec);
  364. //采集开始时间1
  365. HMI_WRITE("clockSet.start1.val=%d",device_status.collecting_sh1);
  366. //采集开始时间2
  367. HMI_WRITE("clockSet.start2.val=%d",device_status.collecting_sh2);
  368. //采集结束时间1
  369. HMI_WRITE("clockSet.end1.val=%d",device_status.collecting_eh1);
  370. //采集结束时间2
  371. HMI_WRITE("clockSet.end2.val=%d",device_status.collecting_eh2);
  372. if(device_status.autotakepic==0) HMI_WRITE("sysTest.auto_flag.txt=\"\"");
  373. }
  374. /**********************************吸虫塔*********************************/
  375. if(device_status.version_type==6)
  376. {
  377. HMI_WRITE("menu.equipid.txt=\"%s\"",device_status.imei);
  378. //更新电压
  379. HMI_WRITE("menu.vbat.txt=\"%sV\"",device_status.voltage);
  380. //工作状态
  381. HMI_WRITE("menu.worksta.val=%d",device_status.work_status);
  382. //网卡0状态
  383. HMI_WRITE("menu.eth0_sta.val=%d",device_status.link_sta);
  384. //更新电流
  385. HMI_WRITE("menu.power.txt=\"%smA\"",device_status.power);
  386. //更新温湿度数据
  387. HMI_WRITE("menu.envHum.txt=\"%s%RH\"",device_status.humidity);
  388. HMI_WRITE("menu.envTem.txt=\"%s℃\"",device_status.tempture);
  389. HMI_WRITE("uploadSet.st.val=%d",device_status.startBar);
  390. HMI_WRITE("uploadSet.et.val=%d",device_status.stopBar);
  391. HMI_WRITE("menu.board_temp.txt=\"%d.%d℃\"",Get_Temprate()/100,Get_Temprate()%100);
  392. //数据上传间隔
  393. HMI_WRITE("menu.datt.val=%d",device_status.dattim);
  394. //SIM卡状态
  395. HMI_WRITE("menu.bt0.val=%d",atoi(device_status.sim));
  396. //更新震动时间
  397. HMI_WRITE("menu.shake_sec.val=%d",device_status.shake_sec);
  398. //校准屏幕的RTC
  399. HMI_WRITE("rtc0=%d",tm.tm_year+1900);
  400. HMI_WRITE("rtc1=%d",tm.tm_mon+1);
  401. HMI_WRITE("rtc2=%d",tm.tm_mday);
  402. HMI_WRITE("rtc3=%d",tm.tm_hour);
  403. HMI_WRITE("rtc4=%d",tm.tm_min);
  404. HMI_WRITE("rtc5=%d",tm.tm_sec);
  405. //更新熄屏时间
  406. HMI_WRITE("thsp=%d",device_status.thsp);
  407. }
  408. /**********************************************************************/
  409. }
  410. else if (strstr(rx_buffer,"getClockData")!=NULL) {
  411. //更新定时模式
  412. HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
  413. //更新光控定时时长
  414. HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
  415. //更新时控开始
  416. HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
  417. //更新时控结束
  418. HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
  419. }
  420. else if (strstr(rx_buffer,"button")!=NULL) {
  421. LOG_D("button!");
  422. DTU_Write("button");
  423. }
  424. //拍照
  425. else if(strstr(rx_buffer,"putTest.switchPhoto=1")!=NULL) {
  426. device_status.photo_ws = 1;
  427. }
  428. else if (strstr(rx_buffer,"putTest.switchPic=1")!=NULL) {
  429. device_status.photo_ws = 1;
  430. }
  431. //打开电磁阀
  432. else if (strstr(rx_buffer,"putTest.switchDrop=1")!=NULL) {
  433. LOG_I("开始滴液!");
  434. #if Color_EN == 1
  435. device_status.run_sta = 5;
  436. #else
  437. ctr_shake(ON, device_status.shake_sec);
  438. #endif
  439. }
  440. //关闭电磁阀
  441. else if (strstr(rx_buffer,"putTest.switchDrop=0")!=NULL) {
  442. LOG_I("停止滴液!");
  443. ctr_shake(OFF, 0);
  444. }
  445. //打开补光
  446. else if (strstr(rx_buffer,"putTest.switchLed=1")!=NULL) {
  447. LOG_I("打开补光!!");
  448. ctr_led(ON);
  449. }
  450. //关闭补光
  451. else if (strstr(rx_buffer,"putTest.switchLed=0")!=NULL) {
  452. LOG_I("关闭补光!!!");
  453. ctr_led(OFF);
  454. }
  455. //关闭加热
  456. else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
  457. device_status.heat_status = 0;
  458. ctr_Heat(OFF);
  459. LOG_I("Close Heat!");
  460. }
  461. //打开加热
  462. else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
  463. device_status.heat_status = 1;
  464. ctr_Heat(ON);
  465. LOG_I("Open Heat!");
  466. }
  467. //打开制冷
  468. else if(strstr(rx_buffer,"putTest.switchCold=1")!=NULL) {
  469. ctr_Cold(ON);
  470. LOG_I("Open Cold!");
  471. }
  472. //关闭制冷
  473. else if(strstr(rx_buffer,"putTest.switchCold=0")!=NULL) {
  474. ctr_Cold(OFF);
  475. LOG_I("Close Cold!");
  476. }
  477. //打开采集
  478. else if(strstr(rx_buffer,"putTest.switchCollect=1")!=NULL){
  479. ctr_Collect_Fan(ON);
  480. LOG_I("采集风机已打开!");
  481. }
  482. //关闭采集
  483. else if(strstr(rx_buffer,"putTest.switchCollect=0")!=NULL){
  484. ctr_Collect_Fan(OFF);
  485. LOG_I("采集风机已关闭!");
  486. }
  487. //打开散热
  488. else if(strstr(rx_buffer,"putTest.switchCool=1")!=NULL){
  489. ctr_Cool_Fan(ON);
  490. LOG_I("散热风机已打开!");
  491. }
  492. //关闭散热
  493. else if(strstr(rx_buffer,"putTest.switchCool=0")!=NULL){
  494. ctr_Cool_Fan(OFF);
  495. LOG_I("散热风机已关闭!");
  496. }
  497. //开始对焦拍照
  498. else if(strstr(rx_buffer,"putTest.switchAutopic=1")!=NULL){
  499. device_status.autotakepic=1;
  500. rt_kprintf("开始对焦拍照!\n");
  501. }
  502. //停止对焦拍照
  503. else if(strstr(rx_buffer,"putTest.switchAutopic=0")!=NULL){
  504. device_status.autotakepic=0;
  505. }
  506. //粘附测试-开
  507. else if(strstr(rx_buffer,"putTest.switchFsl=1")!=NULL){
  508. rt_kprintf("粘附测试开!\n");
  509. device_status.fsl_sw = 1;
  510. }
  511. //粘附测试-关
  512. else if(strstr(rx_buffer,"putTest.switchFsl=0")!=NULL){
  513. rt_kprintf("粘附测试关!\n");
  514. pwm_off(2, 0);
  515. pwm_off(3,0);
  516. }
  517. else if (strstr(rx_buffer,"putTest.switchAutotest=1")!=NULL)
  518. {
  519. LOG_I("开始一键测试!!!");
  520. device_status.auto_test_sw=1;
  521. }
  522. else if (strstr(rx_buffer,"putTest.switchAutotest=1")!=NULL)
  523. {
  524. LOG_I("停止一键测试!!!");
  525. device_status.auto_test_sw=0;
  526. }
  527. //震动
  528. else if (strstr(rx_buffer,"putTest.switchShake=1")!=NULL) {
  529. LOG_I("震动!");
  530. if(device_status.version_type==6)
  531. {
  532. Motor_shake(ON, device_status.shake_sec);
  533. }
  534. else{
  535. ctr_shake(ON,device_status.shake_sec);
  536. }
  537. }
  538. //打开补光
  539. else if (strstr(rx_buffer,"putTest.switchFill=1")!=NULL) {
  540. rt_kprintf("\n打开补光!!!\n");
  541. ctr_led(ON);
  542. }
  543. //关闭补光
  544. else if (strstr(rx_buffer,"putTest.switchFill=0")!=NULL) {
  545. rt_kprintf("\n关闭补光!!!\n");
  546. ctr_led(OFF);
  547. }
  548. //打开灯管
  549. else if (strstr(rx_buffer,"putTest.switchLamp=1")!=NULL)
  550. {
  551. device_status.test_flag=1;
  552. rt_kprintf("Open Lamp!\n");
  553. ctr_lamp(ON,1);
  554. #if LAMP_EN == 1
  555. ctr_lamp(ON,2);
  556. ctr_lamp(ON,3);
  557. #endif
  558. }
  559. //关闭灯管
  560. else if (strstr(rx_buffer,"putTest.switchLamp=0")!=NULL)
  561. {
  562. device_status.test_flag=0;
  563. rt_kprintf("Close Lamp1!\n");
  564. ctr_lamp(OFF,1);
  565. #if LAMP_EN == 1
  566. ctr_lamp(OFF,2);
  567. ctr_lamp(OFF,3);
  568. #endif
  569. }
  570. //关闭加热
  571. else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
  572. device_status.heat_status = 0;
  573. ctr_Heat(OFF);
  574. rt_kprintf("Close Heat!\n");
  575. }
  576. //打开加热
  577. else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
  578. device_status.heat_status = 1;
  579. ctr_Heat(ON);
  580. rt_kprintf("Open Heat!\n");
  581. }
  582. else if(strstr(rx_buffer,"putTest.Testpaichong")!=NULL){
  583. if(device_status.collt_box_sta==0){
  584. device_status.collt_box_sta = 111;
  585. }else{
  586. HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
  587. }
  588. LOG_I("排虫测试!");
  589. }
  590. //排虫
  591. else if(strstr(rx_buffer,"putTest.paichong")!=NULL){
  592. if(device_status.run_sta == 0){
  593. device_status.run_sta = 111;
  594. }else{
  595. HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
  596. }
  597. LOG_I("开始排虫!");
  598. device_status.handle_bugger = 0;
  599. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  600. }
  601. else if(strstr(rx_buffer,"putTest.shouchong")!=NULL){
  602. if(device_status.run_sta == 0){
  603. device_status.run_sta = 112;
  604. }else{
  605. HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
  606. }
  607. LOG_I("开始收虫!");
  608. device_status.handle_bugger = 1;
  609. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  610. }
  611. //设置设备时间
  612. else if (strstr(rx_buffer,"stamp=")!=NULL)
  613. {
  614. var = strstr(rx_buffer,"=");
  615. var ++;
  616. LOG_I("设置时间:%s",var);
  617. static char year_s[5],month_s[3],day_s[3],hour_s[3],min_s[3],sec_s[3];
  618. strncpy(year_s, var, 4);
  619. strncpy(month_s,var+4,2);
  620. strncpy(day_s,var+6,2);
  621. strncpy(hour_s,var+8,2);
  622. strncpy(min_s,var+10,2);
  623. strncpy(sec_s,var+12,2);
  624. 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)
  625. {
  626. if(set_date(atoi(year_s),atoi(month_s),atoi(day_s))==RT_EOK)
  627. {
  628. LOG_I("设置日期:%d年%d月%d日",atoi(year_s),atoi(month_s),atoi(day_s));
  629. 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)
  630. {
  631. LOG_I("设置时间:%d时%d分%d秒",atoi(hour_s),atoi(min_s),atoi(sec_s));
  632. set_time(atoi(hour_s),atoi(min_s),atoi(sec_s));
  633. MA_save();
  634. }
  635. //上传最新数据
  636. device_status.num_updata = 2; //2秒后上报数据更新RTU的时间
  637. }
  638. else {
  639. LOG_E("set_date failed!");
  640. }
  641. }
  642. }
  643. //设备编码设置
  644. else if (strstr(rx_buffer,"deviceId=")!=NULL)
  645. {
  646. char value_str[20];
  647. memset(value_str,0,sizeof(value_str));
  648. LOG_I("设备编码 长度:%d",strlen(rx_buffer));
  649. if(strlen(rx_buffer)!=19){
  650. LOG_E("编码长度错误!");
  651. return;
  652. }
  653. var = strstr(rx_buffer,"=");
  654. var ++;
  655. strncpy(value_str,var,8); //设备编码为16位
  656. if(strstr(value_str,"00000000")!=RT_NULL){
  657. char *config_reset = makeJson_Config_Reset();
  658. //发送json到RTU
  659. DTU_Write("%s",config_reset);
  660. rt_free(config_reset);
  661. //恢复RTU的默认配置参数
  662. }else{
  663. rt_sprintf(device_status.deviceId,"10300101%s",value_str); //设备大类编码103-虫情 设备小类编码 001 生产商代码01
  664. ef_set_env_blob("deviceId", &device_status.deviceId, sizeof(device_status.deviceId));
  665. LOG_I("解析到设备编码:%s",device_status.deviceId);
  666. char *device_id = makeJson_Config_BDH(device_status.deviceId);
  667. //发送json到RTU
  668. DTU_Write("%s",device_id);
  669. rt_free(device_id);
  670. }
  671. }
  672. //定时设置
  673. else if (strstr(rx_buffer,"saveClockSet=")!=NULL) {
  674. char value_str[10];
  675. memset(value_str,0,sizeof(value_str));
  676. if(device_status.dtype==7)
  677. {
  678. var = strstr(rx_buffer,"=");
  679. var ++;
  680. strncpy(value_str,var,2);
  681. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  682. {
  683. device_status.collecting_sh1 = atoi(value_str);
  684. ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1));
  685. }
  686. else {
  687. LOG_E("Set collecting_sh1 Failed!");
  688. }
  689. memset(value_str,0,sizeof(value_str));
  690. strncpy(value_str,var+2,2);
  691. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  692. {
  693. device_status.collecting_eh1 = atoi(value_str);
  694. ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1));
  695. }
  696. else {
  697. LOG_E("Set collecting_eh1 Failed!");
  698. }
  699. memset(value_str,0,sizeof(value_str));
  700. strncpy(value_str,var+4,2);
  701. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  702. {
  703. device_status.collecting_sh2 = atoi(value_str);
  704. ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2));
  705. }
  706. else {
  707. LOG_E("Set collecting_sh2 Failed!");
  708. }
  709. memset(value_str,0,sizeof(value_str));
  710. strncpy(value_str,var+6,2);
  711. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  712. {
  713. device_status.collecting_eh2 = atoi(value_str);
  714. ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2));
  715. }
  716. else {
  717. LOG_E("Set collecting_eh2 Failed!");
  718. }
  719. memset(value_str,0,sizeof(value_str));
  720. strncpy(value_str,var+8,2);
  721. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  722. {
  723. device_status.shake_sec = atoi(value_str);
  724. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
  725. }
  726. else {
  727. LOG_E("Set shake_sec Failed!");
  728. }
  729. memset(value_str,0,sizeof(value_str));
  730. strncpy(value_str,var+10,2);
  731. if(atoi(value_str)>0&&atoi(value_str)<=24)
  732. {
  733. device_status.cul_time = atoi(value_str);
  734. ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
  735. }
  736. else {
  737. LOG_E("Set cul_time Failed!");
  738. }
  739. MA_save();
  740. LOG_I("参数已保存:%d-%d-%d-%d-%d-%d",device_status.collecting_sh1,device_status.collecting_eh1,device_status.collecting_sh2,device_status.collecting_eh2,device_status.shake_sec,device_status.cul_time);
  741. return;
  742. }
  743. LOG_I("时间设置!");
  744. var=strstr(rx_buffer,"=");
  745. var++;
  746. strncpy(value_str,var,2);
  747. if(atoi(value_str) > 0 && atoi(value_str) <60)
  748. {
  749. if(device_status.version_type!=6)
  750. {
  751. #if LAMP_EN == 1
  752. if(device_status.sunBar%3==0)
  753. #endif
  754. device_status.sunBar=atoi(value_str);
  755. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  756. }
  757. else {
  758. device_status.shake_sec = atoi(value_str);
  759. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
  760. }
  761. // time_t now;
  762. // time(&now);
  763. // static struct tm nowstamp;
  764. // nowstamp =*localtime(&now);
  765. // nowstamp.tm_hour = nowstamp.tm_hour - 8;
  766. // static rt_uint32_t nowstamp_num = 0;
  767. // nowstamp_num = mktime(&nowstamp);
  768. // device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
  769. }
  770. else {
  771. LOG_E("参数设置异常(光控时长):%d!!!",atoi(value_str));
  772. }
  773. memset(value_str,0,sizeof(value_str));
  774. //时控开始时间
  775. strncpy(value_str,var+2,2);
  776. if(atoi(value_str) >= 0 && atoi(value_str) < 24)
  777. {
  778. #if 1
  779. device_status.startBar=atoi(value_str);
  780. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  781. #endif
  782. }
  783. else {
  784. LOG_E("参数设置异常(开始):%d!!!",atoi(value_str));
  785. }
  786. memset(value_str,0,sizeof(value_str));
  787. //
  788. strncpy(value_str,var+4,2);
  789. if(atoi(value_str) >= 0&& atoi(value_str) < 24)
  790. {
  791. #if 1
  792. device_status.stopBar=atoi(value_str);
  793. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  794. #endif
  795. }
  796. else {
  797. LOG_E("参数设置异常(结束):%d!!!",atoi(value_str));
  798. }
  799. memset(value_str,0,sizeof(value_str));
  800. //
  801. strncpy(value_str,var+6,2);
  802. if(atoi(value_str) >= 0 && atoi(value_str) <= 1)
  803. {
  804. device_status.timeSwitch=atoi(value_str);
  805. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  806. }
  807. else {
  808. if(device_status.version_type==6)
  809. {
  810. device_status.timeSwitch=1;
  811. device_status.dattim=atoi(value_str);
  812. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
  813. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  814. }
  815. else {
  816. LOG_E("参数设置异常(模式):%d!!!",atoi(value_str));
  817. }
  818. }
  819. //2022/06/23,add:
  820. 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);
  821. json_temp = makeJson_Warn(device_status.json_w_clock, "修改工作时间");
  822. ef_set_env_blob("json_w_clock", &device_status.json_w_clock, sizeof(device_status.json_w_clock)); //将修改屏幕参数操作记录保存到Flash中
  823. if(atoi(device_status.net)==0)
  824. DTU_Write("%s",json_temp);
  825. rt_free(json_temp);
  826. rt_thread_delay(2000);
  827. MA_save();
  828. rt_free(var);
  829. rt_kprintf("工作时间参数已保存:模式-%d,光控时间-%d,时控开始时间-%d,时控结束时间-%d\n",device_status.timeSwitch,device_status.sunBar,device_status.startBar,device_status.stopBar);
  830. }
  831. else if (strstr(rx_buffer,"saveSystemSet")!=NULL) {
  832. static char clt_time_str[3],heattime_str[3],heatvale_str[4],vol_str[4],thsp_str[5];
  833. static char value_temp[5];
  834. LOG_I("系统设置!");
  835. if(device_status.dtype==7)
  836. {
  837. LOG_I("系统设置,孢子仪!");
  838. var = strstr(rx_buffer,"=");
  839. var ++;
  840. memset(value_temp,0,sizeof(value_temp));
  841. strncpy(value_temp,var,2);
  842. if(atoi(value_temp)==0 || atoi(value_temp) == 1)
  843. {
  844. device_status.cold_sw = atoi(value_temp); //制冷开关
  845. ef_set_env_blob("cold_sw", &device_status.cold_sw, sizeof(device_status.cold_sw));
  846. }
  847. else {
  848. LOG_E("制冷开关参数设置错误!");
  849. }
  850. memset(value_temp,0,sizeof(value_temp));
  851. strncpy(value_temp,var+2,2);
  852. if(atoi(value_temp)>=0 && atoi(value_temp) <= 7)
  853. {
  854. device_status.vol = atoi(value_temp); //音量
  855. }
  856. else {
  857. LOG_E("音量参数设置错误!");
  858. }
  859. memset(value_temp,0,sizeof(value_temp));
  860. strncpy(value_temp,var+4,2);
  861. if(atoi(value_temp)>=10 && atoi(value_temp) <= 50)
  862. {
  863. device_status.heatvalue = atoi(value_temp); //设定的培养温度
  864. ef_set_env_blob("heatvalue", &device_status.heatvalue, sizeof(device_status.heatvalue));
  865. }
  866. else {
  867. LOG_E("培养温度参数设置失败!");
  868. }
  869. memset(value_temp,0,sizeof(value_temp));
  870. strncpy(value_temp,var+6,2);
  871. if(atoi(value_temp)>=1 && atoi(value_temp) <= 60)
  872. {
  873. device_status.dattim = atoi(value_temp); //设定的数据上传间隔,单位:分钟
  874. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
  875. }
  876. else {
  877. LOG_E("数据上传间隔参数设置失败!");
  878. }
  879. memset(value_temp,0,sizeof(value_temp));
  880. strncpy(value_temp,var+8,2);
  881. if(atoi(value_temp)>=1 && atoi(value_temp) <= 30)
  882. {
  883. device_status.thsp = atoi(value_temp); //设定的息屏间隔,单位:分钟
  884. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  885. }
  886. else {
  887. LOG_E("数据息屏间隔参数设置失败!");
  888. }
  889. LOG_I("制冷开关:%d",device_status.cold_sw);
  890. LOG_I("系统设置已保存:\n自动熄屏-%d\n音量-%d\n培养温度-%d\n数据上传间隔-%d",device_status.thsp,device_status.vol,device_status.heatvalue,device_status.dattim);
  891. MA_save();
  892. return;
  893. }
  894. var = strstr(rx_buffer,"=");
  895. var ++;
  896. strncpy(clt_time_str,var,2);
  897. if(atoi(clt_time_str)>0 && atoi(clt_time_str) <= 30)
  898. {
  899. device_status.clt_time = atoi(clt_time_str); //收集时间
  900. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  901. }
  902. strncpy(heattime_str,var+2,2);
  903. if(atoi(heattime_str)>0 && atoi(heattime_str) <= 30)
  904. {
  905. rt_kprintf("加热时间:%d\n",atoi(heattime_str));
  906. device_status.heattime = atoi(heattime_str); //加热时间
  907. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  908. }
  909. strncpy(heatvale_str,var+4,3);
  910. if(atoi(heatvale_str) > 0 && atoi(heatvale_str) <= 130)
  911. {
  912. device_status.heatvalue=atoi(heatvale_str);
  913. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  914. }
  915. strncpy(vol_str,var+7,3);
  916. if(atoi(vol_str)>0&&atoi(vol_str)<8)
  917. {
  918. device_status.vol = atoi(vol_str); //音量
  919. DTU_Write("volume=");
  920. }
  921. strncpy(thsp_str,var+10,4);
  922. if(atoi(thsp_str)>0&&atoi(thsp_str)<3600)
  923. {
  924. device_status.thsp = atoi(thsp_str); //熄屏时间
  925. }
  926. else {
  927. rt_kprintf("参数设置失败!!!\n");
  928. }
  929. rt_thread_delay(1000);
  930. MA_save();
  931. rt_free(var);
  932. rt_kprintf("系统设置已保存:收集时间-%d,加热时间-%d,加热温度-%d,音量-%d,自动关屏-%d\n",device_status.clt_time,device_status.heattime,device_status.heatvalue,device_status.vol,device_status.thsp);
  933. }
  934. else if (strstr(rx_buffer,"rtc_h=")!=NULL) {
  935. char rtc_h[2];
  936. var = strstr(rx_buffer,"=");
  937. var++;
  938. strncpy(rtc_h,var,2);
  939. if(atoi(rtc_h)>=0 && atoi(rtc_h) <= 24)
  940. {
  941. set_time(atoi(rtc_h), 99, 99);
  942. }
  943. }
  944. else if (strstr(rx_buffer,"rtc_m=")!=NULL) {
  945. char rtc_m[2];
  946. var = strstr(rx_buffer,"=");
  947. var++;
  948. strncpy(rtc_m,var,2);
  949. if(atoi(rtc_m)>=0 && atoi(rtc_m) <= 24)
  950. {
  951. set_time(99, atoi(rtc_m), 99);
  952. }
  953. }
  954. else if (strstr(rx_buffer,"rtc_s=")!=NULL) {
  955. char rtc_s[2];
  956. var = strstr(rx_buffer,"=");
  957. var++;
  958. strncpy(rtc_s,var,2);
  959. if(atoi(rtc_s)>=0 && atoi(rtc_s) <= 24)
  960. {
  961. set_time(99, 99, atoi(rtc_s));
  962. }
  963. }
  964. else if(strstr(rx_buffer,"saveUploadSet=")!=NULL)
  965. {
  966. static char dattim_str[3];
  967. rt_kprintf("上传间隔设置!\n");
  968. var = strstr(rx_buffer,"=");
  969. var ++;
  970. strncpy(dattim_str,var,2);
  971. if(atoi(dattim_str)>=1&&atoi(dattim_str)<=120)
  972. {
  973. device_status.dattim =atoi(dattim_str); //数据上传间隔
  974. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
  975. MA_save();
  976. }
  977. else {
  978. rt_kprintf("设置失败!!!\n");
  979. }
  980. rt_free(var);
  981. rt_kprintf("数据上传设置:%d\n",device_status.dattim);
  982. }
  983. //光控测试
  984. else if(strstr(rx_buffer,"putTest.switchSun=1")!=NULL)
  985. {
  986. rt_kprintf("光控测试!!!");
  987. ctr_lamp(ON,1);
  988. device_status.sun_test = 1;
  989. }
  990. else if (strstr(rx_buffer,"setshake_sec=")!=NULL)
  991. {
  992. static char shakesec_str[4];
  993. LOG_I("震动时间设置!");
  994. var = strstr(rx_buffer,"=");
  995. var ++;
  996. strncpy(shakesec_str,var,2);
  997. if(atoi(shakesec_str)>=0&&atoi(shakesec_str)<=10)
  998. {
  999. device_status.shake_sec =atoi(shakesec_str)*10; //
  1000. }
  1001. else {
  1002. LOG_E("设置失败!!!");
  1003. }
  1004. rt_free(var);
  1005. LOG_D("震动时间设置:%d",device_status.shake_sec);
  1006. }
  1007. //恢复出厂设置电池
  1008. else if (strstr(rx_buffer,"resetdcDefault")!=NULL)
  1009. {
  1010. ResetParamDefault_DC();
  1011. rt_thread_delay(1000);
  1012. //2022/06/23,add:
  1013. 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);
  1014. json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
  1015. ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
  1016. if(atoi(device_status.net)==0)
  1017. DTU_Write("%s",json_temp);
  1018. rt_free(json_temp);
  1019. }
  1020. //恢复出厂设置-交流
  1021. else if (strstr(rx_buffer,"resetDefault")!=NULL)
  1022. {
  1023. ResetParamDefault();
  1024. rt_thread_delay(1000);
  1025. //2022/06/23,add:
  1026. 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);
  1027. json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
  1028. ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
  1029. if(atoi(device_status.net)==0)
  1030. DTU_Write("%s",json_temp);
  1031. rt_free(json_temp);
  1032. }
  1033. //获取SIM卡信息
  1034. else if(strstr(rx_buffer,"getSim")!=NULL)
  1035. {
  1036. //http://sim.openluat.com/api/wechat/openapidoc
  1037. DTU_Write("getsiminfo");
  1038. }
  1039. else if (strstr(rx_buffer,"DebugEnable")!=NULL) {
  1040. Debug_log_ON();
  1041. }
  1042. else if (strstr(rx_buffer,"DebugDisable")!=NULL) {
  1043. Debug_log_OFF();
  1044. }
  1045. else if((strstr(rx_buffer,"SwversionV7")!=NULL)) {
  1046. if(device_status.dtype!=7)
  1047. {
  1048. LOG_D("设置版本类型:7");
  1049. device_status.dtype = 7;
  1050. device_status.version_type = 7;
  1051. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //设备类型
  1052. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1053. DTU_Write("SwversionV7");
  1054. MA_save();
  1055. }
  1056. }
  1057. else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
  1058. {
  1059. HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
  1060. HMI_WRITE("sysTest.heat_txt.txt=\"%s\"",device_status.heat_power);
  1061. // HMI_WRITE("sysTest.switchHeat.val=%d",device_status.heat_status);
  1062. }
  1063. //立即上传
  1064. else if(strstr(rx_buffer,"uploaddata")!=RT_NULL)
  1065. {
  1066. UpLoad_Data();
  1067. }
  1068. else if (strstr(rx_buffer,"checkupdate")!=NULL)
  1069. {
  1070. time_t now = time(RT_NULL);
  1071. static struct tm tm;
  1072. gmtime_r(&now, &tm);
  1073. 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);
  1074. HMI_WRITE("hardcheck.p0.pic=%d",70);
  1075. //RTC时间判断,如果当前年份小于2020,提示需要设置时间
  1076. if(tm.tm_year+1900<2020)
  1077. {
  1078. 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);
  1079. 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);
  1080. }
  1081. }
  1082. //进入bootloader模式
  1083. else if (strstr(rx_buffer,"bootloader")!=NULL) {
  1084. device_status.stop_in_bootloader = 1;
  1085. ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
  1086. rt_hw_cpu_reset();
  1087. }
  1088. //软件重启
  1089. else if (strstr(rx_buffer,"reboot")!=NULL) {
  1090. rt_hw_cpu_reset();
  1091. }
  1092. //屏幕上触发远程升级
  1093. else if (strstr(rx_buffer,"hmi_update")!=NULL) {
  1094. DTU_Write("hmi_update");
  1095. device_status.update_flag = 1;
  1096. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  1097. rt_thread_delay(2000);
  1098. rt_hw_cpu_reset();
  1099. }else if (strstr(rx_buffer,"checkcamera")!=NULL){
  1100. DTU_Write("{\"ctr_cam\":\"checkcamera\"}");
  1101. //校准屏幕的RTC
  1102. HMI_WRITE("rtc0=%d",tm.tm_year+1900);
  1103. HMI_WRITE("rtc1=%d",tm.tm_mon+1);
  1104. HMI_WRITE("rtc2=%d",tm.tm_mday);
  1105. HMI_WRITE("rtc3=%d",tm.tm_hour);
  1106. HMI_WRITE("rtc4=%d",tm.tm_min);
  1107. HMI_WRITE("rtc5=%d",tm.tm_sec);
  1108. //开启超时定时器
  1109. Start_timer_Uart2();
  1110. }else if (strstr(rx_buffer,"ReadCamParam")!=NULL){
  1111. DTU_Write("{\"ctr_cam\":\"ReadParam\"}");
  1112. //开启超时定时器
  1113. Start_timer_Uart2();
  1114. }//SaveCamParam:2070.00000-0.7-144-30-0-0-5472*5472
  1115. else if (strstr(rx_buffer,"SaveCamParam")!=NULL){
  1116. const char *prefix ="SaveCamParam:";
  1117. size_t prefix_len = strlen(prefix);
  1118. const char *start_pos = strstr(rx_buffer, prefix);
  1119. if(start_pos!=NULL)
  1120. {
  1121. // 移动到前缀之后的位置
  1122. start_pos += prefix_len;
  1123. DTU_Write("%s",makeJson_Cam("SaveParam",start_pos));
  1124. }
  1125. //开启超时定时器
  1126. Start_timer_Uart2();
  1127. }else if (strstr(rx_buffer,"GrabOn")!=NULL){
  1128. DTU_Write("{\"ctr_cam\":\"GrabOn\"}");
  1129. //开启超时定时器
  1130. Start_timer_Uart2();
  1131. }else if (strstr(rx_buffer,"GrabOff")!=NULL){
  1132. DTU_Write("{\"ctr_cam\":\"GrabOff\"}");
  1133. //开启超时定时器
  1134. Start_timer_Uart2();
  1135. }
  1136. else if(strstr(rx_buffer,"SelfCheck")!=NULL)
  1137. {
  1138. //校准屏幕的RTC
  1139. HMI_WRITE("rtc0=%d",tm.tm_year+1900);
  1140. HMI_WRITE("rtc1=%d",tm.tm_mon+1);
  1141. HMI_WRITE("rtc2=%d",tm.tm_mday);
  1142. HMI_WRITE("rtc3=%d",tm.tm_hour);
  1143. HMI_WRITE("rtc4=%d",tm.tm_min);
  1144. HMI_WRITE("rtc5=%d",tm.tm_sec);
  1145. device_status.selfcheck_ws = 2;
  1146. LOG_W("开始自检:%d",device_status.selfcheck_ws);
  1147. }
  1148. }
  1149. #define EPS 1e-3
  1150. // 找出一维数组中最大数的索引
  1151. int findMaxIndex(double arr[], int size) {
  1152. int maxIndex = 0; // 假设最大值的索引为0
  1153. for (int i = 1; i < size; i++) {
  1154. if ((arr[i] - arr[maxIndex])>EPS) {
  1155. maxIndex = i; // 更新最大值的索引
  1156. }
  1157. }
  1158. return maxIndex;
  1159. }
  1160. void send_signal(void)
  1161. {
  1162. rt_thread_kill(ctr_motor, SIGUSR1);
  1163. }
  1164. // 全局状态变量(需在合适位置初始化)
  1165. static float g_best_sharpness = -FLT_MAX; // 全局最佳清晰度
  1166. static int g_best_pos = 0; // 全局最佳位置
  1167. static float g_last_sharpness = -FLT_MAX; // 上一次移动后的清晰度
  1168. static bool g_initial_move = true; // 初始方向判断标志
  1169. static bool focus_done = false;
  1170. int maxIterations = 100;
  1171. uint8_t dir = 1;
  1172. uint8_t stepSize = 20; // 初始步长(单位:步进电机脉冲数)
  1173. int current_pos = 0; // 根据实际类型修改(int/float等)
  1174. static int g_peak_counter = 0; // 连续上升后下降的计数器
  1175. static bool g_last_rising = false; // 记录上次是否上升
  1176. static int counter_sharpness_reduce = 0; //清晰度降低累计
  1177. static int counter_sharpness_diff = 0; //清晰度累计插值 次数变化
  1178. #define MAX(a, b) ((a) > (b) ? (a) : (b)) // 手动定义宏
  1179. void thread1_signal_handler(int sig)
  1180. {
  1181. rt_timer_stop(timer_takephoto);
  1182. LOG_I("[对焦] 清晰度值更新:%.2f", device_status.focus_value);
  1183. slide_para.pulse_period = mapSpeed(1); // 更新电机速度参数
  1184. maxIterations--;
  1185. if (device_status.autotakepic == 2 && maxIterations >= 0) {
  1186. float current_sharpness = device_status.focus_value;
  1187. /* 更新全局最佳状态 */
  1188. if (current_sharpness > g_best_sharpness) {
  1189. g_best_sharpness = current_sharpness;
  1190. g_best_pos = current_pos;
  1191. LOG_I("[对焦] 发现更佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
  1192. }
  1193. /* 初始方向判断(首步移动后) */
  1194. if (g_initial_move) {
  1195. if (current_sharpness > g_last_sharpness) {
  1196. LOG_I("[对焦] 初始方向正确,保持方向:%d", dir);
  1197. } else {
  1198. dir = !dir; // 反转方向
  1199. LOG_I("[对焦] 初始方向错误,反转方向:%d", dir);
  1200. }
  1201. g_initial_move = false;
  1202. } else {
  1203. double diff_sharpness = fabs(current_sharpness-g_last_sharpness);
  1204. if(diff_sharpness<1.0)
  1205. {
  1206. counter_sharpness_diff++;
  1207. if(counter_sharpness_diff>=10){ //持续10次
  1208. stepSize = 20;
  1209. }
  1210. }
  1211. if(diff_sharpness > 3.5) //动态调整,发生明显变化,降低步进幅度
  1212. {
  1213. counter_sharpness_diff = 0;
  1214. stepSize = 4;
  1215. }
  1216. LOG_I("[对焦] 清晰度变化累计%d次小于1.0",counter_sharpness_diff);
  1217. if(current_sharpness< (g_last_sharpness-0.3f)){ //持续3次清晰度降低,调整行进方向
  1218. counter_sharpness_reduce++;
  1219. LOG_I("[对焦] 清晰度下降,次数:%d", counter_sharpness_reduce);
  1220. if(counter_sharpness_reduce>=3){
  1221. counter_sharpness_reduce = 0;
  1222. dir = !dir; // 清晰度下降,反转方向
  1223. LOG_I("[对焦] 连续清晰度下降,调转行进方向!");
  1224. }
  1225. }else {
  1226. counter_sharpness_reduce = 0;
  1227. }
  1228. /* 方向策略调整,检测到清晰度变大 */
  1229. if (current_sharpness > (g_last_sharpness - 3.5f)) { // 噪声容忍阈值3.0
  1230. // 保持方向,当接近峰值时自动减小步长
  1231. LOG_I("保持方向,当接近峰值时自动减小步长...");
  1232. g_last_rising = true;
  1233. stepSize += 2; //动态调整步幅
  1234. } else {
  1235. if(g_last_rising){
  1236. g_peak_counter++;
  1237. LOG_I("[对焦] 检测到清晰度波动[%d/3]", g_peak_counter);
  1238. stepSize = 2;
  1239. }else {
  1240. g_peak_counter = 0; // 连续下降则重置
  1241. }
  1242. g_last_rising = false;
  1243. dir = !dir; // 清晰度下降,反转方向
  1244. LOG_I("[对焦] 清晰度下降,反转方向:%d 步长:%d", dir, stepSize);
  1245. }
  1246. }
  1247. /* 记录本次清晰度值 */
  1248. g_last_sharpness = current_sharpness;
  1249. /* 计算并执行下一步移动 */
  1250. current_pos += dir ? stepSize : -stepSize;
  1251. LOG_I("[对焦] 方向:%d 移动步长:%d 新位置:%d", dir, stepSize, current_pos);
  1252. if(counter_sharpness_diff>=30){
  1253. dir = !dir;
  1254. stepSize += 10; //增大步幅
  1255. counter_sharpness_diff = 0;
  1256. }
  1257. LOG_I("[对焦] 最佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
  1258. if(g_peak_counter>=3&&current_sharpness>g_best_sharpness*0.95){
  1259. focus_done = true;
  1260. }else{
  1261. focus_done = false;
  1262. g_best_sharpness -= 2.0f; //降低阈值,防止找不到
  1263. }
  1264. /* 终止条件检测 */
  1265. if (counter_sharpness_diff>=100||maxIterations <= 0 || focus_done==true) {
  1266. counter_sharpness_reduce = 0;
  1267. maxIterations = 100;
  1268. LOG_I("[对焦] 完成搜索,最佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
  1269. if (g_peak_counter >= 3) {
  1270. LOG_I("[对焦] 连续三次波动确认峰值");
  1271. }
  1272. focus_done = false;
  1273. LOG_I("[对焦] 已到达最佳对焦位置");
  1274. if(maxIterations==0)
  1275. {
  1276. stepSize = 20;
  1277. dir = !dir;
  1278. current_pos = 0;
  1279. }else{
  1280. counter_sharpness_diff = 0;
  1281. char *c0 = makeJson_Warn("auto_focus","auto_focus");
  1282. DTU_Write("%s",c0);
  1283. rt_free(c0);
  1284. device_status.autotakepic = 0; // 退出自动对焦模式
  1285. return;
  1286. }
  1287. }
  1288. slide_para.ydir = dir;
  1289. slide_para.ydis = stepSize;
  1290. slide_para.en_slide = 6; // 触发移动
  1291. while (slide_para.en_slide != 0) {
  1292. rt_thread_delay(500); // 等待移动完成
  1293. }
  1294. }
  1295. }
  1296. //入口函数-电机控制及
  1297. static void Ctr_Mortor_entry(void* parameter)
  1298. {
  1299. /*孢子仪2.0*/
  1300. rt_signal_install(SIGUSR1, thread1_signal_handler);
  1301. rt_signal_unmask(SIGUSR1);
  1302. while(1)
  1303. {
  1304. /*对焦拍照,滑台初始化*/
  1305. if(device_status.autotakepic==1)
  1306. {
  1307. device_status.step_focus = 1;
  1308. slide_para.en_slide =3; //X轴复位
  1309. slide_para.pulse_period = mapSpeed(50);
  1310. while(slide_para.en_slide!=0){
  1311. LOG_D("等待X轴电机完成复位!");
  1312. rt_thread_delay(1000);
  1313. }
  1314. slide_para.en_slide = 4; //Z轴复位
  1315. slide_para.pulse_period = mapSpeed(50);
  1316. while(slide_para.en_slide!=0){
  1317. LOG_D("等待Z轴电机完成复位!");
  1318. rt_thread_delay(1000);
  1319. }
  1320. slide_para.en_slide = 7; //Y轴复位
  1321. slide_para.pulse_period = mapSpeed(50);
  1322. while(slide_para.en_slide!=0){
  1323. LOG_D("等待Y轴电机完成复位!");
  1324. rt_thread_delay(1000);
  1325. }
  1326. //X轴电机运行到胶带位置
  1327. if(rt_pin_read(Limit_Motor_X)==1){
  1328. slide_para.xdir = 1; //1位反向,0位正向;
  1329. slide_para.xdis = device_status.x_init_dis; //1200
  1330. slide_para.pulse_period = mapSpeed(50);
  1331. slide_para.en_slide = 1;
  1332. while(slide_para.en_slide!=0){
  1333. LOG_D("Again:等待X轴电机到位!");
  1334. rt_thread_delay(1000);
  1335. }
  1336. }
  1337. device_status.autotakepic = 3;
  1338. }
  1339. if(device_status.autotakepic==3)
  1340. {
  1341. slide_para.en_slide = 7; //Y轴复位
  1342. slide_para.pulse_period = mapSpeed(50);
  1343. while(slide_para.en_slide!=0){
  1344. LOG_D("等待Y轴电机完成复位!");
  1345. rt_thread_delay(1000);
  1346. }
  1347. rt_thread_delay(1000);
  1348. //Y轴电机运行到指定距离
  1349. slide_para.ydir = 1;
  1350. //slide_para.ydis = 3350;
  1351. slide_para.ydis = device_status.y_init_dis; //9000
  1352. slide_para.pulse_period = mapSpeed(50);
  1353. slide_para.en_slide = 6;
  1354. while(slide_para.en_slide!=0){
  1355. LOG_D("Again:等待y轴电机到位!");
  1356. rt_thread_delay(1000);
  1357. }
  1358. //生成JSON指令
  1359. char *photo = makeJson_Warn("mov_init_y","takephoto_done");
  1360. DTU_Write("%s",photo);
  1361. rt_free(photo);
  1362. device_status.autotakepic = 4;
  1363. rt_timer_start(timer_takephoto);
  1364. }
  1365. if(device_status.autotakepic == 4)
  1366. {
  1367. device_status.autotakepic = 2;
  1368. g_best_sharpness = -FLT_MAX; // 全局最佳清晰度
  1369. g_best_pos = 0; // 全局最佳位置
  1370. g_last_sharpness = -FLT_MAX; // 上一次移动后的清晰度
  1371. g_initial_move = true; // 初始方向判断标志
  1372. maxIterations = 100;
  1373. dir = 1;
  1374. stepSize = 20; // 初始步长(单位:步进电机脉冲数)
  1375. current_pos = 0; // 根据实际类型修改(int/float等)
  1376. g_peak_counter = 0;
  1377. g_last_rising = false;
  1378. focus_done = false;
  1379. //启动超时检测定时器
  1380. }
  1381. if(device_status.fsl_sw==1)
  1382. {
  1383. ctr_Petroleum_jelly(10);
  1384. }
  1385. //一键测试
  1386. if(device_status.auto_test_sw==1)
  1387. {
  1388. //开始采集风机持续5S
  1389. ctr_router(ON);
  1390. rt_thread_delay(1000*60);
  1391. //关闭采集风机
  1392. ctr_router(OFF);
  1393. //胶带传送
  1394. turnlimit();
  1395. //滑台归位,自动对焦
  1396. //拍一张照片上传到平台
  1397. device_status.autotakepic=1;
  1398. device_status.auto_test_sw=0;
  1399. char *take_start = makeJson_Warn("start", "autofocus");
  1400. DTU_Write(take_start);
  1401. rt_free(take_start);
  1402. }
  1403. rt_thread_delay(10);
  1404. }
  1405. }
  1406. /*屏幕写数据*/
  1407. int Hmi_Fresh(void)
  1408. {
  1409. #if 0
  1410. //初始化串口4
  1411. HMI_uart4_init();
  1412. rt_err_t ret = RT_EOK;
  1413. /* 初始化消息队列 */
  1414. rt_mq_init(&rx_mq, "rx_mq",
  1415. msg_pool, /* 存放消息的缓冲区 */
  1416. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  1417. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  1418. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  1419. /* 设置接收回调函数 */
  1420. rt_device_set_rx_indicate(serial, uart_input);
  1421. /* 创建线程*/
  1422. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  1423. Hmi_thread_entry,
  1424. RT_NULL,
  1425. HMI_THREAD_STACK_SIZE,
  1426. HMI_THREAD_PRIORITY,
  1427. HMI_THREAD_TIMESLICE);
  1428. /* 如果获得线程控制块,启动这个线程 */
  1429. if (hmi1 != RT_NULL)
  1430. {
  1431. rt_thread_startup(hmi1);
  1432. }
  1433. else
  1434. {
  1435. LOG_E("rt_thread_startup hmi1 failed!");
  1436. }
  1437. #endif
  1438. /*部分控制的线程*/
  1439. ctr_motor = rt_thread_create("Ctr motor",
  1440. Ctr_Mortor_entry,
  1441. RT_NULL,
  1442. CONTROL_MOTOR_STACK_SIZE,
  1443. CONTROL_MOTOR_PRIORITY,
  1444. CONTROL_MOTOR_TIMESLICE);
  1445. if(ctr_motor != RT_NULL)
  1446. {
  1447. rt_thread_startup(ctr_motor);
  1448. }
  1449. //定时器,串口通信超时监测20S
  1450. timer_uart2 = rt_timer_create("t_uart2",t_uart2_callback,RT_NULL, 20000, RT_TIMER_FLAG_ONE_SHOT);
  1451. if(timer_uart2==RT_NULL)
  1452. {
  1453. LOG_E("rt_timer_create timer_uart2 failed!");
  1454. }
  1455. return 0;
  1456. }
  1457. void Check_ParamConfig(void)
  1458. {
  1459. time_t now = time(RT_NULL);
  1460. static struct tm tm;
  1461. gmtime_r(&now, &tm);
  1462. if(easyflash_init()==EF_NO_ERR) //初始化成功
  1463. {
  1464. ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
  1465. ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
  1466. ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
  1467. device_status.rebootcnt++;
  1468. ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
  1469. LOG_I("REBOOT_TIME:%d-%d-%d",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
  1470. }
  1471. else {
  1472. LOG_E("easyflash init ERRPR!!!");
  1473. }
  1474. //保存默认配置
  1475. if(device_status.iSave!=FLASH_FLAG)
  1476. {
  1477. device_status.iSave=FLASH_FLAG;
  1478. /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
  1479. device_status.dtype = 7;
  1480. device_status.version_type = 7; //4.0
  1481. device_status.Power_Type = 0; //0-交流供电;1-直流供电
  1482. device_status.clt_time = 10; //收集时间
  1483. device_status.heattime = 10; //加热时间
  1484. device_status.heatvalue=100;//加热温度
  1485. device_status.thsp = 300; //默认熄屏时间5分钟
  1486. device_status.sunBar = 9; //光控定时时长
  1487. device_status.startBar = 20; //定时开始时间
  1488. device_status.stopBar = 0; //定时结束时间
  1489. device_status.tph = 60; //高温保护阈值
  1490. device_status.tpl = 10; //低温保护阈值
  1491. device_status.shake_ws = 1; //震动开关,默认开
  1492. device_status.shake_sec = 1; //震动时间,s
  1493. device_status.vol = 7; //音量
  1494. device_status.timeSwitch = 0; //工作模式:光控
  1495. device_status.passWord = 8888; //屏幕密码
  1496. device_status.dattim = 10; //数据上传间隔
  1497. device_status.ds = 1; //设备状态
  1498. device_status.update_flag = 0;
  1499. /*孢子仪*/
  1500. device_status.collecting_sh1 = 9;
  1501. device_status.collecting_eh1 = 10;
  1502. device_status.collecting_sh2 = 14;
  1503. device_status.collecting_eh2 = 16;
  1504. device_status.cold_sw = 0;
  1505. device_status.heat_sw =0;
  1506. device_status.cul_time = 1;
  1507. device_status.run_sta = 0;
  1508. device_status.handle_bugger = 0; //默认排虫
  1509. sprintf(device_status.driver, "%s",VERSION_BZY);
  1510. sprintf(device_status.deviceId,"0");
  1511. rt_sprintf(device_status.tempture, "-15");
  1512. rt_sprintf(device_status.humidity, "31");
  1513. rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
  1514. device_status.x_init_dis = 500;
  1515. device_status.y_init_dis = 6000;
  1516. ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
  1517. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1518. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  1519. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1520. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1521. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1522. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1523. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1524. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1525. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1526. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1527. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1528. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1529. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1530. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1531. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  1532. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1533. ef_set_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture)); //温度
  1534. ef_set_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity)); //湿度
  1535. ef_set_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1)); //上传平台
  1536. ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  1537. ef_set_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw)); //制冷开关
  1538. ef_set_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw)); //加热开关
  1539. ef_set_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1)); //风机开关
  1540. ef_set_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1)); //采集时间
  1541. ef_set_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2)); //采集时间
  1542. ef_set_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2)); //采集时间
  1543. ef_set_env_blob("collecting_sh3",&device_status.collecting_sh3,sizeof(device_status.collecting_sh3)); //采集时间
  1544. ef_set_env_blob("collecting_eh3",&device_status.collecting_eh3,sizeof(device_status.collecting_eh3)); //采集时间
  1545. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta)); //
  1546. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1547. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  1548. ef_set_env_blob("x_init_dis", &device_status.x_init_dis, sizeof(device_status.x_init_dis));
  1549. ef_set_env_blob("y_init_dis", &device_status.y_init_dis, sizeof(device_status.y_init_dis));
  1550. ef_set_and_save_env("collt_min_sh1", "0");
  1551. ef_set_and_save_env("collt_min_eh1", "0");
  1552. ef_set_and_save_env("collt_min_sh2", "0");
  1553. ef_set_and_save_env("collt_min_eh2", "0");
  1554. ef_set_and_save_env("collt_min_sh3", "0");
  1555. ef_set_and_save_env("collt_min_eh3", "0");
  1556. LOG_I("SOFTWARE VERSION:%s",device_status.driver);
  1557. LOG_I("Default paramconf is:");
  1558. LOG_I("stime:%d",device_status.iSave);
  1559. LOG_I("stime:%d",device_status.clt_time);
  1560. LOG_I("startBar:%d",device_status.startBar);
  1561. LOG_I("stopBar:%d",device_status.stopBar);
  1562. LOG_I("timeSwitch:%d",device_status.timeSwitch);
  1563. LOG_I("sunBar:%d",device_status.sunBar);
  1564. LOG_I("jtime:%d",device_status.heattime);
  1565. LOG_I("jheat:%d",device_status.heatvalue);
  1566. LOG_I("thsp:%d", device_status.thsp);
  1567. LOG_I("passwd:%d",device_status.passWord);
  1568. }//从easyflash读取参数配置
  1569. else if (device_status.iSave==FLASH_FLAG) {
  1570. ef_get_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype),NULL); //设备类型
  1571. ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
  1572. ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
  1573. ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
  1574. ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
  1575. ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
  1576. ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
  1577. ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
  1578. ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
  1579. ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
  1580. ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
  1581. ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
  1582. ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
  1583. ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
  1584. ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
  1585. ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
  1586. ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
  1587. ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
  1588. ef_get_env_blob("lat",&device_status.lat,sizeof(device_status.lat),NULL);
  1589. ef_get_env_blob("lng",&device_status.lng,sizeof(device_status.lng),NULL);
  1590. ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL); //开关机状态
  1591. ef_get_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture),NULL); //环境温度
  1592. ef_get_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity),NULL); //环境湿度
  1593. ef_get_env_blob("json_w_clock",&device_status.json_w_clock,sizeof(device_status.json_w_clock),NULL); //时间
  1594. ef_get_env_blob("json_w_reset",&device_status.json_w_reset,sizeof(device_status.json_w_reset),NULL); //重置
  1595. ef_get_env_blob("json_w_platform",&device_status.json_w_platform,sizeof(device_status.json_w_platform),NULL);//平台
  1596. ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
  1597. ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
  1598. ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL); //平台地址
  1599. /*孢子仪*/
  1600. ef_get_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time),NULL); //培养时间
  1601. ef_get_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw),NULL); //制冷开关
  1602. ef_get_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw),NULL); //加热开关
  1603. ef_get_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1),NULL); //采集开始1
  1604. ef_get_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1),NULL); //采集结束1
  1605. ef_get_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2),NULL); //采集开始2
  1606. ef_get_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2),NULL); //采集结束2
  1607. ef_get_env_blob("collecting_sh3",&device_status.collecting_sh3,sizeof(device_status.collecting_sh3),NULL); //采集开始3
  1608. ef_get_env_blob("collecting_eh3",&device_status.collecting_eh3,sizeof(device_status.collecting_eh3),NULL); //采集结束3
  1609. ef_get_env_blob("run_sta",&device_status.run_sta,sizeof(device_status.run_sta),NULL); //运行状态
  1610. ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL); //供电类型
  1611. ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL); //设备编码
  1612. ef_get_env_blob("handle_bugger",&device_status.handle_bugger,sizeof(device_status.handle_bugger),NULL); //排虫
  1613. ef_get_env_blob("x_init_dis",&device_status.x_init_dis,sizeof(device_status.x_init_dis),NULL);
  1614. ef_get_env_blob("y_init_dis",&device_status.y_init_dis,sizeof(device_status.y_init_dis),NULL);
  1615. ef_get_env_blob("collt_min_sh1", &device_status.collt_min_sh1, sizeof(device_status.collt_min_sh1), NULL);
  1616. ef_get_env_blob("collt_min_eh1", &device_status.collt_min_eh1, sizeof(device_status.collt_min_eh1), NULL);
  1617. ef_get_env_blob("collt_min_sh2", &device_status.collt_min_sh2, sizeof(device_status.collt_min_sh2), NULL);
  1618. ef_get_env_blob("collt_min_eh2", &device_status.collt_min_eh2, sizeof(device_status.collt_min_eh2), NULL);
  1619. ef_get_env_blob("collt_min_sh3", &device_status.collt_min_sh3, sizeof(device_status.collt_min_sh3), NULL);
  1620. ef_get_env_blob("collt_min_eh3", &device_status.collt_min_eh3, sizeof(device_status.collt_min_eh3), NULL);
  1621. //光控计数
  1622. device_status.work_done = 0;
  1623. //工作完成标志位
  1624. if(device_status.dattim==0)
  1625. {
  1626. device_status.dattim = 10;
  1627. }
  1628. /*设备类型,7孢子仪*/
  1629. device_status.dtype = 7;
  1630. device_status.version_type = 7;
  1631. if (device_status.version_type==7) {
  1632. rt_sprintf(device_status.driver, "%s",VERSION_BZY);
  1633. //异常处理:20230331,修复第一段开始时间等于第二段结束时间的情况
  1634. if(device_status.collecting_eh1==device_status.collecting_eh2&&device_status.collecting_sh2!=device_status.collecting_eh2)
  1635. {
  1636. device_status.collecting_eh2 = device_status.collecting_sh2 + 2;
  1637. }
  1638. }
  1639. LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
  1640. LOG_I("read flash paramconfis:%d-%s-%s",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
  1641. LOG_I("开机次数:%d",device_status.rebootcnt);
  1642. LOG_I("收集时间:%d",device_status.clt_time);
  1643. LOG_I("定时开始时间:%d",device_status.startBar);
  1644. LOG_I("定时结束时间:%d",device_status.stopBar);
  1645. LOG_I("timeSwitch:%d",device_status.timeSwitch);
  1646. LOG_I("光控定时时长:%d",device_status.sunBar);
  1647. LOG_I("收集时间:%d",device_status.heattime);
  1648. LOG_I("加热温度:%d",device_status.heatvalue);
  1649. LOG_I("震动开关:%d",device_status.shake_ws);
  1650. LOG_I("震动时间:%d",device_status.shake_sec);
  1651. LOG_I("高温保护:%d",device_status.tph);
  1652. LOG_I("低温保护:%d",device_status.tpl);
  1653. LOG_I("thsp:%d", device_status.thsp);
  1654. LOG_I("密码:%d",device_status.passWord);
  1655. LOG_I("数据上传间隔:%d",device_status.dattim);
  1656. LOG_I("温湿度数据:%d-%d",atoi(device_status.tempture),atoi(device_status.humidity));
  1657. LOG_I("上传平台:%s",device_status.mqttcfg1);
  1658. LOG_I("孢子仪运行状态:%d",device_status.run_sta);
  1659. LOG_I("孢子仪采集时间:[%d:%d-%d:%d,%d:%d-%d:%d,%d:%d-%d:%d]",
  1660. device_status.collecting_sh1,device_status.collt_min_sh1,
  1661. device_status.collecting_eh1,device_status.collt_min_eh1,
  1662. device_status.collecting_sh2,device_status.collt_min_sh2,
  1663. device_status.collecting_eh2,device_status.collt_min_eh2,
  1664. device_status.collecting_sh3,device_status.collt_min_sh3,
  1665. device_status.collecting_eh3,device_status.collt_min_eh3);
  1666. LOG_I("PowerType:%d",device_status.Power_Type);
  1667. LOG_I("x_init_dis:%d",device_status.x_init_dis);
  1668. LOG_I("y_init_dis:%d",device_status.y_init_dis);
  1669. }
  1670. //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
  1671. {
  1672. device_status.update_flag = 0;
  1673. //初始化联网状态
  1674. rt_sprintf(device_status.net,"1");
  1675. rt_sprintf(device_status.csq,"0");
  1676. rt_sprintf(device_status.sim,"1");
  1677. rt_sprintf(device_status.gps, "0");
  1678. Hmi_Fresh();
  1679. dtu_data_play();
  1680. sht30_collect();
  1681. slide_Fresh();
  1682. ctr_photo(ON);
  1683. #if SENSOR_EN==1
  1684. mb_master_samlpe();
  1685. #endif
  1686. #if ROBOT_EN == 0
  1687. uint16_t connect_num=0;
  1688. //等待联网,
  1689. while(atoi(device_status.net)==1)
  1690. {
  1691. char *readinfo = makeJson_ReadInfo();
  1692. DTU_Write("%s",readinfo);
  1693. rt_free(readinfo);
  1694. rt_thread_delay(10000);
  1695. connect_num++;
  1696. LOG_I("联网中......%d",connect_num);
  1697. //超时时间为100S
  1698. if(connect_num==10)
  1699. {
  1700. device_status.timeSwitch = 0;
  1701. 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);
  1702. break;
  1703. }
  1704. }
  1705. connect_num = 0;
  1706. rt_thread_delay(2000);
  1707. DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
  1708. rt_thread_delay(1000);
  1709. device_status.num_updata = 1;
  1710. UpLoad_Data();
  1711. Workstatus_check();
  1712. Work_Loop_Task();
  1713. #endif
  1714. }
  1715. }
  1716. void ResetParamDefault(void)
  1717. {
  1718. device_status.ds = 1; //设备状态开机
  1719. device_status.thsp = 300;
  1720. device_status.passWord = 8888;
  1721. device_status.dattim = 10;
  1722. device_status.collecting_sh1 = 9;
  1723. device_status.collecting_eh1 = 10;
  1724. device_status.collecting_sh2 = 14;
  1725. device_status.collecting_eh2 = 16;
  1726. device_status.collt_min_sh1 = 0;
  1727. device_status.collt_min_eh1 = 0;
  1728. device_status.collt_min_sh2 = 0;
  1729. device_status.collt_min_eh2 = 0;
  1730. device_status.collt_min_sh3 = 0;
  1731. device_status.collt_min_eh3 = 0;
  1732. device_status.Power_Type = 0;
  1733. device_status.tph = 70; //高温保护阈值
  1734. device_status.tpl = 10; //低温保护阈值
  1735. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1736. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1737. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1738. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  1739. if(device_status.dtype==7)
  1740. {
  1741. device_status.run_sta = 0;
  1742. device_status.heatvalue = 25; //培养温度
  1743. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  1744. ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1)); //采集时间
  1745. ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1)); //采集时间
  1746. ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2)); //采集时间
  1747. ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2)); //采集时间
  1748. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1749. }
  1750. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1751. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1752. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1753. DTU_Write("reset.mp3");
  1754. rt_thread_delay(1000);
  1755. }
  1756. void ResetParamDefault_DC(void)
  1757. {
  1758. //将温度数据设置为-15摄氏度,以便上传的数据中包含温控数据
  1759. rt_sprintf(device_status.tempture,"%d",-15);
  1760. device_status.clt_time = 10; //收集时间
  1761. device_status.dattim = 10; //数据上传间隔
  1762. #if LAMP_EN == 0
  1763. device_status.startBar = 20; //定时开始时间
  1764. device_status.stopBar = 0; //定时结束时间
  1765. #endif
  1766. device_status.heattime = 10; //加热时间
  1767. device_status.shake_ws = 1; //针对开关
  1768. device_status.shake_sec = 1; //震动时间1-100ms
  1769. device_status.tph = 70; //高温保护阈值
  1770. device_status.tpl = 10; //低温保护阈值
  1771. device_status.timeSwitch = 0; //定时模式
  1772. device_status.heatvalue=100;
  1773. device_status.ds = 1; //设备状态开机
  1774. device_status.thsp = 300;
  1775. device_status.passWord = 8888;
  1776. device_status.timeSwitch = 0;
  1777. device_status.Power_Type = 1;
  1778. device_status.handle_bugger = 0;
  1779. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  1780. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  1781. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1782. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1783. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  1784. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1785. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1786. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1787. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1788. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1789. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1790. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1791. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1792. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1793. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1794. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1795. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1796. DTU_Write("reset.mp3");
  1797. rt_thread_delay(1000);
  1798. }
  1799. //固件备份
  1800. void app_partion_backup(void)
  1801. {
  1802. rt_kprintf("固件恢复!!!\n");
  1803. const char *dst_part_name = "df_area";
  1804. const char *src_part_name = "app";
  1805. const struct fal_partition *dst_part;
  1806. const struct fal_partition *src_part;
  1807. dst_part = fal_partition_find(dst_part_name);
  1808. src_part = fal_partition_find(src_part_name);
  1809. if (dst_part == RT_NULL || src_part == RT_NULL)
  1810. {
  1811. if (dst_part == RT_NULL)
  1812. rt_kprintf("%s partition is not exist!\n", dst_part_name);
  1813. if (src_part == RT_NULL)
  1814. rt_kprintf("%s partition is not exist!\n", src_part_name);
  1815. }
  1816. else
  1817. {
  1818. rt_kprintf("Clone %s partition to %s partition:\n", src_part_name, dst_part_name);
  1819. if (fal_partition_erase(dst_part, 0, dst_part->len) >= 0)
  1820. {
  1821. int clone_pos = 0;
  1822. int clone_len = 0, clone_tol_len;
  1823. rt_uint8_t *buf = rt_malloc(4096);
  1824. if (dst_part->len < src_part->len)
  1825. clone_tol_len = dst_part->len;
  1826. else
  1827. clone_tol_len = src_part->len;
  1828. while ((clone_pos < clone_tol_len) && (buf != RT_NULL))
  1829. {
  1830. clone_len = fal_partition_read(src_part, clone_pos, buf, 4096);
  1831. if (clone_len < 0)
  1832. {
  1833. rt_kprintf("\nread %s partition failed, clone stop!\n", src_part_name);
  1834. break;
  1835. }
  1836. if (fal_partition_write(dst_part, clone_pos, buf, clone_len) < 0)
  1837. {
  1838. rt_kprintf("\nwrite %s partition failed, clone stop!\n", dst_part_name);
  1839. break;
  1840. }
  1841. HMI_WRITE("#");
  1842. rt_kprintf("#");
  1843. clone_pos += clone_len;
  1844. }
  1845. if (clone_pos >= clone_tol_len)
  1846. {
  1847. rt_kprintf("\nClone partition success, total %d bytes!\n", clone_tol_len);
  1848. }
  1849. else
  1850. {
  1851. rt_kprintf("Clone partition failed!");
  1852. }
  1853. if (buf)
  1854. rt_free(buf);
  1855. }
  1856. }
  1857. }
  1858. void Debug_log_ON(void)
  1859. {
  1860. rt_console_set_device("uart4");
  1861. finsh_set_device("uart4");
  1862. }
  1863. void Debug_log_OFF(void)
  1864. {
  1865. rt_console_set_device("uart1");
  1866. finsh_set_device("uart1");
  1867. rt_mq_init(&rx_mq, "rx_mq",
  1868. msg_pool, /* 存放消息的缓冲区 */
  1869. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  1870. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  1871. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  1872. rt_device_set_rx_indicate(serial, uart_input);
  1873. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  1874. Hmi_thread_entry,
  1875. RT_NULL,
  1876. HMI_THREAD_STACK_SIZE,
  1877. HMI_THREAD_PRIORITY,
  1878. HMI_THREAD_TIMESLICE);
  1879. if (hmi1 != RT_NULL)
  1880. {
  1881. rt_thread_startup(hmi1);
  1882. }
  1883. }
  1884. int delete_thread_ctr_motor()
  1885. {
  1886. if(ctr_motor!=RT_NULL)
  1887. {
  1888. rt_thread_delete(ctr_motor);
  1889. }
  1890. }
  1891. MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
  1892. MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
  1893. //
  1894. //INIT_BOARD_EXPORT(HMI_uart4_init);