hmi.c 89 KB

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