| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309 |
- /*
- * Copyright (c) 2006-2020, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-05-26 Administrator the first version
- */
- #include <rtthread.h>
- #include "hmi.h"
- #include <board.h>
- #include <control.h>
- #include <rtdevice.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "stdarg.h"
- #include "string.h"
- #include "sht30_collect.h"
- #include "beep.h"
- #include "easyflash.h"
- #include "sound.h"
- #include "ymodem.h"
- #include <shell.h>
- #include "dtu_uart2.h"
- #include <fal.h>
- #include "selfcheck.h"
- #include <user_mb_app.h>
- #define DBG_ENABLE
- #define DBG_COLOR
- #define DBG_TAG "hmi"
- #define DBG_LEVEL DBG_LOG
- #include <rtdbg.h> //must after of DBG_LVL, DBG_TAG or other options
- #define HMI_THREAD_PRIORITY 5 //线程优先级
- #define HMI_THREAD_STACK_SIZE 2048 //线程栈空间大小
- #define HMI_THREAD_TIMESLICE 10 //时间片
- #define CONTROL_MOTOR_PRIORITY 18
- #define CONTROL_MOTOR_STACK_SIZE 2048
- #define CONTROL_MOTOR_TIMESLICE 5
- static char msg_pool[512];
- static char rx_buffer[HMI_UART_RXBUFFER_SIZE + 1];
- static USHORT sound122[] = {0x736f,0x756e,0x6431,0x3232};
- void list_mem(void);
- int mb_master_samlpe();
- /**/
- Device_Status_typedef device_status;
- extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
- time_t time(time_t *t);
- /* 串口接收消息结构*/
- struct rx_msg
- {
- rt_device_t dev;
- rt_size_t size;
- };
- struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
- ////
- static rt_thread_t hmi1 = RT_NULL;
- static rt_thread_t ctr_motor = RT_NULL;
- rt_device_t serial; /*串口设备句柄*/
- rt_timer_t timer_uart2 = RT_NULL;
- /* 消息队列控制块 */
- static struct rt_messagequeue rx_mq;//接收数据消息队列
- static void HMI_Decode(void);
- static rt_err_t uart_input(rt_device_t dev, rt_size_t size);
- static int HMI_uart4_init(void)
- {
- serial = rt_device_find(UART_NAME);
- /*修改串口配置参数*/
- config.baud_rate = BAUD_RATE_115200; //修改波特率9600
- config.data_bits = DATA_BITS_8; //数据位8
- config.stop_bits = STOP_BITS_1; //停止位1
- #ifdef RT_USING_SERIAL_V2
- config.rx_bufsz = 512;
- config.tx_bufsz = 1024;
- #else
- config.bufsz = 512; //缓冲区128字节
- #endif
- config.parity = PARITY_NONE; //无奇偶校验
- /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
- rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
- // /* step4:打开串口设备。以中断接收及轮询发送模式打开串口设备 */
- //rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
- /* 以 DMA 接收及轮询发送模式打开串口设备 */
- #ifdef RT_USING_SERIAL_V2
- rt_err_t uart_res = rt_device_open(serial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
- #else
- rt_err_t uart_res = rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX); //RT_DEVICE_FLAG_DMA_RX
- #endif
- if(uart_res!=RT_EOK)
- {
- LOG_E("%s打开失败!",UART_NAME);
- }else{
- LOG_I("%s Open Success!",UART_NAME);
- }
- return RT_EOK;
- }
- /*串口屏写数据*/
- void HMI_WRITE(char *fmt, ...)
- {
- va_list ap;
- //末尾需要拼接的3个ff
- static const char hmi_hex[3]={0xff,0xff,0xff};
- static char str[MAX_SIZE];
- //memset(str,'\0',sizeof(str));
- rt_size_t str_length;
- va_start(ap,fmt);
- // 预留3字节空间给 hmi_hex
- str_length = rt_vsnprintf(str, sizeof(str) - 3, fmt, ap);
- va_end(ap);
- if (str_length > MAX_SIZE - 3)
- str_length = MAX_SIZE - 3;
- // 追加三个 0xff
- memcpy(str + str_length, hmi_hex, sizeof(hmi_hex));
- rt_device_write(serial, 0, str, str_length + sizeof(hmi_hex));
- rt_thread_mdelay(5); //2025-0308
- }
- /* 接收数据回调函数 */
- static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
- {
- struct rx_msg msg;
- rt_err_t result;
- msg.dev = dev;
- msg.size = size;
- result = rt_mq_send(&rx_mq, &msg, sizeof(msg));
- if ( result == -RT_EFULL)
- {
- /* 消息队列满 */
- LOG_E("hmi message queue full!\n");
- rt_mq_control(&rx_mq, RT_IPC_CMD_RESET, RT_NULL); // 清空队列
- }
- return result;
- }
- /*入口函数*/
- static void Hmi_thread_entry(void *parameter)
- {
- struct rx_msg msg;
- rt_err_t result;
- rt_uint32_t rx_length;
- if(device_status.dtype==3){
- device_status.collt_box_sta = 0;
- device_status.run_sta = 0;
- }
- device_status.camsta = 1;
- while(1)
- {
- rt_memset(&msg, 0, sizeof(msg));
- /* 从消息队列中读取消息*/
- result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), 50);
- if (result == RT_EOK)
- {
- rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
- rx_buffer[rx_length] = '\0';
- //LOG_I("%s",rx_buffer);
- //\r 对应的hex为0x0d,0x0a,占两个字节,屏幕发送的数据都以\r结尾
- HMI_Decode();
- }
- /*********************************************************************************************************************/
- //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);
- //rt_kprintf("workSta.vbat.txt=%c%d.%02d%c\n",hmi_str,voltage/100,voltage%100,hmi_str);
- }
- }
- /*******************************************************************************************/
- static void t_uart2_callback(void *parameter)
- {
- HMI_WRITE("sysSet.va0.txt=\"指令超时,请重试...\"");
- LOG_E("t_uart2_callback");
- }
- void Start_timer_Uart2(void)
- {
- if(timer_uart2!=RT_NULL)
- {
- rt_timer_start(timer_uart2);
- }
- else
- {
- LOG_E("timer_uart2 start Failed!");
- }
- }
- /***************************** 解析从屏幕收到的数据 begin **********************************/
- static void HMI_Decode(void)
- {
- time_t now = time(RT_NULL);
- static struct tm tm;
- gmtime_r(&now, &tm);
- static char *json_temp;
- static char *var;
- if(device_status.refresh_num==0) device_status.refresh_num = 10;
- if(strstr(rx_buffer,"getFullData") != NULL){
- char *readinfo = makeJson_ReadInfo();
- if(device_status.refresh_num==5)
- {
- device_status.refresh_num = 15;
- DTU_Write("%s",readinfo);
- //list_mem();
- device_status.hmi_fresh = 1;
- rt_thread_delay(100);
- }
- //在解析getinfo中清除超时
- if(device_status.refresh_timeout==30)
- {
- rt_sprintf(device_status.sim,"1");
- rt_sprintf(device_status.net,"1");
- rt_sprintf(device_status.csq,"0");
- device_status.camsta = 1;
- device_status.link_sta=0;
- device_status.refresh_timeout=0;
- }
- rt_free(readinfo);
- device_status.refresh_num--;
- device_status.refresh_timeout++;
- if(device_status.version_type!=6)
- {
- HMI_WRITE("uploadSet.iccid.txt=\"%s\"",device_status.iccid);
- if(strstr(device_status.mqttcfg1,"8.136.98.49")!=NULL)
- {
- HMI_WRITE("uploadSet.plt.val=%d",RESET);
- }
- else if (strstr(device_status.mqttcfg1,"120.27.222.26")!=NULL) {
- HMI_WRITE("uploadSet.plt.val=%d",SET);
- }
- //HMI_WRITE("mqttcfg.mqtt1Message.txt=\"%s\"",device_status.mqttcfg1);
- HMI_WRITE("uploadSet.t0.txt=\"%s\"",device_status.mqttcfg1);
- //更新固件版本号
- HMI_WRITE("debug.t3.txt=\"%s\"",device_status.driver);
- //更新固件编译日期
- HMI_WRITE("debug.t4.txt=\"%s\"",device_status.driver_compile);
- //
- HMI_WRITE("debug.t5.txt=\"%s\"",device_status.driver_bl);
- HMI_WRITE("debug.t7.txt=\"%s\"",device_status.driver_compile);
- //更新dtu/rtu版本
- HMI_WRITE("debug.t9.txt=\"%s\"",device_status.driver_4g);
- //更新时间
- 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);
- 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);
- HMI_WRITE("set.t0.txt=\"%d\"",tm.tm_hour);
- HMI_WRITE("set.t1.txt=\"%d\"",tm.tm_min);
- HMI_WRITE("set.t2.txt=\"%d\"",tm.tm_sec);
- //更新电压
- HMI_WRITE("workSta.vbat.txt=\"%s\"",device_status.voltage);
- //更新电流
- HMI_WRITE("workSta.power.txt=\"%s\"",device_status.power);
- //更新温湿度数据
- HMI_WRITE("workSta.envHum.val=%d",atoi(device_status.humidity));
- HMI_WRITE("workSta.envTem.val=%d",atoi(device_status.tempture));
- //更新电池状态
- HMI_WRITE("workSta.batStatus.val=%d",device_status.bat_status);
- //更新上仓门状态
- HMI_WRITE("workSta.upStatus.val=%d",device_status.up_status);
- //更新下仓门状态
- HMI_WRITE("workSta.downStatus.val=%d",device_status.down_status);
- //更新工作状态
- HMI_WRITE("workSta.workStatus.val=%d",device_status.work_status);
- //更新温控状态
- HMI_WRITE("workSta.tempStatus.val=%d",device_status.temp_status);
- //更新雨控状态
- HMI_WRITE("workSta.rainStatus.val=%d",device_status.rain_status);
- //更新光控状态
- HMI_WRITE("workSta.sunStatus.val=%d",device_status.sun_status);
- //更新有线连接状态
- HMI_WRITE("menu.va_net.val=%d",device_status.link_sta);
- //更新CSQ
- HMI_WRITE("menu.csq_value.txt=\"%s\"",device_status.csq);
- HMI_WRITE("menu.va_csq.val=%d",atoi(device_status.csq));
- HMI_WRITE("workSta.csq_value.txt=\"%s\"",device_status.csq);
- //更新收集时间
- HMI_WRITE("sysSet.stime.val=%d",device_status.clt_time);
- //更新加热时间
- HMI_WRITE("workSta.heatTime.val=%d",device_status.heattime);
- HMI_WRITE("sysSet.jtime.val=%d",device_status.heattime);
- //
- HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
- //更新加热时间和温度
- HMI_WRITE("workSta.heatTem.val=%d",device_status.heattem);
- HMI_WRITE("sysSet.jheat.val=%d",device_status.heatvalue);
- //更新加热状态
- HMI_WRITE("workSta.heatStatus.val=%d",device_status.heat_status);
- //更新密码
- HMI_WRITE("inputPasswd.pwdData.txt=\"8888\"");
- //更新时间设置中的参数
- //更新定时模式
- HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
- //更新光控定时时长
- HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
- //更新时控开始
- HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
- //更新时控结束
- HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
- //SIM卡状态
- HMI_WRITE("workSta.bt0.val=%d",atoi(device_status.sim));
- //ID
- HMI_WRITE("menu.equipid.txt=\"%s\"",device_status.imei);
- HMI_WRITE("menu.deviceId.txt=\"%s\"",device_status.deviceId);
- //HMI_WRITE("workSta.equipid.txt=\"%s\"",device_status.imei);
- //数据上传间隔
- HMI_WRITE("uploadSet.datt.val=%d",device_status.dattim);
- //语音音量
- HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
- //更新熄屏时间
- if(device_status.thsp<60) device_status.thsp = device_status.thsp * 60;
- HMI_WRITE("thsp=%d",device_status.thsp);
- //
- HMI_WRITE("menu.t0.txt=\"%s\"",device_status.link_ip);
- }
- HMI_WRITE("menu.cam_sta.val=%d",device_status.camsta);
- if(atoi(device_status.gps)==1){
- HMI_WRITE("menu.gps_state.txt=\"定位成功:(%s)%d/%d\"",device_status.gps_state,device_status.gps_inuse,device_status.gps_view);
- }else if(atoi(device_status.gps)==2){
- HMI_WRITE("menu.gps_state.txt=\"定位成功:(基站)\"");
- }
- //更新联网状态
- if(atoi(device_status.net)==1)
- {
- HMI_WRITE("menu.net.val=1");
- HMI_WRITE("workSta.net.val=1");
- }
- else {
- HMI_WRITE("workSta.net.val=0");
- HMI_WRITE("menu.net.val=0");
- }
- if(atoi(device_status.csq)==0&&atoi(device_status.net)==1)
- {
- HMI_WRITE("menu.net.val=1");
- HMI_WRITE("workSta.net.val=2");
- }
- /**********************************************************************/
- }
- else if (strstr(rx_buffer,"getClockData")!=NULL) {
- //更新定时模式
- HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
- //更新光控定时时长
- HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
- //更新时控开始
- HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
- //更新时控结束
- HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
- }
- else if (strstr(rx_buffer,"button")!=NULL) {
- LOG_D("button!");
- DTU_Write("button");
- }
- //拍照
- else if(strstr(rx_buffer,"putTest.switchPhoto=1")!=NULL) {
- #if 0
- ctr_led(ON);
- //发送拍照指令
- char *takephotojson = makeJson_takephoto();
- DTU_Write("%s",takephotojson);
- rt_free(takephotojson);
- HMI_WRITE("sysTest.switchPhoto.val=0");
- #else
- device_status.photo_ws = 1;
- #endif
- }
- else if (strstr(rx_buffer,"putTest.switchPic=1")!=NULL) {
- #if 0
- ctr_led(ON);
- //发送拍照指令
- char *takephotojson = makeJson_takephoto();
- DTU_Write("%s",takephotojson);
- rt_free(takephotojson);
- HMI_WRITE("sysTest.switchPhoto.val=0");
- #else
- device_status.photo_ws = 1;
- #endif
- }
- //转盘复位
- else if (strstr(rx_buffer,"turn_init")!=NULL) {
- LOG_I("转仓复位!");
- ctr_turn(0,0);
- }
- //转盘
- else if (strstr(rx_buffer,"turn")!=NULL) {
- LOG_I("转仓!");
- ctr_turn(90,0);
- }
- //打开电磁阀
- else if (strstr(rx_buffer,"putTest.switchDrop=1")!=NULL) {
- LOG_I("开始滴液!");
- #if Color_EN == 1
- device_status.run_sta = 5;
- #else
- ctr_shake(ON, device_status.shake_sec);
- #endif
- }
- //关闭电磁阀
- else if (strstr(rx_buffer,"putTest.switchDrop=0")!=NULL) {
- LOG_I("停止滴液!");
- ctr_shake(OFF, 0);
- }
- //打开补光
- else if (strstr(rx_buffer,"putTest.switchLed=1")!=NULL) {
- LOG_I("打开补光!!");
- ctr_led(ON);
- }
- //关闭补光
- else if (strstr(rx_buffer,"putTest.switchLed=0")!=NULL) {
- LOG_I("关闭补光!!!");
- ctr_led(OFF);
- }
- //关闭加热
- else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
- device_status.heat_status = 0;
- ctr_Heat(OFF);
- LOG_I("Close Heat!");
- }
- //打开加热
- else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
- device_status.heat_status = 1;
- ctr_Heat(ON);
- LOG_I("Open Heat!");
- }
- //打开制冷
- else if(strstr(rx_buffer,"putTest.switchCold=1")!=NULL) {
- ctr_Cold(ON);
- LOG_I("Open Cold!");
- }
- //关闭制冷
- else if(strstr(rx_buffer,"putTest.switchCold=0")!=NULL) {
- ctr_Cold(OFF);
- LOG_I("Close Cold!");
- }
- //打开采集
- else if(strstr(rx_buffer,"putTest.switchCollect=1")!=NULL){
- ctr_Collect_Fan(ON);
- LOG_I("采集风机已打开!");
- }
- //关闭采集
- else if(strstr(rx_buffer,"putTest.switchCollect=0")!=NULL){
- ctr_Collect_Fan(OFF);
- LOG_I("采集风机已关闭!");
- }
- //打开散热
- else if(strstr(rx_buffer,"putTest.switchCool=1")!=NULL){
- ctr_Cool_Fan(ON);
- LOG_I("散热风机已打开!");
- }
- //关闭散热
- else if(strstr(rx_buffer,"putTest.switchCool=0")!=NULL){
- ctr_Cool_Fan(OFF);
- LOG_I("散热风机已关闭!");
- }
- //开始对焦拍照
- else if(strstr(rx_buffer,"putTest.switchAutopic=1")!=NULL){
- device_status.autotakepic=1;
- rt_kprintf("开始对焦拍照!\n");
- }
- //停止对焦拍照
- else if(strstr(rx_buffer,"putTest.switchAutopic=0")!=NULL){
- device_status.autotakepic=0;
- }
- //粘附测试-开
- else if(strstr(rx_buffer,"putTest.switchFsl=1")!=NULL){
- rt_kprintf("粘附测试开!\n");
- device_status.fsl_sw = 1;
- }
- //粘附测试-关
- else if(strstr(rx_buffer,"putTest.switchFsl=0")!=NULL){
- rt_kprintf("粘附测试关!\n");
- pwm_off(2, 0);
- pwm_off(3,0);
- }
- else if (strstr(rx_buffer,"putTest.switchAutotest=1")!=NULL)
- {
- LOG_I("开始一键测试!!!");
- device_status.auto_test_sw=1;
- }
- else if (strstr(rx_buffer,"putTest.switchAutotest=1")!=NULL)
- {
- LOG_I("停止一键测试!!!");
- device_status.auto_test_sw=0;
- }
- //清扫
- else if (strstr(rx_buffer,"clear")!=NULL) {
- rt_kprintf("\n清扫!\n");
- if(device_status.version_type==4||device_status.version_type==41)
- {
- device_status.clear_status=1;
- }
- else if (device_status.version_type==1) {
- turnzp();
- }
- else if (device_status.version_type==6) {
- ctr_JD_Clear(ON);
- }
- }
- //震动
- else if (strstr(rx_buffer,"putTest.switchShake=1")!=NULL) {
- LOG_I("震动!");
- if(device_status.version_type==6)
- {
- Motor_shake(ON, device_status.shake_sec);
- }
- else{
- ctr_shake(ON,device_status.shake_sec);
- }
- }
- //打开补光
- else if (strstr(rx_buffer,"putTest.switchFill=1")!=NULL) {
- rt_kprintf("\n打开补光!!!\n");
- ctr_led(ON);
- }
- //关闭补光
- else if (strstr(rx_buffer,"putTest.switchFill=0")!=NULL) {
- rt_kprintf("\n关闭补光!!!\n");
- ctr_led(OFF);
- }
- //打开灯管
- else if (strstr(rx_buffer,"putTest.switchLamp=1")!=NULL)
- {
- device_status.test_flag=1;
- rt_kprintf("Open Lamp!\n");
- ctr_lamp(ON,1);
- #if LAMP_EN == 1
- ctr_lamp(ON,2);
- ctr_lamp(ON,3);
- #endif
- DTU_Write("{\"cmd\":\"workstart\"}");
- USHORT dkdg[] = {0xb4f2,0xbfaa,0xb5c6,0xb9dc};
- _485_play(dkdg,4);
- }
- //关闭灯管
- else if (strstr(rx_buffer,"putTest.switchLamp=0")!=NULL)
- {
- device_status.test_flag=0;
- rt_kprintf("Close Lamp1!\n");
- ctr_lamp(OFF,1);
- #if LAMP_EN == 1
- ctr_lamp(OFF,2);
- ctr_lamp(OFF,3);
- #endif
- DTU_Write("{\"cmd\":\"workdone\"}");
- USHORT gbdg[] = {0xb9d8,0xb1d5,0xb5c6,0xb9dc};
- _485_play(gbdg,4);
- }
- //关闭加热
- else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
- device_status.heat_status = 0;
- ctr_Heat(OFF);
- rt_kprintf("Close Heat!\n");
- }
- //打开加热
- else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
- device_status.heat_status = 1;
- ctr_Heat(ON);
- rt_kprintf("Open Heat!\n");
- }
- //打开上仓门
- else if(strstr(rx_buffer,"putTest.switchUp=1")!=NULL){
- if(device_status.dtype==7)
- {
- ctr_lamp(ON, 1);
- ctr_Motor_Driver(1, 0,1000000,500);
- LOG_I("开始步进上行!");
- }
- else
- {
- rt_kprintf("Open UP!\n");
- ctr_cangmen_up(OFF);
- device_status.ctr_up_motor = 1;
- }
- }
- //关闭上仓门
- else if(strstr(rx_buffer,"putTest.switchUp=0")!=NULL){
- if(device_status.dtype==7)
- {
- LOG_I("停止步进上行!");
- ctr_lamp(OFF, 1);
- ctr_Motor_Driver(0, 0,0,0);
- }
- else
- {
- rt_kprintf("CLOSE UP!\n");
- ctr_cangmen_up(OFF);
- device_status.ctr_up_motor = 2;
- }
- }
- //打开下仓门
- else if(strstr(rx_buffer,"putTest.switchDown=1")!=NULL){
- if(device_status.dtype==7)
- {
- LOG_I("开始步进下行!");
- ctr_lamp(ON, 1);
- ctr_Motor_Driver(1, 1,1000000,500);
- }
- else
- {
- ctr_cangmen_down(OFF);
- device_status.ctr_down_motor = 1;
- rt_kprintf("Open down!\n");
- }
- }
- //关闭下仓门
- else if(strstr(rx_buffer,"putTest.switchDown=0")!=NULL){
- if(device_status.dtype==7)
- {
- ctr_lamp(OFF, 1);
- ctr_Motor_Driver(0, 0,0,0);
- rt_kprintf("停止步进下行!\n");
- }
- else
- {
- ctr_cangmen_down(OFF);
- device_status.ctr_down_motor = 2;
- rt_kprintf("CLOSE down!\n");
- }
- }
- else if(strstr(rx_buffer,"putTest.Testpaichong")!=NULL){
- if(device_status.collt_box_sta==0){
- device_status.collt_box_sta = 111;
- }else{
- HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
- }
- LOG_I("排虫测试!");
- }
- //排虫
- else if(strstr(rx_buffer,"putTest.paichong")!=NULL){
- if(device_status.run_sta == 0){
- device_status.run_sta = 111;
- }else{
- HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
- }
- LOG_I("开始排虫!");
- device_status.handle_bugger = 0;
- ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
- }
- else if(strstr(rx_buffer,"putTest.shouchong")!=NULL){
- if(device_status.run_sta == 0){
- device_status.run_sta = 112;
- }else{
- HMI_WRITE("sysTest.result.txt=\"请等待当前执行完成再进行操作\"");
- }
- LOG_I("开始收虫!");
- device_status.handle_bugger = 1;
- ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
- }
- //设置设备时间
- else if (strstr(rx_buffer,"stamp=")!=NULL)
- {
- var = strstr(rx_buffer,"=");
- var ++;
- LOG_I("设置时间:%s",var);
- static char year_s[5],month_s[3],day_s[3],hour_s[3],min_s[3],sec_s[3];
- strncpy(year_s, var, 4);
- strncpy(month_s,var+4,2);
- strncpy(day_s,var+6,2);
- strncpy(hour_s,var+8,2);
- strncpy(min_s,var+10,2);
- strncpy(sec_s,var+12,2);
- 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)
- {
- if(set_date(atoi(year_s),atoi(month_s),atoi(day_s))==RT_EOK)
- {
- LOG_I("设置日期:%d年%d月%d日",atoi(year_s),atoi(month_s),atoi(day_s));
- 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)
- {
- LOG_I("设置时间:%d时%d分%d秒",atoi(hour_s),atoi(min_s),atoi(sec_s));
- set_time(atoi(hour_s),atoi(min_s),atoi(sec_s));
- MA_save();
- }
- //上传最新数据
- device_status.num_updata = 2; //2秒后上报数据更新RTU的时间
- }
- else {
- LOG_E("set_date failed!");
- }
- }
- }
- //设备编码设置
- else if (strstr(rx_buffer,"deviceId=")!=NULL)
- {
- char value_str[20];
- memset(value_str,0,sizeof(value_str));
- LOG_I("设备编码 长度:%d",strlen(rx_buffer));
- if(strlen(rx_buffer)!=19){
- LOG_E("编码长度错误!");
- return;
- }
- var = strstr(rx_buffer,"=");
- var ++;
- strncpy(value_str,var,8); //设备编码为16位
- if(strstr(value_str,"00000000")!=RT_NULL){
- char *config_reset = makeJson_Config_Reset();
- //发送json到RTU
- DTU_Write("%s",config_reset);
- rt_free(config_reset);
- //恢复RTU的默认配置参数
- }else{
- rt_sprintf(device_status.deviceId,"10300101%s",value_str); //设备大类编码103-虫情 设备小类编码 001 生产商代码01
- ef_set_env_blob("deviceId", &device_status.deviceId, sizeof(device_status.deviceId));
- LOG_I("解析到设备编码:%s",device_status.deviceId);
- char *device_id = makeJson_Config_BDH(device_status.deviceId);
- //发送json到RTU
- DTU_Write("%s",device_id);
- rt_free(device_id);
- }
- }
- //定时设置
- else if (strstr(rx_buffer,"saveClockSet=")!=NULL) {
- char value_str[10];
- memset(value_str,0,sizeof(value_str));
- if(device_status.dtype==7)
- {
- var = strstr(rx_buffer,"=");
- var ++;
- strncpy(value_str,var,2);
- if(atoi(value_str)>=0&&atoi(value_str)<=23)
- {
- device_status.collecting_sh1 = atoi(value_str);
- ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1));
- }
- else {
- LOG_E("Set collecting_sh1 Failed!");
- }
- memset(value_str,0,sizeof(value_str));
- strncpy(value_str,var+2,2);
- if(atoi(value_str)>=0&&atoi(value_str)<=23)
- {
- device_status.collecting_eh1 = atoi(value_str);
- ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1));
- }
- else {
- LOG_E("Set collecting_eh1 Failed!");
- }
- memset(value_str,0,sizeof(value_str));
- strncpy(value_str,var+4,2);
- if(atoi(value_str)>=0&&atoi(value_str)<=23)
- {
- device_status.collecting_sh2 = atoi(value_str);
- ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2));
- }
- else {
- LOG_E("Set collecting_sh2 Failed!");
- }
- memset(value_str,0,sizeof(value_str));
- strncpy(value_str,var+6,2);
- if(atoi(value_str)>=0&&atoi(value_str)<=23)
- {
- device_status.collecting_eh2 = atoi(value_str);
- ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2));
- }
- else {
- LOG_E("Set collecting_eh2 Failed!");
- }
- memset(value_str,0,sizeof(value_str));
- strncpy(value_str,var+8,2);
- if(atoi(value_str)>=0&&atoi(value_str)<=23)
- {
- device_status.shake_sec = atoi(value_str);
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
- }
- else {
- LOG_E("Set shake_sec Failed!");
- }
- memset(value_str,0,sizeof(value_str));
- strncpy(value_str,var+10,2);
- if(atoi(value_str)>0&&atoi(value_str)<=24)
- {
- device_status.cul_time = atoi(value_str);
- ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
- }
- else {
- LOG_E("Set cul_time Failed!");
- }
- MA_save();
- 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);
- return;
- }
- LOG_I("时间设置!");
- var=strstr(rx_buffer,"=");
- var++;
- strncpy(value_str,var,2);
- if(atoi(value_str) > 0 && atoi(value_str) <60)
- {
- if(device_status.version_type!=6)
- {
- device_status.sunBar=atoi(value_str);
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
- }
- else {
- device_status.shake_sec = atoi(value_str);
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
- }
- // time_t now;
- // time(&now);
- // static struct tm nowstamp;
- // nowstamp =*localtime(&now);
- // nowstamp.tm_hour = nowstamp.tm_hour - 8;
- // static rt_uint32_t nowstamp_num = 0;
- // nowstamp_num = mktime(&nowstamp);
- // device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
- }
- else {
- LOG_E("参数设置异常(光控时长):%d!!!",atoi(value_str));
- }
- memset(value_str,0,sizeof(value_str));
- //时控开始时间
- strncpy(value_str,var+2,2);
- if(atoi(value_str) >= 0 && atoi(value_str) < 24)
- {
- #if 1
- device_status.startBar=atoi(value_str);
- ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
- #endif
- }
- else {
- LOG_E("参数设置异常(开始):%d!!!",atoi(value_str));
- }
- memset(value_str,0,sizeof(value_str));
- //
- strncpy(value_str,var+4,2);
- if(atoi(value_str) >= 0&& atoi(value_str) < 24)
- {
- #if 1
- device_status.stopBar=atoi(value_str);
- ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
- #endif
- }
- else {
- LOG_E("参数设置异常(结束):%d!!!",atoi(value_str));
- }
- memset(value_str,0,sizeof(value_str));
- //
- strncpy(value_str,var+6,2);
- if(atoi(value_str) >= 0 && atoi(value_str) <= 1)
- {
- device_status.timeSwitch=atoi(value_str);
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
- }
- else {
- if(device_status.version_type==6)
- {
- device_status.timeSwitch=1;
- device_status.dattim=atoi(value_str);
- ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
- }
- else {
- LOG_E("参数设置异常(模式):%d!!!",atoi(value_str));
- }
- }
- //2022/06/23,add:
- 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);
- json_temp = makeJson_Warn(device_status.json_w_clock, "修改工作时间");
- ef_set_env_blob("json_w_clock", &device_status.json_w_clock, sizeof(device_status.json_w_clock)); //将修改屏幕参数操作记录保存到Flash中
- if(atoi(device_status.net)==0)
- DTU_Write("%s",json_temp);
- rt_free(json_temp);
- rt_thread_delay(2000);
- MA_save();
- rt_kprintf("工作时间参数已保存:模式-%d,光控时间-%d,时控开始时间-%d,时控结束时间-%d\n",device_status.timeSwitch,device_status.sunBar,device_status.startBar,device_status.stopBar);
- }
- else if (strstr(rx_buffer,"saveSystemSet")!=NULL) {
- static char clt_time_str[3],heattime_str[3],heatvale_str[4],vol_str[4],thsp_str[5];
- static char value_temp[5];
- LOG_I("系统设置!");
- if(device_status.dtype==7)
- {
- LOG_I("系统设置,孢子仪!");
- var = strstr(rx_buffer,"=");
- var ++;
- memset(value_temp,0,sizeof(value_temp));
- strncpy(value_temp,var,2);
- if(atoi(value_temp)==0 || atoi(value_temp) == 1)
- {
- device_status.cold_sw = atoi(value_temp); //制冷开关
- ef_set_env_blob("cold_sw", &device_status.cold_sw, sizeof(device_status.cold_sw));
- }
- else {
- LOG_E("制冷开关参数设置错误!");
- }
- memset(value_temp,0,sizeof(value_temp));
- strncpy(value_temp,var+2,2);
- if(atoi(value_temp)>=0 && atoi(value_temp) <= 7)
- {
- device_status.vol = atoi(value_temp); //音量
- }
- else {
- LOG_E("音量参数设置错误!");
- }
- memset(value_temp,0,sizeof(value_temp));
- strncpy(value_temp,var+4,2);
- if(atoi(value_temp)>=10 && atoi(value_temp) <= 50)
- {
- device_status.heatvalue = atoi(value_temp); //设定的培养温度
- ef_set_env_blob("heatvalue", &device_status.heatvalue, sizeof(device_status.heatvalue));
- }
- else {
- LOG_E("培养温度参数设置失败!");
- }
- memset(value_temp,0,sizeof(value_temp));
- strncpy(value_temp,var+6,2);
- if(atoi(value_temp)>=1 && atoi(value_temp) <= 60)
- {
- device_status.dattim = atoi(value_temp); //设定的数据上传间隔,单位:分钟
- ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
- }
- else {
- LOG_E("数据上传间隔参数设置失败!");
- }
- memset(value_temp,0,sizeof(value_temp));
- strncpy(value_temp,var+8,2);
- if(atoi(value_temp)>=1 && atoi(value_temp) <= 30)
- {
- device_status.thsp = atoi(value_temp); //设定的息屏间隔,单位:分钟
- ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
- }
- else {
- LOG_E("数据息屏间隔参数设置失败!");
- }
- LOG_I("制冷开关:%d",device_status.cold_sw);
- LOG_I("系统设置已保存:\n自动熄屏-%d\n音量-%d\n培养温度-%d\n数据上传间隔-%d",device_status.thsp,device_status.vol,device_status.heatvalue,device_status.dattim);
- MA_save();
- return;
- }
- var = strstr(rx_buffer,"=");
- var ++;
- strncpy(clt_time_str,var,2);
- if(atoi(clt_time_str)>0 && atoi(clt_time_str) <= 30)
- {
- device_status.clt_time = atoi(clt_time_str); //收集时间
- ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
- }
- strncpy(heattime_str,var+2,2);
- if(atoi(heattime_str)>0 && atoi(heattime_str) <= 30)
- {
- device_status.heattime = atoi(heattime_str); //加热时间
- LOG_I("设置加热时间:%d",atoi(heattime_str));
- ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
- }
- strncpy(heatvale_str,var+4,3);
- if(atoi(heatvale_str) > 0 && atoi(heatvale_str) <= 130)
- {
- device_status.heatvalue=atoi(heatvale_str);
- LOG_I("设置加热温度:%d",device_status.heatvalue);
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
- }
- strncpy(vol_str,var+7,3);
- if(atoi(vol_str)>0&&atoi(vol_str)<8)
- {
- device_status.vol = atoi(vol_str); //音量
- LOG_I("设置音量:%d",device_status.vol);
- //DTU_Write("volume=");
- }
- strncpy(thsp_str,var+10,4);
- if(atoi(thsp_str)>0&&atoi(thsp_str)<3600)
- {
- device_status.thsp = atoi(thsp_str); //熄屏时间
- LOG_I("设置熄屏时间:%d",device_status.thsp);
- }
- else {
- LOG_E("参数设置失败!!!");
- }
- rt_thread_delay(1000);
- MA_save();
- //rt_kprintf("系统设置已保存:收集时间-%d,加热时间-%d,加热温度-%d,音量-%d,自动关屏-%d\n",device_status.clt_time,device_status.heattime,device_status.heatvalue,device_status.vol,device_status.thsp);
- }
- else if (strstr(rx_buffer,"rtc_h=")!=NULL) {
- char rtc_h[2];
- var = strstr(rx_buffer,"=");
- var++;
- strncpy(rtc_h,var,2);
- if(atoi(rtc_h)>=0 && atoi(rtc_h) <= 24)
- {
- set_time(atoi(rtc_h), 99, 99);
- }
- }
- else if (strstr(rx_buffer,"rtc_m=")!=NULL) {
- char rtc_m[2];
- var = strstr(rx_buffer,"=");
- var++;
- strncpy(rtc_m,var,2);
- if(atoi(rtc_m)>=0 && atoi(rtc_m) <= 24)
- {
- set_time(99, atoi(rtc_m), 99);
- }
- }
- else if (strstr(rx_buffer,"rtc_s=")!=NULL) {
- char rtc_s[2];
- var = strstr(rx_buffer,"=");
- var++;
- strncpy(rtc_s,var,2);
- if(atoi(rtc_s)>=0 && atoi(rtc_s) <= 24)
- {
- set_time(99, 99, atoi(rtc_s));
- }
- }
- else if(strstr(rx_buffer,"saveUploadSet=")!=NULL)
- {
- static char dattim_str[3];
- rt_kprintf("上传间隔设置!\n");
- var = strstr(rx_buffer,"=");
- var ++;
- strncpy(dattim_str,var,2);
- if(atoi(dattim_str)>=1&&atoi(dattim_str)<=120)
- {
- device_status.dattim =atoi(dattim_str); //数据上传间隔
- ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
- MA_save();
- }
- else {
- rt_kprintf("设置失败!!!\n");
- }
- rt_kprintf("数据上传设置:%d\n",device_status.dattim);
- }
- //光控测试
- else if(strstr(rx_buffer,"putTest.switchSun=1")!=NULL)
- {
- rt_kprintf("光控测试!!!");
- ctr_lamp(ON,1);
- device_status.sun_test = 1;
- }
- else if (strstr(rx_buffer,"setshake_sec=")!=NULL)
- {
- static char shakesec_str[4];
- LOG_I("震动时间设置!");
- var = strstr(rx_buffer,"=");
- var ++;
- strncpy(shakesec_str,var,2);
- if(atoi(shakesec_str)>=0&&atoi(shakesec_str)<=10)
- {
- device_status.shake_sec =atoi(shakesec_str); //
- }
- else {
- LOG_E("设置失败!!!");
- }
- LOG_D("震动时间设置:%d",device_status.shake_sec);
- }
- //恢复出厂设置电池
- else if (strstr(rx_buffer,"resetdcDefault")!=NULL)
- {
- ResetParamDefault_DC();
- rt_thread_delay(1000);
- //2022/06/23,add:
- 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);
- json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
- ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
- if(atoi(device_status.net)==0)
- DTU_Write("%s",json_temp);
- rt_free(json_temp);
- }
- //恢复出厂设置-交流
- else if (strstr(rx_buffer,"resetDefault")!=NULL)
- {
- ResetParamDefault();
- rt_thread_delay(1000);
- //2022/06/23,add:
- 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);
- json_temp = makeJson_Warn(device_status.json_w_reset, "系统重置");
- ef_set_env_blob("json_w_reset", &device_status.json_w_reset, sizeof(device_status.json_w_reset)); //将修改屏幕参数操作记录保存到Flash中
- if(atoi(device_status.net)==0)
- DTU_Write("%s",json_temp);
- rt_free(json_temp);
- }
- //获取SIM卡信息
- else if(strstr(rx_buffer,"getSim")!=NULL)
- {
- //http://sim.openluat.com/api/wechat/openapidoc
- DTU_Write("getsiminfo");
- }
- else if (strstr(rx_buffer,"DebugEnable")!=NULL) {
- Debug_log_ON();
- }
- else if (strstr(rx_buffer,"DebugDisable")!=NULL) {
- Debug_log_OFF();
- }
- //3.0测报灯
- else if (strstr(rx_buffer,"SwversionV3.0")!=NULL)
- {
- device_status.dtype = 3;
- if(device_status.version_type != 30)
- {
- device_status.version_type = 30;
- sprintf(device_status.driver, "%s",VERSION_UVC);
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
- MA_save();
- }
- else {
- }
- }
- //高空
- else if (strstr(rx_buffer,"SwversionV11")!=NULL)
- {
- device_status.dtype = 3;
- if(device_status.version_type != 11)
- {
- device_status.version_type = 11;
- sprintf(device_status.driver, "%s",VERSION_GK);
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
- MA_save();
- }
- else {
- }
- }
- //1.0
- else if (strstr(rx_buffer,"SwversionV1")!=NULL)
- {
- if(device_status.version_type != 1)
- {
- device_status.dtype = 3;
- device_status.version_type = 1;
- sprintf(device_status.driver, "%s",VERSION_ZP);
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
- MA_save();
- }
- else {
- }
- }
- //4.0
- else if (strstr(rx_buffer,"SwversionV41")!=NULL) {
- device_status.dtype = 3;
- if(device_status.version_type != 41)
- {
- device_status.dtype = 3;
- device_status.version_type = 41;
- sprintf(device_status.driver, "%s",VERSION_HK);
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型+
- DTU_Write("SwversionV41");
- MA_save();
- }
- else {
- }
- }
- //水稻
- else if (strstr(rx_buffer,"SwversionV4")!=NULL) {
- device_status.dtype = 3;
- if(device_status.version_type != 4)
- {
- device_status.version_type = 4;
- sprintf(device_status.driver, "%s",VERSION_HK_2000W);
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
- DTU_Write("SwversionV4");
- MA_save();
- }
- else {
- }
- }
- //5.0测报灯
- else if (strstr(rx_buffer,"SwversionV5")!=NULL) {
- device_status.dtype = 3;
- if(device_status.version_type!=5)
- {
- device_status.version_type = 5;
- sprintf(device_status.driver, "%s",VERSION_V5);
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
- ef_set_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype)); //版本类型
- MA_save();
- }
- }
- else if (strstr(rx_buffer,"putTest.switchFAN_PU=1")!=NULL) {
- ctr_Fan_PUT(ON);
- }
- else if (strstr(rx_buffer,"putTest.switchFAN_PU=0")!=NULL) {
- ctr_Fan_PUT(OFF);
- }
- else if (strstr(rx_buffer,"putTest.switchFAN_IN=1")!=NULL) {
- ctr_Fan_IN(ON);
- }
- else if (strstr(rx_buffer,"putTest.switchFAN_IN=0")!=NULL) {
- ctr_Fan_IN(OFF);
- }
- else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
- {
- HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
- HMI_WRITE("sysTest.heat_txt.txt=\"%s\"",device_status.heat_power);
- // HMI_WRITE("sysTest.switchHeat.val=%d",device_status.heat_status);
- }
- //立即上传
- else if(strstr(rx_buffer,"uploaddata")!=RT_NULL)
- {
- UpLoad_Data();
- }
- else if (strstr(rx_buffer,"checkupdate")!=NULL)
- {
- time_t now = time(RT_NULL);
- static struct tm tm;
- gmtime_r(&now, &tm);
- 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);
- HMI_WRITE("hardcheck.p0.pic=%d",70);
- //RTC时间判断,如果当前年份小于2020,提示需要设置时间
- if(tm.tm_year+1900<2020)
- {
- 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);
- 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);
- }
- }
- //进入bootloader模式
- else if (strstr(rx_buffer,"bootloader")!=NULL) {
- device_status.stop_in_bootloader = 1;
- ef_set_env_blob("stop_in_bootloader", &device_status.stop_in_bootloader, sizeof(device_status.stop_in_bootloader));
- rt_hw_cpu_reset();
- }
- //软件重启
- else if (strstr(rx_buffer,"reboot")!=NULL) {
- rt_hw_cpu_reset();
- }
- //屏幕上触发远程升级
- else if (strstr(rx_buffer,"hmi_update")!=NULL) {
- DTU_Write("hmi_update");
- device_status.update_flag = 1;
- ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
- rt_thread_delay(2000);
- rt_hw_cpu_reset();
- }else if (strstr(rx_buffer,"checkcamera")!=NULL){
- DTU_Write("{\"ctr_cam\":\"checkcamera\"}");
- //校准屏幕的RTC
- HMI_WRITE("rtc0=%d",tm.tm_year+1900);
- HMI_WRITE("rtc1=%d",tm.tm_mon+1);
- HMI_WRITE("rtc2=%d",tm.tm_mday);
- HMI_WRITE("rtc3=%d",tm.tm_hour);
- HMI_WRITE("rtc4=%d",tm.tm_min);
- HMI_WRITE("rtc5=%d",tm.tm_sec);
- //开启超时定时器
- Start_timer_Uart2();
- }else if (strstr(rx_buffer,"ReadCamParam")!=NULL){
- DTU_Write("{\"ctr_cam\":\"ReadParam\"}");
- //开启超时定时器
- Start_timer_Uart2();
- }//SaveCamParam:2070.00000-0.7-144-30-0-0-5472*5472
- else if (strstr(rx_buffer,"SaveCamParam")!=NULL){
- const char *prefix ="SaveCamParam:";
- size_t prefix_len = strlen(prefix);
- const char *start_pos = strstr(rx_buffer, prefix);
- if(start_pos!=NULL)
- {
- // 移动到前缀之后的位置
- start_pos += prefix_len;
- DTU_Write("%s",makeJson_Cam("SaveParam",start_pos));
- }
- //开启超时定时器
- Start_timer_Uart2();
- }else if (strstr(rx_buffer,"GrabOn")!=NULL){
- DTU_Write("{\"ctr_cam\":\"GrabOn\"}");
- //开启超时定时器
- Start_timer_Uart2();
- }else if (strstr(rx_buffer,"GrabOff")!=NULL){
- DTU_Write("{\"ctr_cam\":\"GrabOff\"}");
- //开启超时定时器
- Start_timer_Uart2();
- }
- else if(strstr(rx_buffer,"SelfCheck")!=NULL)
- {
- //校准屏幕的RTC
- HMI_WRITE("rtc0=%d",tm.tm_year+1900);
- HMI_WRITE("rtc1=%d",tm.tm_mon+1);
- HMI_WRITE("rtc2=%d",tm.tm_mday);
- HMI_WRITE("rtc3=%d",tm.tm_hour);
- HMI_WRITE("rtc4=%d",tm.tm_min);
- HMI_WRITE("rtc5=%d",tm.tm_sec);
- if(device_status.selfcheck_ws==2)
- {
- LOG_I("自检进行中!");
- }else {
- device_status.selfcheck_ws = 2;
- LOG_W("开始自检:%d",device_status.selfcheck_ws);
- }
- }else if(strstr(rx_buffer,"haichong")!=NULL)
- {
- _485_play(sound122, 4);
- HMI_WRITE("sysTest.result.txt=\"害虫测试!\"");
- ctr_Motor_Driver_Power(ON);
- //使用硬件定时器控制
- device_status.autotakepic = 10;
- }else if(strstr(rx_buffer,"yichong")!=NULL)
- {
- _485_play(sound122, 4);
- HMI_WRITE("sysTest.result.txt=\"益虫测试!\"");
- ctr_Motor_Driver_Power(ON);
- device_status.autotakepic = 11;
- }
- }
- //入口函数-电机控制及
- static void Ctr_Mortor_entry(void* parameter)
- {
- rt_uint16_t num_up_open = 200; //20s
- rt_uint16_t num_up_close = 200; //
- rt_uint16_t num_down_open = 200; //
- rt_uint16_t num_down_close = 200; //
- rt_int16_t photo_led_sec = 900; //55S
- rt_uint8_t num_tg_open = 200; //20S
- rt_uint8_t num_tg_init = 200;
- //int current_t[200];
- /*孢子仪拍照数量*/
- rt_uint16_t photo_setup = 0;
- while(1)
- {
- #if 1
- time_t time_reset12V;
- time(&time_reset12V);
- static struct tm alarm_reset12V;
- alarm_reset12V =*localtime(&time_reset12V);
- if((alarm_reset12V.tm_hour)==8&&(alarm_reset12V.tm_min==19)&&(alarm_reset12V.tm_sec==50))
- {
- ctr_RTU_DTU(OFF);
- rt_thread_delay(1000*10);
- ctr_RTU_DTU(ON);
- }
- #endif
- if(device_status.ctr_up_motor==1)
- {
- #if 0
- if(num_up_open==200&&device_status.clear_status==0&&device_status.work_status==1)
- {
- motor_current = atoi(device_status.power);
- LOG_D("上仓门待机电流:%d",motor_current);
- }
- //打开上仓门
- if(num_up_open<200)
- #endif
- ctr_cangmen_up(OPEN);
- num_up_open--;
- // current_t[num_up_open] = atoi(device_status.power);
- if (num_up_open == 0)
- {
- ctr_cangmen_up(OFF);
- num_up_open = 200;
- // bubblesort(current_t, 200);
- // if(current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
- // {
- // LOG_E("上仓门打开电机电流不足:%d!!!",current_t[199]);
- // char * ctr_cm_up_warn = makeJson_Warn("电流不足,打开", "上仓门电机");
- // DTU_Write("%s",ctr_cm_up_warn);
- // rt_free(ctr_cm_up_warn);
- // }
- }
- // else {
- // LOG_D("上仓门打开电流:%d",current_t[num_up_open]);
- // }
- }
- else if(device_status.ctr_up_motor==2)
- {
- // if(num_up_close==200&&device_status.clear_status==0&&device_status.work_status==1)
- // {
- // motor_current = atoi(device_status.power);
- // LOG_D("上仓门待机电流:%d",motor_current);
- // }
- // if(num_up_close<200)
- ctr_cangmen_up(CLOSE);
- num_up_close --;
- // current_t[num_up_close] = atoi(device_status.power);
- if (num_up_close == 0)
- {
- ctr_cangmen_up(OFF);
- num_up_close= 200;
- // bubblesort(current_t, 200);
- // if(current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
- // {
- //
- // LOG_E("上仓门电机电流不足!!!-%d",current_t[199]);
- // char * ctr_cm_up_warn = makeJson_Warn("电流不足,关闭", "上仓门电机");
- // DTU_Write("%s",ctr_cm_up_warn);
- // rt_free(ctr_cm_up_warn);
- // }
- }
- //LOG_D("上仓门关闭电流:%d",current_t[num_up_close]);
- }
- if (device_status.ctr_down_motor == 1)
- {
- // if(num_down_open==200&&device_status.clear_status==0&&device_status.work_status==1)
- // {
- // motor_current = atoi(device_status.power);
- // LOG_D("下仓门待机电流:%d",motor_current);
- // }
- // if(num_down_open<200)
- ctr_cangmen_down(OPEN);
- num_down_open--;
- // current_t[num_down_open] = atoi(device_status.power);
- //如果关闭仓门1S后检测不到电流增大,则判定为异常
- if (num_down_open == 0)
- {
- ctr_cangmen_down(OFF);
- num_down_open = 200;
- // bubblesort(current_t, 200);
- // if (current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
- // {
- // LOG_E("下仓门电机电流不足!!!-%d",current_t[199]);
- // char * ctr_cm_down_warn = makeJson_Warn("电流不足,打开", "下仓门电机");
- // DTU_Write("%s",ctr_cm_down_warn);
- // rt_free(ctr_cm_down_warn);
- // }
- }
- // LOG_D("下仓门打开电流:%d",current_t[num_down_open]);
- }
- else if (device_status.ctr_down_motor == 2)
- {
- // if(num_down_close==200&&device_status.clear_status==0&&device_status.work_status==1)
- // {
- // motor_current = atoi(device_status.power);
- // LOG_D("下仓门待机电流:%d",motor_current);
- // }
- // if(num_down_close<200)
- ctr_cangmen_down(CLOSE);
- num_down_close--;
- // current_t[num_down_close] = atoi(device_status.power);
- if (num_down_close == 0)
- {
- ctr_cangmen_down(OFF);
- num_down_close = 200;
- // bubblesort(current_t, 200);
- // //如果关闭仓门5S后检测不到电流增大,则判定为异常
- // if (current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
- // {
- // LOG_E("下仓门关闭电机电流不足!!!-%d",current_t[199]);
- // char * ctr_cm_down_warn = makeJson_Warn("电流不足,关闭", "下仓门电机");
- // DTU_Write("%s",ctr_cm_down_warn);
- // rt_free(ctr_cm_down_warn);
- //
- // }
- }
- // LOG_D("下仓门关闭电流:%d",current_t[num_down_close]);
- }
- if(device_status.sun_test==1)
- {
- SunTest();
- }
- //拍照
- if(device_status.photo_ws==1)
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- device_status.photo_stamp = tv.tv_sec-8*3600;
- if(photo_led_sec==900)
- ctr_led(ON);
- //打开补光灯
- if(photo_led_sec==800)
- {
- LOG_I("测试拍照!");
- #if 1
- char *takephotojson = makeJson_takephoto();
- DTU_Write("%s",takephotojson);
- rt_free(takephotojson);
- #endif
- rt_thread_delay(5000); //延时
- }
- //15S后执行拍照
- else if (photo_led_sec==750)
- {
- DTU_Write("takephoto.mp3");
- //延时
- rt_thread_delay(1000);
- LOG_I("测试拍照!");
- Hk_Take_io();
- }
- photo_led_sec--;
- if(photo_led_sec==300) //
- {
- ctr_led(OFF);
- photo_led_sec = 900;
- device_status.photo_ws = 0;
- HMI_WRITE("sysTest.switchPhoto.val=0");
- HMI_WRITE("sysTest.switchFill.val=0");
- }
- }else{
- photo_led_sec = 900;
- }
- /*对焦拍照*/
- if(device_status.autotakepic==1)
- {
- DTU_Write("autotakephoto");
- HMI_WRITE("sysTest.auto_flag.txt=\"Autotest\"");
- //打开步进电机驱动器电源
- ctr_lamp(ON, 1);
- //打开补光灯
- ctr_led(ON);
- //电机向下运动
- ctr_Motor_Driver(1, 1, 1000000,1000);
- rt_thread_delay(1000);
- LOG_I("电机到达下方!!!");
- Hk_Take_io();
- rt_thread_delay(1000);
- LOG_I("电机开始向上!!!");
- rt_pin_write(Motor_EN, 1);
- rt_pin_write(Motor_DIR, 0);
- beep_set(1000000, 200000); //2kzh - 50%
- while(rt_pin_read(LIMIT_UP)==1)
- {
- HMI_WRITE("sysTest.result.txt=\"对焦拍照触发次数:%d\"",photo_setup);
- HMI_WRITE("sysTest.auto_flag.txt=\"AutoTeststart\"");
- rt_pin_write(Motor_EN, 0);
- beep_set(0, 0);//驱动器失能
- Hk_Take_io(); //触发拍照
- rt_thread_mdelay(200); //10ms
- rt_pin_write(Motor_EN, 1);
- beep_set(1000000, 200000); //驱动器使能
- rt_thread_mdelay(100); //10ms
- beep_set(0, 0); //驱动器失能
- rt_pin_write(Motor_EN, 0);
- if(photo_setup>300) //限制最大拍照数量
- {
- ctr_led(OFF);
- device_status.autotakepic=0;
- rt_pin_write(Motor_EN, 0); //驱动器失能
- beep_set(1000000, 0); //2kzh - 50%
- HMI_WRITE("sysTest.switchAutopic.val=%d",0);
- HMI_WRITE("sysTest.auto_flag.txt=\"\"");
- ctr_lamp(OFF, 1);
- break;
- }
- photo_setup++;
- LOG_I("对焦拍照:%d",photo_setup);
- }
- DTU_Write("takephotodone");
- ctr_led(OFF);
- rt_pin_write(Motor_EN, 0); //驱动器失能
- beep_set(1000000, 0); //2kzh - 50%
- HMI_WRITE("sysTest.switchAutopic.val=%d",0);
- device_status.autotakepic=0;
- photo_setup = 0;
- HMI_WRITE("sysTest.auto_flag.txt=\"\"");
- HMI_WRITE("sysTest.switchAutopic.val=%d",0);
- //关闭步进电机驱动器电源
- ctr_lamp(OFF, 1);
- //重置运行标志位
- device_status.run_sta = 0;
- ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
- }
- else if (device_status.autotakepic==10) {
- hwtimer2_pwm3_output(1,20000,1,0);
- device_status.autotakepic = 0;
- }
- else if (device_status.autotakepic==11) {
- hwtimer2_pwm3_output(1,20000,1,1);
- device_status.autotakepic = 0;
- }
- if(device_status.fsl_sw==1)
- {
- ctr_Petroleum_jelly(10);
- }
- if(device_status.collt_box_sta==111){
- ctr_Fan_IN(ON); //推杆电机收缩(供电打开,复位)
- num_tg_init--;
- if(num_tg_init%10==0)
- HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
- if(num_tg_init==0){
- HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
- ctr_Fan_PUT(ON);
- num_tg_init = 200;
- device_status.collt_box_sta=112;
- }
- }else if(device_status.collt_box_sta==112){
- num_tg_open--;
- if(num_tg_open%10==0)
- HMI_WRITE("sysTest.result.txt=\"开始执行排虫:%d\"",num_tg_open/10);
- if(num_tg_open==0){
- HMI_WRITE("sysTest.result.txt=\"排虫复位中\"");
- ctr_Fan_PUT(OFF);
- num_tg_open = 200;
- device_status.collt_box_sta=113;
- }
- }else if(device_status.collt_box_sta==113){
- num_tg_init--;
- if(num_tg_init%10==0)
- HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
- if(num_tg_init==0){
- HMI_WRITE("sysTest.result.txt=\"排虫机执行已完成!\"");
- ctr_Fan_PUT(OFF);
- ctr_Fan_IN(OFF);
- num_tg_init = 200;
- device_status.collt_box_sta=0;
- }
- }
- if(device_status.run_sta==111){ //排虫-收缩
- ctr_Fan_IN(ON); //推杆电机收缩(供电打开,复位)
- ctr_Fan_PUT(OFF);
- num_tg_init--;
- if(num_tg_init%10==0)
- HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
- if(num_tg_init==0){
- HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
- ctr_Fan_IN(OFF);
- num_tg_init = 200;
- device_status.run_sta=0;
- }
- }else if(device_status.run_sta==112){ //收虫-推出
- ctr_Fan_IN(ON);
- ctr_Fan_PUT(ON);
- num_tg_open--;
- if(num_tg_open%10==0)
- HMI_WRITE("sysTest.result.txt=\"开始执行收虫:%d\"",num_tg_open/10);
- if(num_tg_open==0){
- HMI_WRITE("sysTest.result.txt=\"收虫中...\"");
- ctr_Fan_PUT(OFF);
- ctr_Fan_IN(OFF);
- num_tg_open = 200;
- device_status.run_sta=0;
- }
- }
- //一键测试
- if(device_status.auto_test_sw==1)
- {
- HMI_WRITE("sysTest.auto_flag.txt=\"Autotest\"");
- //转盘复位
- LOG_I("转盘复位!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:转盘复位!\"");
- rt_thread_delay(2000);
- ctr_turn(0,0);
- //转90
- LOG_I("第一次转盘!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:第一次转盘!\"");
- ctr_turn(90,0);
- rt_thread_delay(2000);
- //推杆电机:测试粘附:
- LOG_I("涂凡士林!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:涂凡士林!\"");
- ctr_Petroleum_jelly(10);
- rt_thread_delay(2000);
- //转90
- LOG_I("第二次转盘!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:第二次转盘!\"");
- ctr_turn(90,0);
- rt_thread_delay(2000);
- //采集,打开风机
- LOG_I("采集,打开风机!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:采集,打开风机!\"");
- ctr_Collect_Fan(ON);
- rt_thread_delay(5000);
- LOG_I("采集结束,关闭风机!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:采集结束,关闭风机!\"");
- rt_thread_delay(2000);
- ctr_Collect_Fan(OFF);
- //散热
- LOG_I("打开散热!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:打开散热!\"");
- rt_thread_delay(2000);
- ctr_Cool_Fan(ON);
- rt_thread_delay(5000);
- LOG_I("关闭散热!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:关闭散热!\"");
- rt_thread_delay(2000);
- ctr_Cool_Fan(OFF);
- //转90
- LOG_I("第三次转盘!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:第三次转盘!\"");
- ctr_turn(90,0);
- rt_thread_delay(5000);
- //滴液
- LOG_I("开始滴液!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:开始滴液!\"");
- rt_thread_delay(2000);
- ctr_shake(ON,device_status.shake_sec);
- rt_thread_delay(5000);
- LOG_I("停止滴液!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:停止滴液!\"");
- rt_thread_delay(2000);
- //加热
- LOG_I("开始加热!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:开始加热!\"");
- rt_thread_delay(2000);
- ctr_Heat(ON);
- rt_thread_delay(5000);
- LOG_I("停止加热!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:停止加热!\"");
- rt_thread_delay(2000);
- ctr_Heat(OFF);
- //制冷
- LOG_I("开始制冷!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:开始制冷!\"");
- rt_thread_delay(2000);
- ctr_Cold(ON);
- rt_thread_delay(5000);
- LOG_I("停止制冷!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:停止制冷!\"");
- rt_thread_delay(2000);
- ctr_Cold(OFF);
- //转90
- LOG_I("第四次转盘!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:第四次转盘!\"");
- ctr_turn(90,0);
- LOG_I("打开补光灯!!!");
- HMI_WRITE("sysTest.result.txt=\"一键测试:打开补光灯!\"");
- rt_thread_delay(2000);
- ctr_led(ON);
- device_status.autotakepic=1;
- device_status.auto_test_sw=0;
- HMI_WRITE("sysTest.auto_flag.txt=\"\"");
- }
- if(device_status.selfcheck_ws==2)
- {
- selfcheck(1);
- }
- rt_thread_delay(100);
- }
- }
- /*屏幕写数据*/
- int Hmi_Fresh(void)
- {
- //初始化串口4
- //HMI_uart4_init();
- rt_err_t ret = RT_EOK;
- /* 初始化消息队列 */
- rt_mq_init(&rx_mq, "rx_mq",
- msg_pool, /* 存放消息的缓冲区 */
- sizeof(struct rx_msg), /* 一条消息的最大长度 */
- sizeof(msg_pool), /* 存放消息的缓冲区大小 */
- RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
- /* 设置接收回调函数 */
- rt_device_set_rx_indicate(serial, uart_input);
- /* 创建线程*/
- hmi1 = rt_thread_create("Hmi_Fresh_thread",
- Hmi_thread_entry,
- RT_NULL,
- HMI_THREAD_STACK_SIZE,
- HMI_THREAD_PRIORITY,
- HMI_THREAD_TIMESLICE);
- /*部分控制的线程*/
- ctr_motor = rt_thread_create("Ctr motor",
- Ctr_Mortor_entry,
- RT_NULL,
- CONTROL_MOTOR_STACK_SIZE,
- CONTROL_MOTOR_PRIORITY,
- CONTROL_MOTOR_TIMESLICE);
- if(ctr_motor != RT_NULL)
- {
- rt_thread_startup(ctr_motor);
- }
- /* 如果获得线程控制块,启动这个线程 */
- if (hmi1 != RT_NULL)
- {
- rt_thread_startup(hmi1);
- }
- else
- {
- ret = RT_ERROR;
- }
- //定时器,串口通信超时监测20S
- timer_uart2 = rt_timer_create("t_uart2",t_uart2_callback,RT_NULL, 20000, RT_TIMER_FLAG_ONE_SHOT);
- if(timer_uart2==RT_NULL)
- {
- LOG_E("rt_timer_create timer_uart2 failed!");
- }
- return ret;
- }
- void Check_ParamConfig(void)
- {
- time_t now = time(RT_NULL);
- static struct tm tm;
- gmtime_r(&now, &tm);
- if(easyflash_init()==EF_NO_ERR) //初始化成功
- {
- ef_get_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt), NULL); //读出reboot_time的值
- ef_get_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag), NULL); //读出updateflag的值
- ef_get_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave), NULL); //判断是否用户配置了程序
- device_status.rebootcnt++;
- ef_set_env_blob("reboot_time", &device_status.rebootcnt, sizeof(device_status.rebootcnt));
- LOG_I("REBOOT_TIME:%d-%d-%d",device_status.rebootcnt,device_status.iSave,device_status.update_flag);
- }
- else {
- LOG_E("easyflash init ERRPR!!!");
- }
- //保存默认配置
- if(device_status.iSave!=FLASH_FLAG)
- {
- device_status.iSave=FLASH_FLAG;
- /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
- device_status.dtype = 3;
- device_status.version_type = 4; //4.0
- device_status.Power_Type = 0; //0-交流供电;1-直流供电
- device_status.clt_time = 10; //收集时间
- device_status.heattime = 10; //加热时间
- device_status.heatvalue=100;//加热温度
- device_status.thsp = 300; //默认熄屏时间5分钟
- device_status.sunBar = 9; //光控定时时长
- device_status.startBar = 20; //定时开始时间
- device_status.stopBar = 0; //定时结束时间
- device_status.tph = 70; //高温保护阈值
- device_status.tpl = 5; //低温保护阈值
- device_status.shake_ws = 1; //震动开关,默认开
- device_status.shake_sec = 1; //震动时间,s
- device_status.vol = 7; //音量
- device_status.timeSwitch = 0; //工作模式:光控
- device_status.passWord = 8888; //屏幕密码
- device_status.dattim = 10; //数据上传间隔
- device_status.ds = 1; //设备状态
- device_status.update_flag = 0;
- /*孢子仪*/
- device_status.collecting_sh1 = 9;
- device_status.collecting_eh1 = 10;
- device_status.collecting_sh2 = 14;
- device_status.collecting_eh2 = 16;
- device_status.cold_sw = 0;
- device_status.heat_sw =0;
- device_status.cul_time = 1;
- device_status.run_sta = 0;
- device_status.handle_bugger = 0; //默认排虫
- sprintf(device_status.driver, "%s",VERSION_HK);
- sprintf(device_status.deviceId,"0");
- rt_sprintf(device_status.tempture, "-15");
- rt_sprintf(device_status.humidity, "31");
- rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
- ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave)); //
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
- ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
- ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
- ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
- ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
- ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
- ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
- ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
- ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
- ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
- ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type)); //版本类型
- ef_set_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture)); //温度
- ef_set_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity)); //湿度
- ef_set_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1)); //上传平台
- ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time)); //采集时间
- ef_set_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw)); //制冷开关
- ef_set_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw)); //加热开关
- ef_set_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1)); //风机开关
- ef_set_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1)); //采集时间
- ef_set_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2)); //采集时间
- ef_set_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2)); //采集时间
- ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta)); //
- ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
- ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
- LOG_I("SOFTWARE VERSION:%s",device_status.driver);
- LOG_I("Default paramconf is:");
- LOG_I("stime:%d",device_status.iSave);
- LOG_I("stime:%d",device_status.clt_time);
- LOG_I("startBar:%d",device_status.startBar);
- LOG_I("stopBar:%d",device_status.stopBar);
- LOG_I("timeSwitch:%d",device_status.timeSwitch);
- LOG_I("sunBar:%d",device_status.sunBar);
- LOG_I("jtime:%d",device_status.heattime);
- LOG_I("jheat:%d",device_status.heatvalue);
- LOG_I("thsp:%d", device_status.thsp);
- LOG_I("passwd:%d",device_status.passWord);
- }//从easyflash读取参数配置
- else if (device_status.iSave==FLASH_FLAG) {
- ef_get_env_blob("dtype",&device_status.dtype,sizeof(device_status.dtype),NULL); //设备类型
- ef_get_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim),NULL); //数据上传间隔
- ef_get_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time), NULL); //收集时间
- ef_get_env_blob("startBar", &device_status.startBar,sizeof(device_status.startBar), NULL); //开始时间
- ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL); //结束时间
- ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL); //模式
- ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL); //光控时间
- ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL); //加热时间
- ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL); //加热温度
- ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL); //震动开关
- ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL); //震动时间
- ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL); //高温保护
- ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL); //低温保护
- ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL); //数据上传间隔
- ef_get_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp), NULL); //熄屏时间
- ef_get_env_blob("passWord",&device_status.passWord,sizeof(device_status.passWord),NULL); //密码
- ef_get_env_blob("imei",&device_status.imei,sizeof(device_status.imei),NULL); //IMEI
- ef_get_env_blob("iccid",&device_status.iccid,sizeof(device_status.iccid),NULL); //ICCID
- ef_get_env_blob("lat",&device_status.lat,sizeof(device_status.lat),NULL);
- ef_get_env_blob("lng",&device_status.lng,sizeof(device_status.lng),NULL);
- ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL); //开关机状态
- ef_get_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture),NULL); //环境温度
- ef_get_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity),NULL); //环境湿度
- ef_get_env_blob("json_w_clock",&device_status.json_w_clock,sizeof(device_status.json_w_clock),NULL); //时间
- ef_get_env_blob("json_w_reset",&device_status.json_w_reset,sizeof(device_status.json_w_reset),NULL); //重置
- ef_get_env_blob("json_w_platform",&device_status.json_w_platform,sizeof(device_status.json_w_platform),NULL);//平台
- ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL); //版本类型
- ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL); //BL版本号 进BL的时候存储到FLASH
- ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL); //平台地址
- /*孢子仪*/
- ef_get_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time),NULL); //培养时间
- ef_get_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw),NULL); //制冷开关
- ef_get_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw),NULL); //加热开关
- ef_get_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1),NULL); //采集开始1
- ef_get_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1),NULL); //采集结束1
- ef_get_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2),NULL); //采集开始2
- ef_get_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2),NULL); //采集结束2
- ef_get_env_blob("run_sta",&device_status.run_sta,sizeof(device_status.run_sta),NULL); //运行状态
- ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL); //供电类型
- ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL); //设备编码
- ef_get_env_blob("handle_bugger",&device_status.handle_bugger,sizeof(device_status.handle_bugger),NULL); //排虫
- device_status.light_over_tim = device_status.sunBar * 3600; //光控计数
- device_status.work_done = 0;
- //工作完成标志位
- if(device_status.dattim==0)
- {
- device_status.dattim = 10;
- }
- /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
- if(device_status.dtype!=7)
- {
- device_status.dtype = 3;
- }
- else {
- device_status.version_type = 7;
- }
- if(device_status.version_type==0)
- {
- app_partion_backup(); //固件备份至df_area
- device_status.version_type = 41;
- rt_sprintf(device_status.driver, "%s",VERSION_HK);
- ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
- }
- else if(device_status.version_type==1)
- {
- rt_sprintf(device_status.driver, "%s",VERSION_ZP);
- }
- else if (device_status.version_type==11)
- {
- rt_sprintf(device_status.driver, "%s",VERSION_GK);
- }
- else if (device_status.version_type==4)
- {
- rt_sprintf(device_status.driver, "%s",VERSION_HK_2000W);
- }
- else if (device_status.version_type==41) {
- rt_sprintf(device_status.driver, "%s",VERSION_HK);
- }
- else if (device_status.version_type==5) {
- rt_sprintf(device_status.driver, "%s",VERSION_V5);
- }else if (device_status.version_type==30) {
- rt_sprintf(device_status.driver, "%s",VERSION_UVC);
- }
- /*定制三色光源*/
- #if LAMP_EN == 1
- if(device_status.sunBar%3!=0)
- {
- device_status.sunBar = 3;
- }
- // device_status.timeSwitch = 1;
- // device_status.startBar = 20;
- // device_status.stopBar = 23;
- #endif
- LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
- LOG_I("read flash paramconfis:%d-%s-%s",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
- LOG_I("开机次数:%d",device_status.rebootcnt);
- LOG_I("收集时间:%d",device_status.clt_time);
- LOG_I("定时开始时间:%d",device_status.startBar);
- LOG_I("定时结束时间:%d",device_status.stopBar);
- LOG_I("timeSwitch:%d",device_status.timeSwitch);
- LOG_I("光控定时时长:%d",device_status.sunBar);
- LOG_I("收集时间:%d",device_status.heattime);
- LOG_I("加热温度:%d",device_status.heatvalue);
- LOG_I("震动开关:%d",device_status.shake_ws);
- LOG_I("震动时间:%d",device_status.shake_sec);
- LOG_I("高温保护:%d",device_status.tph);
- LOG_I("低温保护:%d",device_status.tpl);
- LOG_I("thsp:%d", device_status.thsp);
- LOG_I("密码:%d",device_status.passWord);
- LOG_I("数据上传间隔:%d",device_status.dattim);
- LOG_I("温湿度数据:%d-%d",atoi(device_status.tempture),atoi(device_status.humidity));
- LOG_I("上传平台:%s",device_status.mqttcfg1);
- LOG_I("孢子仪运行状态:%d",device_status.run_sta);
- LOG_I("孢子仪采集时间:[%d-%d,%d-%d]",device_status.collecting_sh1,device_status.collecting_eh1,device_status.collecting_sh2,device_status.collecting_eh2);
- LOG_I("PowerType:%d",device_status.Power_Type);
- LOG_I("deviceId:%s",device_status.deviceId);
- LOG_I("handle_bugger:%d",device_status.handle_bugger);
- }
- //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
- if(device_status.update_flag==1)
- {
- device_status.update_flag = 0;
- ef_set_env_blob("update_flag", &device_status.update_flag, sizeof(device_status.update_flag));
- ymodem_ota(1,0);
- }
- else {
- device_status.update_flag = 0;
- //初始化联网状态
- rt_sprintf(device_status.net,"1");
- rt_sprintf(device_status.csq,"0");
- rt_sprintf(device_status.sim,"1");
- ctr_router(ON);
- Hmi_Fresh();
- if(device_status.dtype!=7)
- {
- Control_clear();
- Control_heat();
- }
- dtu_data_play();
- sht30_collect();
- #if SENSOR_EN==1
- mb_master_samlpe();
- thread_485_play();
- #endif
- #if ROBOT_EN == 0
- uint16_t connect_num=0;
- //等待联网,
- while(atoi(device_status.net)==1)
- {
- if(Read_Real_Voltage()/100>5&&device_status.power_status==0)
- ctr_RTU_DTU(ON);
- if(device_status.dtype==7)
- HMI_WRITE("sysTest.auto_flag.txt=\"0\"");
- char *readinfo = makeJson_ReadInfo();
- DTU_Write("%s",readinfo);
- rt_free(readinfo);
- rt_thread_delay(1000);
- connect_num++;
- LOG_I("联网中......%d",connect_num);
- //超时时间为3分钟
- if(connect_num==180) //180
- {
- device_status.timeSwitch = 0;
- 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);
- #if 0
- set_date(2020, 1, 1);
- set_time(0, 0, 0);
- #endif
- break;
- }
- if(tm.tm_year>=2021)
- break;
- }
- connect_num = 0;
- while(atoi(device_status.net)==0)
- {
- char *readinfo = makeJson_ReadInfo();
- DTU_Write("%s",readinfo);
- rt_free(readinfo);
- rt_thread_delay(2000);
- connect_num++;
- if(connect_num>5) break;
- }
- if(device_status.version_type==6) device_status.timeSwitch = 1;
- DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
- rt_thread_delay(1000);
- if(device_status.update_flag==0)
- {
- Workstatus_check();
- //工作流程
- Work_Loop_Task();
- }
- #endif
- }
- }
- void ResetParamDefault(void)
- {
- rt_sprintf(device_status.tempture,"%d",-15);
- device_status.ds = 1; //设备状态开机
- device_status.thsp = 300;
- device_status.passWord = 8888;
- device_status.dattim = 10;
- device_status.collecting_sh1 = 9;
- device_status.collecting_eh1 = 10;
- device_status.collecting_sh2 = 14;
- device_status.collecting_eh2 = 16;
- device_status.Power_Type = 0;
- ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
- ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
- if(device_status.dtype==3)
- {
- device_status.clt_time = 10; //收集时间
- #if LAMP_EN == 0
- device_status.startBar = 20; //定时开始时间
- device_status.stopBar = 5; //定时结束时间
- #endif
- device_status.heattime = 10; //加热时间
- device_status.shake_ws = 1; //针对开关
- device_status.shake_sec = 1; //震动时间1-100ms
- #if LAMP_EN == 1
- device_status.sunBar = 3; //光控定时时长
- #else
- device_status.sunBar = 8;
- #endif
- device_status.tph = 70; //高温保护阈值
- device_status.tpl = -5; //低温保护阈值
- device_status.timeSwitch = 0; //定时模式:光控
- device_status.heatvalue=100; //加热温度
- ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
- ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
- ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
- ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
- ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
- ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
- ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
- device_status.handle_bugger = 0;
- ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
- }
- else if(device_status.dtype==7)
- {
- device_status.run_sta = 0;
- device_status.heatvalue = 25; //培养温度
- ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
- ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1)); //采集时间
- ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1)); //采集时间
- ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2)); //采集时间
- ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2)); //采集时间
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
- }
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
- ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
- ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
- HMI_WRITE("play %d,%d,%d",1,5,0);
- DTU_Write("reset.mp3");
- rt_thread_delay(1000);
- }
- void ResetParamDefault_DC(void)
- {
- //将温度数据设置为-15摄氏度,以便上传的数据中包含温控数据
- rt_sprintf(device_status.tempture,"%d",-15);
- device_status.clt_time = 10; //收集时间
- device_status.dattim = 10; //数据上传间隔
- #if LAMP_EN == 0
- device_status.startBar = 20; //定时开始时间
- device_status.stopBar = 0; //定时结束时间
- #endif
- device_status.heattime = 10; //加热时间
- device_status.shake_ws = 1; //针对开关
- device_status.shake_sec = 1; //震动时间1-100ms
- #if LAMP_EN == 1
- device_status.sunBar = 3; //光控定时时长
- #else
- device_status.sunBar = 4;
- #endif
- device_status.tph = 70; //高温保护阈值
- device_status.tpl = -5; //低温保护阈值
- device_status.timeSwitch = 0; //定时模式
- device_status.heatvalue=100;
- device_status.ds = 1; //设备状态开机
- device_status.thsp = 300;
- device_status.passWord = 8888;
- device_status.timeSwitch = 0;
- device_status.Power_Type = 1;
- device_status.handle_bugger = 0;
- ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim)); //上传时间
- ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
- ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
- ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
- ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
- ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
- ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
- ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
- ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
- ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
- ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
- ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
- ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
- ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws)); //震动开关
- ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec)); //震动时间
- ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
- ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
- DTU_Write("reset.mp3");
- rt_thread_delay(1000);
- }
- //固件备份
- void app_partion_backup(void)
- {
- rt_kprintf("固件恢复!!!\n");
- const char *dst_part_name = "df_area";
- const char *src_part_name = "app";
- const struct fal_partition *dst_part;
- const struct fal_partition *src_part;
- dst_part = fal_partition_find(dst_part_name);
- src_part = fal_partition_find(src_part_name);
- if (dst_part == RT_NULL || src_part == RT_NULL)
- {
- if (dst_part == RT_NULL)
- rt_kprintf("%s partition is not exist!\n", dst_part_name);
- if (src_part == RT_NULL)
- rt_kprintf("%s partition is not exist!\n", src_part_name);
- }
- else
- {
- rt_kprintf("Clone %s partition to %s partition:\n", src_part_name, dst_part_name);
- if (fal_partition_erase(dst_part, 0, dst_part->len) >= 0)
- {
- int clone_pos = 0;
- int clone_len = 0, clone_tol_len;
- rt_uint8_t *buf = rt_malloc(4096);
- if (dst_part->len < src_part->len)
- clone_tol_len = dst_part->len;
- else
- clone_tol_len = src_part->len;
- while ((clone_pos < clone_tol_len) && (buf != RT_NULL))
- {
- clone_len = fal_partition_read(src_part, clone_pos, buf, 4096);
- if (clone_len < 0)
- {
- rt_kprintf("\nread %s partition failed, clone stop!\n", src_part_name);
- break;
- }
- if (fal_partition_write(dst_part, clone_pos, buf, clone_len) < 0)
- {
- rt_kprintf("\nwrite %s partition failed, clone stop!\n", dst_part_name);
- break;
- }
- HMI_WRITE("#");
- rt_kprintf("#");
- clone_pos += clone_len;
- }
- if (clone_pos >= clone_tol_len)
- {
- rt_kprintf("\nClone partition success, total %d bytes!\n", clone_tol_len);
- }
- else
- {
- rt_kprintf("Clone partition failed!");
- }
- if (buf)
- rt_free(buf);
- }
- }
- }
- void Debug_log_ON(void)
- {
- rt_console_set_device("uart4");
- finsh_set_device("uart4");
- }
- void Debug_log_OFF(void)
- {
- rt_console_set_device("uart1");
- finsh_set_device("uart1");
- rt_mq_init(&rx_mq, "rx_mq",
- msg_pool, /* 存放消息的缓冲区 */
- sizeof(struct rx_msg), /* 一条消息的最大长度 */
- sizeof(msg_pool), /* 存放消息的缓冲区大小 */
- RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
- rt_device_set_rx_indicate(serial, uart_input);
- hmi1 = rt_thread_create("Hmi_Fresh_thread",
- Hmi_thread_entry,
- RT_NULL,
- HMI_THREAD_STACK_SIZE,
- HMI_THREAD_PRIORITY,
- HMI_THREAD_TIMESLICE);
- if (hmi1 != RT_NULL)
- {
- rt_thread_startup(hmi1);
- }
- }
- MSH_CMD_EXPORT(Debug_log_ON,Debug_log_ON);
- MSH_CMD_EXPORT(Debug_log_OFF,Debug_log_OFF);
- //
- INIT_BOARD_EXPORT(HMI_uart4_init);
|