hmi.c 90 KB

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