hmi.c 94 KB

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