hmi.c 86 KB

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