增加信号超时检测

This commit is contained in:
zzh 2025-06-18 10:03:50 +08:00
parent 0c8b097636
commit d1a6d12878

56
main.c
View File

@ -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(&current_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;
}