删除一些冗余代码 2280/1 2280/head 2281/target/1
authorcheng <chengyf@zhihuishixun.com>
Wed, 17 Sep 2025 11:21:01 +0000 (19:21 +0800)
committercheng <chengyf@zhihuishixun.com>
Wed, 17 Sep 2025 11:21:01 +0000 (19:21 +0800)
code/sdk/zhihui/leiniao/imsl_ln/ln_api.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c

index 957ba4b..7417323 100644 (file)
@@ -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);
         }
     }
 }
index fdbe99d..949d383 100644 (file)
@@ -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;
index e693263..03c22e2 100644 (file)
@@ -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)
     {
index a767cbf..54a0532 100644 (file)
@@ -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)
     {