From d1a6d12878200e5247cedc276463b7cee997ed6f Mon Sep 17 00:00:00 2001 From: zzh Date: Wed, 18 Jun 2025 10:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=A1=E5=8F=B7=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/main.c b/main.c index 78c39ac..1f3268b 100644 --- a/main.c +++ b/main.c @@ -82,6 +82,12 @@ int searchTimeNew=0; int lightsnNum=0; int mqtt_port=1883; +static time_t last_2323_time = 0; // 记录上次收到0x2323的时间 +static bool waiting_for_4646 = false; // 是否在等待0x4646 + +// 函数声明 +void *thread_timeout_check(void *arg); + int getLedOtaVersion(char *filename); int getApOtaVersion(char *filename,char *modename); void hmacsha1(char *key,char* data,char *signbase64,int signbase64_len); @@ -1280,11 +1286,15 @@ void *thread_uart_recv_ack(void *arg){ prctl(PR_SET_NAME, "uart_ack"); uint16_t parm_ack; int ret=0; + while(1){ ret=uart_data_receive_ack(&uartSend,&parm_ack); if(ret>0){ LOG_I("ack:%x\n",parm_ack); if(parm_ack==0x2323){ + // 记录收到0x2323的时间,并设置等待0x4646标志 + time(&last_2323_time); + waiting_for_4646 = true; if(isLightOn){ char *flash=mqtt_parm.msg_flash; char *light=mqtt_parm.msg_lightDuration; @@ -1406,8 +1416,12 @@ void *thread_uart_recv_ack(void *arg){ isLabelUp=false; } }else if(parm_ack==0x4646){ + last_2323_time = 0; // 重置时间 + waiting_for_4646 = false; // 重置等待状态 isSendComEnd=true; }else if(parm_ack==0x4f4f){ + last_2323_time = 0; // 重置时间 + waiting_for_4646 = false; // 重置等待状态 isSendComEnd=true; if(isOtaEnable){ otaCount++; @@ -1419,12 +1433,18 @@ void *thread_uart_recv_ack(void *arg){ } } }else if(parm_ack==0x5252){ + last_2323_time = 0; // 重置时间 + waiting_for_4646 = false; // 重置等待状态 uart_data_receive_version(&uartSend); isSendComEnd=true; isAPOtaSuccess=true; }else if(parm_ack==0x5454){ + last_2323_time = 0; // 重置时间 + waiting_for_4646 = false; // 重置等待状态 isSendComEnd=true; }else if(parm_ack==0x4848){ + last_2323_time = 0; // 重置时间 + waiting_for_4646 = false; // 重置等待状态 isAPBack=true; } } @@ -2070,6 +2090,7 @@ int main(int argc, char *argv[]) int getTimeCount=0; char *readresult=NULL; char networktype[32]={0}; + pthread_t timeout_thread; // 添加超时检测线程变量 LOG_I("version:%s\n",softwareVersion); system("insmod /system/lib/modules/wk2xxx_spi.ko"); @@ -2179,6 +2200,16 @@ int main(int argc, char *argv[]) pthread_detach(pt_removelog); } + // 创建超时检测线程 + ret = pthread_create(&timeout_thread, NULL, thread_timeout_check, NULL); + if(ret!=0){ + LOG_I("pthread_create timeout_check fail\n"); + system("reboot"); + }else{ + LOG_I("pthread_create timeout_check success\n"); + pthread_detach(timeout_thread); + } + ret = pthread_create(&pt_ota,NULL,thread_ota,NULL); if(ret!=0){ LOG_I("pthread_create ota fail\n"); @@ -2276,6 +2307,31 @@ int main(int argc, char *argv[]) } } #endif + return 0; } +// 超时检测线程 +void *thread_timeout_check(void *arg) { + prctl(PR_SET_NAME, "timeout_check"); + + while(1) { + if(last_2323_time != 0 && waiting_for_4646) { // 只有在等待0x4646时才检查超时 + time_t current_time; + time(¤t_time); + if(difftime(current_time, last_2323_time) >= 10.0) { // 超过10秒 + LOG_I("thread_timeout_check: Timeout after receiving 0x2323, no 0x4646 received, setting isSendComEnd to 1\n"); + isSendComEnd = 1; + last_2323_time = 0; // 重置时间 + waiting_for_4646 = false; // 重置等待状态 + isLightEnable = 1; // 重置点亮使能标志 + isLightOn = false; // 重置点亮状态 + isLightOnByRule = false; // 重置规则点亮状态 + isLabelUp = false; // 重置标签更新状态 + } + } + usleep(100*1000); // 每100ms检查一次 + } + return NULL; +} +