From 1e3ad0c4648c3ef508960dd90e130b472c374492 Mon Sep 17 00:00:00 2001 From: Caisking Date: Sat, 24 Jan 2026 15:01:59 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96pgnss=E6=98=9F=E5=8E=86?= =?utf8?q?=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../gnss/sample/pgnss_sample/pgnss_sample.c | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c b/code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c index 16bd8df41..7ffc61cb0 100644 --- a/code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c +++ b/code/sdk/zhihui/services/gnss/sample/pgnss_sample/pgnss_sample.c @@ -1018,12 +1018,14 @@ static int check_agnss_folder_expired(void) uint32_t time_diff = 0; if (current_timestamp >= folder_timestamp) { time_diff = current_timestamp - folder_timestamp; - } else { - time_diff = folder_timestamp - current_timestamp; - } - + } + // else { + // time_diff = folder_timestamp - current_timestamp; + // } + // printf("current_timestamp:%d,folder_timestamp:%d,time_diff : %d\n",current_timestamp,folder_timestamp,time_diff); // 检查是否在24小时内 - if (time_diff < 86400) { // 24小时 = 86400秒 + if (time_diff < 86400 && time_diff > 0) // 24小时 = 86400秒 + { // 构建完整路径以检查文件数量 char full_folder_path[512]; int path_ret = snprintf(full_folder_path, sizeof(full_folder_path), "%s/%s", PGNSS_DATA_PATH, entry->d_name); @@ -1042,27 +1044,27 @@ static int check_agnss_folder_expired(void) // 检查文件数量是否为26个 if (file_count >= 20) { found_valid_folder = 1; - if (time_diff < min_time_diff) { - min_time_diff = time_diff; - // 更新全局变量,存储最接近的时间戳文件夹路径 - if (g_current_agnss_folder != NULL) { - free(g_current_agnss_folder); - g_current_agnss_folder = NULL; - } - g_current_agnss_folder = malloc(256); - if (g_current_agnss_folder != NULL) { - int ret = snprintf(g_current_agnss_folder, 256, "%s/%s", PGNSS_DATA_PATH, entry->d_name); - if (ret < 0 || ret >= 256) { - printf("ERROR: snprintf failed or buffer overflow for g_current_agnss_folder\n"); + if (time_diff < min_time_diff) { + min_time_diff = time_diff; + // 更新全局变量,存储最接近的时间戳文件夹路径 + if (g_current_agnss_folder != NULL) { free(g_current_agnss_folder); g_current_agnss_folder = NULL; } - } else { - printf("ERROR: Failed to allocate memory for g_current_agnss_folder\n"); + g_current_agnss_folder = malloc(256); + if (g_current_agnss_folder != NULL) { + int ret = snprintf(g_current_agnss_folder, 256, "%s/%s", PGNSS_DATA_PATH, entry->d_name); + if (ret < 0 || ret >= 256) { + printf("ERROR: snprintf failed or buffer overflow for g_current_agnss_folder\n"); + free(g_current_agnss_folder); + g_current_agnss_folder = NULL; + } + } else { + printf("ERROR: Failed to allocate memory for g_current_agnss_folder\n"); + } } - } - printf("Found valid AGNSS folder: %s (time diff: %u seconds, file count: %d)\n", - entry->d_name, time_diff, file_count); + printf("Found valid AGNSS folder: %s (time diff: %u seconds, file count: %d)\n", + entry->d_name, time_diff, file_count); } else { printf("Found AGNSS folder with invalid file count: %s (time diff: %u seconds, file count: %d/26)\n", entry->d_name, time_diff, file_count); @@ -1112,7 +1114,8 @@ static int check_agnss_folder_expired(void) printf("Cycle %d: Checking %s - file count: %d/26\n", current_cycle, candidate_folder_name, file_count); - if (file_count == 26) { + if (file_count >= 20) + { printf("SUCCESS: AGNSS folder now has 26 files! %s\n", candidate_folder_name); // 更新全局变量,存储有效的文件夹路径 -- 2.17.1