hmi.c 101 KB

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