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) {
// }
// }
// {
-// "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)
{
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) {
}
}
- 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字符串