广播点亮之前重置sn变量,防止被3015污染
This commit is contained in:
parent
170c437364
commit
97cc10364b
108
main.c
108
main.c
@ -99,6 +99,54 @@ void doCommand_help(int argc, char *argv[])
|
||||
"************************************************************\r\n");
|
||||
}
|
||||
|
||||
static int safe_rename(const char *src, const char *dst) {
|
||||
if (rename(src, dst) != 0) {
|
||||
LOG_E("Failed to rename %s to %s: %s", src, dst, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int safe_remove_dir(const char *path) {
|
||||
if (rmdir(path) != 0) {
|
||||
LOG_E("Failed to remove directory %s: %s", path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int safe_remove_file(const char *path) {
|
||||
if (unlink(path) != 0) {
|
||||
LOG_E("Failed to remove file %s: %s", path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int safe_mkdir(const char *path) {
|
||||
if (mkdir(path, 0755) != 0 && errno != EEXIST) {
|
||||
LOG_E("Failed to create directory %s: %s", path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 安全的命令执行函数
|
||||
static int safe_exec_cmd(const char *cmd) {
|
||||
// 检查命令是否包含危险字符
|
||||
if (strstr(cmd, ";") || strstr(cmd, "|") || strstr(cmd, "&") || strstr(cmd, "..")) {
|
||||
LOG_E("Dangerous command detected: %s", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = system(cmd);
|
||||
if (ret != 0) {
|
||||
LOG_E("Command failed: %s, error: %s", cmd, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void doCommand(int argc, char *argv[])
|
||||
{
|
||||
//sendData(argv[1],argv[0]);
|
||||
@ -1576,6 +1624,56 @@ void *thread_remove_duplicate_tag(void *arg){
|
||||
}
|
||||
}
|
||||
|
||||
// 检查文件是否存在的函数
|
||||
static int file_exists(const char *path) {
|
||||
struct stat st;
|
||||
return (stat(path, &st) == 0);
|
||||
}
|
||||
|
||||
// 检查压缩包是否解压完成
|
||||
static int check_unzip_complete(const char *zip_file) {
|
||||
char cmd[256];
|
||||
char last_file[256] = {0};
|
||||
FILE *fp;
|
||||
|
||||
// 获取压缩包中最后一个文件
|
||||
snprintf(cmd, sizeof(cmd), "unzip -l %s | tail -n 1 | awk '{print $4}'", zip_file);
|
||||
fp = popen(cmd, "r");
|
||||
if (fp == NULL) {
|
||||
LOG_E("Failed to execute command: %s", cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fgets(last_file, sizeof(last_file), fp) == NULL) {
|
||||
LOG_E("Failed to get last file from zip");
|
||||
pclose(fp);
|
||||
return -1;
|
||||
}
|
||||
pclose(fp);
|
||||
|
||||
// 去除换行符
|
||||
last_file[strcspn(last_file, "\n")] = 0;
|
||||
|
||||
// 检查文件是否存在
|
||||
char full_path[512];
|
||||
snprintf(full_path, sizeof(full_path), "tx_ota/%s", last_file);
|
||||
|
||||
int retry_count = 0;
|
||||
const int max_retries = 30; // 最多等待30秒
|
||||
|
||||
while (!file_exists(full_path) && retry_count < max_retries) {
|
||||
usleep(1000000); // 等待1秒
|
||||
retry_count++;
|
||||
}
|
||||
|
||||
if (retry_count >= max_retries) {
|
||||
LOG_E("Timeout waiting for unzip to complete");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *thread_mqtt_recv(void *arg){
|
||||
prctl(PR_SET_NAME, "mqtt_recv");
|
||||
char payload[1024]={0};
|
||||
@ -1818,12 +1916,18 @@ void *thread_mqtt_recv(void *arg){
|
||||
if(isLightEnable){
|
||||
mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"ok",1,productid);
|
||||
|
||||
// 设置规则并广播点亮
|
||||
// 设置规则并广播点亮,重置变量,防止被3015污染
|
||||
isSendComEnd=false;
|
||||
isLightOn=true;
|
||||
isLightOn=false;
|
||||
isLightOnByRule=true; // 使用规则控制
|
||||
isLabelUp=false;
|
||||
|
||||
memset(lightsn1, 0, sizeof(lightsn1));
|
||||
memset(lightsn2, 0, sizeof(lightsn2));
|
||||
memset(lightsn3, 0, sizeof(lightsn3));
|
||||
memset(lightsn4, 0, sizeof(lightsn4));
|
||||
memset(lightsn5, 0, sizeof(lightsn5));
|
||||
|
||||
// 设置label1和label2不参与匹配
|
||||
strcpy(mqtt_parm.msg_label1Rule, "04"); // ∅ 不参与匹配
|
||||
strcpy(mqtt_parm.msg_label2Rule, "04"); // ∅ 不参与匹配
|
||||
|
||||
Loading…
Reference in New Issue
Block a user