hmi.c 82 KB

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