From 476cee11dc2a59b8c003592317f6c04258cbaeae Mon Sep 17 00:00:00 2001 From: cheng Date: Wed, 17 Sep 2025 19:21:01 +0800 Subject: [PATCH] =?utf8?q?=E5=88=A0=E9=99=A4=E4=B8=80=E4=BA=9B=E5=86=97?= =?utf8?q?=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/zhihui/leiniao/imsl_ln/ln_api.c | 37 ++++++++----------- .../leiniao/imsl_ln/ln_api_device_info.c | 3 ++ .../leiniao/imsl_ln/ln_api_speech_chat.c | 11 ++++-- .../leiniao/imsl_ln/ln_api_story_choose.c | 7 ++-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c index 957ba4b20..741732397 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c @@ -1131,12 +1131,6 @@ static void ln_http_server_recv_task(void const *arg) continue; } - // 消息有效性检查 - if (!mail.data || mail.len <= 0) - { - continue; - } - // 分类处理消息 const char *tag = "UNKNOWN"; if (mail.cmd == LN_HTTP_SERVICE_CMD_SSE_RECV) { @@ -1155,29 +1149,28 @@ static void ln_http_server_recv_task(void const *arg) tag = "DEVICE_USER_ID"; } else if (mail.cmd == LN_HTTP_RECV_OTA_TASK) { tag = "OTA_TASK"; - } else if (mail.cmd == LN_HTTP_RECV_OTA_DOWNLOAD_MSG) { - tag = "OTA_DOWNLOAD_MSG"; - } - - printf("[%s] 数据长度: %u\n", tag, mail.len); - /* 确保可打印:追加\0 */ - char *buf = (char *)malloc(mail.len + 1); - if (buf) { - memcpy(buf, mail.data, mail.len); - buf[mail.len] = '\0'; - printf("[%s] 原始数据:%s\n", tag, buf); /* 在收到 OTA_TASK 后,根据升级策略决定是否触发下载 */ - if (mail.cmd == LN_HTTP_RECV_OTA_TASK) { - ln_handle_ota_task_response(buf, (int)mail.len); + if (mail.data) { + ln_handle_ota_task_response(mail.data, (int)mail.len); } + } else if (mail.cmd == LN_HTTP_RECV_OTA_DOWNLOAD_MSG) { + tag = "OTA_DOWNLOAD_MSG"; /* 在收到 OTA_DOWNLOAD_MSG 后,解析状态并回调处理(进度/完成/失败) */ - if (mail.cmd == LN_HTTP_RECV_OTA_DOWNLOAD_MSG) { + if (mail.data) + { OtaDownloadMsg m = {0}; - if (parse_ota_download_msg(buf, &m) == 0) { + if (parse_ota_download_msg(mail.data, &m) == 0) { handle_ota_download_msg(&m); + } else { + printf("OTA_DOWNLOAD_MSG: parse failed\n"); } } - free(buf); + } + printf("[%s] 数据长度: %u\n", tag, mail.len); + if (mail.data) + { + printf("free(mail.data)\n"); + free(mail.data); } } } 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 fdbe99d5c..949d38364 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 @@ -208,6 +208,7 @@ uint32_t uapi_ln_device_get_user_id(LnDeviceBindStatus *out_status, char *out_us } int code = HttpClientGetResponseCode(&client); + printf("device getUserId: HTTP %d\n", code); if (code == 200) { /* 成功响应:解析JSON,判断 data 是否为 null 或字符串 */ @@ -253,6 +254,8 @@ uint32_t uapi_ln_device_get_user_id(LnDeviceBindStatus *out_status, char *out_us *out_status = LN_DEVICE_BIND_STATUS_ERROR; } + printf("device getUserId: out_status %d\n", *out_status); + HttpClientUnprepare(&clientData); HttpClientClse(&client); return ERRCODE_SUCC; 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 e693263be..03c22e2f2 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 @@ -16,7 +16,7 @@ static uint8_t *ln_read_file_all_speech_chat(const char *path, int *out_len) fseek(fp, 0, SEEK_END); long sz = ftell(fp); fseek(fp, 0, SEEK_SET); - if (sz <= 0 || sz > (10 * 1024 * 1024)) + if (sz <= 0) { fclose(fp); return NULL; @@ -110,7 +110,13 @@ uint32_t ln_speech_chat_stream_http(const char *device_id, /* boundary */ char boundary[64]; - snprintf(boundary, sizeof(boundary), "----LNBOUNDARY-%u", (unsigned)uapi_tcxo_get_ms()); + int boundary_len = snprintf(boundary, sizeof(boundary), "----LNBOUNDARY-%u", (unsigned)uapi_tcxo_get_ms()); + if (boundary_len <= 0 || boundary_len >= (int)sizeof(boundary)) + { + printf("chatstream: create boundary failed\n"); + free(audio_buf); + return ERRCODE_FAIL; + } /* 组包 */ char *body = NULL; @@ -183,7 +189,6 @@ uint32_t ln_speech_chat_stream_http(const char *device_id, return ret; } - // 发送GET请求 ret = HttpClientSend(&client, LN_CHAT_URL, HTTP_POST, &clientData); if (ret != 0) { diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c index a767cbf48..54a05322b 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c @@ -16,7 +16,7 @@ static uint8_t *ln_read_file_all_story(const char *path, int *out_len) fseek(fp, 0, SEEK_END); long sz = ftell(fp); fseek(fp, 0, SEEK_SET); - if (sz <= 0 || sz > (10 * 1024 * 1024)) + if (sz <= 0) { fclose(fp); return NULL; @@ -133,14 +133,14 @@ uint32_t ln_story_choose_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 = {0}; HttpClientData clientData = {0}; @@ -187,7 +187,6 @@ uint32_t ln_story_choose_http(const char *device_id, return ret; } - // 发送GET请求 ret = HttpClientSend(&client, LN_STORY_CHOOSE_URL, HTTP_POST, &clientData); if (ret != 0) { -- 2.17.1