From: xue <2144439972@qq.com> Date: Sun, 28 Dec 2025 04:27:18 +0000 (+0800) Subject: 修复ln_api中bug X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=ab8c9d670c27b8cf3a55cbffac899f3093b0ad19;p=mirrors%2FFD230.git 修复ln_api中bug --- diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c index 6088eb2aa..a35d84b77 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c @@ -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); + } } } diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c index ab2986596..857b92fef 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c @@ -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; } /* 发送随机故事请求 */