| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924 |
- /*
- * 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>
- #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
- #include "test.h"
- #include <Work_SY2.h>
- #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[256];
- static char rx_buffer[HMI_UART_RXBUFFER_SIZE + 1];
- void list_mem(void);
- int mb_master_samlpe();
- volatile uint8_t ef_cfged = 0;
- volatile char bdhid[20] = {0};
- uint8_t stopreflashTakePhoto = 0;
- /**/
- Device_Status_typedef device_status;
- extern volatile JD_Test_Sta jts;
- extern volatile Reflash_test_sta rts;
- void getEcodeData(uint8_t type);
- extern uint8_t sex_enread;
- extern SYSCFG syscfg;
- 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; /*串口设备句柄*/
- /* 消息队列控制块 */
- 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);
- /**
- * @brief 用于驱动串口屏的串口初始化
- *
- * @return int -
- */
- 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
- config.bufsz = 512; // 缓冲区128字节
- 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 接收及轮询发送模式打开串口设备 */
- rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX);
- return RT_EOK;
- }
- /*串口屏写数据*/
- /*串口屏写数据*/
- /**
- * @brief 向串口屏写数据
- *
- * @param fmt 字符串模板
- * @param ... 可变参数
- */
- void HMI_WRITE(char *fmt, ...)
- {
- va_list ap;
- // 末尾需要拼接的3个ff
- 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);
- str_length = rt_vsnprintf(str, sizeof(str) - 1, fmt, ap);
- if (str_length > MAX_SIZE - 1)
- str_length = MAX_SIZE - 1;
- // if(strstr(str,"jd_test.pic") != NULL)
- // {
- // rt_kprintf("jd_test.pic >>> %s\n" , str);
- // }
- rt_device_write(serial, 0, str, str_length);
- // if(strstr(str, "result") != NULL)
- // rt_kprintf("str > %s \n" , str);
- va_end(ap);
- rt_device_write(serial, 0, hmi_hex, 3);
- }
- /* 接收数据回调函数 */
- 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)
- // {
- // /* 消息队列满 */
- // rt_kprintf("message queue full! B\n");
- // while (1)
- // {
- // result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), 50);
- // if (result == RT_EOK)
- // {
- // char rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
- // rx_buffer[rx_length] = '\0';
- // rt_kprintf("%s\n", rx_buffer);
- // }
- // else
- // {
- // break;
- // }
-
- // }
- // }
- if (rt_mq_send(&rx_mq, &msg, sizeof(msg)) == -RT_EFULL)
- {
- /* 非阻塞腾位置 */
- struct rx_msg dummy;
- if (rt_mq_recv(&rx_mq, &dummy, sizeof(dummy), RT_WAITING_NO) == RT_EOK)
- {
- rt_mq_send(&rx_mq, &msg, sizeof(msg));
- }
- else
- {
- rt_kprintf("rx mq full, drop msg\n");
- }
- }
- return result;
- }
- /*入口函数*/
- /**
- * @brief 串口屏指令响应线程
- *
- * @param parameter 字符串
- */
- static void Hmi_thread_entry(void *parameter)
- {
- struct rx_msg msg;
- rt_err_t result;
- rt_uint32_t rx_length;
- rt_thread_mdelay(10000);
- //rt_kprintf("Hmi_thread_entry\n");
- /* 初始化消息队列 */
- 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);
- 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';
- //rt_kprintf(" Hmi_thread_entry %s\n", 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);
- }
- }
- /*******************************************************************************************/
- /***************************** 解析从屏幕收到的数据 begin **********************************/
- #include "rs485.h"
- #include <Work_SY2.h>
- extern void ReflashWorkSta(void);
- extern Sensor sensor[MAX_SENSOR_NUM];
- extern Limit limit;
- extern wm_Def workmode;
- void CMD_getFullData(void)
- {
- static struct tm tm;
- time_t now = time(RT_NULL);
- gmtime_r(&now, &tm);
- if (1)
- {
- //rt_kprintf("CMD_getFullData\n");
- if (device_status.refresh_num == 5)
- {
- device_status.refresh_num = 15;
- if (rt_pin_read(RTU_DTU))
- {
- SendReadInfo('B');
- }
- device_status.hmi_fresh = 1;
- rt_thread_mdelay(3000);
- }
- // 在解析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.link_sta = 0;
- device_status.refresh_timeout = 0;
- }
- 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.Traplamp.val=%d", device_status.traplampsta);
- // 更新工作状态
- 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("workSta.equipid.txt=\"%s\"",device_status.imei);
- // 数据上传间隔
- // HMI_WRITE("uploadSet.datt.val=%d", syscfg.dattim);
- // 语音音量
- HMI_WRITE("sysSet.vol.val=%d", device_status.vol);
- // 北大荒ID
- HMI_WRITE("menu.t9.txt=\"%s\"", bdhid);
- // 更新熄屏时间
- if (device_status.thsp < 60)
- device_status.thsp = device_status.thsp * 60;
- HMI_WRITE("thsp=%d", device_status.thsp);
- }
- #if BOOT_ERR == 1
- 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=\"定位成功:(基站)\"");
- }
- #endif
- // 更新联网状态
- 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");
- }
- if (device_status.dtype == 7 && device_status.version_type != vt_BZY_JD)
- {
- // 更新温湿度数据
- // HMI_WRITE("workSta.env_hum.txt=\"%s\"", device_status.humidity);
- // HMI_WRITE("workSta.env_tem.txt=\"%s\"", device_status.tempture);
- HMI_WRITE("workSta.on_off.val=%d", device_status.ds);
- HMI_WRITE("workSta.work_sta.val=%d", device_status.work_status);
- HMI_WRITE("workSta.collect_fan.val=%d", device_status.collect_fan_status);
- // 更新电池状态
- HMI_WRITE("workSta.bat_sta.val=%d", device_status.bat_status);
- // 更新开关状态
- HMI_WRITE("workSta.on_off.val=%d", device_status.ds);
- // 更新工作状态
- HMI_WRITE("workSta.work_sta.val=%d", device_status.work_status);
- // 数据上传间隔
- // HMI_WRITE("sysSet.datt.val=%d", syscfg.dattim);
- HMI_WRITE("sysSet.lcd_time.val=%d", device_status.thsp * 60);
- // 采集开始时间1
- HMI_WRITE("clockSet.start1.val=%d", device_status.collecting_sh1);
- // 采集结束时间1
- HMI_WRITE("clockSet.end1.val=%d", device_status.collecting_eh1);
- if (device_status.autotakepic == 0)
- HMI_WRITE("sysTest.auto_flag.txt=\"\"");
- }
- if (device_status.version_type == vt_XCT) // 小虫体
- {
- // 更新温湿度数据
- // if (sensor[s_Temp].online && sensor[s_Humi].online)
- // {
- // // HMI_WRITE("workSta.env_hum.txt=\"%s\"", sensor[s_Humi].eValue);
- // // HMI_WRITE("workSta.env_tem.txt=\"%s\"", sensor[s_Temp].eValue);
- // HMI_WRITE("workSta.sensor_sta.aph=0");
- // }
- // else
- // {
- // HMI_WRITE("workSta.env_hum.txt=\"%s\"", device_status.humidity);
- // HMI_WRITE("workSta.env_tem.txt=\"%s\"", device_status.tempture);
- // HMI_WRITE("workSta.sensor_sta.aph=127");
- // }
- HMI_WRITE("workSta.on_off.val=%d", device_status.ds);
- HMI_WRITE("workSta.work_sta.val=%d", device_status.work_status);
- HMI_WRITE("workSta.collect_fan.val=%d", device_status.collect_fan_status);
- // 更新开关状态
- HMI_WRITE("workSta.on_off.val=%d", device_status.ds);
- // 更新工作状态
- HMI_WRITE("workSta.work_sta.val=%d", device_status.work_status);
- // 数据上传间隔
- // HMI_WRITE("sysSet.datt.val=%d", syscfg.dattim);
- HMI_WRITE("sysSet.lcd_time.val=%d", device_status.thsp * 60);
- // 采集开始时间1
- HMI_WRITE("clockSet.startTime1.val=%d", device_status.collecting_sh1);
- // 采集开始时间2
- HMI_WRITE("clockSet.endTime1.val=%d", device_status.collecting_eh1);
- // 控的开关同步
- HMI_WRITE("clockSet.wm0.val=%d", syscfg.en_tigmode);
- HMI_WRITE("clockSet.sw_temp.val=%d", limit.temhumEN);
- // 温湿控的参数同步
- HMI_WRITE("clockSet.temp_limup.val=%d", limit.temp_up);
- HMI_WRITE("clockSet.temp_limdn.val=%d", limit.temp_dw);
- // HMI_WRITE("clockSet.humi_limup.val=%d", limit.humi_up);
- // HMI_WRITE("clockSet.humi_limdn.val=%d", limit.humi_dw);
- HMI_WRITE("workSta.coll_cnt.val=%d", Get_REMAIN());
- if (device_status.autotakepic == 0)
- {
- HMI_WRITE("sysTest.auto_flag.txt=\"\"");
- }
- // 显示版本号
- HMI_WRITE("workSta.ver.txt=\"Ver : %s-%s\"", VERSION_NUM, device_status.driver_4g);
- HMI_WRITE("sysSet.datt.val=%d", syscfg.dattim);
- HMI_WRITE("sysSet.pho.val=%d", syscfg.photim);
- // rt_kprintf("device_status.driver >>> %s\n" , device_status.driver );
- // switch(workmode)
- // {
- // case RunLight_wx:
- // HMI_WRITE("workSta.t1.txt=\"工作状态 - 光控\"");
- // break;
- // case RunTime_wx:
- // HMI_WRITE("workSta.t1.txt=\"工作状态 - 时控\"");
- // break;
- // default:break;
- // }
- ReflashWorkSta();
- /**
- * @brief 250925 禁用部分控件
- *
- */
- // HMI_WRITE("workSta.t11.aph=%d", 100);
- // HMI_WRITE("workSta.ta3.aph=%d", 100);
- // HMI_WRITE("workSta.ta4.aph=%d", 100);
- // HMI_WRITE("workSta.env_tem.aph=%d", 100);
- // HMI_WRITE("workSta.env_hum.aph=%d", 0);
- // HMI_WRITE("workSta.t10.aph=%d", 0);
- HMI_WRITE("sysTest.t3.aph=%d", 0);
- HMI_WRITE("sysTest.scm.x=%d", 800);
- // HMI_WRITE("clockSet.h0.y=%d", 500);
- // HMI_WRITE("clockSet.h1.y=%d", 500);
- // HMI_WRITE("clockSet.sw_temp.y=%d", 500);
- HMI_WRITE("clockSet.wm0.y=%d", 500);
- HMI_WRITE("clockSet.t3.y=%d", 500);
- // HMI_WRITE("clockSet.t15.y=%d", 500);
- // HMI_WRITE("clockSet.t11.aph=%d", 0);
- // HMI_WRITE("clockSet.t14.aph=%d", 0);
- // HMI_WRITE("clockSet.temp_limup.aph=%d", 0);
- // HMI_WRITE("clockSet.temp_limdn.aph=%d", 0);
- // HMI_WRITE("clockSet.t9.aph=%d", 0);
- // HMI_WRITE("clockSet.t10.aph=%d", 0);
- HMI_WRITE("sysTest.t7.txt=\"卷带测试\"");
- char temp_c[6] = {0};
- char humi_c[6] = {0};
- get_now_temphumi(temp_c , humi_c);
- if(temp_c != NULL && humi_c != NULL)
- {
- HMI_WRITE("workSta.env_hum.txt=\"%s\"", humi_c);
- HMI_WRITE("workSta.env_tem.txt=\"%s\"", temp_c);
- }
-
- HMI_WRITE("workSta.t4.txt=\"%s\"", "卷带余量");
-
- /**
- * @brief 250925 禁用部分控件
- *
- */
- }
- /**********************************************************************/
- }
- }
- extern char *makeJson_Config_BDH(char *deviceId);
- extern void RunModeSet0(void);
- extern void Clear_WorkDay(void);
- extern void prase_test_cmd(char *cmd);
- extern void ex_set_sensor(char *cmd);
- extern void ex_read_sensor(char *cmd);
- extern void prase_paraset(char *cmd);
- extern uint16_t RayTigCnt;
- /**
- * @brief 解码HMI指令
- *
- */
- static void HMI_Decode(void)
- {
- time_t now = time(RT_NULL);
- static struct tm tm;
- gmtime_r(&now, &tm);
- char *json_temp;
- if (device_status.refresh_num == 0)
- {
- device_status.refresh_num = 10;
- }
- //rt_kprintf("HMI_Decode > %s \n" , rx_buffer );
- if (strstr(rx_buffer, "getFullData") != NULL )
- {
- CMD_getFullData();
- }
- 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, "systest") != NULL) && (strstr(rx_buffer, "touch") != NULL))
- {
- prase_test_cmd(rx_buffer);
- }
- else if (strstr(rx_buffer, "saveSensor") != NULL) // 保存温湿度传感器参数
- {
- ex_set_sensor(rx_buffer);
- }
- else if (strstr(rx_buffer, "SensorReadTest") != NULL) // 读取温湿度进行测试
- {
- ex_read_sensor(rx_buffer);
- }
- else if (strstr(rx_buffer, "PageSensor") != NULL) // 刷新界面
- {
- sex_enread = 1;
- }
- else if (strstr(rx_buffer, "ExitSensorpage") != NULL) // 刷新界面
- {
- sex_enread = 0;
- }
- else if (strstr(rx_buffer, "sw_temp=ON") != NULL) // 开温控
- {
- if (ef_cfged)
- {
- // ef_get_env_blob("limlt", &limit, sizeof(limit), NULL);
- limit.temhumEN = ON;
- LOG_W("limit SET %d", ef_set_env_blob("limit", &limit, sizeof(Limit)));
- LOG_W("开温控");
- }
- }
- else if (strstr(rx_buffer, "sw_temp=OFF") != NULL) // 关温控
- {
- if (ef_cfged)
- {
- // ef_get_env_blob("limlt", &limit, sizeof(limit), NULL);
- limit.temhumEN = OFF;
- LOG_W("limit SET %d", ef_set_env_blob("limit", &limit, sizeof(Limit)));
- LOG_W("关温控");
- }
- }
- else if (strstr(rx_buffer, "sw_lux=ON") != NULL) // 开光控
- {
- if (ef_cfged)
- {
- // ef_get_env_blob("limlt", &limit, sizeof(limit), NULL);
- limit.LuxEN = ON;
- if (limit.LuxTime == 0)
- {
- limit.LuxTime = gktime_def;
- }
- LOG_W("limit SET %d", ef_set_env_blob("limit", &limit, sizeof(Limit)));
- LOG_W("开光控");
- }
- }
- else if (strstr(rx_buffer, "sw_lux=OFF") != NULL) // 关光控
- {
- if (ef_cfged)
- {
- // 关温控ef_get_env_blob("limlt", &limit, sizeof(limit), NULL);
- limit.LuxEN = OFF;
- LOG_W("limit SET %d", ef_set_env_blob("limit", &limit, sizeof(Limit)));
- LOG_W("关光控");
- }
- }
- else if (strstr(rx_buffer, "sw_rain=ON") != NULL) // 开雨控
- {
- if (ef_cfged)
- {
- // ef_get_env_blob("limlt", &limit, sizeof(limit), NULL);
- limit.RainEN = ON;
- LOG_W("limit SET %d", ef_set_env_blob("limit", &limit, sizeof(Limit)));
- LOG_W("开雨控");
- }
- }
- else if (strstr(rx_buffer, "sw_rain=OFF") != NULL) // 关雨控
- {
- if (ef_cfged)
- {
- // ef_get_env_blob("limlt", &limit, sizeof(limit), NULL);
- limit.RainEN = OFF;
- LOG_W("limit SET %d", ef_set_env_blob("limit", &limit, sizeof(Limit)));
- LOG_W("关雨控");
- }
- }
- else if (strstr(rx_buffer, "wm0=INR") != NULL) // 切换工作模式为间隔
- {
- if (ef_cfged)
- {
- syscfg.en_tigmode = 0;
- ef_set_env_blob("syscfg", (const char *)&syscfg, sizeof(syscfg));
- rt_kprintf("Change Workmod Inr OK\n");
- }
- }
- else if (strstr(rx_buffer, "wm0=TIG") != NULL) // 切换工作模式为触发
- {
- if (ef_cfged)
- {
- syscfg.en_tigmode = 1;
- ef_set_env_blob("syscfg", (const char *)&syscfg, sizeof(syscfg));
- rt_kprintf("Change Workmod Tig OK\n");
- }
- }
- else if (strstr(rx_buffer, "save") != NULL && strstr(rx_buffer, "Set") != NULL)
- {
- prase_paraset(rx_buffer);
- }
- else if (strstr(rx_buffer, "ResetCollCnt") != NULL)
- {
- RTC_SET_TigVal(0);
- HMI_WRITE("workSta.coll_cnt.val=%d", Get_REMAIN());
- Recode_e_code(e_CNT_RESET, 1, "屏幕清空计数");
- }
- else if (strstr(rx_buffer, "ResetRunSta") != NULL)
- {
- LOG_W("工作状态已复位");
- Recode_e_code(e_ResetRunStaManual, 0, "屏幕操作:工作状态已复位");
- // RunModeSet0();
- Clear_WorkDay();
- LOG_W("Reboot now");
- HMI_WRITE("workSta.tips.txt=\"工作状态已复位 即将自动重启\"");
- rt_thread_mdelay(5000);
- HMI_WRITE("rest");
- rt_hw_cpu_reset();
- }
- // 打开灯管
- 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
- }
- // 关闭灯管
- 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
- }
- // 切换大数据平台
- else if (strstr(rx_buffer, "8.136.98.49") != NULL)
- {
- memset(device_status.json_w_platform, 0, sizeof(device_status.json_w_platform));
- rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
- ef_set_env_blob("platform", &device_status.mqttcfg1, sizeof(device_status.mqttcfg1));
- // 给RTU发送切换指令
- if (strstr(device_status.project, "DTU_CBD") != NULL)
- {
- DTU_Write("%s", makeJson_platform("8.136.98.49"));
- rt_free(makeJson_platform("8.136.98.49"));
- rt_thread_delay(1000);
- }
- // 2022/06/23,add:
- rt_sprintf(device_status.json_w_platform, "屏幕操作:切换平台:8.136.98.49,操作时间:%s", device_status.stamp);
- json_temp = makeJson_Warn(device_status.json_w_platform, "切换平台");
- ef_set_env_blob("json_w_platform", &device_status.json_w_platform, sizeof(device_status.json_w_platform)); // 将修改屏幕参数操作记录保存到Flash中
- if (atoi(device_status.net) == 0)
- DTU_Write("%s", json_temp);
- rt_free(json_temp);
- rt_thread_delay(1000);
- MA_save();
- }
- else if (strstr(rx_buffer, "120.27.222.26") != NULL)
- {
- memset(device_status.json_w_platform, 0, sizeof(device_status.json_w_platform));
- rt_sprintf(device_status.mqttcfg1, "120.27.222.26");
- ef_set_env_blob("platform", &device_status.mqttcfg1, sizeof(device_status.mqttcfg1));
- // 给RTU发送切换指令
- if (strstr(device_status.project, "DTU_CBD") != NULL)
- {
- DTU_Write("%s", makeJson_platform("120.27.222.26"));
- rt_free(makeJson_platform("120.27.222.26"));
- rt_thread_delay(1000);
- }
- // 2022/06/23,add:
- rt_sprintf(device_status.json_w_platform, "屏幕操作:切换平台:120.27.222.26,操作时间:%04d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
- json_temp = makeJson_Warn(device_status.json_w_platform, "切换平台");
- ef_set_env_blob("json_w_platform", &device_status.json_w_platform, sizeof(device_status.json_w_platform)); // 将修改屏幕参数操作记录保存到Flash中
- if (atoi(device_status.net) == 0)
- DTU_Write("%s", json_temp);
- rt_free(json_temp);
- rt_thread_delay(1000);
- MA_save();
- }
- // 恢复出厂设置电池
- 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();
- }
- // 1.0
- else if ((strstr(rx_buffer, "SwversionVB") != NULL))
- {
- if (device_status.dtype != dt_BZY || device_status.version_type != vt_XCT)
- {
- LOG_D("设置版本类型:B 小虫体 SwversionVB");
- device_status.dtype = dt_BZY;
- device_status.version_type = vt_XCT;
- rt_kprintf(" dtype = %d SET %d vtype = %d SET %d\n\n",
- device_status.dtype,
- ef_set_env_blob("dtype", &device_status.dtype, sizeof(device_status.dtype)),
- device_status.version_type,
- ef_set_env_blob("version_type", &device_status.version_type, sizeof(device_status.version_type)));
- DTU_Write("SwversionV11");
- 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.switchHeat.val=%d",device_status.heat_status);
- }
- // 立即上传
- else if (strstr(rx_buffer, "uploaddata") != RT_NULL)
- {
- UpLoad_Data(0);
- rt_kprintf("UpLoad_Data Mark G \n\n"); // 串口屏触发
- }
- 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, "getEcodeData") != NULL)
- {
- getEcodeData(0);
- }
- else if (strstr(rx_buffer, "clearEcodeData") != NULL)
- {
- ef_log_clean();
- }
- static char cnt = 0;
- if(cnt++ >= 10)
- {
- CMD_getFullData();
- cnt = 0;
- }
- rt_thread_mdelay(100);
-
- }
- // 入口函数-电机控制及
- /**
- * @brief 控制电机的线程
- *
- * @param parameter -
- */
- static void Ctr_Mortor_entry(void *parameter)
- {
- // rt_int16_t motor_current = 0; //
- 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
- // int current_t[200];
- /*孢子仪拍照数量*/
- rt_uint16_t photo_setup = 0;
- #if Color_EN == 1
- ctr_Color_board(RESET, 1200);
- #endif
- while (1)
- {
- #if Color_EN == 1
- // 定时执行把粘虫板更换的操作,每天一次
- if (device_status.run_sta == 5)
- {
- rt_thread_delay(2000);
- device_status.run_sta = 0;
- ctr_Color_board(OPEN, 1000);
- }
- #endif
- time_t time_reset12V;
- time(&time_reset12V);
- static struct tm alarm_reset12V;
- alarm_reset12V = *localtime(&time_reset12V);
- if ((alarm_reset12V.tm_hour) == 7 && (alarm_reset12V.tm_min == 19) && (alarm_reset12V.tm_sec == 50))
- {
- ctr_RTU_DTU(OFF);
- rt_thread_delay(1000 * 10);
- ctr_RTU_DTU(ON);
- }
- 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)
- {
- device_status.test_flag = 0;
- ctr_led(ON);
- // 打开补光灯
- if (photo_led_sec == 300 && device_status.version_type == 48)
- {
- DTU_Write("takephoto.mp3");
- // 延时
- rt_thread_delay(1000);
- LOG_I("测试拍照!");
- Hk_Take_io(4);
- char *takephotojson = makeJson_takephoto();
- DTU_Write("%s", takephotojson);
- rt_free(takephotojson);
- }
- // 15S后执行拍照
- else if (photo_led_sec == 750 && device_status.version_type != 48)
- {
- DTU_Write("takephoto.mp3");
- // 延时
- rt_thread_delay(1000);
- LOG_I("测试拍照!");
- Hk_Take_io(5);
- char *takephotojson = makeJson_takephoto();
- DTU_Write("%s", takephotojson);
- rt_free(takephotojson);
- }
- photo_led_sec--;
- if (photo_led_sec == 0 && device_status.version_type == 48) // 4800W相机
- {
- ctr_led(OFF);
- photo_led_sec = 900;
- device_status.photo_ws = 0;
- HMI_WRITE_Force("sysTest.switchPhoto.val=0");
- HMI_WRITE_Force("sysTest.switchFill.val=0");
- }
- else if (photo_led_sec == 550 && device_status.version_type != 48)
- {
- ctr_led(OFF);
- photo_led_sec = 900;
- device_status.photo_ws = 0;
- HMI_WRITE_Force("sysTest.switchPhoto.val=0");
- HMI_WRITE_Force("sysTest.switchFill.val=0");
- }
- }
- /*对焦拍照*/
- if (device_status.autotakepic == 1)
- {
- uint8_t camstacnt = 0;
- while (device_status.camsta)
- {
- stopreflashTakePhoto = 1;
- LOG_I("相机未连接!!!");
- HMI_WRITE("workSta.workinfo.txt=\"相机未连接... %ds后跳过等待\"", 122 - camstacnt);
- rt_thread_delay(1000);
- if (camstacnt++ > 120)
- {
- Recode_e_code(e_cam_offline, 0, "相机拍照超时");
- break;
- }
- }
- stopreflashTakePhoto = 0;
- DTU_Write("autotakephoto");
- HMI_WRITE_Force("sysTest.auto_flag.txt=\"Autotest\"");
- // 打开步进电机驱动器电源
- ctr_lamp(ON, 1);
- // 打开补光灯
- ctr_led(ON);
- // 电机向下运动
- ctr_Motor_Driver(1, 1, 1000000, (MAX_StepTime * 1000) / 50);
- rt_thread_delay(1000);
- LOG_I("电机到达下方!!!");
- Hk_Take_io(6);
- 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)
- {
- ctr_lamp(ON, 1);
- HMI_WRITE_Force("sysTest.result.txt=\"对焦拍照触发次数:%d\"", photo_setup);
- HMI_WRITE_Force("sysTest.auto_flag.txt=\"AutoTeststart\"");
- rt_pin_write(Motor_EN, 0);
- beep_set(0, 0); // 驱动器失能
- Hk_Take_io(7); // 触发拍照
- rt_thread_mdelay(200); // 10ms
- rt_pin_write(Motor_EN, 1);
- beep_set(1000000, 200000); // 驱动器使能
- rt_thread_mdelay(100); // 100ms
- beep_set(0, 0); // 驱动器失能
- rt_pin_write(Motor_EN, 0);
- if (photo_setup > 60) // 限制最大拍照数量
- {
- ctr_led(OFF);
- device_status.autotakepic = 0;
- rt_pin_write(Motor_EN, 0); // 驱动器失能
- beep_set(1000000, 0); // 2kzh - 50%
- HMI_WRITE_Force("sysTest.switchAutopic.val=%d", 0);
- HMI_WRITE_Force("sysTest.auto_flag.txt=\"\"");
- ctr_lamp(OFF, 0);
- Recode_e_code(e_StepUp_Fail, 4, "步进超时:最大拍照数量限制"); // 最大拍照数量限制记录
- break;
- }
- photo_setup++;
- LOG_I("对焦拍照:%d", photo_setup);
- Check_TestFree();
- }
- ctr_lamp(OFF, 1);
- DTU_Write("takephotodone");
- ctr_led(OFF);
- rt_pin_write(Motor_EN, 0); // 驱动器失能
- beep_set(1000000, 0); // 2kzh - 50%
- HMI_WRITE_Force("sysTest.switchAutopic.val=%d", 0);
- device_status.autotakepic = 0;
- photo_setup = 0;
- HMI_WRITE_Force("sysTest.auto_flag.txt=\"\"");
- HMI_WRITE_Force("sysTest.switchAutopic.val=%d", 0);
- // 关闭步进电机驱动器电源
- ctr_lamp(OFF, 0);
- // 重置运行标志位
- device_status.run_sta = 0;
- ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
- }
- if (device_status.fsl_sw == 1)
- {
- ctr_Petroleum_jelly(10);
- }
- // 一键测试
- if (device_status.auto_test_sw == 1)
- {
- if (device_status.version_type == vt_BZY)
- {
- 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=\"\"");
- }
- }
- rt_thread_delay(100);
- }
- }
- /*屏幕写数据*/
- /**
- * @brief 创建刷新屏幕显示和电机控制的线程
- *
- * @return int 结果
- */
- int Hmi_Fresh(void)
- {
- // 初始化串口4
- rt_err_t ret = RT_EOK;
- /* 创建线程*/
- 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);
- }
- else
- {
- ret = RT_ERROR;
- }
- return ret;
- }
- INIT_APP_EXPORT(Hmi_Fresh);
- extern RTC_DateTypeDef GetDate;
- extern uint8_t ReFlash_RTC(void);
- /**
- * @brief 从ef中取出保存的参数
- *
- * 若未保存则设置默认值
- * 若保存过则读取保存值
- *
- */
- void Check_ParamConfig(void)
- {
- uint16_t log_en_inr = 60; // 打印log的速度 数值越小 打印越频繁
- static int16_t log_en_cnt = -1;
- 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));
- ef_get_env_blob("bdhid", (char *)bdhid, sizeof(bdhid), NULL); // 读保存的北大荒ID
- 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.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 = 20; // 数据上传间隔
- device_status.ds = 1; // 设备状态
- device_status.update_flag = 0;
- /*孢子仪*/
- device_status.collecting_sh1 = 20;
- device_status.collecting_eh1 = 4;
- 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;
- sprintf(device_status.driver, "%s", VERSION_NUM);
- 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)); //
- 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("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); // 运行状态
- device_status.light_over_tim = device_status.sunBar * 3600; // 光控计数
- /**
- * 241216 新增参数
- */
- // ef_get_env_blob("photim", &device_status.photim, sizeof(device_status.photim), NULL); // 照片上传间隔
- //
- // if(device_status.dattim == 0)
- // {
- // device_status.dattim = 60; // 默认值
- // ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim));
- // }
- // if(device_status.photim == 0)
- // {
- // device_status.photim = 240; // 默认值
- // ef_set_env_blob("photim", &device_status.photim, sizeof(device_status.photim));
- // }
- /**
- * 241216 新增参数
- */
- device_status.work_done = 0;
- // 工作完成标志位
- // if (device_status.dattim == 0)
- // {
- // device_status.dattim = 20;
- // }
- /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
- if (device_status.dtype != 7)
- {
- device_status.dtype = 3;
- }
- else if (device_status.version_type != vt_BZY && device_status.version_type != vt_BZY_JD && device_status.version_type != vt_XCT)
- {
- device_status.version_type = vt_XCT;
- }
- if (device_status.version_type == 0)
- {
- app_partion_backup(); // 固件备份至df_area
- device_status.version_type = 41;
- rt_sprintf(device_status.driver, "%s", VERSION_NUM);
- ef_set_env_blob("version_type", &device_status.version_type, sizeof(device_status.version_type));
- }
- else if (device_status.version_type == 6)
- {
- // 打开相机供电;
- // ctr_Camera_Power(ON);
- rt_sprintf(device_status.driver, "%s", VERSION_NUM);
- }
- else if (device_status.version_type == vt_BZY || device_status.version_type == vt_BZY_JD)
- {
- // rt_sprintf(device_status.driver, "%s", VERSION_BZY);
- // 异常处理:20230331,修复第一段开始时间等于第二段结束时间的情况
- if (device_status.collecting_eh1 == device_status.collecting_eh2 && device_status.collecting_sh2 != device_status.collecting_eh2)
- {
- device_status.collecting_eh2 = device_status.collecting_sh2 + 2;
- }
- }
- device_status.dtype = dt_BZY;
- device_status.version_type = vt_XCT;
- rt_kprintf(" dtype = %d vtype = %d \n\n", device_status.dtype, device_status.version_type);
- if (device_status.version_type == vt_XCT)
- {
- rt_kprintf("Version : %s %s\n\n", VERSION_NUM, device_status.driver_compile);
- }
- /*定制三色光源*/
- #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", device_status.dattim);
- }
- // 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));
- device_status.update_flag = 1;
- ymodem_ota(1, 0);
- }
- else
- {
- ef_cfged = 1;
- 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);
-
- #if Color_EN == 1
- Control_clear();
- Control_heat();
- #endif
- if (device_status.dtype != dt_BZY)
- {
- Control_clear();
- Control_heat();
- }
- dtu_data_play();
- sht30_collect();
- #if SENSOR_EN == 1
- // mb_master_samlpe();
- #endif
- #if ROBOT_EN == 0
- uint16_t connect_num = 0;
- // 等待联网,
- /**
- * @brief 250414 新增开机后先给外设供电
- *
- */
- CTL_5V1(); // 485 + 5V + 3.3V2
- CTL_SENSOR_12V1(); // 传感器
- ctr_RTU_DTU(ON); // RTU上电
- /**
- * @brief 250414 新增开机后先给外设供电
- *
- */
- while (atoi(device_status.net) == 1 && connect_num < 30) // 此处需要修改为30
- {
- ctr_RTU_DTU(ON); // 联网的时候 肯定要给rtu上电
- 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\"");
- SendReadInfo('F');
- rt_thread_mdelay(1000);
- connect_num++;
- if (chk_log_time || 1)
- {
- LOG_I("联网中......%d", connect_num);
- }
- }
- connect_num = 0;
- while (atoi(device_status.net) == 0)
- {
- if (SendReadInfo('C') == res_ok)
- {
- connect_num++;
- rt_kprintf("connect_num %d GetDate.Year %d\n", connect_num, GetDate.Year);
- }
- rt_thread_mdelay(2000);
- ReFlash_RTC();
- if (connect_num > 15)
- {
- break;
- }
- else if (connect_num > 5 && GetDate.Year > 24 && GetDate.Year < 66)
- {
- break;
- }
- }
- if (device_status.version_type == 6)
- device_status.timeSwitch = 1;
- DTU_Write("%s", makeJson_Warn("turnon", "device_stm32"));
- rt_thread_mdelay(1000);
- #endif
- }
- }
- /**
- * @brief 将某些参数回复到默认值
- *
- */
- 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 = 30;
- device_status.collecting_sh1 = 20;
- device_status.collecting_eh1 = 7;
- device_status.collecting_sh2 = 14;
- device_status.collecting_eh2 = 16;
- if (device_status.dtype == 3)
- {
- device_status.clt_time = 10; // 收集时间
- // device_status.dattim = 20; // 数据上传间隔
- #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)); // 震动时间
- }
- 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);
- }
- /**
- * @brief 将某些参数回复到默认值
- *
- */
- void ResetParamDefault_DC(void)
- {
- // 将温度数据设置为-15摄氏度,以便上传的数据中包含温控数据
- rt_sprintf(device_status.tempture, "%d", -15);
- device_status.clt_time = 10; // 收集时间
- // device_status.dattim = 20; // 数据上传间隔
- #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;
- 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);
- }
- }
- }
- /**
- * @brief 切换调试输出口到串口4(串口屏)
- *
- */
- void Debug_log_ON(void)
- {
- rt_console_set_device("uart4");
- finsh_set_device("uart4");
- }
- /**
- * @brief 默认使用 调试口输出到板载端子
- *
- */
- 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);
|