hmi.c 97 KB

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