hmi.c 92 KB

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