hmi.c 102 KB

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