hmi.c 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433
  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. //中端款
  1187. else if (strstr(rx_buffer,"SwversionV43")!=NULL) {
  1188. device_status.dtype = 3;
  1189. if(device_status.version_type != 43)
  1190. {
  1191. device_status.version_type = 43;
  1192. sprintf(device_status.driver, "%s",VERSION_HK_2000W);
  1193. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1194. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
  1195. MA_save();
  1196. }
  1197. else {
  1198. }
  1199. }
  1200. //低端款
  1201. else if (strstr(rx_buffer,"SwversionV42")!=NULL) {
  1202. device_status.dtype = 3;
  1203. if(device_status.version_type != 42)
  1204. {
  1205. device_status.version_type = 42;
  1206. sprintf(device_status.driver, "%s",VERSION_HK_2000W);
  1207. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1208. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
  1209. MA_save();
  1210. }
  1211. else {
  1212. }
  1213. }
  1214. //4.0
  1215. else if (strstr(rx_buffer,"SwversionV41")!=NULL) {
  1216. device_status.dtype = 3;
  1217. if(device_status.version_type != 41)
  1218. {
  1219. device_status.dtype = 3;
  1220. device_status.version_type = 41;
  1221. sprintf(device_status.driver, "%s",VERSION_HK);
  1222. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1223. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
  1224. DTU_Write("SwversionV41");
  1225. MA_save();
  1226. }
  1227. else {
  1228. }
  1229. }
  1230. //水稻
  1231. else if (strstr(rx_buffer,"SwversionV4")!=NULL) {
  1232. device_status.dtype = 3;
  1233. if(device_status.version_type != 4)
  1234. {
  1235. device_status.version_type = 4;
  1236. sprintf(device_status.driver, "%s",VERSION_HK_2000W);
  1237. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1238. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
  1239. DTU_Write("SwversionV4");
  1240. MA_save();
  1241. }
  1242. else {
  1243. }
  1244. }
  1245. //5.0测报灯
  1246. else if (strstr(rx_buffer,"SwversionV5")!=NULL) {
  1247. device_status.dtype = 3;
  1248. if(device_status.version_type!=5)
  1249. {
  1250. device_status.version_type = 5;
  1251. sprintf(device_status.driver, "%s",VERSION_V5);
  1252. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1253. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
  1254. MA_save();
  1255. }
  1256. }
  1257. //吸虫塔
  1258. else if (strstr(rx_buffer,"SwversionV6")!=NULL) {
  1259. device_status.dtype = 3;
  1260. if(device_status.version_type != 6)
  1261. {
  1262. device_status.version_type = 6;
  1263. sprintf(device_status.driver, "%s",VERSION_XCT);
  1264. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1265. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
  1266. MA_save();
  1267. }
  1268. }
  1269. else if (strstr(rx_buffer,"SwversionV30")!=NULL) {
  1270. if(device_status.version_type != 30)
  1271. {
  1272. device_status.version_type = 30;
  1273. sprintf(device_status.driver, "%s",VERSION_Robot);
  1274. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1275. MA_save();
  1276. }
  1277. }
  1278. else if((strstr(rx_buffer,"SwversionV7")!=NULL)) {
  1279. if(device_status.dtype!=7)
  1280. {
  1281. LOG_D("设置版本类型:7");
  1282. device_status.dtype = 7;
  1283. device_status.version_type = 7;
  1284. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //设备类型
  1285. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1286. DTU_Write("SwversionV7");
  1287. MA_save();
  1288. }
  1289. }
  1290. else if (strstr(rx_buffer,"putTest.switchFAN_PU=1")!=NULL) {
  1291. ctr_Fan_PUT(ON);
  1292. }
  1293. else if (strstr(rx_buffer,"putTest.switchFAN_PU=0")!=NULL) {
  1294. ctr_Fan_PUT(OFF);
  1295. }
  1296. else if (strstr(rx_buffer,"putTest.switchFAN_IN=1")!=NULL) {
  1297. ctr_Fan_IN(ON);
  1298. }
  1299. else if (strstr(rx_buffer,"putTest.switchFAN_IN=0")!=NULL) {
  1300. ctr_Fan_IN(OFF);
  1301. }
  1302. else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
  1303. {
  1304. HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
  1305. HMI_WRITE("sysTest.heat_txt.txt=\"%s\"",device_status.heat_power);
  1306. // HMI_WRITE("sysTest.switchHeat.val=%d",device_status.heat_status);
  1307. }
  1308. //立即上传
  1309. else if(strstr(rx_buffer,"uploaddata")!=RT_NULL)
  1310. {
  1311. UpLoad_Data();
  1312. }
  1313. else if (strstr(rx_buffer,"checkupdate")!=NULL)
  1314. {
  1315. time_t now = time(RT_NULL);
  1316. static struct tm tm;
  1317. gmtime_r(&now, &tm);
  1318. 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);
  1319. HMI_WRITE("hardcheck.p0.pic=%d",70);
  1320. //RTC时间判断,如果当前年份小于2020,提示需要设置时间
  1321. if(tm.tm_year+1900<2020)
  1322. {
  1323. 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);
  1324. 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);
  1325. }
  1326. }
  1327. //进入bootloader模式
  1328. else if (strstr(rx_buffer,"bootloader")!=NULL) {
  1329. device_status.stop_in_bootloader = 1;
  1330. ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
  1331. rt_hw_cpu_reset();
  1332. }
  1333. //软件重启
  1334. else if (strstr(rx_buffer,"reboot")!=NULL) {
  1335. rt_hw_cpu_reset();
  1336. }
  1337. //屏幕上触发远程升级
  1338. else if (strstr(rx_buffer,"hmi_update")!=NULL) {
  1339. DTU_Write("hmi_update");
  1340. device_status.update_flag = 1;
  1341. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  1342. rt_thread_delay(2000);
  1343. rt_hw_cpu_reset();
  1344. }else if (strstr(rx_buffer,"checkcamera")!=NULL){
  1345. DTU_Write("{\"ctr_cam\":\"checkcamera\"}");
  1346. //校准屏幕的RTC
  1347. HMI_WRITE("rtc0=%d",tm.tm_year+1900);
  1348. HMI_WRITE("rtc1=%d",tm.tm_mon+1);
  1349. HMI_WRITE("rtc2=%d",tm.tm_mday);
  1350. HMI_WRITE("rtc3=%d",tm.tm_hour);
  1351. HMI_WRITE("rtc4=%d",tm.tm_min);
  1352. HMI_WRITE("rtc5=%d",tm.tm_sec);
  1353. //开启超时定时器
  1354. Start_timer_Uart2();
  1355. }else if (strstr(rx_buffer,"ReadCamParam")!=NULL){
  1356. DTU_Write("{\"ctr_cam\":\"ReadParam\"}");
  1357. //开启超时定时器
  1358. Start_timer_Uart2();
  1359. }//SaveCamParam:2070.00000-0.7-144-30-0-0-5472*5472
  1360. else if (strstr(rx_buffer,"SaveCamParam")!=NULL){
  1361. const char *prefix ="SaveCamParam:";
  1362. size_t prefix_len = strlen(prefix);
  1363. const char *start_pos = strstr(rx_buffer, prefix);
  1364. if(start_pos!=NULL)
  1365. {
  1366. // 移动到前缀之后的位置
  1367. start_pos += prefix_len;
  1368. DTU_Write("%s",makeJson_Cam("SaveParam",start_pos));
  1369. }
  1370. //开启超时定时器
  1371. Start_timer_Uart2();
  1372. }else if (strstr(rx_buffer,"GrabOn")!=NULL){
  1373. DTU_Write("{\"ctr_cam\":\"GrabOn\"}");
  1374. //开启超时定时器
  1375. Start_timer_Uart2();
  1376. }else if (strstr(rx_buffer,"GrabOff")!=NULL){
  1377. DTU_Write("{\"ctr_cam\":\"GrabOff\"}");
  1378. //开启超时定时器
  1379. Start_timer_Uart2();
  1380. }
  1381. else if(strstr(rx_buffer,"SelfCheck")!=NULL)
  1382. {
  1383. //校准屏幕的RTC
  1384. HMI_WRITE("rtc0=%d",tm.tm_year+1900);
  1385. HMI_WRITE("rtc1=%d",tm.tm_mon+1);
  1386. HMI_WRITE("rtc2=%d",tm.tm_mday);
  1387. HMI_WRITE("rtc3=%d",tm.tm_hour);
  1388. HMI_WRITE("rtc4=%d",tm.tm_min);
  1389. HMI_WRITE("rtc5=%d",tm.tm_sec);
  1390. device_status.selfcheck_ws = 2;
  1391. LOG_W("开始自检:%d",device_status.selfcheck_ws);
  1392. }
  1393. }
  1394. //入口函数-电机控制及
  1395. static void Ctr_Mortor_entry(void* parameter)
  1396. {
  1397. rt_int16_t motor_current = 0; //
  1398. rt_uint16_t num_up_open = 200; //20s
  1399. rt_uint16_t num_up_close = 200; //
  1400. rt_uint16_t num_down_open = 200; //
  1401. rt_uint16_t num_down_close = 200; //
  1402. rt_int16_t photo_led_sec = 900; //55S
  1403. rt_uint8_t num_tg_open = 200; //20S
  1404. rt_uint8_t num_tg_init = 200;
  1405. //int current_t[200];
  1406. /*孢子仪拍照数量*/
  1407. rt_uint16_t photo_setup = 0;
  1408. #if Color_EN ==1
  1409. ctr_Color_board(RESET, 1200);
  1410. #endif
  1411. while(1)
  1412. {
  1413. #if Color_EN ==1
  1414. //定时执行把粘虫板更换的操作,每天一次
  1415. if(device_status.run_sta==5)
  1416. {
  1417. rt_thread_delay(2000);
  1418. device_status.run_sta = 0;
  1419. ctr_Color_board(OPEN, 1000);
  1420. }
  1421. #endif
  1422. #if 1
  1423. time_t time_reset12V;
  1424. time(&time_reset12V);
  1425. static struct tm alarm_reset12V;
  1426. alarm_reset12V =*localtime(&time_reset12V);
  1427. if((alarm_reset12V.tm_hour)==8&&(alarm_reset12V.tm_min==19)&&(alarm_reset12V.tm_sec==50))
  1428. {
  1429. ctr_RTU_DTU(OFF);
  1430. rt_thread_delay(1000*10);
  1431. ctr_RTU_DTU(ON);
  1432. }
  1433. #endif
  1434. if(device_status.ctr_up_motor==1)
  1435. {
  1436. #if 0
  1437. if(num_up_open==200&&device_status.clear_status==0&&device_status.work_status==1)
  1438. {
  1439. motor_current = atoi(device_status.power);
  1440. LOG_D("上仓门待机电流:%d",motor_current);
  1441. }
  1442. //打开上仓门
  1443. if(num_up_open<200)
  1444. #endif
  1445. ctr_cangmen_up(OPEN);
  1446. num_up_open--;
  1447. // current_t[num_up_open] = atoi(device_status.power);
  1448. if (num_up_open == 0)
  1449. {
  1450. ctr_cangmen_up(OFF);
  1451. num_up_open = 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. // LOG_E("上仓门打开电机电流不足:%d!!!",current_t[199]);
  1456. // char * ctr_cm_up_warn = makeJson_Warn("电流不足,打开", "上仓门电机");
  1457. // DTU_Write("%s",ctr_cm_up_warn);
  1458. // rt_free(ctr_cm_up_warn);
  1459. // }
  1460. }
  1461. // else {
  1462. // LOG_D("上仓门打开电流:%d",current_t[num_up_open]);
  1463. // }
  1464. }
  1465. else if(device_status.ctr_up_motor==2)
  1466. {
  1467. // if(num_up_close==200&&device_status.clear_status==0&&device_status.work_status==1)
  1468. // {
  1469. // motor_current = atoi(device_status.power);
  1470. // LOG_D("上仓门待机电流:%d",motor_current);
  1471. // }
  1472. // if(num_up_close<200)
  1473. ctr_cangmen_up(CLOSE);
  1474. num_up_close --;
  1475. // current_t[num_up_close] = atoi(device_status.power);
  1476. if (num_up_close == 0)
  1477. {
  1478. ctr_cangmen_up(OFF);
  1479. num_up_close= 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. //
  1484. // LOG_E("上仓门电机电流不足!!!-%d",current_t[199]);
  1485. // char * ctr_cm_up_warn = makeJson_Warn("电流不足,关闭", "上仓门电机");
  1486. // DTU_Write("%s",ctr_cm_up_warn);
  1487. // rt_free(ctr_cm_up_warn);
  1488. // }
  1489. }
  1490. //LOG_D("上仓门关闭电流:%d",current_t[num_up_close]);
  1491. }
  1492. if (device_status.ctr_down_motor == 1)
  1493. {
  1494. // if(num_down_open==200&&device_status.clear_status==0&&device_status.work_status==1)
  1495. // {
  1496. // motor_current = atoi(device_status.power);
  1497. // LOG_D("下仓门待机电流:%d",motor_current);
  1498. // }
  1499. // if(num_down_open<200)
  1500. ctr_cangmen_down(OPEN);
  1501. num_down_open--;
  1502. // current_t[num_down_open] = atoi(device_status.power);
  1503. //如果关闭仓门1S后检测不到电流增大,则判定为异常
  1504. if (num_down_open == 0)
  1505. {
  1506. ctr_cangmen_down(OFF);
  1507. num_down_open = 200;
  1508. // bubblesort(current_t, 200);
  1509. // if (current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
  1510. // {
  1511. // LOG_E("下仓门电机电流不足!!!-%d",current_t[199]);
  1512. // char * ctr_cm_down_warn = makeJson_Warn("电流不足,打开", "下仓门电机");
  1513. // DTU_Write("%s",ctr_cm_down_warn);
  1514. // rt_free(ctr_cm_down_warn);
  1515. // }
  1516. }
  1517. // LOG_D("下仓门打开电流:%d",current_t[num_down_open]);
  1518. }
  1519. else if (device_status.ctr_down_motor == 2)
  1520. {
  1521. // if(num_down_close==200&&device_status.clear_status==0&&device_status.work_status==1)
  1522. // {
  1523. // motor_current = atoi(device_status.power);
  1524. // LOG_D("下仓门待机电流:%d",motor_current);
  1525. // }
  1526. // if(num_down_close<200)
  1527. ctr_cangmen_down(CLOSE);
  1528. num_down_close--;
  1529. // current_t[num_down_close] = atoi(device_status.power);
  1530. if (num_down_close == 0)
  1531. {
  1532. ctr_cangmen_down(OFF);
  1533. num_down_close = 200;
  1534. // bubblesort(current_t, 200);
  1535. // //如果关闭仓门5S后检测不到电流增大,则判定为异常
  1536. // if (current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
  1537. // {
  1538. // LOG_E("下仓门关闭电机电流不足!!!-%d",current_t[199]);
  1539. // char * ctr_cm_down_warn = makeJson_Warn("电流不足,关闭", "下仓门电机");
  1540. // DTU_Write("%s",ctr_cm_down_warn);
  1541. // rt_free(ctr_cm_down_warn);
  1542. //
  1543. // }
  1544. }
  1545. // LOG_D("下仓门关闭电流:%d",current_t[num_down_close]);
  1546. }
  1547. if(device_status.sun_test==1)
  1548. {
  1549. SunTest();
  1550. }
  1551. //拍照
  1552. if(device_status.photo_ws==1)
  1553. {
  1554. struct timeval tv;
  1555. gettimeofday(&tv, NULL);
  1556. device_status.photo_stamp = tv.tv_sec-8*3600;
  1557. if(photo_led_sec==900)
  1558. ctr_led(ON);
  1559. //打开补光灯
  1560. if(photo_led_sec==800)
  1561. {
  1562. LOG_I("测试拍照!");
  1563. #if 1
  1564. char *takephotojson = makeJson_takephoto();
  1565. DTU_Write("%s",takephotojson);
  1566. rt_free(takephotojson);
  1567. #endif
  1568. rt_thread_delay(5000); //延时
  1569. }
  1570. //15S后执行拍照
  1571. else if (photo_led_sec==750)
  1572. {
  1573. DTU_Write("takephoto.mp3");
  1574. //延时
  1575. rt_thread_delay(1000);
  1576. LOG_I("测试拍照!");
  1577. Hk_Take_io();
  1578. }
  1579. photo_led_sec--;
  1580. if(photo_led_sec==300) //
  1581. {
  1582. ctr_led(OFF);
  1583. photo_led_sec = 900;
  1584. device_status.photo_ws = 0;
  1585. HMI_WRITE("sysTest.switchPhoto.val=0");
  1586. HMI_WRITE("sysTest.switchFill.val=0");
  1587. }
  1588. }else{
  1589. photo_led_sec = 900;
  1590. }
  1591. /*对焦拍照*/
  1592. if(device_status.autotakepic==1)
  1593. {
  1594. DTU_Write("autotakephoto");
  1595. HMI_WRITE("sysTest.auto_flag.txt=\"Autotest\"");
  1596. //打开步进电机驱动器电源
  1597. ctr_lamp(ON, 1);
  1598. //打开补光灯
  1599. ctr_led(ON);
  1600. //电机向下运动
  1601. ctr_Motor_Driver(1, 1, 1000000,1000);
  1602. rt_thread_delay(1000);
  1603. LOG_I("电机到达下方!!!");
  1604. Hk_Take_io();
  1605. rt_thread_delay(1000);
  1606. LOG_I("电机开始向上!!!");
  1607. rt_pin_write(Motor_EN, 1);
  1608. rt_pin_write(Motor_DIR, 0);
  1609. beep_set(1000000, 200000); //2kzh - 50%
  1610. while(rt_pin_read(LIMIT_UP)==1)
  1611. {
  1612. HMI_WRITE("sysTest.result.txt=\"对焦拍照触发次数:%d\"",photo_setup);
  1613. HMI_WRITE("sysTest.auto_flag.txt=\"AutoTeststart\"");
  1614. rt_pin_write(Motor_EN, 0);
  1615. beep_set(0, 0);//驱动器失能
  1616. Hk_Take_io(); //触发拍照
  1617. rt_thread_mdelay(200); //10ms
  1618. rt_pin_write(Motor_EN, 1);
  1619. beep_set(1000000, 200000); //驱动器使能
  1620. rt_thread_mdelay(100); //10ms
  1621. beep_set(0, 0); //驱动器失能
  1622. rt_pin_write(Motor_EN, 0);
  1623. if(photo_setup>300) //限制最大拍照数量
  1624. {
  1625. ctr_led(OFF);
  1626. device_status.autotakepic=0;
  1627. rt_pin_write(Motor_EN, 0); //驱动器失能
  1628. beep_set(1000000, 0); //2kzh - 50%
  1629. HMI_WRITE("sysTest.switchAutopic.val=%d",0);
  1630. HMI_WRITE("sysTest.auto_flag.txt=\"\"");
  1631. ctr_lamp(OFF, 1);
  1632. break;
  1633. }
  1634. photo_setup++;
  1635. LOG_I("对焦拍照:%d",photo_setup);
  1636. }
  1637. DTU_Write("takephotodone");
  1638. ctr_led(OFF);
  1639. rt_pin_write(Motor_EN, 0); //驱动器失能
  1640. beep_set(1000000, 0); //2kzh - 50%
  1641. HMI_WRITE("sysTest.switchAutopic.val=%d",0);
  1642. device_status.autotakepic=0;
  1643. photo_setup = 0;
  1644. HMI_WRITE("sysTest.auto_flag.txt=\"\"");
  1645. HMI_WRITE("sysTest.switchAutopic.val=%d",0);
  1646. //关闭步进电机驱动器电源
  1647. ctr_lamp(OFF, 1);
  1648. //重置运行标志位
  1649. device_status.run_sta = 0;
  1650. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  1651. }
  1652. if(device_status.fsl_sw==1)
  1653. {
  1654. ctr_Petroleum_jelly(10);
  1655. }
  1656. if(device_status.collt_box_sta==111){
  1657. ctr_Fan_IN(ON); //推杆电机收缩(供电打开,复位)
  1658. num_tg_init--;
  1659. if(num_tg_init%10==0)
  1660. HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
  1661. if(num_tg_init==0){
  1662. HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
  1663. ctr_Fan_PUT(ON);
  1664. num_tg_init = 200;
  1665. device_status.collt_box_sta=112;
  1666. }
  1667. }else if(device_status.collt_box_sta==112){
  1668. num_tg_open--;
  1669. if(num_tg_open%10==0)
  1670. HMI_WRITE("sysTest.result.txt=\"开始执行排虫:%d\"",num_tg_open/10);
  1671. if(num_tg_open==0){
  1672. HMI_WRITE("sysTest.result.txt=\"排虫复位中\"");
  1673. ctr_Fan_PUT(OFF);
  1674. num_tg_open = 200;
  1675. device_status.collt_box_sta=113;
  1676. }
  1677. }else if(device_status.collt_box_sta==113){
  1678. num_tg_init--;
  1679. if(num_tg_init%10==0)
  1680. HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
  1681. if(num_tg_init==0){
  1682. HMI_WRITE("sysTest.result.txt=\"排虫机执行已完成!\"");
  1683. ctr_Fan_PUT(OFF);
  1684. ctr_Fan_IN(OFF);
  1685. num_tg_init = 200;
  1686. device_status.collt_box_sta=0;
  1687. }
  1688. }
  1689. if(device_status.run_sta==111){ //排虫-收缩
  1690. ctr_Fan_IN(ON); //推杆电机收缩(供电打开,复位)
  1691. ctr_Fan_PUT(OFF);
  1692. num_tg_init--;
  1693. if(num_tg_init%10==0)
  1694. HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
  1695. if(num_tg_init==0){
  1696. HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
  1697. ctr_Fan_IN(OFF);
  1698. num_tg_init = 200;
  1699. device_status.run_sta=0;
  1700. }
  1701. }else if(device_status.run_sta==112){ //收虫-推出
  1702. ctr_Fan_IN(ON);
  1703. ctr_Fan_PUT(ON);
  1704. num_tg_open--;
  1705. if(num_tg_open%10==0)
  1706. HMI_WRITE("sysTest.result.txt=\"开始执行收虫:%d\"",num_tg_open/10);
  1707. if(num_tg_open==0){
  1708. HMI_WRITE("sysTest.result.txt=\"收虫中...\"");
  1709. ctr_Fan_PUT(OFF);
  1710. ctr_Fan_IN(OFF);
  1711. num_tg_open = 200;
  1712. device_status.run_sta=0;
  1713. }
  1714. }
  1715. //一键测试
  1716. if(device_status.auto_test_sw==1)
  1717. {
  1718. HMI_WRITE("sysTest.auto_flag.txt=\"Autotest\"");
  1719. //转盘复位
  1720. LOG_I("转盘复位!!!");
  1721. HMI_WRITE("sysTest.result.txt=\"一键测试:转盘复位!\"");
  1722. rt_thread_delay(2000);
  1723. ctr_turn(0,0);
  1724. //转90
  1725. LOG_I("第一次转盘!!!");
  1726. HMI_WRITE("sysTest.result.txt=\"一键测试:第一次转盘!\"");
  1727. ctr_turn(90,0);
  1728. rt_thread_delay(2000);
  1729. //推杆电机:测试粘附:
  1730. LOG_I("涂凡士林!!!");
  1731. HMI_WRITE("sysTest.result.txt=\"一键测试:涂凡士林!\"");
  1732. ctr_Petroleum_jelly(10);
  1733. rt_thread_delay(2000);
  1734. //转90
  1735. LOG_I("第二次转盘!!!");
  1736. HMI_WRITE("sysTest.result.txt=\"一键测试:第二次转盘!\"");
  1737. ctr_turn(90,0);
  1738. rt_thread_delay(2000);
  1739. //采集,打开风机
  1740. LOG_I("采集,打开风机!!!");
  1741. HMI_WRITE("sysTest.result.txt=\"一键测试:采集,打开风机!\"");
  1742. ctr_Collect_Fan(ON);
  1743. rt_thread_delay(5000);
  1744. LOG_I("采集结束,关闭风机!!!");
  1745. HMI_WRITE("sysTest.result.txt=\"一键测试:采集结束,关闭风机!\"");
  1746. rt_thread_delay(2000);
  1747. ctr_Collect_Fan(OFF);
  1748. //散热
  1749. LOG_I("打开散热!!!");
  1750. HMI_WRITE("sysTest.result.txt=\"一键测试:打开散热!\"");
  1751. rt_thread_delay(2000);
  1752. ctr_Cool_Fan(ON);
  1753. rt_thread_delay(5000);
  1754. LOG_I("关闭散热!!!");
  1755. HMI_WRITE("sysTest.result.txt=\"一键测试:关闭散热!\"");
  1756. rt_thread_delay(2000);
  1757. ctr_Cool_Fan(OFF);
  1758. //转90
  1759. LOG_I("第三次转盘!!!");
  1760. HMI_WRITE("sysTest.result.txt=\"一键测试:第三次转盘!\"");
  1761. ctr_turn(90,0);
  1762. rt_thread_delay(5000);
  1763. //滴液
  1764. LOG_I("开始滴液!!!");
  1765. HMI_WRITE("sysTest.result.txt=\"一键测试:开始滴液!\"");
  1766. rt_thread_delay(2000);
  1767. ctr_shake(ON,device_status.shake_sec);
  1768. rt_thread_delay(5000);
  1769. LOG_I("停止滴液!!!");
  1770. HMI_WRITE("sysTest.result.txt=\"一键测试:停止滴液!\"");
  1771. rt_thread_delay(2000);
  1772. //加热
  1773. LOG_I("开始加热!!!");
  1774. HMI_WRITE("sysTest.result.txt=\"一键测试:开始加热!\"");
  1775. rt_thread_delay(2000);
  1776. ctr_Heat(ON);
  1777. rt_thread_delay(5000);
  1778. LOG_I("停止加热!!!");
  1779. HMI_WRITE("sysTest.result.txt=\"一键测试:停止加热!\"");
  1780. rt_thread_delay(2000);
  1781. ctr_Heat(OFF);
  1782. //制冷
  1783. LOG_I("开始制冷!!!");
  1784. HMI_WRITE("sysTest.result.txt=\"一键测试:开始制冷!\"");
  1785. rt_thread_delay(2000);
  1786. ctr_Cold(ON);
  1787. rt_thread_delay(5000);
  1788. LOG_I("停止制冷!!!");
  1789. HMI_WRITE("sysTest.result.txt=\"一键测试:停止制冷!\"");
  1790. rt_thread_delay(2000);
  1791. ctr_Cold(OFF);
  1792. //转90
  1793. LOG_I("第四次转盘!!!");
  1794. HMI_WRITE("sysTest.result.txt=\"一键测试:第四次转盘!\"");
  1795. ctr_turn(90,0);
  1796. LOG_I("打开补光灯!!!");
  1797. HMI_WRITE("sysTest.result.txt=\"一键测试:打开补光灯!\"");
  1798. rt_thread_delay(2000);
  1799. ctr_led(ON);
  1800. device_status.autotakepic=1;
  1801. device_status.auto_test_sw=0;
  1802. HMI_WRITE("sysTest.auto_flag.txt=\"\"");
  1803. }
  1804. if(device_status.selfcheck_ws==2)
  1805. {
  1806. selfcheck(1);
  1807. }
  1808. rt_thread_delay(100);
  1809. }
  1810. }
  1811. /*屏幕写数据*/
  1812. int Hmi_Fresh(void)
  1813. {
  1814. //初始化串口4
  1815. rt_err_t ret = RT_EOK;
  1816. /* 初始化消息队列 */
  1817. rt_mq_init(&rx_mq, "rx_mq",
  1818. msg_pool, /* 存放消息的缓冲区 */
  1819. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  1820. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  1821. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  1822. /* 设置接收回调函数 */
  1823. rt_device_set_rx_indicate(serial, uart_input);
  1824. /* 创建线程*/
  1825. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  1826. Hmi_thread_entry,
  1827. RT_NULL,
  1828. HMI_THREAD_STACK_SIZE,
  1829. HMI_THREAD_PRIORITY,
  1830. HMI_THREAD_TIMESLICE);
  1831. /*部分控制的线程*/
  1832. ctr_motor = rt_thread_create("Ctr motor",
  1833. Ctr_Mortor_entry,
  1834. RT_NULL,
  1835. CONTROL_MOTOR_STACK_SIZE,
  1836. CONTROL_MOTOR_PRIORITY,
  1837. CONTROL_MOTOR_TIMESLICE);
  1838. if(ctr_motor != RT_NULL)
  1839. {
  1840. rt_thread_startup(ctr_motor);
  1841. }
  1842. /* 如果获得线程控制块,启动这个线程 */
  1843. if (hmi1 != RT_NULL)
  1844. {
  1845. rt_thread_startup(hmi1);
  1846. }
  1847. else
  1848. {
  1849. ret = RT_ERROR;
  1850. }
  1851. //定时器,串口通信超时监测20S
  1852. timer_uart2 = rt_timer_create("t_uart2",t_uart2_callback,RT_NULL, 20000, RT_TIMER_FLAG_ONE_SHOT);
  1853. if(timer_uart2==RT_NULL)
  1854. {
  1855. LOG_E("rt_timer_create timer_uart2 failed!");
  1856. }
  1857. return ret;
  1858. }
  1859. void Check_ParamConfig(void)
  1860. {
  1861. time_t now = time(RT_NULL);
  1862. static struct tm tm;
  1863. gmtime_r(&now, &tm);
  1864. if(easyflash_init()==EF_NO_ERR) //初始化成功
  1865. {
  1866. ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
  1867. ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
  1868. ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
  1869. device_status.rebootcnt++;
  1870. ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
  1871. LOG_I("REBOOT_TIME:%d-%d-%d",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
  1872. }
  1873. else {
  1874. LOG_E("easyflash init ERRPR!!!");
  1875. }
  1876. //保存默认配置
  1877. if(device_status.iSave!=FLASH_FLAG)
  1878. {
  1879. device_status.iSave=FLASH_FLAG;
  1880. /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
  1881. device_status.dtype = 3;
  1882. device_status.version_type = 4; //4.0
  1883. device_status.Power_Type = 0; //0-交流供电;1-直流供电
  1884. device_status.clt_time = 10; //收集时间
  1885. device_status.heattime = 10; //加热时间
  1886. device_status.heatvalue=100;//加热温度
  1887. device_status.thsp = 300; //默认熄屏时间5分钟
  1888. device_status.sunBar = 9; //光控定时时长
  1889. device_status.startBar = 20; //定时开始时间
  1890. device_status.stopBar = 0; //定时结束时间
  1891. device_status.tph = 70; //高温保护阈值
  1892. device_status.tpl = 5; //低温保护阈值
  1893. device_status.shake_ws = 1; //震动开关,默认开
  1894. device_status.shake_sec = 1; //震动时间,s
  1895. device_status.vol = 7; //音量
  1896. device_status.timeSwitch = 0; //工作模式:光控
  1897. device_status.passWord = 8888; //屏幕密码
  1898. device_status.dattim = 10; //数据上传间隔
  1899. device_status.ds = 1; //设备状态
  1900. device_status.update_flag = 0;
  1901. /*孢子仪*/
  1902. device_status.collecting_sh1 = 9;
  1903. device_status.collecting_eh1 = 10;
  1904. device_status.collecting_sh2 = 14;
  1905. device_status.collecting_eh2 = 16;
  1906. device_status.cold_sw = 0;
  1907. device_status.heat_sw =0;
  1908. device_status.cul_time = 1;
  1909. device_status.run_sta = 0;
  1910. device_status.handle_bugger = 0; //默认排虫
  1911. sprintf(device_status.driver, "%s",VERSION_HK);
  1912. sprintf(device_status.deviceId,"0");
  1913. rt_sprintf(device_status.tempture, "-15");
  1914. rt_sprintf(device_status.humidity, "31");
  1915. rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
  1916. ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
  1917. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1918. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  1919. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1920. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1921. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1922. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1923. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1924. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1925. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1926. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1927. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1928. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1929. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1930. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1931. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  1932. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1933. ef_set_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture)); //温度
  1934. ef_set_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity)); //湿度
  1935. ef_set_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1)); //上传平台
  1936. ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  1937. ef_set_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw)); //制冷开关
  1938. ef_set_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw)); //加热开关
  1939. ef_set_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1)); //风机开关
  1940. ef_set_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1)); //采集时间
  1941. ef_set_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2)); //采集时间
  1942. ef_set_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2)); //采集时间
  1943. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta)); //
  1944. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1945. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  1946. LOG_I("SOFTWARE VERSION:%s",device_status.driver);
  1947. LOG_I("Default paramconf is:");
  1948. LOG_I("stime:%d",device_status.iSave);
  1949. LOG_I("stime:%d",device_status.clt_time);
  1950. LOG_I("startBar:%d",device_status.startBar);
  1951. LOG_I("stopBar:%d",device_status.stopBar);
  1952. LOG_I("timeSwitch:%d",device_status.timeSwitch);
  1953. LOG_I("sunBar:%d",device_status.sunBar);
  1954. LOG_I("jtime:%d",device_status.heattime);
  1955. LOG_I("jheat:%d",device_status.heatvalue);
  1956. LOG_I("thsp:%d", device_status.thsp);
  1957. LOG_I("passwd:%d",device_status.passWord);
  1958. }//从easyflash读取参数配置
  1959. else if (device_status.iSave==FLASH_FLAG) {
  1960. ef_get_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype),NULL); //设备类型
  1961. ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
  1962. ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
  1963. ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
  1964. ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
  1965. ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
  1966. ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
  1967. ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
  1968. ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
  1969. ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
  1970. ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
  1971. ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
  1972. ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
  1973. ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
  1974. ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
  1975. ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
  1976. ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
  1977. ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
  1978. ef_get_env_blob("lat",&device_status.lat,sizeof(device_status.lat),NULL);
  1979. ef_get_env_blob("lng",&device_status.lng,sizeof(device_status.lng),NULL);
  1980. ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL); //开关机状态
  1981. ef_get_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture),NULL); //环境温度
  1982. ef_get_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity),NULL); //环境湿度
  1983. ef_get_env_blob("json_w_clock",&device_status.json_w_clock,sizeof(device_status.json_w_clock),NULL); //时间
  1984. ef_get_env_blob("json_w_reset",&device_status.json_w_reset,sizeof(device_status.json_w_reset),NULL); //重置
  1985. ef_get_env_blob("json_w_platform",&device_status.json_w_platform,sizeof(device_status.json_w_platform),NULL);//平台
  1986. ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
  1987. ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
  1988. ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL); //平台地址
  1989. /*孢子仪*/
  1990. ef_get_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time),NULL); //培养时间
  1991. ef_get_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw),NULL); //制冷开关
  1992. ef_get_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw),NULL); //加热开关
  1993. ef_get_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1),NULL); //采集开始1
  1994. ef_get_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1),NULL); //采集结束1
  1995. ef_get_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2),NULL); //采集开始2
  1996. ef_get_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2),NULL); //采集结束2
  1997. ef_get_env_blob("run_sta",&device_status.run_sta,sizeof(device_status.run_sta),NULL); //运行状态
  1998. ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL); //供电类型
  1999. ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL); //设备编码
  2000. ef_get_env_blob("handle_bugger",&device_status.handle_bugger,sizeof(device_status.handle_bugger),NULL); //排虫
  2001. device_status.light_over_tim = device_status.sunBar * 3600; //光控计数
  2002. device_status.work_done = 0;
  2003. //工作完成标志位
  2004. if(device_status.dattim==0)
  2005. {
  2006. device_status.dattim = 10;
  2007. }
  2008. /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
  2009. if(device_status.dtype!=7)
  2010. {
  2011. device_status.dtype = 3;
  2012. }
  2013. else {
  2014. device_status.version_type = 7;
  2015. }
  2016. if(device_status.version_type==0)
  2017. {
  2018. app_partion_backup(); //固件备份至df_area
  2019. device_status.version_type = 41;
  2020. rt_sprintf(device_status.driver, "%s",VERSION_HK);
  2021. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
  2022. }
  2023. else if(device_status.version_type==1)
  2024. {
  2025. rt_sprintf(device_status.driver, "%s",VERSION_ZP);
  2026. }
  2027. else if (device_status.version_type==11)
  2028. {
  2029. rt_sprintf(device_status.driver, "%s",VERSION_GK);
  2030. }
  2031. else if (device_status.version_type==4)
  2032. {
  2033. rt_sprintf(device_status.driver, "%s",VERSION_HK_2000W);
  2034. }
  2035. else if (device_status.version_type==41) {
  2036. rt_sprintf(device_status.driver, "%s",VERSION_HK);
  2037. }
  2038. else if (device_status.version_type==5) {
  2039. rt_sprintf(device_status.driver, "%s",VERSION_V5);
  2040. }
  2041. else if (device_status.version_type==6)
  2042. {
  2043. //打开相机供电;
  2044. ctr_Camera_Power(ON);
  2045. rt_sprintf(device_status.driver, "%s",VERSION_XCT);
  2046. }
  2047. else if (device_status.version_type==7) {
  2048. rt_sprintf(device_status.driver, "%s",VERSION_BZY);
  2049. //异常处理:20230331,修复第一段开始时间等于第二段结束时间的情况
  2050. if(device_status.collecting_eh1==device_status.collecting_eh2&&device_status.collecting_sh2!=device_status.collecting_eh2)
  2051. {
  2052. device_status.collecting_eh2 = device_status.collecting_sh2 + 2;
  2053. }
  2054. }
  2055. else if (device_status.version_type==30) {
  2056. rt_sprintf(device_status.driver, "%s",VERSION_Robot);
  2057. }
  2058. /*定制三色光源*/
  2059. #if LAMP_EN == 1
  2060. if(device_status.sunBar%3!=0)
  2061. {
  2062. device_status.sunBar = 3;
  2063. }
  2064. // device_status.timeSwitch = 1;
  2065. // device_status.startBar = 20;
  2066. // device_status.stopBar = 23;
  2067. #endif
  2068. LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
  2069. LOG_I("read flash paramconfis:%d-%s-%s",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
  2070. LOG_I("开机次数:%d",device_status.rebootcnt);
  2071. LOG_I("收集时间:%d",device_status.clt_time);
  2072. LOG_I("定时开始时间:%d",device_status.startBar);
  2073. LOG_I("定时结束时间:%d",device_status.stopBar);
  2074. LOG_I("timeSwitch:%d",device_status.timeSwitch);
  2075. LOG_I("光控定时时长:%d",device_status.sunBar);
  2076. LOG_I("收集时间:%d",device_status.heattime);
  2077. LOG_I("加热温度:%d",device_status.heatvalue);
  2078. LOG_I("震动开关:%d",device_status.shake_ws);
  2079. LOG_I("震动时间:%d",device_status.shake_sec);
  2080. LOG_I("高温保护:%d",device_status.tph);
  2081. LOG_I("低温保护:%d",device_status.tpl);
  2082. LOG_I("thsp:%d", device_status.thsp);
  2083. LOG_I("密码:%d",device_status.passWord);
  2084. LOG_I("数据上传间隔:%d",device_status.dattim);
  2085. LOG_I("温湿度数据:%d-%d",atoi(device_status.tempture),atoi(device_status.humidity));
  2086. LOG_I("上传平台:%s",device_status.mqttcfg1);
  2087. LOG_I("孢子仪运行状态:%d",device_status.run_sta);
  2088. LOG_I("孢子仪采集时间:[%d-%d,%d-%d]",device_status.collecting_sh1,device_status.collecting_eh1,device_status.collecting_sh2,device_status.collecting_eh2);
  2089. LOG_I("PowerType:%d",device_status.Power_Type);
  2090. LOG_I("deviceId:%s",device_status.deviceId);
  2091. LOG_I("handle_bugger:%d",device_status.handle_bugger);
  2092. }
  2093. //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
  2094. if(device_status.update_flag==1)
  2095. {
  2096. device_status.update_flag = 0;
  2097. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  2098. ymodem_ota(1,0);
  2099. }
  2100. else {
  2101. device_status.update_flag = 0;
  2102. //初始化联网状态
  2103. rt_sprintf(device_status.net,"1");
  2104. rt_sprintf(device_status.csq,"0");
  2105. rt_sprintf(device_status.sim,"1");
  2106. ctr_router(ON);
  2107. Hmi_Fresh();
  2108. if(device_status.dtype!=7)
  2109. {
  2110. Control_clear();
  2111. Control_heat();
  2112. }
  2113. dtu_data_play();
  2114. sht30_collect();
  2115. #if SENSOR_EN==1
  2116. mb_master_samlpe();
  2117. #endif
  2118. #if ROBOT_EN == 0
  2119. uint16_t connect_num=0;
  2120. //等待联网,
  2121. while(atoi(device_status.net)==1)
  2122. {
  2123. if(Read_Real_Voltage()/100>5&&device_status.power_status==0)
  2124. ctr_RTU_DTU(ON);
  2125. if(device_status.dtype==7)
  2126. HMI_WRITE("sysTest.auto_flag.txt=\"0\"");
  2127. char *readinfo = makeJson_ReadInfo();
  2128. DTU_Write("%s",readinfo);
  2129. rt_free(readinfo);
  2130. rt_thread_delay(1000);
  2131. connect_num++;
  2132. LOG_I("联网中......%d",connect_num);
  2133. //超时时间为3分钟
  2134. if(connect_num==180)
  2135. {
  2136. device_status.timeSwitch = 0;
  2137. 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);
  2138. #if 0
  2139. set_date(2020, 1, 1);
  2140. set_time(0, 0, 0);
  2141. #endif
  2142. break;
  2143. }
  2144. if(tm.tm_year>=2021)
  2145. break;
  2146. }
  2147. connect_num = 0;
  2148. while(atoi(device_status.net)==0)
  2149. {
  2150. char *readinfo = makeJson_ReadInfo();
  2151. DTU_Write("%s",readinfo);
  2152. rt_free(readinfo);
  2153. rt_thread_delay(2000);
  2154. connect_num++;
  2155. if(connect_num>5) break;
  2156. }
  2157. if(device_status.version_type==6) device_status.timeSwitch = 1;
  2158. DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
  2159. rt_thread_delay(1000);
  2160. #endif
  2161. }
  2162. }
  2163. void ResetParamDefault(void)
  2164. {
  2165. rt_sprintf(device_status.tempture,"%d",-15);
  2166. device_status.ds = 1; //设备状态开机
  2167. device_status.thsp = 300;
  2168. device_status.passWord = 8888;
  2169. device_status.dattim = 10;
  2170. device_status.collecting_sh1 = 9;
  2171. device_status.collecting_eh1 = 10;
  2172. device_status.collecting_sh2 = 14;
  2173. device_status.collecting_eh2 = 16;
  2174. device_status.Power_Type = 0;
  2175. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  2176. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  2177. if(device_status.dtype==3)
  2178. {
  2179. device_status.clt_time = 10; //收集时间
  2180. #if LAMP_EN == 0
  2181. device_status.startBar = 20; //定时开始时间
  2182. device_status.stopBar = 5; //定时结束时间
  2183. #endif
  2184. device_status.heattime = 10; //加热时间
  2185. device_status.shake_ws = 1; //针对开关
  2186. device_status.shake_sec = 1; //震动时间1-100ms
  2187. #if LAMP_EN == 1
  2188. device_status.sunBar = 3; //光控定时时长
  2189. #else
  2190. device_status.sunBar = 8;
  2191. #endif
  2192. device_status.tph = 70; //高温保护阈值
  2193. device_status.tpl = -5; //低温保护阈值
  2194. device_status.timeSwitch = 0; //定时模式:光控
  2195. device_status.heatvalue=100; //加热温度
  2196. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  2197. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  2198. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  2199. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  2200. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  2201. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  2202. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  2203. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  2204. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  2205. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  2206. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  2207. device_status.handle_bugger = 0;
  2208. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  2209. }
  2210. else if(device_status.dtype==7)
  2211. {
  2212. device_status.run_sta = 0;
  2213. device_status.heatvalue = 25; //培养温度
  2214. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  2215. ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1)); //采集时间
  2216. ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1)); //采集时间
  2217. ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2)); //采集时间
  2218. ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2)); //采集时间
  2219. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  2220. }
  2221. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  2222. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  2223. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  2224. HMI_WRITE("play %d,%d,%d",1,5,0);
  2225. DTU_Write("reset.mp3");
  2226. rt_thread_delay(1000);
  2227. }
  2228. void ResetParamDefault_DC(void)
  2229. {
  2230. //将温度数据设置为-15摄氏度,以便上传的数据中包含温控数据
  2231. rt_sprintf(device_status.tempture,"%d",-15);
  2232. device_status.clt_time = 10; //收集时间
  2233. device_status.dattim = 10; //数据上传间隔
  2234. #if LAMP_EN == 0
  2235. device_status.startBar = 20; //定时开始时间
  2236. device_status.stopBar = 0; //定时结束时间
  2237. #endif
  2238. device_status.heattime = 10; //加热时间
  2239. device_status.shake_ws = 1; //针对开关
  2240. device_status.shake_sec = 1; //震动时间1-100ms
  2241. #if LAMP_EN == 1
  2242. device_status.sunBar = 3; //光控定时时长
  2243. #else
  2244. device_status.sunBar = 4;
  2245. #endif
  2246. device_status.tph = 70; //高温保护阈值
  2247. device_status.tpl = -5; //低温保护阈值
  2248. device_status.timeSwitch = 0; //定时模式
  2249. device_status.heatvalue=100;
  2250. device_status.ds = 1; //设备状态开机
  2251. device_status.thsp = 300;
  2252. device_status.passWord = 8888;
  2253. device_status.timeSwitch = 0;
  2254. device_status.Power_Type = 1;
  2255. device_status.handle_bugger = 0;
  2256. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  2257. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  2258. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  2259. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  2260. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  2261. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  2262. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  2263. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  2264. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  2265. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  2266. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  2267. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  2268. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  2269. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  2270. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  2271. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  2272. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  2273. DTU_Write("reset.mp3");
  2274. rt_thread_delay(1000);
  2275. }
  2276. //固件备份
  2277. void app_partion_backup(void)
  2278. {
  2279. rt_kprintf("固件恢复!!!\n");
  2280. const char *dst_part_name = "df_area";
  2281. const char *src_part_name = "app";
  2282. const struct fal_partition *dst_part;
  2283. const struct fal_partition *src_part;
  2284. dst_part = fal_partition_find(dst_part_name);
  2285. src_part = fal_partition_find(src_part_name);
  2286. if (dst_part == RT_NULL || src_part == RT_NULL)
  2287. {
  2288. if (dst_part == RT_NULL)
  2289. rt_kprintf("%s partition is not exist!\n", dst_part_name);
  2290. if (src_part == RT_NULL)
  2291. rt_kprintf("%s partition is not exist!\n", src_part_name);
  2292. }
  2293. else
  2294. {
  2295. rt_kprintf("Clone %s partition to %s partition:\n", src_part_name, dst_part_name);
  2296. if (fal_partition_erase(dst_part, 0, dst_part->len) >= 0)
  2297. {
  2298. int clone_pos = 0;
  2299. int clone_len = 0, clone_tol_len;
  2300. rt_uint8_t *buf = rt_malloc(4096);
  2301. if (dst_part->len < src_part->len)
  2302. clone_tol_len = dst_part->len;
  2303. else
  2304. clone_tol_len = src_part->len;
  2305. while ((clone_pos < clone_tol_len) && (buf != RT_NULL))
  2306. {
  2307. clone_len = fal_partition_read(src_part, clone_pos, buf, 4096);
  2308. if (clone_len < 0)
  2309. {
  2310. rt_kprintf("\nread %s partition failed, clone stop!\n", src_part_name);
  2311. break;
  2312. }
  2313. if (fal_partition_write(dst_part, clone_pos, buf, clone_len) < 0)
  2314. {
  2315. rt_kprintf("\nwrite %s partition failed, clone stop!\n", dst_part_name);
  2316. break;
  2317. }
  2318. HMI_WRITE("#");
  2319. rt_kprintf("#");
  2320. clone_pos += clone_len;
  2321. }
  2322. if (clone_pos >= clone_tol_len)
  2323. {
  2324. rt_kprintf("\nClone partition success, total %d bytes!\n", clone_tol_len);
  2325. }
  2326. else
  2327. {
  2328. rt_kprintf("Clone partition failed!");
  2329. }
  2330. if (buf)
  2331. rt_free(buf);
  2332. }
  2333. }
  2334. }
  2335. void Debug_log_ON(void)
  2336. {
  2337. rt_console_set_device("uart4");
  2338. finsh_set_device("uart4");
  2339. }
  2340. void Debug_log_OFF(void)
  2341. {
  2342. rt_console_set_device("uart1");
  2343. finsh_set_device("uart1");
  2344. rt_mq_init(&rx_mq, "rx_mq",
  2345. msg_pool, /* 存放消息的缓冲区 */
  2346. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  2347. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  2348. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  2349. rt_device_set_rx_indicate(serial, uart_input);
  2350. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  2351. Hmi_thread_entry,
  2352. RT_NULL,
  2353. HMI_THREAD_STACK_SIZE,
  2354. HMI_THREAD_PRIORITY,
  2355. HMI_THREAD_TIMESLICE);
  2356. if (hmi1 != RT_NULL)
  2357. {
  2358. rt_thread_startup(hmi1);
  2359. }
  2360. }
  2361. MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
  2362. MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
  2363. //
  2364. INIT_BOARD_EXPORT(HMI_uart4_init);