Commit a9d72472 authored by DESKTOP-MC5UL36\dell's avatar DESKTOP-MC5UL36\dell

hardware_iic读取失败会导致不上线,python文件下载的bug

parent dcbd8165
......@@ -77,11 +77,9 @@ int hardware_iic_write(uint8_t device_addr, uint8_t reg_addr, const uint8_t *dat
my_zlog_warn("错误:向设备 0x%02X 寄存器 0x%02X 写入数据失败。", device_addr, reg_addr);
break;
}
pthread_mutex_unlock(&i2c_mutex);
ret = 0; // 成功
ret = 0; // 成功
}while(0);
pthread_mutex_unlock(&i2c_mutex);
// my_zlog_info("成功向设备 0x%02X 寄存器 0x%02X 写入 %d 字节数据。", device_addr, reg_addr, len);
return ret;
}
......
......@@ -290,79 +290,78 @@ int go_deploy_check_and_update(void) {
if (access(target_file_path, F_OK) == 0) {
chmod(target_file_path, 0777);
}
}
// ---------------------------------------------------------
// 处理 video_proxy.7z
// ---------------------------------------------------------
cJSON *pythonUrl = cJSON_GetObjectItem(moreInfo, "pythonUrl");
if (pythonUrl && cJSON_IsString(pythonUrl) && strlen(pythonUrl->valuestring) > 0) {
char target_7z_path[512];
snprintf(target_7z_path, sizeof(target_7z_path), "%s/video_proxy.7z", target_dir);
int need_download_7z = 0;
// 检查文件是否存在
if (access(target_7z_path, F_OK) != 0) {
my_zlog_info("video_proxy.7z not found, need download.");
need_download_7z = 1;
} else {
// 检查 Hash (使用 pythonHash)
cJSON *pythonHash = cJSON_GetObjectItem(moreInfo, "pythonHash");
if (pythonHash && cJSON_IsString(pythonHash)) {
char local_hash[65] = {0};
if (calculate_file_hash(target_7z_path, local_hash) == 0) {
if (strcasecmp(local_hash, pythonHash->valuestring) != 0) {
my_zlog_info("7z Hash mismatch. Local: %s, Cloud: %s. Re-downloading...", local_hash, goHash->valuestring);
need_download_7z = 1;
// 处理 video_proxy.7z
cJSON *pythonUrl = cJSON_GetObjectItem(moreInfo, "pythonUrl");
if (pythonUrl && cJSON_IsString(pythonUrl) && strlen(pythonUrl->valuestring) > 0) {
char target_7z_path[512];
snprintf(target_7z_path, sizeof(target_7z_path), "%s/video_proxy.7z", target_dir);
int need_download_7z = 0;
// 检查文件是否存在
my_zlog_info("target_7z_path:%s",target_7z_path);
if (access(target_7z_path, F_OK) != 0) {
my_zlog_info("video_proxy.7z not found, need download.");
need_download_7z = 1;
} else {
// 检查 Hash (使用 pythonHash)
cJSON *pythonHash = cJSON_GetObjectItem(moreInfo, "pythonHash");
if (pythonHash && cJSON_IsString(pythonHash)) {
char local_hash[65] = {0};
if (calculate_file_hash(target_7z_path, local_hash) == 0) {
if (strcasecmp(local_hash, pythonHash->valuestring) != 0) {
my_zlog_info("7z Hash mismatch. Local: %s, Cloud: %s. Re-downloading...", local_hash, goHash->valuestring);
need_download_7z = 1;
} else {
my_zlog_info("7z Hash verified.");
}
} else {
my_zlog_info("7z Hash verified.");
my_zlog_error("Failed to calculate 7z local hash");
need_download_7z = 1;
}
} else {
my_zlog_error("Failed to calculate 7z local hash");
need_download_7z = 1;
my_zlog_warn("goHash missing for 7z check");
}
} else {
my_zlog_warn("goHash missing for 7z check");
}
}
if (need_download_7z) {
my_zlog_info("Downloading 7z from: %s", pythonUrl->valuestring);
if (download_file(pythonUrl->valuestring, target_7z_path) == 0) {
my_zlog_info("Download 7z success. Preparing to extract...");
// 检查 7z 是否安装
if (system("which 7z > /dev/null 2>&1") != 0) {
my_zlog_info("7z not found. Installing p7zip-full...");
// 尝试安装 p7zip-full (Ubuntu)
int install_ret = system("sudo apt-get update && sudo apt-get install -y p7zip-full");
if (install_ret != 0) {
my_zlog_error("Failed to install p7zip-full, return code: %d", install_ret);
} else {
my_zlog_info("p7zip-full installation completed successfully.");
if (need_download_7z) {
my_zlog_info("Downloading 7z from: %s", pythonUrl->valuestring);
if (download_file(pythonUrl->valuestring, target_7z_path) == 0) {
my_zlog_info("Download 7z success. Preparing to extract...");
// 检查 7z 是否安装
if (system("which 7z > /dev/null 2>&1") != 0) {
my_zlog_info("7z not found. Installing p7zip-full...");
// 尝试安装 p7zip-full (Ubuntu)
int install_ret = system("sudo apt-get update && sudo apt-get install -y p7zip-full");
if (install_ret != 0) {
my_zlog_error("Failed to install p7zip-full, return code: %d", install_ret);
} else {
my_zlog_info("p7zip-full installation completed successfully.");
}
}
}
// 解压
char cmd[1024];
// 使用密码 fcrs2025606 解压, -y 自动覆盖, -o 指定输出目录
snprintf(cmd, sizeof(cmd), "7z x \"%s\" -o\"%s\" -pfcrs2025606 -y", target_7z_path, target_dir);
my_zlog_info("Executing: %s", cmd);
// 解压
char cmd[1024];
// 使用密码 fcrs2025606 解压, -y 自动覆盖, -o 指定输出目录
snprintf(cmd, sizeof(cmd), "7z x \"%s\" -o\"%s\" -pfcrs2025606 -y", target_7z_path, target_dir);
my_zlog_info("Executing: %s", cmd);
int extract_ret = system(cmd);
if (extract_ret == 0) {
my_zlog_info("Extraction success.");
int extract_ret = system(cmd);
if (extract_ret == 0) {
my_zlog_info("Extraction success.");
} else {
my_zlog_error("Extraction failed with code: %d", extract_ret);
}
} else {
my_zlog_error("Extraction failed with code: %d", extract_ret);
my_zlog_error("Download 7z failed.");
}
} else {
my_zlog_error("Download 7z failed.");
}
}
}
}
}
}
cJSON_Delete(root);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment