// 全局静态变量用于防止重复处理
static int g_processing_count = 0;
+// 全局标志位:标记是否已经获取到有效的JSON数据
+static int g_has_valid_json_data = 0;
+
static unsigned long g_app_recv_queue= 0xFFFFFFFF;
static unsigned long g_app_send_queue= 0xFFFFFFFF;
// 发送完成信号到接收任务
do_gnss_http_server_recv_data(GNSS_HTTP_SERVICE_CMD_AGNSS_RECV, NULL, 0);
+ } else {
+ // HTTP请求失败,标志位由download_agnss_files函数管理
+ printf("HTTP request failed (result: %d, code: %d)\n", result, response_code);
}
}
}
// 尝试查找JSON开始位置
for (size_t i = 0; i < len; i++) {
if (data[i] == '{') {
- printf("Found JSON start at position %zu, adjusting data\n", i);
+ // printf("Found JSON start at position %zu, adjusting data\n", i);
data += i;
len -= i;
break;
verify_files_recursive(PGNSS_DATA_PATH, &total_count);
printf("Total: %d files in timestamp folder: %s/%u\n", total_count, PGNSS_DATA_PATH, selected_timestamp);
+
+ // 下载完成,标志位由download_agnss_files函数管理
}
// 验证JSON格式并修复截断问题 - 更智能的版本
if (g_agnss_response_buffer[0] != '{' || g_agnss_response_buffer[g_agnss_response_size - 1] != '}')
{
- printf("Warning: Response doesn't appear to be valid JSON\n");
- printf("First char: '%c', Last char: '%c'\n",
- g_agnss_response_buffer[0],
- g_agnss_response_buffer[g_agnss_response_size - 1]);
+ // printf("Warning: Response doesn't appear to be valid JSON\n");
+ // printf("First char: '%c', Last char: '%c'\n",
+ // g_agnss_response_buffer[0],
+ // g_agnss_response_buffer[g_agnss_response_size - 1]);
// 检查是否有明显的截断标记
if (strstr(g_agnss_response_buffer, "1ff8") || strstr(g_agnss_response_buffer, "0x0D"))
{
- printf("Warning: JSON data appears to be truncated with corruption markers\n");
+ // printf("Warning: JSON data appears to be truncated with corruption markers\n");
// 尝试找到最后一个完整的JSON对象
char *last_complete = NULL;
char *search_pos = g_agnss_response_buffer;
size_t new_size = last_complete - g_agnss_response_buffer;
g_agnss_response_size = new_size;
g_agnss_response_buffer[g_agnss_response_size] = '\0';
- printf("Truncated JSON to last complete object, new size: %zu bytes\n", g_agnss_response_size);
+ // printf("Truncated JSON to last complete object, new size: %zu bytes\n", g_agnss_response_size);
}
}
// 检查是否有截断的JSON数据
if (strstr(g_agnss_response_buffer, "1ff8") || strstr(g_agnss_response_buffer, "0x0D"))
{
- printf("Warning: Detected corrupted JSON data with truncation markers\n");
+ // printf("Warning: Detected corrupted JSON data with truncation markers\n");
// 尝试找到最后一个完整的JSON对象
char *last_complete = NULL;
char *search_pos = g_agnss_response_buffer;
if (last_complete)
{
json_end = last_complete - 1; // 指向 '}' 字符
- printf("Truncated to last complete JSON object at position %ld\n",
- json_end - g_agnss_response_buffer);
+ // printf("Truncated to last complete JSON object at position %ld\n",
+ // json_end - g_agnss_response_buffer);
}
}
if (json_start && json_end && json_end > json_start)
{
- printf("Found JSON content between positions %ld and %ld\n",
- json_start - g_agnss_response_buffer,
- json_end - g_agnss_response_buffer);
+ // printf("Found JSON content between positions %ld and %ld\n",
+ // json_start - g_agnss_response_buffer,
+ // json_end - g_agnss_response_buffer);
// 验证这个JSON片段是否完整
int brace_count = 0;
memmove(g_agnss_response_buffer, json_start, new_size);
g_agnss_response_size = new_size;
g_agnss_response_buffer[g_agnss_response_size] = '\0';
- printf("Adjusted buffer size to %zu bytes (complete JSON)\n", g_agnss_response_size);
+ // printf("Adjusted buffer size to %zu bytes (complete JSON)\n", g_agnss_response_size);
}
else
{
- printf("Found JSON fragment but structure incomplete - braces: %d, brackets: %d\n", brace_count, bracket_count);
+ // printf("Found JSON fragment but structure incomplete - braces: %d, brackets: %d\n", brace_count, bracket_count);
// 尝试查找最后一个完整的JSON对象
char *last_complete = NULL;
char *search_pos = g_agnss_response_buffer;
size_t new_size = last_complete - g_agnss_response_buffer;
g_agnss_response_size = new_size;
g_agnss_response_buffer[g_agnss_response_size] = '\0';
- printf("Truncated to last complete JSON object, size: %zu bytes\n", g_agnss_response_size);
+ // printf("Truncated to last complete JSON object, size: %zu bytes\n", g_agnss_response_size);
}
else
{
- printf("Could not find any complete JSON structure, using original data\n");
+ // printf("Could not find any complete JSON structure, using original data\n");
}
}
}
else
{
- printf("Error: Could not find valid JSON boundaries\n");
- printf("JSON start found: %s\n", json_start ? "yes" : "no");
- printf("JSON end found: %s\n", json_end ? "yes" : "no");
+ // printf("Error: Could not find valid JSON boundaries\n");
+ // printf("JSON start found: %s\n", json_start ? "yes" : "no");
+ // printf("JSON end found: %s\n", json_end ? "yes" : "no");
// 尝试查找最后一个完整的JSON对象
char *last_complete = NULL;
size_t new_size = last_complete - g_agnss_response_buffer;
g_agnss_response_size = new_size;
g_agnss_response_buffer[g_agnss_response_size] = '\0';
- printf("Truncated to last complete JSON object, size: %zu bytes\n", g_agnss_response_size);
+ // printf("Truncated to last complete JSON object, size: %zu bytes\n", g_agnss_response_size);
}
else
{
- printf("Could not find any complete JSON structure, using original data\n");
+ // printf("Could not find any complete JSON structure, using original data\n");
}
}
}
- printf("AGNSS JSON data:\n%s\n", g_agnss_response_buffer);
+ // printf("AGNSS JSON data:\n%s\n", g_agnss_response_buffer);
// 检查JSON数据完整性
int brace_count = 0;
}
if (brace_count != 0 || bracket_count != 0) {
- printf("Warning: JSON structure incomplete - braces: %d, brackets: %d\n", brace_count, bracket_count);
+ // printf("Warning: JSON structure incomplete - braces: %d, brackets: %d\n", brace_count, bracket_count);
// 如果JSON结构不完整,尝试修复
if (brace_count > 0 || bracket_count > 0) {
// 缺少右大括号或右方括号,尝试添加
- printf("Attempting to fix incomplete JSON by adding missing braces/brackets\n");
+ // printf("Attempting to fix incomplete JSON by adding missing braces/brackets\n");
size_t needed_braces = (brace_count > 0) ? brace_count : 0;
size_t needed_brackets = (bracket_count > 0) ? bracket_count : 0;
}
g_agnss_response_buffer[g_agnss_response_size] = '\0';
- printf("Fixed JSON structure, new size: %zu bytes\n", g_agnss_response_size);
+ // printf("Fixed JSON structure, new size: %zu bytes\n", g_agnss_response_size);
} else {
- printf("Failed to allocate memory for JSON fix\n");
+ // printf("Failed to allocate memory for JSON fix\n");
}
}
}
} else {
- printf("JSON structure appears complete\n");
+ // printf("JSON structure appears complete\n");
}
// 使用已在函数开始处声明的文件列表变量
}
} else {
printf("AGNSS API call failed or returned error\n");
+ // API调用失败,标志位由download_agnss_files函数管理
}
// 清理缓冲区
int download_agnss_files(void)
{
+ // 进入函数时设置标志位,表示正在下载
+ g_has_valid_json_data = 1;
+ printf("Starting AGNSS download, set download flag\n");
+
//通讯开始,唤醒cat1
cat1_api_add_cat1_vote();
cat1_api_wakeup_cat1(1);
if (result != HTTP_SUCCESS) {
agnss_download_result_handler(NULL, result, 0, NULL, 0);
+ // 下载失败,清除标志位
+ g_has_valid_json_data = 0;
+ printf("Download failed, cleared download flag\n");
+ } else {
+ // 下载成功,清除标志位
+ g_has_valid_json_data = 0;
+ printf("Download completed successfully, cleared download flag\n");
}
return 0;
if (new_size < g_agnss_response_size) {
g_agnss_response_size = new_size;
g_agnss_response_buffer[g_agnss_response_size] = '\0';
- printf("Smart JSON cleanup: truncated to %zu bytes\n", g_agnss_response_size);
+ // printf("Smart JSON cleanup: truncated to %zu bytes\n", g_agnss_response_size);
}
}
}