#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"
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) {
}
}
+// 全局失败计数器
+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",
} 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)
// 下载完成,设置完成状态
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");
+ }
}
#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;
}