修复GPS关闭bug 3130/1 3130/head 3131/target/1
author1624952103 <pl@DESKTOP-EN9LKR5.localdomain>
Fri, 23 Jan 2026 10:23:50 +0000 (18:23 +0800)
committer1624952103 <pl@DESKTOP-EN9LKR5.localdomain>
Fri, 23 Jan 2026 10:23:50 +0000 (18:23 +0800)
code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c

index 5cc7e97..16bd8df 100644 (file)
@@ -65,7 +65,7 @@ static char *pgnss_log = NULL;
 // GPS停止等待定时器相关变量
 static osTimerId_t g_stop_wait_timer = NULL;
 static int g_stop_wait_count = 0;
-static const int MAX_WAIT_COUNT = 80;  // 最多等待8秒 (80 * 100ms)
+static const int MAX_WAIT_COUNT = 8;  // 最多等待8秒 (80 * 100ms)
 
 // 全局变量,存储当前有效的时间戳文件夹路径
 static char *g_current_agnss_folder = NULL;
@@ -693,8 +693,8 @@ static void gps_stop_wait_timer_callback(int data)
     g_stop_wait_count++;
     
     // 检查数据监听是否已停止
-    if (g_is_listening_data == 0) {
-        printf("PGnssServerStop: Data listening stopped, executing cleanup...\r\n");
+    if (g_is_listening_data == 1) {
+        printf("PGnssServerStop: GPS has initialized and is listening, executing safe cleanup...\r\n");
         
         // 停止定时器
         if (g_stop_wait_timer != NULL) {
@@ -710,9 +710,9 @@ static void gps_stop_wait_timer_callback(int data)
     }
     
     // 打印等待进度(每1秒打印一次)
-    if (g_stop_wait_count % 10 == 0) {
-        printf("PGnssServerStop: Waiting for data listening to stop... (%d/%d ms)\r\n", 
-               g_stop_wait_count * 100, MAX_WAIT_COUNT * 100);
+    if (g_stop_wait_count % 2 == 0) {
+        printf("PGnssServerStop: Waiting for data listening to stop... (%d/%d s)\r\n", 
+               g_stop_wait_count * 2, MAX_WAIT_COUNT * 2);
     }
     
     // 超时处理:如果等待时间超过最大值,强制执行清理
@@ -743,7 +743,7 @@ void PGnssServerStop(void)
     }
 
     // 如果数据监听已经停止,直接执行清理
-    if (g_is_listening_data == 0) {
+    if (g_is_listening_data == 1) {
         printf("PGnssServerStop: Data listening already stopped, executing cleanup immediately\r\n");
         do_gps_stop_cleanup();
         return;
@@ -769,7 +769,7 @@ void PGnssServerStop(void)
     }
     
     // 启动定时器(100ms间隔)
-    int tick = osMs2Tick(100);
+    int tick = osMs2Tick(1000);
     osStatus_t ret = osTimerStart(g_stop_wait_timer, tick);
     if (ret != osOK) {
         printf("PGnssServerStop: Failed to start wait timer (ret=%d), executing cleanup immediately\r\n", ret);