hmi.c 105 KB

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