优化产测二维码信息显示,优化pgnss星历下载,增加获取BT地址的AT(补) 2483/1 2483/head 2484/target/1
authorpenglei <1624952103@qq.com>
Fri, 10 Oct 2025 10:41:52 +0000 (18:41 +0800)
committerpenglei <1624952103@qq.com>
Fri, 10 Oct 2025 10:41:52 +0000 (18:41 +0800)
code/sdk/zhihui/services/gnss/src/gnss_http_server.c

index 798a6c9..d485686 100644 (file)
@@ -14,6 +14,7 @@
 #include "custom_runtime.h"
 #include <dirent.h>
 #include "pm_definition.h"
+#include "pm_veto.h"
 #include "mbedtls/md5.h"
 #include "mbedtls/base64.h"
 #include "cJSON.h"
@@ -232,8 +233,14 @@ static HTTPC_RESULT gnss_http_prepare_auto(HttpClientData *clientData, int heade
     return ret;
 }
 
+// 前向声明
+static void reset_failure_counter(void);
+
 static void update_file_progress(const char *filename)
 {
+    // 成功下载文件时重置失败计数器
+    reset_failure_counter();
+    
     g_downloaded_files++;
     
     if (g_total_files > 0) {
@@ -260,9 +267,14 @@ static void update_file_progress(const char *filename)
     }
 }
 
+// 全局失败计数器
+static int g_consecutive_failures = 0;
+
 // 显示文件下载失败信息 - 不增加计数器
 static void update_file_progress_failed(const char *filename, HTTPC_RESULT error)
 {
+    g_consecutive_failures++;
+    
     if (g_total_files > 0) {
         int actual_percent = (g_downloaded_files * 100) / g_total_files;
         printf("✗ %s: request failed %d (进度保持 %d%% [%d/%d])\\n", 
@@ -270,6 +282,23 @@ static void update_file_progress_failed(const char *filename, HTTPC_RESULT error
     } else {
         printf("✗ %s: request failed %d\\n", filename, error);
     }
+    
+    // 如果连续失败次数过多,可能需要清理GPS睡眠阻止
+    if (g_consecutive_failures >= 10) {
+        printf("Warning: Too many consecutive download failures (%d), checking GPS sleep veto\n", g_consecutive_failures);
+        uint8_t cnt = pm_veto_get_id_cnt(PM_ID_GPS);
+        if (cnt == 1) {
+            uapi_pm_remove_sleep_veto(PM_ID_GPS);
+            printf("Removed GPS sleep veto due to excessive download failures\n");
+        }
+        g_consecutive_failures = 0; // 重置计数器
+    }
+}
+
+// 重置失败计数器的辅助函数
+static void reset_failure_counter(void)
+{
+    g_consecutive_failures = 0;
 }
 
 static HTTPC_RESULT download_file_with_httpclient(const char *filename, const char *url)
@@ -807,6 +836,14 @@ static void verify_downloaded_files(uint32_t selected_timestamp)
     // 下载完成,设置完成状态
     g_download_status = 10;
     printf("Status: 10 (所有文件下载完成!)\n");
+    
+    // 所有文件下载完成,移除GPS睡眠阻止
+    uint8_t cnt = pm_veto_get_id_cnt(PM_ID_GPS);
+    if (cnt == 1) 
+    {
+        uapi_pm_remove_sleep_veto(PM_ID_GPS);
+        printf("Removed GPS sleep veto after all files download completed\n");
+    }
 }
 
 
@@ -1620,17 +1657,10 @@ int download_agnss_files(void)
 #endif
 
     } else {
-        // 下载成功,清除标志位
+        // JSON数据获取成功,但文件下载还没开始,不要移除GPS睡眠阻止
         g_has_valid_json_data = 0;
-        printf("Download completed successfully, cleared download flag\n");
-        
-        // 移除GPS睡眠阻止
-        cnt = pm_veto_get_id_cnt(PM_ID_GPS);
-        if (cnt == 1) 
-        {
-            uapi_pm_remove_sleep_veto(PM_ID_GPS);
-            printf("Removed GPS sleep veto after download success\n");
-        }
+        printf("AGNSS JSON data received successfully, file download will start soon\n");
+        printf("GPS sleep veto remains active during file download process\n");
     }
     return 0;
 }