hmi.c 85 KB

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