hmi.c 78 KB

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