Merge #2813 into sdk650pathc0423 from refs/changes/2813/head 2816/target/1
author胡传军 <1224667075@qq.com>
Fri, 28 Nov 2025 05:50:50 +0000 (05:50 +0000)
committeraliyun3243248791 <accounts_67aaf52ad497cd558d73ac32@mail.teambition.com>
Fri, 28 Nov 2025 05:50:50 +0000 (05:50 +0000)
Code review from 胡传军

* refs/changes/2813/head: (3 commits squashed)

  - 屏蔽VAD认证

  - Merge branch &#39;sdk650pathc0423&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650pathc0423

  - 增加文件保存测试开关

Signed-off-by: aliyun8003852482 <1224667075@qq.com>
Merged-by: 薛文强 <accounts_67aaf52ad497cd558d73ac32@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/2813
code/sdk/zhihui/dmp/dmp_dev_authentication.c
code/sdk/zhihui/imsl/src/vad_server.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c

index 33c5426..8a1b24a 100644 (file)
@@ -612,17 +612,18 @@ bool dmp_aut_login(void)//登录
      char out_buf[1024]={0};
 
     int ret= dmp_http_post(json_string,HTTP_JSON_SERVER_NAME POST_URL,out_buf);
-
-    if(ret==200)
-    {   
-        dmp_read_dev_token_save(out_buf);
-    }
+    cJSON_free(json_string);
 
     aut_login_time=timestamp;
 
-    cJSON_free(json_string);
-
-    return true;
+    if(ret==200)
+    {
+        return dmp_read_dev_token_save(out_buf);
+    }
+    else
+    {
+        return false;
+    }
 }
 
 
@@ -734,7 +735,7 @@ bool dmp_read_dev_token_save(char *indata)
     }
     cJSON_Delete(data);
    
-    return true;
+    return false;
 }
 
 static void dmp_read_file_put(void )
index b333bc5..6b1f9f7 100644 (file)
@@ -127,7 +127,7 @@ static void vad_mp3_pcm_callback(const int16_t *pcm_data, int samples, int chann
 }
 #endif
 
-static uint8_t dmp_auth=0;
+static uint8_t dmp_auth=1;
 uint32_t dmp_auth_max_count=10;
 
 /**
@@ -166,7 +166,8 @@ LOGIN_SUCC:
             }
             else
             {
-                 return ERRCODE_FAIL;
+                
+                return ERRCODE_FAIL;
             }
         }  
     }
index 28d41a2..73f64c3 100644 (file)
@@ -5,6 +5,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include "cJSON.h" // Added for JSON parsing
 #include "custom_utils.h"
 #include "soc_osal.h"
@@ -19,6 +21,7 @@
 #endif
 // 功能开关宏定义
 #define ENABLE_BINARY_DATA_INTERRUPT_CHECK 1  // 启用二进制数据间隔检查
+#define ENABLE_AUDIO_FILE_WRITE 0  // 启用音频文件写入功能(根据chat_id生成文件)
 
 // 主线程循环间隔时长(毫秒)
 #define LN_WS_MAIN_THREAD_INTERVAL_MS 500
@@ -125,6 +128,7 @@ static void ln_ws_audio_buffer_cleanup(void);
 static int ln_ws_audio_buffer_add(const uint8_t *audio_data, uint32_t audio_size, bool finished);
 static void ln_ws_audio_buffer_flush(void);
 static int ln_ws_send_audio_data_direct(const uint8_t *audio_data, uint32_t audio_size, bool finished);
+static int ln_ws_write_audio_to_file(const uint8_t *audio_data, uint32_t audio_size, const char *chat_id);
 const char* ln_ws_get_connection_state_string(void);
 
 /* Base64缓存管理函数 */
@@ -583,6 +587,13 @@ int ln_ws_send_audio_data(const uint8_t *audio_data, uint32_t audio_size, bool f
     char message_id[128];
     generate_message_id(message_id, sizeof(message_id), g_audio_chat_ctx.chat_id, g_audio_chat_ctx.message_counter);
     
+#if ENABLE_AUDIO_FILE_WRITE
+    // 写入本地文件(根据chat_id生成文件,已有文件不生成但追加写入数据)
+    if (audio_data != NULL && audio_size > 0) {
+        ln_ws_write_audio_to_file(audio_data, audio_size, g_audio_chat_ctx.chat_id);
+    }
+#endif
+    
     // Base64编码音频数据(如果是结束消息,则使用空字符串)
     char *audio_base64 = NULL;
     if (audio_size == 0) {
@@ -2961,6 +2972,60 @@ static void ln_ws_audio_buffer_flush(void)
     LN_WS_INFO("Audio buffer flush completed\n");
 }
 
+/**
+ * @brief 将音频数据写入本地文件(根据chat_id生成文件,已有文件不生成但追加写入数据)
+ * @param audio_data 音频数据
+ * @param audio_size 数据大小
+ * @param chat_id 聊天ID
+ * @return 0成功,-1失败
+ */
+static int ln_ws_write_audio_to_file(const uint8_t *audio_data, uint32_t audio_size, const char *chat_id)
+{
+#if ENABLE_AUDIO_FILE_WRITE
+    if (audio_data == NULL || audio_size == 0 || chat_id == NULL) {
+        return -1;
+    }
+    
+    char file_path[128];
+    snprintf(file_path, sizeof(file_path), "/user/audio_%s.MP3", chat_id);
+    
+    // 检查文件是否存在
+    struct stat file_stat;
+    const char *mode;
+    if (stat(file_path, &file_stat) != 0) {
+        // 文件不存在,创建新文件
+        mode = "wb";
+    } else {
+        // 文件已存在,追加写入
+        mode = "ab";
+    }
+    
+    FILE *fp = fopen(file_path, mode);
+    if (fp != NULL) {
+        size_t written = fwrite(audio_data, 1, audio_size, fp);
+        fclose(fp);
+        if (written == audio_size) {
+            LN_WS_DEBUG("Audio data written to file: %s, size: %u, mode: %s\n", 
+                       file_path, audio_size, mode);
+            return 0;
+        } else {
+            LN_WS_WARN("Failed to write all audio data to file: %s, written: %zu, expected: %u\n", 
+                      file_path, written, audio_size);
+            return -1;
+        }
+    } else {
+        LN_WS_WARN("Failed to open audio file: %s, mode: %s\n", file_path, mode);
+        return -1;
+    }
+#else
+    // 功能未启用,直接返回成功
+    (void)audio_data;
+    (void)audio_size;
+    (void)chat_id;
+    return 0;
+#endif
+}
+
 /**
  * 直接发送音频数据(跳过状态检查)
  * @param audio_data 音频数据
@@ -2981,6 +3046,8 @@ static int ln_ws_send_audio_data_direct(const uint8_t *audio_data, uint32_t audi
         LN_WS_ERROR("Invalid audio data parameters\n");
         return -1;
     }
+
+
     
     // 如果聊天未开始,生成新的聊天ID
     if (!g_audio_chat_ctx.is_active) {
@@ -2993,6 +3060,10 @@ static int ln_ws_send_audio_data_direct(const uint8_t *audio_data, uint32_t audi
         reset_chat_id_match();
         LN_WS_DEBUG("New chat started: %s\n", g_audio_chat_ctx.chat_id);
     }
+
+    
+
+    
     
     // 增加消息计数器
     g_audio_chat_ctx.message_counter++;
@@ -3011,6 +3082,13 @@ static int ln_ws_send_audio_data_direct(const uint8_t *audio_data, uint32_t audi
     char message_id[128];
     generate_message_id(message_id, sizeof(message_id), g_audio_chat_ctx.chat_id, g_audio_chat_ctx.message_counter);
     
+#if ENABLE_AUDIO_FILE_WRITE
+    // 写入本地文件(根据chat_id生成文件,已有文件不生成但追加写入数据)
+    if (audio_data != NULL && audio_size > 0) {
+        ln_ws_write_audio_to_file(audio_data, audio_size, g_audio_chat_ctx.chat_id);
+    }
+#endif
+    
     // Base64编码音频数据(如果是结束消息,则使用空字符串)
     char *audio_base64 = NULL;
     if (audio_size == 0) {