hmi.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157
  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. #if MATCH_DEVICE == 0
  321. HMI_WRITE("workSta.net.val=0");
  322. HMI_WRITE("menu.net.val=0");
  323. #else
  324. HMI_WRITE("workSta.net.val=1");
  325. HMI_WRITE("menu.net.val=1");
  326. #endif
  327. }
  328. if(atoi(device_status.csq)==0&&atoi(device_status.net)==1)
  329. {
  330. HMI_WRITE("menu.net.val=1");
  331. HMI_WRITE("workSta.net.val=2");
  332. }
  333. /**********************************************************************/
  334. }
  335. else if (strstr(rx_buffer,"getClockData")!=NULL) {
  336. //更新定时模式
  337. HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
  338. //更新光控定时时长
  339. HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
  340. //更新时控开始
  341. HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
  342. //更新时控结束
  343. HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
  344. }
  345. else if (strstr(rx_buffer,"button")!=NULL) {
  346. LOG_D("button!");
  347. DTU_Write("button");
  348. }
  349. //拍照
  350. else if(strstr(rx_buffer,"putTest.switchPhoto=1")!=NULL) {
  351. #if MATCH_DEVICE == 1
  352. ctr_led(ON);
  353. //发送拍照指令
  354. char *takephotojson = makeJson_takephoto();
  355. DTU_Write("%s",takephotojson);
  356. rt_free(takephotojson);
  357. HMI_WRITE("sysTest.switchPhoto.val=0");
  358. #else
  359. device_status.photo_ws = 1;
  360. #endif
  361. }
  362. else if (strstr(rx_buffer,"putTest.switchPic=1")!=NULL) {
  363. #if MATCH_DEVICE == 1
  364. ctr_led(ON);
  365. //发送拍照指令
  366. char *takephotojson = makeJson_takephoto();
  367. DTU_Write("%s",takephotojson);
  368. rt_free(takephotojson);
  369. HMI_WRITE("sysTest.switchPhoto.val=0");
  370. #else
  371. device_status.photo_ws = 1;
  372. #endif
  373. }
  374. //转盘复位
  375. else if (strstr(rx_buffer,"turn_init")!=NULL) {
  376. LOG_I("转仓复位!");
  377. ctr_turn(0,0);
  378. }
  379. //转盘
  380. else if (strstr(rx_buffer,"turn")!=NULL) {
  381. LOG_I("转仓!");
  382. ctr_turn(90,0);
  383. }
  384. //打开电磁阀
  385. else if (strstr(rx_buffer,"putTest.switchDrop=1")!=NULL) {
  386. LOG_I("开始滴液!");
  387. #if Color_EN == 1
  388. device_status.run_sta = 5;
  389. #else
  390. ctr_shake(ON, device_status.shake_sec);
  391. #endif
  392. }
  393. //关闭电磁阀
  394. else if (strstr(rx_buffer,"putTest.switchDrop=0")!=NULL) {
  395. LOG_I("停止滴液!");
  396. ctr_shake(OFF, 0);
  397. }
  398. //打开补光
  399. else if (strstr(rx_buffer,"putTest.switchLed=1")!=NULL) {
  400. LOG_I("打开补光!!");
  401. ctr_led(ON);
  402. }
  403. //关闭补光
  404. else if (strstr(rx_buffer,"putTest.switchLed=0")!=NULL) {
  405. LOG_I("关闭补光!!!");
  406. ctr_led(OFF);
  407. }
  408. //关闭加热
  409. else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
  410. device_status.heat_status = 0;
  411. ctr_Heat(OFF);
  412. LOG_I("Close Heat!");
  413. }
  414. //打开加热
  415. else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
  416. device_status.heat_status = 1;
  417. ctr_Heat(ON);
  418. LOG_I("Open Heat!");
  419. }
  420. //打开制冷
  421. else if(strstr(rx_buffer,"putTest.switchCold=1")!=NULL) {
  422. ctr_Cold(ON);
  423. LOG_I("Open Cold!");
  424. }
  425. //关闭制冷
  426. else if(strstr(rx_buffer,"putTest.switchCold=0")!=NULL) {
  427. ctr_Cold(OFF);
  428. LOG_I("Close Cold!");
  429. }
  430. //打开采集
  431. else if(strstr(rx_buffer,"putTest.switchCollect=1")!=NULL){
  432. ctr_Collect_Fan(ON);
  433. LOG_I("采集风机已打开!");
  434. }
  435. //关闭采集
  436. else if(strstr(rx_buffer,"putTest.switchCollect=0")!=NULL){
  437. ctr_Collect_Fan(OFF);
  438. LOG_I("采集风机已关闭!");
  439. }
  440. //打开散热
  441. else if(strstr(rx_buffer,"putTest.switchCool=1")!=NULL){
  442. ctr_Cool_Fan(ON);
  443. LOG_I("散热风机已打开!");
  444. }
  445. //关闭散热
  446. else if(strstr(rx_buffer,"putTest.switchCool=0")!=NULL){
  447. ctr_Cool_Fan(OFF);
  448. LOG_I("散热风机已关闭!");
  449. }
  450. //开始对焦拍照
  451. else if(strstr(rx_buffer,"putTest.switchAutopic=1")!=NULL){
  452. device_status.autotakepic=1;
  453. rt_kprintf("开始对焦拍照!\n");
  454. }
  455. //停止对焦拍照
  456. else if(strstr(rx_buffer,"putTest.switchAutopic=0")!=NULL){
  457. device_status.autotakepic=0;
  458. }
  459. //粘附测试-开
  460. else if(strstr(rx_buffer,"putTest.switchFsl=1")!=NULL){
  461. rt_kprintf("粘附测试开!\n");
  462. device_status.fsl_sw = 1;
  463. }
  464. //粘附测试-关
  465. else if(strstr(rx_buffer,"putTest.switchFsl=0")!=NULL){
  466. rt_kprintf("粘附测试关!\n");
  467. pwm_off(2, 0);
  468. pwm_off(3,0);
  469. }
  470. else if (strstr(rx_buffer,"putTest.switchAutotest=1")!=NULL)
  471. {
  472. LOG_I("开始一键测试!!!");
  473. device_status.auto_test_sw=1;
  474. }
  475. else if (strstr(rx_buffer,"putTest.switchAutotest=1")!=NULL)
  476. {
  477. LOG_I("停止一键测试!!!");
  478. device_status.auto_test_sw=0;
  479. }
  480. else if (strstr(rx_buffer,"turnzp")!=NULL) {
  481. LOG_W("转仓!");
  482. device_status.clear_status=2;
  483. }
  484. //清扫
  485. else if (strstr(rx_buffer,"clear")!=NULL) {
  486. LOG_W("清扫!");
  487. device_status.clear_status=1;
  488. }
  489. //震动
  490. else if (strstr(rx_buffer,"putTest.switchShake=1")!=NULL) {
  491. LOG_I("震动!");
  492. if(device_status.version_type==6)
  493. {
  494. Motor_shake(ON, device_status.shake_sec);
  495. }
  496. else{
  497. ctr_shake(ON,device_status.shake_sec);
  498. ctr_router(ON);
  499. }
  500. }
  501. //打开补光
  502. else if (strstr(rx_buffer,"putTest.switchFill=1")!=NULL) {
  503. rt_kprintf("\n打开补光!!!\n");
  504. ctr_led(ON);
  505. }
  506. //关闭补光
  507. else if (strstr(rx_buffer,"putTest.switchFill=0")!=NULL) {
  508. rt_kprintf("\n关闭补光!!!\n");
  509. ctr_led(OFF);
  510. }
  511. //打开灯管
  512. else if (strstr(rx_buffer,"putTest.switchLamp=1")!=NULL)
  513. {
  514. device_status.test_flag=1;
  515. rt_kprintf("Open Lamp!\n");
  516. ctr_lamp(ON,1);
  517. #if LAMP_EN == 1
  518. ctr_lamp(ON,2);
  519. ctr_lamp(ON,3);
  520. #endif
  521. DTU_Write("{\"cmd\":\"workstart\"}");
  522. USHORT dkdg[] = {0xb4f2,0xbfaa,0xb5c6,0xb9dc};
  523. _485_play(dkdg,4);
  524. }
  525. //关闭灯管
  526. else if (strstr(rx_buffer,"putTest.switchLamp=0")!=NULL)
  527. {
  528. device_status.test_flag=0;
  529. rt_kprintf("Close Lamp1!\n");
  530. ctr_lamp(OFF,1);
  531. #if LAMP_EN == 1
  532. ctr_lamp(OFF,2);
  533. ctr_lamp(OFF,3);
  534. #endif
  535. DTU_Write("{\"cmd\":\"workdone\"}");
  536. USHORT gbdg[] = {0xb9d8,0xb1d5,0xb5c6,0xb9dc};
  537. _485_play(gbdg,4);
  538. }
  539. //关闭加热
  540. else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
  541. device_status.heat_status = 0;
  542. ctr_Heat(OFF);
  543. rt_kprintf("Close Heat!\n");
  544. }
  545. //打开加热
  546. else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
  547. device_status.heat_status = 1;
  548. ctr_Heat(ON);
  549. rt_kprintf("Open Heat!\n");
  550. }
  551. //打开上仓门
  552. else if(strstr(rx_buffer,"putTest.switchUp=1")!=NULL){
  553. if(device_status.dtype==7)
  554. {
  555. ctr_lamp(ON, 1);
  556. ctr_Motor_Driver(1, 0,1000000,500);
  557. LOG_I("开始步进上行!");
  558. }
  559. else
  560. {
  561. rt_kprintf("Open UP!\n");
  562. ctr_cangmen_up(OFF);
  563. device_status.ctr_up_motor = 1;
  564. }
  565. }
  566. //关闭上仓门
  567. else if(strstr(rx_buffer,"putTest.switchUp=0")!=NULL){
  568. if(device_status.dtype==7)
  569. {
  570. LOG_I("停止步进上行!");
  571. ctr_lamp(OFF, 1);
  572. ctr_Motor_Driver(0, 0,0,0);
  573. }
  574. else
  575. {
  576. rt_kprintf("CLOSE UP!\n");
  577. ctr_cangmen_up(OFF);
  578. device_status.ctr_up_motor = 2;
  579. }
  580. }
  581. //打开下仓门
  582. else if(strstr(rx_buffer,"putTest.switchDown=1")!=NULL){
  583. if(device_status.dtype==7)
  584. {
  585. LOG_I("开始步进下行!");
  586. ctr_lamp(ON, 1);
  587. ctr_Motor_Driver(1, 1,1000000,500);
  588. }
  589. else
  590. {
  591. ctr_cangmen_down(OFF);
  592. device_status.ctr_down_motor = 1;
  593. rt_kprintf("Open down!\n");
  594. }
  595. }
  596. //关闭下仓门
  597. else if(strstr(rx_buffer,"putTest.switchDown=0")!=NULL){
  598. if(device_status.dtype==7)
  599. {
  600. ctr_lamp(OFF, 1);
  601. ctr_Motor_Driver(0, 0,0,0);
  602. rt_kprintf("停止步进下行!\n");
  603. }
  604. else
  605. {
  606. ctr_cangmen_down(OFF);
  607. device_status.ctr_down_motor = 2;
  608. rt_kprintf("CLOSE down!\n");
  609. }
  610. }
  611. else if(strstr(rx_buffer,"putTest.Testpaichong")!=NULL){
  612. if(device_status.collt_box_sta==0){
  613. device_status.collt_box_sta = 111;
  614. }else{
  615. HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
  616. }
  617. LOG_I("排虫测试!");
  618. }
  619. //排虫
  620. else if(strstr(rx_buffer,"putTest.paichong")!=NULL){
  621. if(device_status.run_sta == 0){
  622. device_status.run_sta = 111;
  623. }else{
  624. HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
  625. }
  626. LOG_I("开始排虫!");
  627. device_status.handle_bugger = 0;
  628. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  629. }
  630. else if(strstr(rx_buffer,"putTest.shouchong")!=NULL){
  631. if(device_status.run_sta == 0){
  632. device_status.run_sta = 112;
  633. }else{
  634. HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
  635. }
  636. LOG_I("开始收虫!");
  637. device_status.handle_bugger = 1;
  638. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  639. }
  640. //设置设备时间
  641. else if (strstr(rx_buffer,"stamp=")!=NULL)
  642. {
  643. var = strstr(rx_buffer,"=");
  644. var ++;
  645. LOG_I("设置时间:%s",var);
  646. static char year_s[5],month_s[3],day_s[3],hour_s[3],min_s[3],sec_s[3];
  647. strncpy(year_s, var, 4);
  648. strncpy(month_s,var+4,2);
  649. strncpy(day_s,var+6,2);
  650. strncpy(hour_s,var+8,2);
  651. strncpy(min_s,var+10,2);
  652. strncpy(sec_s,var+12,2);
  653. 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)
  654. {
  655. if(set_date(atoi(year_s),atoi(month_s),atoi(day_s))==RT_EOK)
  656. {
  657. LOG_I("设置日期:%d年%d月%d日",atoi(year_s),atoi(month_s),atoi(day_s));
  658. 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)
  659. {
  660. LOG_I("设置时间:%d时%d分%d秒",atoi(hour_s),atoi(min_s),atoi(sec_s));
  661. set_time(atoi(hour_s),atoi(min_s),atoi(sec_s));
  662. MA_save();
  663. }
  664. //上传最新数据
  665. device_status.num_updata = 2; //2秒后上报数据更新RTU的时间
  666. }
  667. else {
  668. LOG_E("set_date failed!");
  669. }
  670. }
  671. }
  672. //设备编码设置
  673. else if (strstr(rx_buffer,"deviceId=")!=NULL)
  674. {
  675. char value_str[20];
  676. memset(value_str,0,sizeof(value_str));
  677. LOG_I("设备编码 长度:%d",strlen(rx_buffer));
  678. if(strlen(rx_buffer)!=19){
  679. LOG_E("编码长度错误!");
  680. return;
  681. }
  682. var = strstr(rx_buffer,"=");
  683. var ++;
  684. strncpy(value_str,var,8); //设备编码为16位
  685. if(strstr(value_str,"00000000")!=RT_NULL){
  686. char *config_reset = makeJson_Config_Reset();
  687. //发送json到RTU
  688. DTU_Write("%s",config_reset);
  689. rt_free(config_reset);
  690. //恢复RTU的默认配置参数
  691. }else{
  692. rt_sprintf(device_status.deviceId,"10300101%s",value_str); //设备大类编码103-虫情 设备小类编码 001 生产商代码01
  693. ef_set_env_blob("deviceId", &device_status.deviceId, sizeof(device_status.deviceId));
  694. LOG_I("解析到设备编码:%s",device_status.deviceId);
  695. char *device_id = makeJson_Config_BDH(device_status.deviceId);
  696. //发送json到RTU
  697. DTU_Write("%s",device_id);
  698. rt_free(device_id);
  699. }
  700. }
  701. //定时设置
  702. else if (strstr(rx_buffer,"saveClockSet=")!=NULL) {
  703. char value_str[10];
  704. memset(value_str,0,sizeof(value_str));
  705. if(device_status.dtype==7)
  706. {
  707. var = strstr(rx_buffer,"=");
  708. var ++;
  709. strncpy(value_str,var,2);
  710. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  711. {
  712. device_status.collecting_sh1 = atoi(value_str);
  713. ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1));
  714. }
  715. else {
  716. LOG_E("Set collecting_sh1 Failed!");
  717. }
  718. memset(value_str,0,sizeof(value_str));
  719. strncpy(value_str,var+2,2);
  720. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  721. {
  722. device_status.collecting_eh1 = atoi(value_str);
  723. ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1));
  724. }
  725. else {
  726. LOG_E("Set collecting_eh1 Failed!");
  727. }
  728. memset(value_str,0,sizeof(value_str));
  729. strncpy(value_str,var+4,2);
  730. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  731. {
  732. device_status.collecting_sh2 = atoi(value_str);
  733. ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2));
  734. }
  735. else {
  736. LOG_E("Set collecting_sh2 Failed!");
  737. }
  738. memset(value_str,0,sizeof(value_str));
  739. strncpy(value_str,var+6,2);
  740. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  741. {
  742. device_status.collecting_eh2 = atoi(value_str);
  743. ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2));
  744. }
  745. else {
  746. LOG_E("Set collecting_eh2 Failed!");
  747. }
  748. memset(value_str,0,sizeof(value_str));
  749. strncpy(value_str,var+8,2);
  750. if(atoi(value_str)>=0&&atoi(value_str)<=23)
  751. {
  752. device_status.shake_sec = atoi(value_str);
  753. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
  754. }
  755. else {
  756. LOG_E("Set shake_sec Failed!");
  757. }
  758. memset(value_str,0,sizeof(value_str));
  759. strncpy(value_str,var+10,2);
  760. if(atoi(value_str)>0&&atoi(value_str)<=24)
  761. {
  762. device_status.cul_time = atoi(value_str);
  763. ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
  764. }
  765. else {
  766. LOG_E("Set cul_time Failed!");
  767. }
  768. MA_save();
  769. 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);
  770. return;
  771. }
  772. LOG_I("时间设置!");
  773. var=strstr(rx_buffer,"=");
  774. var++;
  775. strncpy(value_str,var,2);
  776. if(atoi(value_str) > 0 && atoi(value_str) <60)
  777. {
  778. if(device_status.version_type!=6)
  779. {
  780. device_status.sunBar=atoi(value_str);
  781. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  782. }
  783. else {
  784. device_status.shake_sec = atoi(value_str);
  785. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
  786. }
  787. // time_t now;
  788. // time(&now);
  789. // static struct tm nowstamp;
  790. // nowstamp =*localtime(&now);
  791. // nowstamp.tm_hour = nowstamp.tm_hour - 8;
  792. // static rt_uint32_t nowstamp_num = 0;
  793. // nowstamp_num = mktime(&nowstamp);
  794. // device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
  795. }
  796. else {
  797. LOG_E("参数设置异常(光控时长):%d!!!",atoi(value_str));
  798. }
  799. memset(value_str,0,sizeof(value_str));
  800. //时控开始时间
  801. strncpy(value_str,var+2,2);
  802. if(atoi(value_str) >= 0 && atoi(value_str) < 24)
  803. {
  804. #if 1
  805. device_status.startBar=atoi(value_str);
  806. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  807. #endif
  808. }
  809. else {
  810. LOG_E("参数设置异常(开始):%d!!!",atoi(value_str));
  811. }
  812. memset(value_str,0,sizeof(value_str));
  813. //
  814. strncpy(value_str,var+4,2);
  815. if(atoi(value_str) >= 0&& atoi(value_str) < 24)
  816. {
  817. #if 1
  818. device_status.stopBar=atoi(value_str);
  819. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  820. #endif
  821. }
  822. else {
  823. LOG_E("参数设置异常(结束):%d!!!",atoi(value_str));
  824. }
  825. memset(value_str,0,sizeof(value_str));
  826. //
  827. strncpy(value_str,var+6,2);
  828. if(atoi(value_str) >= 0 && atoi(value_str) <= 1)
  829. {
  830. device_status.timeSwitch=atoi(value_str);
  831. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  832. }
  833. else {
  834. if(device_status.version_type==6)
  835. {
  836. device_status.timeSwitch=1;
  837. device_status.dattim=atoi(value_str);
  838. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
  839. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  840. }
  841. else {
  842. LOG_E("参数设置异常(模式):%d!!!",atoi(value_str));
  843. }
  844. }
  845. //2022/06/23,add:
  846. 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);
  847. json_temp = makeJson_Warn(device_status.json_w_clock, "修改工作时间");
  848. ef_set_env_blob("json_w_clock", &device_status.json_w_clock, sizeof(device_status.json_w_clock)); //将修改屏幕参数操作记录保存到Flash中
  849. if(atoi(device_status.net)==0)
  850. DTU_Write("%s",json_temp);
  851. rt_free(json_temp);
  852. rt_thread_delay(2000);
  853. MA_save();
  854. rt_kprintf("工作时间参数已保存:模式-%d,光控时间-%d,时控开始时间-%d,时控结束时间-%d\n",device_status.timeSwitch,device_status.sunBar,device_status.startBar,device_status.stopBar);
  855. }
  856. else if (strstr(rx_buffer,"saveSystemSet")!=NULL) {
  857. static char clt_time_str[3],heattime_str[3],heatvale_str[4],vol_str[4],thsp_str[5];
  858. static char value_temp[5];
  859. LOG_I("系统设置!");
  860. if(device_status.dtype==7)
  861. {
  862. LOG_I("系统设置,孢子仪!");
  863. var = strstr(rx_buffer,"=");
  864. var ++;
  865. memset(value_temp,0,sizeof(value_temp));
  866. strncpy(value_temp,var,2);
  867. if(atoi(value_temp)==0 || atoi(value_temp) == 1)
  868. {
  869. device_status.cold_sw = atoi(value_temp); //制冷开关
  870. ef_set_env_blob("cold_sw", &device_status.cold_sw, sizeof(device_status.cold_sw));
  871. }
  872. else {
  873. LOG_E("制冷开关参数设置错误!");
  874. }
  875. memset(value_temp,0,sizeof(value_temp));
  876. strncpy(value_temp,var+2,2);
  877. if(atoi(value_temp)>=0 && atoi(value_temp) <= 7)
  878. {
  879. device_status.vol = atoi(value_temp); //音量
  880. }
  881. else {
  882. LOG_E("音量参数设置错误!");
  883. }
  884. memset(value_temp,0,sizeof(value_temp));
  885. strncpy(value_temp,var+4,2);
  886. if(atoi(value_temp)>=10 && atoi(value_temp) <= 50)
  887. {
  888. device_status.heatvalue = atoi(value_temp); //设定的培养温度
  889. ef_set_env_blob("heatvalue", &device_status.heatvalue, sizeof(device_status.heatvalue));
  890. }
  891. else {
  892. LOG_E("培养温度参数设置失败!");
  893. }
  894. memset(value_temp,0,sizeof(value_temp));
  895. strncpy(value_temp,var+6,2);
  896. if(atoi(value_temp)>=1 && atoi(value_temp) <= 60)
  897. {
  898. device_status.dattim = atoi(value_temp); //设定的数据上传间隔,单位:分钟
  899. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
  900. }
  901. else {
  902. LOG_E("数据上传间隔参数设置失败!");
  903. }
  904. memset(value_temp,0,sizeof(value_temp));
  905. strncpy(value_temp,var+8,2);
  906. if(atoi(value_temp)>=1 && atoi(value_temp) <= 30)
  907. {
  908. device_status.thsp = atoi(value_temp); //设定的息屏间隔,单位:分钟
  909. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  910. }
  911. else {
  912. LOG_E("数据息屏间隔参数设置失败!");
  913. }
  914. LOG_I("制冷开关:%d",device_status.cold_sw);
  915. LOG_I("系统设置已保存:\n自动熄屏-%d\n音量-%d\n培养温度-%d\n数据上传间隔-%d",device_status.thsp,device_status.vol,device_status.heatvalue,device_status.dattim);
  916. MA_save();
  917. return;
  918. }
  919. var = strstr(rx_buffer,"=");
  920. var ++;
  921. strncpy(clt_time_str,var,2);
  922. if(atoi(clt_time_str)>0 && atoi(clt_time_str) <= 30)
  923. {
  924. device_status.clt_time = atoi(clt_time_str); //收集时间
  925. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  926. }
  927. strncpy(heattime_str,var+2,2);
  928. if(atoi(heattime_str)>0 && atoi(heattime_str) <= 30)
  929. {
  930. device_status.heattime = atoi(heattime_str); //加热时间
  931. LOG_I("设置加热时间:%d",atoi(heattime_str));
  932. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  933. }
  934. strncpy(heatvale_str,var+4,3);
  935. if(atoi(heatvale_str) > 0 && atoi(heatvale_str) <= 130)
  936. {
  937. device_status.heatvalue=atoi(heatvale_str);
  938. LOG_I("设置加热温度:%d",device_status.heatvalue);
  939. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  940. }
  941. strncpy(vol_str,var+7,3);
  942. if(atoi(vol_str)>0&&atoi(vol_str)<8)
  943. {
  944. device_status.vol = atoi(vol_str); //音量
  945. LOG_I("设置音量:%d",device_status.vol);
  946. //DTU_Write("volume=");
  947. }
  948. strncpy(thsp_str,var+10,4);
  949. if(atoi(thsp_str)>0&&atoi(thsp_str)<3600)
  950. {
  951. device_status.thsp = atoi(thsp_str); //熄屏时间
  952. LOG_I("设置熄屏时间:%d",device_status.thsp);
  953. }
  954. else {
  955. LOG_E("参数设置失败!!!");
  956. }
  957. rt_thread_delay(1000);
  958. MA_save();
  959. //rt_kprintf("系统设置已保存:收集时间-%d,加热时间-%d,加热温度-%d,音量-%d,自动关屏-%d\n",device_status.clt_time,device_status.heattime,device_status.heatvalue,device_status.vol,device_status.thsp);
  960. }
  961. else if (strstr(rx_buffer,"rtc_h=")!=NULL) {
  962. char rtc_h[2];
  963. var = strstr(rx_buffer,"=");
  964. var++;
  965. strncpy(rtc_h,var,2);
  966. if(atoi(rtc_h)>=0 && atoi(rtc_h) <= 24)
  967. {
  968. set_time(atoi(rtc_h), 99, 99);
  969. }
  970. }
  971. else if (strstr(rx_buffer,"rtc_m=")!=NULL) {
  972. char rtc_m[2];
  973. var = strstr(rx_buffer,"=");
  974. var++;
  975. strncpy(rtc_m,var,2);
  976. if(atoi(rtc_m)>=0 && atoi(rtc_m) <= 24)
  977. {
  978. set_time(99, atoi(rtc_m), 99);
  979. }
  980. }
  981. else if (strstr(rx_buffer,"rtc_s=")!=NULL) {
  982. char rtc_s[2];
  983. var = strstr(rx_buffer,"=");
  984. var++;
  985. strncpy(rtc_s,var,2);
  986. if(atoi(rtc_s)>=0 && atoi(rtc_s) <= 24)
  987. {
  988. set_time(99, 99, atoi(rtc_s));
  989. }
  990. }
  991. else if(strstr(rx_buffer,"saveUploadSet=")!=NULL)
  992. {
  993. static char dattim_str[3];
  994. rt_kprintf("上传间隔设置!\n");
  995. var = strstr(rx_buffer,"=");
  996. var ++;
  997. strncpy(dattim_str,var,2);
  998. if(atoi(dattim_str)>=1&&atoi(dattim_str)<=120)
  999. {
  1000. device_status.dattim =atoi(dattim_str); //数据上传间隔
  1001. ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
  1002. MA_save();
  1003. }
  1004. else {
  1005. rt_kprintf("设置失败!!!\n");
  1006. }
  1007. rt_kprintf("数据上传设置:%d\n",device_status.dattim);
  1008. }
  1009. //光控测试
  1010. else if(strstr(rx_buffer,"putTest.switchSun=1")!=NULL)
  1011. {
  1012. rt_kprintf("光控测试!!!");
  1013. ctr_lamp(ON,1);
  1014. device_status.sun_test = 1;
  1015. }
  1016. else if (strstr(rx_buffer,"setshake_sec=")!=NULL)
  1017. {
  1018. static char shakesec_str[4];
  1019. LOG_I("震动时间设置!");
  1020. var = strstr(rx_buffer,"=");
  1021. var ++;
  1022. strncpy(shakesec_str,var,2);
  1023. if(atoi(shakesec_str)>=0&&atoi(shakesec_str)<=10)
  1024. {
  1025. device_status.shake_sec =atoi(shakesec_str); //
  1026. }
  1027. else {
  1028. LOG_E("设置失败!!!");
  1029. }
  1030. LOG_D("震动时间设置:%d",device_status.shake_sec);
  1031. }
  1032. //恢复出厂设置电池
  1033. else if (strstr(rx_buffer,"resetdcDefault")!=NULL)
  1034. {
  1035. ResetParamDefault_DC();
  1036. rt_thread_delay(1000);
  1037. //2022/06/23,add:
  1038. 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);
  1039. json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
  1040. ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
  1041. if(atoi(device_status.net)==0)
  1042. DTU_Write("%s",json_temp);
  1043. rt_free(json_temp);
  1044. }
  1045. //恢复出厂设置-交流
  1046. else if (strstr(rx_buffer,"resetDefault")!=NULL)
  1047. {
  1048. ResetParamDefault();
  1049. rt_thread_delay(1000);
  1050. //2022/06/23,add:
  1051. 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);
  1052. json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
  1053. ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
  1054. if(atoi(device_status.net)==0)
  1055. DTU_Write("%s",json_temp);
  1056. rt_free(json_temp);
  1057. }
  1058. //获取SIM卡信息
  1059. else if(strstr(rx_buffer,"getSim")!=NULL)
  1060. {
  1061. //http://sim.openluat.com/api/wechat/openapidoc
  1062. DTU_Write("getsiminfo");
  1063. }
  1064. else if (strstr(rx_buffer,"DebugEnable")!=NULL) {
  1065. Debug_log_ON();
  1066. }
  1067. else if (strstr(rx_buffer,"DebugDisable")!=NULL) {
  1068. Debug_log_OFF();
  1069. }
  1070. //高空
  1071. else if (strstr(rx_buffer,"SwversionV11")!=NULL)
  1072. {
  1073. device_status.dtype = 3;
  1074. if(device_status.version_type != 11)
  1075. {
  1076. device_status.version_type = 11;
  1077. sprintf(device_status.driver, "%s",VERSION_GK);
  1078. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1079. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
  1080. MA_save();
  1081. }
  1082. else {
  1083. }
  1084. }
  1085. //1.0
  1086. else if (strstr(rx_buffer,"SwversionV1")!=NULL)
  1087. {
  1088. if(device_status.version_type != 1)
  1089. {
  1090. device_status.dtype = 3;
  1091. device_status.version_type = 1;
  1092. sprintf(device_status.driver, "%s",VERSION_ZP);
  1093. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1094. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
  1095. MA_save();
  1096. }
  1097. else {
  1098. }
  1099. }
  1100. //中端款
  1101. else if (strstr(rx_buffer,"SwversionV43")!=NULL) {
  1102. device_status.dtype = 3;
  1103. if(device_status.version_type != 43)
  1104. {
  1105. device_status.dtype = 3;
  1106. device_status.version_type = 43;
  1107. sprintf(device_status.driver, "%s",VERSION_HK);
  1108. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1109. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
  1110. MA_save();
  1111. }
  1112. else {
  1113. }
  1114. }
  1115. //低端款
  1116. else if (strstr(rx_buffer,"SwversionV42")!=NULL) {
  1117. device_status.dtype = 3;
  1118. if(device_status.version_type != 42)
  1119. {
  1120. device_status.dtype = 3;
  1121. device_status.version_type = 42;
  1122. sprintf(device_status.driver, "%s",VERSION_HK);
  1123. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1124. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
  1125. MA_save();
  1126. }
  1127. else {
  1128. }
  1129. }
  1130. //4.0
  1131. else if (strstr(rx_buffer,"SwversionV41")!=NULL) {
  1132. device_status.dtype = 3;
  1133. if(device_status.version_type != 41)
  1134. {
  1135. device_status.dtype = 3;
  1136. device_status.version_type = 41;
  1137. sprintf(device_status.driver, "%s",VERSION_HK);
  1138. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1139. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
  1140. MA_save();
  1141. }
  1142. else {
  1143. }
  1144. }
  1145. //水稻
  1146. else if (strstr(rx_buffer,"SwversionV4")!=NULL) {
  1147. device_status.dtype = 3;
  1148. if(device_status.version_type != 4)
  1149. {
  1150. device_status.version_type = 4;
  1151. sprintf(device_status.driver, "%s",VERSION_HK_2000W);
  1152. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1153. ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
  1154. MA_save();
  1155. }
  1156. else {
  1157. }
  1158. }
  1159. else if (strstr(rx_buffer,"putTest.switchFAN_PU=1")!=NULL) {
  1160. ctr_Fan_PUT(ON);
  1161. }
  1162. else if (strstr(rx_buffer,"putTest.switchFAN_PU=0")!=NULL) {
  1163. ctr_Fan_PUT(OFF);
  1164. }
  1165. else if (strstr(rx_buffer,"putTest.switchFAN_IN=1")!=NULL) {
  1166. ctr_Fan_IN(ON);
  1167. }
  1168. else if (strstr(rx_buffer,"putTest.switchFAN_IN=0")!=NULL) {
  1169. ctr_Fan_IN(OFF);
  1170. }
  1171. else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
  1172. {
  1173. HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
  1174. HMI_WRITE("sysTest.heat_txt.txt=\"%s\"",device_status.heat_power);
  1175. // HMI_WRITE("sysTest.switchHeat.val=%d",device_status.heat_status);
  1176. }
  1177. //立即上传
  1178. else if(strstr(rx_buffer,"uploaddata")!=RT_NULL)
  1179. {
  1180. UpLoad_Data();
  1181. }
  1182. else if (strstr(rx_buffer,"checkupdate")!=NULL)
  1183. {
  1184. time_t now = time(RT_NULL);
  1185. static struct tm tm;
  1186. gmtime_r(&now, &tm);
  1187. 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);
  1188. HMI_WRITE("hardcheck.p0.pic=%d",70);
  1189. //RTC时间判断,如果当前年份小于2020,提示需要设置时间
  1190. if(tm.tm_year+1900<2020)
  1191. {
  1192. 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);
  1193. 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);
  1194. }
  1195. }
  1196. //进入bootloader模式
  1197. else if (strstr(rx_buffer,"bootloader")!=NULL) {
  1198. device_status.stop_in_bootloader = 1;
  1199. ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
  1200. rt_hw_cpu_reset();
  1201. }
  1202. //软件重启
  1203. else if (strstr(rx_buffer,"reboot")!=NULL) {
  1204. rt_hw_cpu_reset();
  1205. }
  1206. else if (strstr(rx_buffer,"dtu_reboot")!=NULL) {
  1207. DTU_Write("{\"cmd\": \"dtu_reboot\"}");
  1208. }
  1209. else if (strstr(rx_buffer,"saveLog_usb")!=NULL) {
  1210. DTU_Write("{\"cmd\": \"saveLog_usb\"}");
  1211. }
  1212. //屏幕上触发远程升级
  1213. else if (strstr(rx_buffer,"hmi_update")!=NULL) {
  1214. DTU_Write("hmi_update");
  1215. device_status.update_flag = 1;
  1216. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  1217. rt_thread_delay(2000);
  1218. rt_hw_cpu_reset();
  1219. }else if (strstr(rx_buffer,"SaveRecordParam")!=NULL){
  1220. //"SaveRecordParam:10000-200"
  1221. int param1, param2;
  1222. // 从冒号后开始扫描
  1223. if (sscanf(rx_buffer + strlen("SaveRecordParam:"), "%d-%d", &param1, &param2) == 2) {
  1224. printf("Param1: %d\n", param1);
  1225. printf("Param2: %d\n", param2);
  1226. char temp_val_mqtt[10],temp_val_pic[10];
  1227. itoa(param1, temp_val_pic, 10);
  1228. itoa(param2, temp_val_mqtt, 10);
  1229. char *write_record_param = makeJson_record_write(temp_val_mqtt,temp_val_pic);
  1230. DTU_Write(write_record_param);
  1231. free(write_record_param);
  1232. } else {
  1233. LOG_E("Parse failed.\n");
  1234. }
  1235. }
  1236. else if (strstr(rx_buffer,"ReadRecordParam")!=NULL){
  1237. LOG_I("读离线存储参数");
  1238. char* read_record =makeJson_record_read("data");
  1239. DTU_Write(read_record);
  1240. free(read_record);
  1241. }
  1242. else if (strstr(rx_buffer,"checkcamera")!=NULL){
  1243. DTU_Write("{\"ctr_cam\":\"checkcamera\"}");
  1244. //校准屏幕的RTC
  1245. HMI_WRITE("rtc0=%d",tm.tm_year+1900);
  1246. HMI_WRITE("rtc1=%d",tm.tm_mon+1);
  1247. HMI_WRITE("rtc2=%d",tm.tm_mday);
  1248. HMI_WRITE("rtc3=%d",tm.tm_hour);
  1249. HMI_WRITE("rtc4=%d",tm.tm_min);
  1250. HMI_WRITE("rtc5=%d",tm.tm_sec);
  1251. //开启超时定时器
  1252. Start_timer_Uart2();
  1253. }else if (strstr(rx_buffer,"ReadCamParam")!=NULL){
  1254. DTU_Write("{\"ctr_cam\":\"ReadParam\"}");
  1255. //开启超时定时器
  1256. Start_timer_Uart2();
  1257. }//SaveCamParam:2070.00000-0.7-144-30-0-0-5472*5472
  1258. else if (strstr(rx_buffer,"SaveCamParam")!=NULL){
  1259. const char *prefix ="SaveCamParam:";
  1260. size_t prefix_len = strlen(prefix);
  1261. const char *start_pos = strstr(rx_buffer, prefix);
  1262. if(start_pos!=NULL)
  1263. {
  1264. // 移动到前缀之后的位置
  1265. start_pos += prefix_len;
  1266. DTU_Write("%s",makeJson_Cam("SaveParam",start_pos));
  1267. }
  1268. //开启超时定时器
  1269. Start_timer_Uart2();
  1270. }else if (strstr(rx_buffer,"GrabOn")!=NULL){
  1271. DTU_Write("{\"ctr_cam\":\"GrabOn\"}");
  1272. //开启超时定时器
  1273. Start_timer_Uart2();
  1274. }else if (strstr(rx_buffer,"GrabOff")!=NULL){
  1275. DTU_Write("{\"ctr_cam\":\"GrabOff\"}");
  1276. //开启超时定时器
  1277. Start_timer_Uart2();
  1278. }
  1279. else if(strstr(rx_buffer,"SelfCheck")!=NULL)
  1280. {
  1281. //校准屏幕的RTC
  1282. HMI_WRITE("rtc0=%d",tm.tm_year+1900);
  1283. HMI_WRITE("rtc1=%d",tm.tm_mon+1);
  1284. HMI_WRITE("rtc2=%d",tm.tm_mday);
  1285. HMI_WRITE("rtc3=%d",tm.tm_hour);
  1286. HMI_WRITE("rtc4=%d",tm.tm_min);
  1287. HMI_WRITE("rtc5=%d",tm.tm_sec);
  1288. if(device_status.selfcheck_ws==2||device_status.selfcheck_ws==3)
  1289. {
  1290. LOG_I("自检进行中!");
  1291. }else {
  1292. device_status.selfcheck_ws = 2;
  1293. LOG_W("开始自检:%d",device_status.selfcheck_ws);
  1294. }
  1295. }else if(strstr(rx_buffer,"haichong")!=NULL)
  1296. {
  1297. _485_play(sound122, 4);
  1298. HMI_WRITE("sysTest.result.txt=\"害虫测试!\"");
  1299. // ctr_Motor_Driver_Power(ON);
  1300. // ctr_xmove(400,200);//旋转清虫
  1301. //使用硬件定时器控制
  1302. device_status.autotakepic = 10;
  1303. }else if(strstr(rx_buffer,"yichong")!=NULL)
  1304. {
  1305. _485_play(sound122, 4);
  1306. HMI_WRITE("sysTest.result.txt=\"益虫测试!\"");
  1307. // ctr_Motor_Driver_Power(ON);
  1308. // ctr_xmove(400,200);//旋转清虫
  1309. device_status.autotakepic = 11;
  1310. }
  1311. }
  1312. //入口函数-电机控制及
  1313. static void Ctr_Mortor_entry(void* parameter)
  1314. {
  1315. rt_uint16_t num_up_open = 200; //20s 上仓门打开时间
  1316. rt_uint16_t num_up_close = 200; // 上仓门关闭时间
  1317. rt_uint16_t num_down_open = 200; // 下仓门打开时间
  1318. rt_uint16_t num_down_close = 200; // 下仓门关闭时间
  1319. rt_int16_t photo_led_sec = 900; //55S
  1320. rt_uint8_t num_tg_open = 200; //20S
  1321. rt_uint8_t num_tg_init = 200;
  1322. static rt_uint16_t route_off_t = 0;
  1323. device_status.route_off_t = 0;
  1324. rt_pin_mode(CTR_UPC_LIMIT, PIN_MODE_INPUT);
  1325. while(1)
  1326. {
  1327. #if 1
  1328. time_t time_reset12V;
  1329. time(&time_reset12V);
  1330. static struct tm alarm_reset12V;
  1331. alarm_reset12V =*localtime(&time_reset12V);
  1332. if((alarm_reset12V.tm_hour)==8&&(alarm_reset12V.tm_min==19)&&(alarm_reset12V.tm_sec==50))
  1333. {
  1334. ctr_RTU_DTU(OFF);
  1335. rt_thread_delay(1000*10);
  1336. ctr_RTU_DTU(ON);
  1337. }
  1338. #endif
  1339. if(device_status.ctr_up_motor==1)
  1340. {
  1341. ctr_cangmen_up(OPEN);
  1342. num_up_open--;
  1343. if (num_up_open == 0)
  1344. {
  1345. ctr_cangmen_up(OFF);
  1346. num_up_open = 200;
  1347. }
  1348. num_up_close = 200;
  1349. }
  1350. else if(device_status.ctr_up_motor==2)
  1351. {
  1352. ctr_cangmen_up(CLOSE);
  1353. num_up_close --;
  1354. if (num_up_close == 0)
  1355. {
  1356. ctr_cangmen_up(OFF);
  1357. num_up_close= 200;
  1358. }
  1359. num_up_open = 200;
  1360. }
  1361. if (device_status.ctr_down_motor == 1)
  1362. {
  1363. ctr_cangmen_down(OPEN);
  1364. num_down_open--;
  1365. if (num_down_open == 0) //2025-07-07,增加限位检测
  1366. {
  1367. ctr_cangmen_down(OFF);
  1368. num_down_open = 200;
  1369. }
  1370. num_down_close = 200;
  1371. }
  1372. else if (device_status.ctr_down_motor == 2)
  1373. {
  1374. ctr_cangmen_down(CLOSE);
  1375. num_down_close--;
  1376. if (num_down_close == 0)
  1377. {
  1378. ctr_cangmen_down(OFF);
  1379. num_down_close = 200;
  1380. }
  1381. num_down_open = 200;
  1382. }
  1383. if(device_status.sun_test==1)
  1384. {
  1385. SunTest();
  1386. }
  1387. //拍照
  1388. if(device_status.photo_ws==1)
  1389. {
  1390. struct timeval tv;
  1391. gettimeofday(&tv, NULL);
  1392. device_status.photo_stamp = tv.tv_sec-8*3600;
  1393. if(photo_led_sec==900)
  1394. ctr_led(ON);
  1395. //打开补光灯
  1396. if(photo_led_sec==800)
  1397. {
  1398. LOG_I("测试拍照!");
  1399. #if 1
  1400. char *takephotojson = makeJson_takephoto();
  1401. DTU_Write("%s",takephotojson);
  1402. rt_free(takephotojson);
  1403. #endif
  1404. rt_thread_delay(5000); //延时
  1405. }
  1406. //15S后执行拍照
  1407. else if (photo_led_sec==750)
  1408. {
  1409. //DTU_Write("takephoto.mp3");
  1410. //延时
  1411. rt_thread_delay(1000);
  1412. LOG_I("测试拍照!");
  1413. Hk_Take_io();
  1414. }
  1415. photo_led_sec--;
  1416. if(photo_led_sec==300) //
  1417. {
  1418. ctr_led(OFF);
  1419. device_status.photo_ws = 0;
  1420. if(device_status.work_status==1)
  1421. {
  1422. device_status.clear_status = 1;
  1423. }
  1424. HMI_WRITE("sysTest.switchPhoto.val=0");
  1425. HMI_WRITE("sysTest.switchFill.val=0");
  1426. }
  1427. }else{
  1428. photo_led_sec = 900;
  1429. }
  1430. if(device_status.collt_box_sta==111){
  1431. ctr_Fan_IN(ON); //推杆电机收缩(供电打开,复位)
  1432. num_tg_init--;
  1433. if(num_tg_init%10==0)
  1434. HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
  1435. if(num_tg_init==0){
  1436. HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
  1437. ctr_Fan_PUT(ON);
  1438. num_tg_init = 200;
  1439. device_status.collt_box_sta=112;
  1440. }
  1441. }else if(device_status.collt_box_sta==112){
  1442. num_tg_open--;
  1443. if(num_tg_open%10==0)
  1444. HMI_WRITE("sysTest.result.txt=\"开始执行排虫:%d\"",num_tg_open/10);
  1445. if(num_tg_open==0){
  1446. HMI_WRITE("sysTest.result.txt=\"排虫复位中\"");
  1447. ctr_Fan_PUT(OFF);
  1448. num_tg_open = 200;
  1449. device_status.collt_box_sta=113;
  1450. }
  1451. }else if(device_status.collt_box_sta==113){
  1452. num_tg_init--;
  1453. if(num_tg_init%10==0)
  1454. HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
  1455. if(num_tg_init==0){
  1456. HMI_WRITE("sysTest.result.txt=\"排虫机执行已完成!\"");
  1457. ctr_Fan_PUT(OFF);
  1458. ctr_Fan_IN(OFF);
  1459. num_tg_init = 200;
  1460. device_status.collt_box_sta=0;
  1461. }
  1462. }
  1463. if(device_status.run_sta==111){ //排虫-收缩
  1464. ctr_Fan_IN(ON); //推杆电机收缩(供电打开,复位)
  1465. ctr_Fan_PUT(OFF);
  1466. num_tg_init--;
  1467. if(num_tg_init%10==0)
  1468. HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
  1469. if(num_tg_init==0){
  1470. HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
  1471. ctr_Fan_IN(OFF);
  1472. num_tg_init = 200;
  1473. device_status.run_sta=0;
  1474. }
  1475. }else if(device_status.run_sta==112){ //收虫-推出
  1476. ctr_Fan_IN(ON);
  1477. ctr_Fan_PUT(ON);
  1478. num_tg_open--;
  1479. if(num_tg_open%10==0)
  1480. HMI_WRITE("sysTest.result.txt=\"开始执行收虫:%d\"",num_tg_open/10);
  1481. if(num_tg_open==0){
  1482. HMI_WRITE("sysTest.result.txt=\"收虫中...\"");
  1483. ctr_Fan_PUT(OFF);
  1484. ctr_Fan_IN(OFF);
  1485. num_tg_open = 200;
  1486. device_status.run_sta=0;
  1487. }
  1488. }
  1489. if(device_status.selfcheck_ws==2)
  1490. {
  1491. selfcheck(1);
  1492. }else if (device_status.selfcheck_ws==3) {
  1493. selfcheck(0);
  1494. }
  1495. if(device_status.route_off_t!=0)
  1496. {
  1497. ctr_router(OFF);
  1498. route_off_t = device_status.route_off_t * 60 * 10;
  1499. device_status.route_off_t = 0;
  1500. }
  1501. if(route_off_t>0)
  1502. {
  1503. route_off_t--;
  1504. if(route_off_t==1)
  1505. {
  1506. ctr_router(ON);
  1507. route_off_t = 0;
  1508. }
  1509. }
  1510. rt_thread_delay(100);
  1511. }
  1512. }
  1513. /*屏幕写数据*/
  1514. int Hmi_Fresh(void)
  1515. {
  1516. //初始化串口4
  1517. //HMI_uart4_init();
  1518. rt_err_t ret = RT_EOK;
  1519. /* 初始化消息队列 */
  1520. rt_mq_init(&rx_mq, "rx_mq",
  1521. msg_pool, /* 存放消息的缓冲区 */
  1522. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  1523. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  1524. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  1525. /* 设置接收回调函数 */
  1526. rt_device_set_rx_indicate(serial, uart_input);
  1527. /* 创建线程*/
  1528. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  1529. Hmi_thread_entry,
  1530. RT_NULL,
  1531. HMI_THREAD_STACK_SIZE,
  1532. HMI_THREAD_PRIORITY,
  1533. HMI_THREAD_TIMESLICE);
  1534. /*部分控制的线程*/
  1535. ctr_motor = rt_thread_create("Ctr motor",
  1536. Ctr_Mortor_entry,
  1537. RT_NULL,
  1538. CONTROL_MOTOR_STACK_SIZE,
  1539. CONTROL_MOTOR_PRIORITY,
  1540. CONTROL_MOTOR_TIMESLICE);
  1541. if(ctr_motor != RT_NULL)
  1542. {
  1543. rt_thread_startup(ctr_motor);
  1544. }
  1545. /* 如果获得线程控制块,启动这个线程 */
  1546. if (hmi1 != RT_NULL)
  1547. {
  1548. rt_thread_startup(hmi1);
  1549. }
  1550. else
  1551. {
  1552. ret = RT_ERROR;
  1553. }
  1554. //定时器,串口通信超时监测20S
  1555. timer_uart2 = rt_timer_create("t_uart2",t_uart2_callback,RT_NULL, 20000, RT_TIMER_FLAG_ONE_SHOT);
  1556. if(timer_uart2==RT_NULL)
  1557. {
  1558. LOG_E("rt_timer_create timer_uart2 failed!");
  1559. }
  1560. return ret;
  1561. }
  1562. void Check_ParamConfig(void)
  1563. {
  1564. time_t now = time(RT_NULL);
  1565. static struct tm tm;
  1566. gmtime_r(&now, &tm);
  1567. if(easyflash_init()==EF_NO_ERR) //初始化成功
  1568. {
  1569. ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
  1570. ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
  1571. ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
  1572. device_status.rebootcnt++;
  1573. ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
  1574. LOG_I("REBOOT_TIME:%d-%d-%d",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
  1575. }
  1576. else {
  1577. LOG_E("easyflash init ERRPR!!!");
  1578. }
  1579. //保存默认配置
  1580. if(device_status.iSave!=FLASH_FLAG)
  1581. {
  1582. device_status.iSave=FLASH_FLAG;
  1583. /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
  1584. device_status.dtype = 3;
  1585. device_status.version_type = 4; //4.0
  1586. device_status.Power_Type = 0; //0-交流供电;1-直流供电
  1587. device_status.clt_time = 10; //收集时间
  1588. device_status.heattime = 10; //加热时间
  1589. device_status.heatvalue=100;//加热温度
  1590. device_status.thsp = 300; //默认熄屏时间5分钟
  1591. device_status.sunBar = 9; //光控定时时长
  1592. device_status.startBar = 20; //定时开始时间
  1593. device_status.stopBar = 0; //定时结束时间
  1594. device_status.tph = 70; //高温保护阈值
  1595. device_status.tpl = 5; //低温保护阈值
  1596. device_status.shake_ws = 1; //震动开关,默认开
  1597. device_status.shake_sec = 1; //震动时间,s
  1598. device_status.vol = 7; //音量
  1599. device_status.timeSwitch = 0; //工作模式:光控
  1600. device_status.passWord = 8888; //屏幕密码
  1601. device_status.dattim = 10; //数据上传间隔
  1602. device_status.ds = 1; //设备状态
  1603. device_status.update_flag = 0;
  1604. /*孢子仪*/
  1605. device_status.collecting_sh1 = 9;
  1606. device_status.collecting_eh1 = 10;
  1607. device_status.collecting_sh2 = 14;
  1608. device_status.collecting_eh2 = 16;
  1609. device_status.cold_sw = 0;
  1610. device_status.heat_sw = 0;
  1611. device_status.cul_time = 1;
  1612. device_status.run_sta = 0;
  1613. device_status.handle_bugger = 0; //默认排虫
  1614. sprintf(device_status.driver, "%s",VERSION_HK);
  1615. sprintf(device_status.deviceId,"0");
  1616. rt_sprintf(device_status.tempture, "-15");
  1617. rt_sprintf(device_status.humidity, "31");
  1618. rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
  1619. ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
  1620. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1621. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  1622. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1623. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1624. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1625. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1626. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1627. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1628. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1629. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1630. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1631. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1632. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1633. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1634. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  1635. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
  1636. ef_set_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture)); //温度
  1637. ef_set_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity)); //湿度
  1638. ef_set_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1)); //上传平台
  1639. ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
  1640. ef_set_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw)); //制冷开关
  1641. ef_set_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw)); //加热开关
  1642. ef_set_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1)); //风机开关
  1643. ef_set_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1)); //采集时间
  1644. ef_set_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2)); //采集时间
  1645. ef_set_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2)); //采集时间
  1646. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta)); //
  1647. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1648. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  1649. LOG_I("SOFTWARE VERSION:%s",device_status.driver);
  1650. LOG_I("Default paramconf is:");
  1651. LOG_I("stime:%d",device_status.iSave);
  1652. LOG_I("stime:%d",device_status.clt_time);
  1653. LOG_I("startBar:%d",device_status.startBar);
  1654. LOG_I("stopBar:%d",device_status.stopBar);
  1655. LOG_I("timeSwitch:%d",device_status.timeSwitch);
  1656. LOG_I("sunBar:%d",device_status.sunBar);
  1657. LOG_I("jtime:%d",device_status.heattime);
  1658. LOG_I("jheat:%d",device_status.heatvalue);
  1659. LOG_I("thsp:%d", device_status.thsp);
  1660. LOG_I("passwd:%d",device_status.passWord);
  1661. }//从easyflash读取参数配置
  1662. else if (device_status.iSave==FLASH_FLAG) {
  1663. ef_get_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype),NULL); //设备类型
  1664. ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
  1665. ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
  1666. ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
  1667. ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
  1668. ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
  1669. ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
  1670. ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
  1671. ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
  1672. ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
  1673. ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
  1674. ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
  1675. ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
  1676. ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
  1677. ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
  1678. ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
  1679. ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
  1680. ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
  1681. ef_get_env_blob("lat",&device_status.lat,sizeof(device_status.lat),NULL);
  1682. ef_get_env_blob("lng",&device_status.lng,sizeof(device_status.lng),NULL);
  1683. ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL); //开关机状态
  1684. ef_get_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture),NULL); //环境温度
  1685. ef_get_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity),NULL); //环境湿度
  1686. ef_get_env_blob("json_w_clock",&device_status.json_w_clock,sizeof(device_status.json_w_clock),NULL); //时间
  1687. ef_get_env_blob("json_w_reset",&device_status.json_w_reset,sizeof(device_status.json_w_reset),NULL); //重置
  1688. ef_get_env_blob("json_w_platform",&device_status.json_w_platform,sizeof(device_status.json_w_platform),NULL);//平台
  1689. ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
  1690. ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
  1691. ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL); //平台地址
  1692. /*孢子仪*/
  1693. ef_get_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time),NULL); //培养时间
  1694. ef_get_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw),NULL); //制冷开关
  1695. ef_get_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw),NULL); //加热开关
  1696. ef_get_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1),NULL); //采集开始1
  1697. ef_get_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1),NULL); //采集结束1
  1698. ef_get_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2),NULL); //采集开始2
  1699. ef_get_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2),NULL); //采集结束2
  1700. ef_get_env_blob("run_sta",&device_status.run_sta,sizeof(device_status.run_sta),NULL); //运行状态
  1701. ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL); //供电类型
  1702. ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL); //设备编码
  1703. ef_get_env_blob("handle_bugger",&device_status.handle_bugger,sizeof(device_status.handle_bugger),NULL); //排虫
  1704. device_status.light_over_tim = device_status.sunBar * 3600; //光控计数
  1705. device_status.work_done = 0;
  1706. //工作完成标志位
  1707. if(device_status.dattim==0)
  1708. {
  1709. device_status.dattim = 10;
  1710. }
  1711. if(device_status.clt_time==0) device_status.clt_time = 10;
  1712. if(device_status.heattime==0) device_status.heattime = 10;
  1713. if(device_status.tph==0) device_status.tph = 70;
  1714. if(device_status.heatvalue==0) device_status.heatvalue = 100;
  1715. /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
  1716. if(device_status.dtype!=7)
  1717. {
  1718. device_status.dtype = 3;
  1719. }
  1720. else {
  1721. device_status.version_type = 7;
  1722. }
  1723. if(device_status.version_type==0)
  1724. {
  1725. app_partion_backup(); //固件备份至df_area
  1726. device_status.version_type = 41;
  1727. rt_sprintf(device_status.driver, "%s",VERSION_HK);
  1728. ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
  1729. }
  1730. else if(device_status.version_type==1)
  1731. {
  1732. rt_sprintf(device_status.driver, "%s",VERSION_ZP);
  1733. }
  1734. else if (device_status.version_type==11)
  1735. {
  1736. rt_sprintf(device_status.driver, "%s",VERSION_GK);
  1737. }
  1738. else if (device_status.version_type==4)
  1739. {
  1740. rt_sprintf(device_status.driver, "%s",VERSION_HK_2000W);
  1741. }
  1742. else if (device_status.version_type==41) {
  1743. rt_sprintf(device_status.driver, "%s",VERSION_HK);
  1744. }
  1745. /*定制三色光源*/
  1746. #if LAMP_EN == 1
  1747. if(device_status.sunBar%3!=0)
  1748. {
  1749. device_status.sunBar = 3;
  1750. }
  1751. // device_status.timeSwitch = 1;
  1752. // device_status.startBar = 20;
  1753. // device_status.stopBar = 23;
  1754. #endif
  1755. LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
  1756. LOG_I("read flash paramconfis:%d-%s-%s",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
  1757. LOG_I("开机次数:%d",device_status.rebootcnt);
  1758. LOG_I("收集时间:%d",device_status.clt_time);
  1759. LOG_I("定时开始时间:%d",device_status.startBar);
  1760. LOG_I("定时结束时间:%d",device_status.stopBar);
  1761. LOG_I("timeSwitch:%d",device_status.timeSwitch);
  1762. LOG_I("光控定时时长:%d",device_status.sunBar);
  1763. LOG_I("加热开关:%d",device_status.heat_sw);
  1764. LOG_I("加热时间:%d",device_status.heattime);
  1765. LOG_I("加热温度:%d",device_status.heatvalue);
  1766. LOG_I("震动开关:%d",device_status.shake_ws);
  1767. LOG_I("震动时间:%d",device_status.shake_sec);
  1768. LOG_I("高温保护:%d",device_status.tph);
  1769. LOG_I("低温保护:%d",device_status.tpl);
  1770. LOG_I("thsp:%d", device_status.thsp);
  1771. LOG_I("密码:%d",device_status.passWord);
  1772. LOG_I("数据上传间隔:%d",device_status.dattim);
  1773. LOG_I("温湿度数据:%d-%d",atoi(device_status.tempture),atoi(device_status.humidity));
  1774. LOG_I("上传平台:%s",device_status.mqttcfg1);
  1775. LOG_I("孢子仪运行状态:%d",device_status.run_sta);
  1776. LOG_I("孢子仪采集时间:[%d-%d,%d-%d]",device_status.collecting_sh1,device_status.collecting_eh1,device_status.collecting_sh2,device_status.collecting_eh2);
  1777. LOG_I("PowerType:%d",device_status.Power_Type);
  1778. LOG_I("deviceId:%s",device_status.deviceId);
  1779. LOG_I("handle_bugger:%d",device_status.handle_bugger);
  1780. }
  1781. //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
  1782. if(device_status.update_flag==1)
  1783. {
  1784. device_status.update_flag = 0;
  1785. ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
  1786. ymodem_ota(1,0);
  1787. }
  1788. else {
  1789. device_status.update_flag = 0;
  1790. //初始化联网状态
  1791. rt_sprintf(device_status.net,"1");
  1792. rt_sprintf(device_status.csq,"0");
  1793. rt_sprintf(device_status.sim,"1");
  1794. #ifdef RT_USING_ALARM
  1795. alarm_app_router();
  1796. #endif
  1797. #if MATCH_DEVICE== 0
  1798. ctr_router(ON);
  1799. #else
  1800. ctr_router(OFF);
  1801. #endif
  1802. Hmi_Fresh();
  1803. Control_clear();
  1804. Control_Check(); //自检
  1805. dtu_data_play();
  1806. sht30_collect();
  1807. #if SENSOR_EN==1
  1808. mb_master_samlpe();
  1809. #endif
  1810. uint16_t connect_num=0;
  1811. //等待联网,
  1812. while(atoi(device_status.net)==1)
  1813. {
  1814. if(Read_Real_Voltage()/100>5&&device_status.power_status==0)
  1815. ctr_RTU_DTU(ON);
  1816. char *readinfo = makeJson_ReadInfo();
  1817. DTU_Write("%s",readinfo);
  1818. rt_free(readinfo);
  1819. rt_thread_delay(1000);
  1820. connect_num++;
  1821. LOG_I("联网中......%d",connect_num);
  1822. //超时时间为3分钟
  1823. #if MATCH_DEVICE == 1
  1824. if(connect_num==60) //180
  1825. {
  1826. device_status.timeSwitch = 1;
  1827. 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);
  1828. #if 0
  1829. set_date(2020, 1, 1);
  1830. set_time(0, 0, 0);
  1831. #endif
  1832. break;
  1833. }
  1834. #else
  1835. if(connect_num==180) //180
  1836. {
  1837. device_status.timeSwitch = 0;
  1838. 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);
  1839. #if 0
  1840. set_date(2020, 1, 1);
  1841. set_time(0, 0, 0);
  1842. #endif
  1843. break;
  1844. }
  1845. #endif
  1846. }
  1847. connect_num = 0;
  1848. while(atoi(device_status.net)==0)
  1849. {
  1850. char *readinfo = makeJson_ReadInfo();
  1851. DTU_Write("%s",readinfo);
  1852. rt_free(readinfo);
  1853. rt_thread_delay(2000);
  1854. connect_num++;
  1855. if(connect_num>5) break;
  1856. }
  1857. DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
  1858. rt_thread_delay(1000);
  1859. dtu_send_data_start();
  1860. Workstatus_check();
  1861. Work_Loop_Task();
  1862. }
  1863. }
  1864. void ResetParamDefault(void)
  1865. {
  1866. #if MATCH_DEVICE == 1
  1867. rt_sprintf(device_status.tempture,"%d",30);
  1868. #else
  1869. rt_sprintf(device_status.tempture,"%d",-15);
  1870. #endif
  1871. device_status.ds = 1; //设备状态开机
  1872. device_status.thsp = 300;
  1873. device_status.passWord = 8888;
  1874. device_status.dattim = 10;
  1875. device_status.collecting_sh1 = 9;
  1876. device_status.collecting_eh1 = 10;
  1877. device_status.collecting_sh2 = 14;
  1878. device_status.collecting_eh2 = 16;
  1879. device_status.Power_Type = 0;
  1880. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1881. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  1882. if(device_status.dtype==3)
  1883. {
  1884. device_status.clt_time = 10; //收集时间
  1885. #if LAMP_EN == 0
  1886. device_status.startBar = 20; //定时开始时间
  1887. device_status.stopBar = 5; //定时结束时间
  1888. #endif
  1889. device_status.heattime = 10; //加热时间
  1890. device_status.shake_ws = 1; //针对开关
  1891. device_status.shake_sec = 1; //震动时间1-100ms
  1892. #if LAMP_EN == 1
  1893. device_status.sunBar = 3; //光控定时时长
  1894. #else
  1895. device_status.sunBar = 8;
  1896. #endif
  1897. device_status.tph = 70; //高温保护阈值
  1898. device_status.tpl = -5; //低温保护阈值
  1899. device_status.timeSwitch = 0; //定时模式:光控
  1900. device_status.heatvalue=100; //加热温度
  1901. device_status.heat_sw = 1;
  1902. ef_set_env_blob("heat_sw", &device_status.heat_sw, sizeof(device_status.heat_sw));
  1903. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  1904. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1905. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1906. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1907. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1908. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1909. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1910. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1911. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1912. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1913. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1914. device_status.handle_bugger = 0;
  1915. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  1916. }
  1917. else if(device_status.dtype==7)
  1918. {
  1919. device_status.run_sta = 0;
  1920. device_status.heatvalue = 25; //培养温度
  1921. ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
  1922. ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1)); //采集时间
  1923. ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1)); //采集时间
  1924. ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2)); //采集时间
  1925. ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2)); //采集时间
  1926. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1927. }
  1928. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1929. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1930. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1931. HMI_WRITE("play %d,%d,%d",1,5,0);
  1932. DTU_Write("reset.mp3");
  1933. rt_thread_delay(1000);
  1934. }
  1935. void ResetParamDefault_DC(void)
  1936. {
  1937. //将温度数据设置为-15摄氏度,以便上传的数据中包含温控数据
  1938. rt_sprintf(device_status.tempture,"%d",-15);
  1939. device_status.clt_time = 10; //收集时间
  1940. device_status.dattim = 10; //数据上传间隔
  1941. #if LAMP_EN == 0
  1942. device_status.startBar = 20; //定时开始时间
  1943. device_status.stopBar = 0; //定时结束时间
  1944. #endif
  1945. device_status.heattime = 10; //加热时间
  1946. device_status.shake_ws = 1; //针对开关
  1947. device_status.shake_sec = 1; //震动时间1-100ms
  1948. #if LAMP_EN == 1
  1949. device_status.sunBar = 3; //光控定时时长
  1950. #else
  1951. device_status.sunBar = 4;
  1952. #endif
  1953. device_status.tph = 70; //高温保护阈值
  1954. device_status.tpl = -5; //低温保护阈值
  1955. device_status.timeSwitch = 0; //定时模式
  1956. device_status.heatvalue=100;
  1957. device_status.ds = 1; //设备状态开机
  1958. device_status.thsp = 300;
  1959. device_status.passWord = 8888;
  1960. device_status.timeSwitch = 0;
  1961. device_status.Power_Type = 1;
  1962. device_status.handle_bugger = 0;
  1963. device_status.heat_sw = 0;
  1964. ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
  1965. ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
  1966. ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
  1967. ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
  1968. ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
  1969. ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
  1970. ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
  1971. ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
  1972. ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
  1973. ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
  1974. ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
  1975. ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
  1976. ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
  1977. ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
  1978. ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
  1979. ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
  1980. ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
  1981. ef_set_env_blob("heat_sw", &device_status.heat_sw,sizeof(device_status.heat_sw));
  1982. DTU_Write("reset.mp3");
  1983. rt_thread_delay(1000);
  1984. }
  1985. //固件备份
  1986. void app_partion_backup(void)
  1987. {
  1988. rt_kprintf("固件恢复!!!\n");
  1989. const char *dst_part_name = "df_area";
  1990. const char *src_part_name = "app";
  1991. const struct fal_partition *dst_part;
  1992. const struct fal_partition *src_part;
  1993. dst_part = fal_partition_find(dst_part_name);
  1994. src_part = fal_partition_find(src_part_name);
  1995. if (dst_part == RT_NULL || src_part == RT_NULL)
  1996. {
  1997. if (dst_part == RT_NULL)
  1998. rt_kprintf("%s partition is not exist!\n", dst_part_name);
  1999. if (src_part == RT_NULL)
  2000. rt_kprintf("%s partition is not exist!\n", src_part_name);
  2001. }
  2002. else
  2003. {
  2004. rt_kprintf("Clone %s partition to %s partition:\n", src_part_name, dst_part_name);
  2005. if (fal_partition_erase(dst_part, 0, dst_part->len) >= 0)
  2006. {
  2007. int clone_pos = 0;
  2008. int clone_len = 0, clone_tol_len;
  2009. rt_uint8_t *buf = rt_malloc(4096);
  2010. if (dst_part->len < src_part->len)
  2011. clone_tol_len = dst_part->len;
  2012. else
  2013. clone_tol_len = src_part->len;
  2014. while ((clone_pos < clone_tol_len) && (buf != RT_NULL))
  2015. {
  2016. clone_len = fal_partition_read(src_part, clone_pos, buf, 4096);
  2017. if (clone_len < 0)
  2018. {
  2019. rt_kprintf("\nread %s partition failed, clone stop!\n", src_part_name);
  2020. break;
  2021. }
  2022. if (fal_partition_write(dst_part, clone_pos, buf, clone_len) < 0)
  2023. {
  2024. rt_kprintf("\nwrite %s partition failed, clone stop!\n", dst_part_name);
  2025. break;
  2026. }
  2027. HMI_WRITE("#");
  2028. rt_kprintf("#");
  2029. clone_pos += clone_len;
  2030. }
  2031. if (clone_pos >= clone_tol_len)
  2032. {
  2033. rt_kprintf("\nClone partition success, total %d bytes!\n", clone_tol_len);
  2034. }
  2035. else
  2036. {
  2037. rt_kprintf("Clone partition failed!");
  2038. }
  2039. if (buf)
  2040. rt_free(buf);
  2041. }
  2042. }
  2043. }
  2044. void Debug_log_ON(void)
  2045. {
  2046. rt_console_set_device("uart4");
  2047. finsh_set_device("uart4");
  2048. }
  2049. void Debug_log_OFF(void)
  2050. {
  2051. rt_console_set_device("uart1");
  2052. finsh_set_device("uart1");
  2053. rt_mq_init(&rx_mq, "rx_mq",
  2054. msg_pool, /* 存放消息的缓冲区 */
  2055. sizeof(struct rx_msg), /* 一条消息的最大长度 */
  2056. sizeof(msg_pool), /* 存放消息的缓冲区大小 */
  2057. RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
  2058. rt_device_set_rx_indicate(serial, uart_input);
  2059. hmi1 = rt_thread_create("Hmi_Fresh_thread",
  2060. Hmi_thread_entry,
  2061. RT_NULL,
  2062. HMI_THREAD_STACK_SIZE,
  2063. HMI_THREAD_PRIORITY,
  2064. HMI_THREAD_TIMESLICE);
  2065. if (hmi1 != RT_NULL)
  2066. {
  2067. rt_thread_startup(hmi1);
  2068. }
  2069. }
  2070. MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
  2071. MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
  2072. //
  2073. INIT_BOARD_EXPORT(HMI_uart4_init);