From 1cbd2a87b36ca8dc747137792fc14203c6302097 Mon Sep 17 00:00:00 2001 From: cheng Date: Thu, 18 Sep 2025 16:35:53 +0800 Subject: [PATCH] =?utf8?q?=E9=9B=B7=E9=B8=9Fln=5Fhttp=5Fprepare=5Fauto?= =?utf8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../leiniao/imsl_ln/ln_api_device_info.c | 79 ++++++++++--------- code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c | 10 +-- .../leiniao/imsl_ln/ln_api_speech_chat.c | 6 +- .../leiniao/imsl_ln/ln_api_story_random.c | 9 +-- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c index ce607889f..5048ac198 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c @@ -7,8 +7,10 @@ ScheduleReminder g_schedule_reminder = {0}; /* 安全写入帮助函数 */ static inline void ln_safe_strcpy(char *dst, size_t dst_size, const char *src) { - if (!dst || dst_size == 0) return; - if (src == NULL) { + if (!dst || dst_size == 0) + return; + if (src == NULL) + { dst[0] = '\0'; return; } @@ -26,7 +28,8 @@ void ln_parse_character_config(const char *json_buf, int json_len) } char *text = (char *)malloc((size_t)json_len + 1); - if (!text) return; + if (!text) + return; memcpy(text, json_buf, (size_t)json_len); text[json_len] = '\0'; @@ -60,13 +63,13 @@ void ln_parse_character_config(const char *json_buf, int json_len) /* 基础字段 */ cJSON *cid = cJSON_GetObjectItem(data, "characterId"); cJSON *cname = cJSON_GetObjectItem(data, "characterName"); - ln_safe_strcpy(g_ln_character_config.character_id, - sizeof(g_ln_character_config.character_id), - (cid && cJSON_IsString(cid)) ? cid->valuestring : ""); - - ln_safe_strcpy(g_ln_character_config.character_name, - sizeof(g_ln_character_config.character_name), - (cname && cJSON_IsString(cname)) ? cname->valuestring : ""); + ln_safe_strcpy(g_ln_character_config.character_id, + sizeof(g_ln_character_config.character_id), + (cid && cJSON_IsString(cid)) ? cid->valuestring : ""); + + ln_safe_strcpy(g_ln_character_config.character_name, + sizeof(g_ln_character_config.character_name), + (cname && cJSON_IsString(cname)) ? cname->valuestring : ""); /* 头像配置 */ cJSON *avatar = cJSON_GetObjectItem(data, "characterAvatar"); @@ -79,29 +82,28 @@ void ln_parse_character_config(const char *json_buf, int json_len) cJSON *screenImage = cJSON_GetObjectItem(avatar, "screenImage"); cJSON *screenImageAsEmoji = cJSON_GetObjectItem(avatar, "screenImageAsEmoji"); - ln_safe_strcpy(g_ln_character_config.avatar_hair_color, - sizeof(g_ln_character_config.avatar_hair_color), - (hairColor && cJSON_IsString(hairColor)) ? hairColor->valuestring : ""); - - ln_safe_strcpy(g_ln_character_config.avatar_eyes_color, - sizeof(g_ln_character_config.avatar_eyes_color), - (eyesColor && cJSON_IsString(eyesColor)) ? eyesColor->valuestring : ""); - - ln_safe_strcpy(g_ln_character_config.avatar_hair_style, - sizeof(g_ln_character_config.avatar_hair_style), - (hairStyle && cJSON_IsString(hairStyle)) ? hairStyle->valuestring : ""); - - ln_safe_strcpy(g_ln_character_config.avatar_eyes_shape, - sizeof(g_ln_character_config.avatar_eyes_shape), - (eyesShape && cJSON_IsString(eyesShape)) ? eyesShape->valuestring : ""); - - ln_safe_strcpy(g_ln_character_config.avatar_screen_image, - sizeof(g_ln_character_config.avatar_screen_image), - (screenImage && cJSON_IsString(screenImage)) ? screenImage->valuestring : ""); - - g_ln_character_config.avatar_screen_image_as_emoji = - (screenImageAsEmoji && cJSON_IsBool(screenImageAsEmoji)) ? - (cJSON_IsTrue(screenImageAsEmoji) ? 1 : 0) : 0; + ln_safe_strcpy(g_ln_character_config.avatar_hair_color, + sizeof(g_ln_character_config.avatar_hair_color), + (hairColor && cJSON_IsString(hairColor)) ? hairColor->valuestring : ""); + + ln_safe_strcpy(g_ln_character_config.avatar_eyes_color, + sizeof(g_ln_character_config.avatar_eyes_color), + (eyesColor && cJSON_IsString(eyesColor)) ? eyesColor->valuestring : ""); + + ln_safe_strcpy(g_ln_character_config.avatar_hair_style, + sizeof(g_ln_character_config.avatar_hair_style), + (hairStyle && cJSON_IsString(hairStyle)) ? hairStyle->valuestring : ""); + + ln_safe_strcpy(g_ln_character_config.avatar_eyes_shape, + sizeof(g_ln_character_config.avatar_eyes_shape), + (eyesShape && cJSON_IsString(eyesShape)) ? eyesShape->valuestring : ""); + + ln_safe_strcpy(g_ln_character_config.avatar_screen_image, + sizeof(g_ln_character_config.avatar_screen_image), + (screenImage && cJSON_IsString(screenImage)) ? screenImage->valuestring : ""); + + g_ln_character_config.avatar_screen_image_as_emoji = + (screenImageAsEmoji && cJSON_IsBool(screenImageAsEmoji)) ? (cJSON_IsTrue(screenImageAsEmoji) ? 1 : 0) : 0; } else { @@ -136,14 +138,14 @@ uint32_t ln_device_get_character_http(const char *device_id, if (!device_id || !device_token) return ERRCODE_FAIL; - #ifdef SUPPORT_CAT1_SERVICE +#ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); cat1_api_wakeup_cat1(1); cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(1); LOS_Msleep(200); - #endif +#endif HttpClient client = (HttpClient){0}; HttpClientData clientData = (HttpClientData){0}; @@ -207,14 +209,14 @@ uint32_t ln_device_get_user_id_http(const char *device_id, if (!device_id || !device_token) return ERRCODE_FAIL; - #ifdef SUPPORT_CAT1_SERVICE +#ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); cat1_api_wakeup_cat1(1); cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(1); LOS_Msleep(200); - #endif +#endif HttpClient client = (HttpClient){0}; HttpClientData clientData = (HttpClientData){0}; @@ -320,7 +322,7 @@ uint32_t uapi_ln_device_get_user_id(LnDeviceBindStatus *out_status, char *out_us } HttpClientSetCustomHeader(&client, header_buf); - HTTPC_RESULT prep = ln_http_prepare_auto(&clientData, 2048, LN_CLIENT_PREPARE_SIZE); + HTTPC_RESULT prep = ln_http_prepare_auto(&clientData, 2048, LN_CLIENT_PREPARE_SIZE * 2); if (prep != HTTP_SUCCESS) { return ERRCODE_FAIL; @@ -387,4 +389,3 @@ uint32_t uapi_ln_device_get_user_id(LnDeviceBindStatus *out_status, char *out_us HttpClientClse(&client); return ERRCODE_SUCC; } - \ No newline at end of file diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c index 4824af86d..190b4d866 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c @@ -8,14 +8,14 @@ uint32_t ln_ota_get_task_http(const char *device_id, if (!device_id || !device_token || !source_version) return ERRCODE_FAIL; - #ifdef SUPPORT_CAT1_SERVICE +#ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); cat1_api_wakeup_cat1(1); cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(1); LOS_Msleep(200); - #endif +#endif HttpClient client = (HttpClient){0}; HttpClientData clientData = (HttpClientData){0}; @@ -107,14 +107,14 @@ static int ln_download_file_to_path(const char *full_url, const char *save_path, printf("[OTA] starting download: %s -> %s, total_size=%d bytes\n", full_url, save_path, total_size); - #ifdef SUPPORT_CAT1_SERVICE +#ifdef SUPPORT_CAT1_SERVICE /* CAT1 网络保活处理 */ cat1_api_add_cat1_vote(); cat1_api_wakeup_cat1(1); cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(1); LOS_Msleep(500); // 等待模块就绪 - #endif +#endif /* 初始化HTTP客户端(与http_download风格一致) */ HttpClient client = {0}; @@ -130,7 +130,7 @@ static int ln_download_file_to_path(const char *full_url, const char *save_path, return -1; } - HTTPC_RESULT prep = ln_http_prepare_auto(&client_data, 2048, LN_CLIENT_PREPARE_SIZE); + HTTPC_RESULT prep = ln_http_prepare_auto(&client_data, 2048, LN_CLIENT_PREPARE_SIZE * 3); if (prep != HTTP_SUCCESS) { printf("[OTA] range prepare failed: %d\n", prep); diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c index 2283a0304..418832a48 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c @@ -136,14 +136,14 @@ uint32_t ln_speech_chat_stream_http(const char *device_id, } free(audio_buf); - #ifdef SUPPORT_CAT1_SERVICE +#ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); cat1_api_wakeup_cat1(1); cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(1); LOS_Msleep(500); - #endif +#endif HttpClient client = (HttpClient){0}; HttpClientData clientData = (HttpClientData){0}; @@ -165,7 +165,7 @@ uint32_t ln_speech_chat_stream_http(const char *device_id, printf("chatstream header_buf: %s\n", header_buf); /* 准备缓冲区(自适应) */ - HTTPC_RESULT prep = ln_http_prepare_auto(&clientData, 2048, LN_CLIENT_PREPARE_SIZE*2); + HTTPC_RESULT prep = ln_http_prepare_auto(&clientData, 2048, LN_CLIENT_PREPARE_SIZE * 2); if (prep != HTTP_SUCCESS) { free(body); diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c index 2c48113cd..99d42f8e6 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c @@ -19,7 +19,6 @@ static void ln_parse_story_random_file(void) } } - uint32_t ln_story_random_http(const char *device_id, const char *device_token, const char *story_theme) @@ -30,14 +29,14 @@ uint32_t ln_story_random_http(const char *device_id, return ERRCODE_FAIL; } - #ifdef SUPPORT_CAT1_SERVICE +#ifdef SUPPORT_CAT1_SERVICE /* CAT1 网络保活处理 */ cat1_api_add_cat1_vote(); cat1_api_wakeup_cat1(1); cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(1); LOS_Msleep(500); - #endif +#endif HttpClient client = {0}; HttpClientData clientData = {0}; @@ -61,7 +60,7 @@ uint32_t ln_story_random_http(const char *device_id, HttpClientSetCustomHeader(&client, header_buf); /* 自适应准备 HTTP 缓冲区 */ - HTTPC_RESULT prep = ln_http_prepare_auto(&clientData, 2048, LN_CLIENT_PREPARE_SIZE); + HTTPC_RESULT prep = ln_http_prepare_auto(&clientData, 2048, LN_CLIENT_PREPARE_SIZE * 2); if (prep != HTTP_SUCCESS) { printf("story random: prepare HTTP buffer failed (code: %d)\n", prep); @@ -123,7 +122,7 @@ uint32_t ln_story_random_http(const char *device_id, } // 发送GET请求 - ret = HttpClientSend(&client, LN_STORY_RANDOM_URL, HTTP_POST, &clientData); + ret = HttpClientSend(&client, LN_STORY_RANDOM_URL, HTTP_POST, &clientData); if (ret != 0) { printf("[OTA] send request failed, ret=0x%x\n", ret); -- 2.17.1