hmi.c 93 KB

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