修复ln_api中bug
authorxue <2144439972@qq.com>
Sun, 28 Dec 2025 04:27:18 +0000 (12:27 +0800)
committerxue <2144439972@qq.com>
Sun, 28 Dec 2025 04:27:18 +0000 (12:27 +0800)
code/sdk/zhihui/leiniao/imsl_ln/ln_api.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c

index 6088eb2..a35d84b 100644 (file)
@@ -886,7 +886,9 @@ void ln_ws_process_message(const ws_data_msg_t *data_msg, ws_command_t type)
         do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_GET_CHARACTER, NULL, 0);
         push_bind_and_unbind_notification(LN_DEVICE_BIND_STATUS_BOUND);
         uapi_ln_set_device_bound(1);
-        ln_ws_ack_user_id_from_json(json_str);
+        if (json_str) {
+            ln_ws_ack_user_id_from_json(json_str);
+        }
         ln_ws_send_device_bind_ack(uapi_ln_get_user_id(), true, "绑定成功");
         break;
     }
@@ -895,14 +897,16 @@ void ln_ws_process_message(const ws_data_msg_t *data_msg, ws_command_t type)
         printf("[WS] DeviceUnbind:设备解绑\n");
         push_bind_and_unbind_notification(LN_DEVICE_BIND_STATUS_UNBOUND);
         uapi_ln_set_device_bound(0);
-        ln_ws_ack_user_id_from_json(json_str);
+        if (json_str) {
+            ln_ws_ack_user_id_from_json(json_str);
+        }
         ln_ws_send_device_unbind_ack(uapi_ln_get_user_id(), true, "解绑成功");
         break;
     }
     case WS_CMD_SCHEDULE_REMINDER:
     {
         printf("[WS] ScheduleReminder:日程提醒\n");
-        // if (json_str)
+        if (json_str)
         {
             do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_SCHEDULE_REMINDER, json_str, strlen(json_str));
         }
@@ -1102,31 +1106,42 @@ void ln_ws_process_message(const ws_data_msg_t *data_msg, ws_command_t type)
     }
     case WS_CMD_CHOOSE_STORY_RESPONSE:
     {
-        push_text_to_ui(data_msg->text_content);
-        // 如果finished=true,通知ThunderBirdModel
-        if (data_msg && data_msg->finished) {
-            push_story_response_finished_notification(true);
+        if (data_msg) {
+            if (data_msg->text_content) {
+                push_text_to_ui(data_msg->text_content);
+            }
+            // 如果finished=true,通知ThunderBirdModel
+            if (data_msg->finished) {
+                push_story_response_finished_notification(true);
+            }
+            if (ln_http_download_is_initialized() && data_msg->audio_url && data_msg->audio_url[0] != '\0') {
+                ln_http_download_file(data_msg->audio_url, 100*1000);
+            }
         }
-        if(ln_http_download_is_initialized())
-        ln_http_download_file(data_msg->audio_url, 100*1000);
 
          break;
     }
     case WS_CMD_RANDOM_STORY_RESPONSE:
     {
-        push_text_to_ui(data_msg->text_content);
-        // 如果finished=true,通知ThunderBirdModel
-        if (data_msg && data_msg->finished) {
-            push_story_response_finished_notification(true);
+        if (data_msg) {
+            if (data_msg->text_content) {
+                push_text_to_ui(data_msg->text_content);
+            }
+            // 如果finished=true,通知ThunderBirdModel
+            if (data_msg->finished) {
+                push_story_response_finished_notification(true);
+            }
+            if (ln_http_download_is_initialized() && data_msg->audio_url && data_msg->audio_url[0] != '\0') {
+                ln_http_download_file(data_msg->audio_url, 100*1000);
+            }
         }
-        if(ln_http_download_is_initialized())
-        ln_http_download_file(data_msg->audio_url, 100*1000);
 
         break;
     }
     case WS_CMD_AUDIO_PLAYBACK_START:
     {
         uapi_ln_set_audio_play_status(1);
+        break;
     }
     case WS_CMD_AUDIO_PLAYBACK_END:
     {
@@ -1417,6 +1432,9 @@ void do_ln_http_server_send_data(int cmd, char *data, uint32_t len)
     if (ret != OSAL_SUCCESS)
     {
         printf("Error ln http send failed! err=0x%x! \r\n", ret);
+        if (send_data.data != NULL) {
+            free(send_data.data);
+        }
     }
 }
 
index ab29865..857b92f 100644 (file)
@@ -144,7 +144,7 @@ static void record_audio_duration(uint32_t duration);
 static bool check_playback_completion_by_duration(void);
 static bool check_playback_completion_by_timeout(void);
 
-static const char story_theme_cache[64]={0};
+static char story_theme_cache[64]={0};
 
 
 uint16_t send_audio=0;
@@ -1580,7 +1580,7 @@ int ln_ws_send_text(const char *text)
 
 int ln_ws_send_random_story_cache(const char *story_theme)
 {
-    memcpy(story_theme_cache,story_theme,strlen(story_theme));
+    memcpy_s(story_theme_cache,sizeof(story_theme_cache),story_theme,strlen(story_theme));
     return 0;
 }
 /* 发送随机故事请求 */