hmi.c 94 KB

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