协议内容修改
authorhcj <1224667075@qq.com>
Thu, 6 Nov 2025 02:18:53 +0000 (10:18 +0800)
committerhcj <1224667075@qq.com>
Thu, 6 Nov 2025 02:18:53 +0000 (10:18 +0800)
code/sdk/zhihui/leiniao/imsl_ln/ln_api.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api.h
code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c

index 812f6bd..8852939 100644 (file)
@@ -932,14 +932,14 @@ void ln_ws_process_message(const ws_data_msg_t *data_msg, ws_command_t type)
         }
         break;
     }
-    case WS_CMD_SLEEP_MODE_INQUIRE:
+    case WS_CMD_SLEEP_MODE_INQUIRE_ACK:
     {
-        printf("[WS] SleepModeInquire:睡眠模式询问\n");
+        printf("[WS] SleepModeInquireAck:睡眠模式询问响应\n");
         if (data_msg)
         {
-            printf("[WS] SleepModeInquire - intention: %s, chatId: %s\n", 
-                   data_msg->text_content, data_msg->chat_id);
-            // 可以在这里添加具体的处理逻辑,比如触发UI通知等
+            printf("[WS] SleepModeInquireAck - textContent: %s, audioUrl: %s, audioDuration: %u, chatId: %s\n", 
+                   data_msg->text_content, data_msg->audio_url, data_msg->audio_duration, data_msg->chat_id);
+            // 可以在这里添加具体的处理逻辑,比如播放音频、显示文本等
         }
         break;
     }
index 1b439ac..4a6ae7f 100644 (file)
@@ -388,7 +388,8 @@ typedef enum {
     WS_CMD_CHARACTER_CONFIG_CHANGE, /* 角色配置更改 (CharacterConfigChange) */
     WS_CMD_SLEEP_MODE_START,         /* 哄睡模式开始 (SleepModeStart) */
     WS_CMD_SLEEP_MODE_END,           /* 哄睡模式结束 (SleepModeEnd) */
-    WS_CMD_SLEEP_MODE_INQUIRE,       /* 睡眠模式询问 (SleepModeInquire) */
+    WS_CMD_SLEEP_MODE_INQUIRE,       /* 睡眠模式询问 (SleepModeInquire) - 发送 */
+    WS_CMD_SLEEP_MODE_INQUIRE_ACK,   /* 睡眠模式询问响应 (SleepModeInquireAck) - 接收 */
     WS_CMD_DEVICE_BIND,              /* 设备绑定 (DeviceBind) */
     WS_CMD_DEVICE_UNBIND,            /* 设备解绑 (DeviceUnbind) */
     WS_CMD_SCHEDULE_REMINDER,        /* 日程提醒 (ScheduleReminder) */
index 6f6c628..a61e206 100644 (file)
@@ -1560,6 +1560,8 @@ static ws_command_t ln_ws_parse_command_string(const char *command_str)
         return WS_CMD_SLEEP_MODE_END;
     } else if (strcmp(command_str, "SleepModeInquire") == 0) {
         return WS_CMD_SLEEP_MODE_INQUIRE;
+    } else if (strcmp(command_str, "SleepModeInquireAck") == 0) {
+        return WS_CMD_SLEEP_MODE_INQUIRE_ACK;
     } else if (strcmp(command_str, "DeviceBind") == 0) {
         return WS_CMD_DEVICE_BIND;
     } else if (strcmp(command_str, "DeviceUnbind") == 0) {
@@ -1635,15 +1637,18 @@ static ws_command_t ln_ws_parse_command_string(const char *command_str)
 //     }
 //   }
 // {
-//     "deviceId": "DEVICE_001",
-//     "timestamp": 1640995200,
-//     "messageId": "sleep_inquire_001",
-//     "command": "SleepModeInquire",
-//     "data": {
-//       "intention": "START_SLEEP_MODE",
-//       "chatId": "chat_12345"
-//     }
+//   "deviceId": "DEVICE_001",
+//   "timestamp": 1640995201,
+//   "messageId": "sleep_inquire_ack_001",
+//   "command": "SleepModeInquireAck",
+//   "data": {
+//     "intention": "START_SLEEP_MODE",
+//     "textContent": "你想听故事吗?如果想听,请告诉我你想听什么类型的故事",
+//     "audioUrl": "https://example.com/audio/sleep_inquire.mp3",
+//     "audioDuration": 3000,
+//     "chatId": "chat_12345"
 //   }
+// }
 // {"deviceId":"860132063148589","timestamp":1760408698,"messageId":"1edfb1fc9d904ceb8ca5579241aee1ee","command":"VoiceChatResponse","data":{"finished":false,"chatId":"chat_1760408691_1125307275","data":{"audioDuration":1583,"audioUrl":"http://ambybox-api.test.leiniao.com/ambybox-device-api/file/933515348189_20251014102458_1760408698051.mp3","textContent":"有什么想聊聊的吗?","intention":"None","npcEmotion":"winking"}}}
 static int ln_ws_parse_data_message(const char *json_str, ws_data_msg_t *data_msg)
 {
@@ -1910,17 +1915,40 @@ static int ln_ws_parse_data_message(const char *json_str, ws_data_msg_t *data_ms
                data_msg->text_content, data_msg->audio_url);
     }
     
-    // 解析SleepModeInquire特定字段
-    if (data_msg->command == WS_CMD_SLEEP_MODE_INQUIRE) {
+    // 解析SleepModeInquireAck特定字段
+    if (data_msg->command == WS_CMD_SLEEP_MODE_INQUIRE_ACK) {
         cJSON *data_obj = cJSON_GetObjectItem(root, "data");
+        cJSON *intention = NULL;
         if (data_obj && cJSON_IsObject(data_obj)) {
-            // 解析intention字段,存储到text_content中
-            cJSON *intention = cJSON_GetObjectItem(data_obj, "intention");
+            // 解析intention字段
+            intention = cJSON_GetObjectItem(data_obj, "intention");
             if (intention && cJSON_IsString(intention) && intention->valuestring) {
-                strncpy(data_msg->text_content, intention->valuestring, sizeof(data_msg->text_content) - 1);
+                // intention 可以用于日志记录,但不覆盖 textContent
+                LN_WS_DEBUG("SleepModeInquireAck intention: %s\n", intention->valuestring);
+            }
+            
+            // 解析textContent字段,存储到text_content中
+            cJSON *text_content = cJSON_GetObjectItem(data_obj, "textContent");
+            if (text_content && cJSON_IsString(text_content) && text_content->valuestring) {
+                strncpy(data_msg->text_content, text_content->valuestring, sizeof(data_msg->text_content) - 1);
                 data_msg->text_content[sizeof(data_msg->text_content) - 1] = '\0';
             }
             
+            // 解析audioUrl字段
+            cJSON *audio_url = cJSON_GetObjectItem(data_obj, "audioUrl");
+            if (audio_url && cJSON_IsString(audio_url) && audio_url->valuestring) {
+                strncpy(data_msg->audio_url, audio_url->valuestring, sizeof(data_msg->audio_url) - 1);
+                data_msg->audio_url[sizeof(data_msg->audio_url) - 1] = '\0';
+            }
+            
+            // 解析audioDuration字段
+            cJSON *audio_duration = cJSON_GetObjectItem(data_obj, "audioDuration");
+            if (audio_duration && cJSON_IsNumber(audio_duration)) {
+                data_msg->audio_duration = (uint32_t)audio_duration->valuedouble;
+                // 记录音频时长
+                record_audio_duration(data_msg->audio_duration);
+            }
+            
             // 解析chatId字段
             cJSON *chat_id = cJSON_GetObjectItem(data_obj, "chatId");
             if (chat_id && cJSON_IsString(chat_id) && chat_id->valuestring) {
@@ -1929,8 +1957,9 @@ static int ln_ws_parse_data_message(const char *json_str, ws_data_msg_t *data_ms
             }
         }
         
-        LN_WS_DEBUG("SleepModeInquire parsed: intention=%s, chatId=%s\n",
-               data_msg->text_content, data_msg->chat_id);
+        LN_WS_DEBUG("SleepModeInquireAck parsed: intention=%s, textContent=%s, audioUrl=%s, audioDuration=%u, chatId=%s\n",
+               (intention && cJSON_IsString(intention) && intention->valuestring ? intention->valuestring : "N/A"),
+               data_msg->text_content, data_msg->audio_url, data_msg->audio_duration, data_msg->chat_id);
     }
     
     // 保存原始JSON字符串