From 6657e52378ff65ac2515c1b16d96589c100a717f Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Thu, 25 Sep 2025 14:42:46 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A0=E5=93=84=E7=9D=A1=E6=A8=A1?= =?utf8?q?=E5=BC=8F=E5=BC=80=E5=A7=8B=E5=92=8C=E7=BB=93=E6=9D=9Fat?= =?utf8?q?=E6=B5=8B=E8=AF=95=EF=BC=8C=E5=BE=85ui=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/include/uiservice/ui_service.h | 2 + .../nativeui/uiservice/src/ui_service.cpp | 19 ++++- .../zhihui/leiniao/imsl_ln/leiniao_api_at.c | 75 ++++++++++++++++++- code/sdk/zhihui/leiniao/imsl_ln/ln_api.c | 4 +- .../leiniao/imsl_ln/ln_api_story_random.c | 43 +++++++++++ .../leiniao/ln_api_cpp/ln_api_interface.cpp | 11 ++- .../leiniao/ln_api_cpp/ln_api_interface.h | 4 + 7 files changed, 152 insertions(+), 6 deletions(-) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h index d6618077c..100160330 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h @@ -54,6 +54,8 @@ typedef enum { HAND_SCHEDULE_REMINDER_NOTIFY, // 日程提醒通知 HAND_TASK_REMINDER_NOTIFY, // 任务提醒通知 HAND_CHARACTER_CONFIG_CHANGE_NOTIFY, // 角色配置更改通知 + HAND_SLEEP_MODE_START_NOTIFY, // 哄睡模式开始通知 + HAND_SLEEP_MODE_END_NOTIFY, // 哄睡模式结束通知 MAX_NUM_HANDLER, } UiServiceMsgId; diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp index fd3309b41..6e9956132 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -88,14 +88,16 @@ static void HandleJumpOtaView(Request *request); static void HandScheduleReminderNotify(Request *request); static void HandTaskReminderNotify(Request *request); static void HandTaskCharacterConfigNotify(Request *request); - +static void HandSleepModeStartNotify(Request *request); +static void HandSleepModeEndNotify(Request *request); // 消息处理程序项数组(每个消息类型对应一个处理函数,函数名以 Handle 开头) MsgHandlerEntry msgHandlers[] = { {HANDLE_JUMP_OTA_VIEW, HandleJumpOtaView}, {HAND_SCHEDULE_REMINDER_NOTIFY,HandScheduleReminderNotify}, {HAND_TASK_REMINDER_NOTIFY,HandTaskReminderNotify}, {HAND_CHARACTER_CONFIG_CHANGE_NOTIFY,HandTaskCharacterConfigNotify}, - + {HAND_SLEEP_MODE_START_NOTIFY,HandSleepModeStartNotify}, + {HAND_SLEEP_MODE_END_NOTIFY,HandSleepModeEndNotify}, }; /* -------------------------------------------------------------------------- */ void ScreenTurnOn(int32_t timeout) @@ -368,6 +370,19 @@ void HandTaskCharacterConfigNotify(Request *request) WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTaskCharacterConfigNotify msg_id = %d",request->msgId); int status = *(int *)request->data; } + +// 哄睡模式开始通知 +void HandSleepModeStartNotify(Request *request) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandSleepModeStartNotify msg_id = %d", request->msgId); + std::string theme(static_cast(request->data), request->len); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandSleepModeStartNotify storyTheme = %s", theme.c_str()); +} +// 哄睡模式结束通知 +void HandSleepModeEndNotify(Request *request) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandSleepModeEndNotify msg_id = %d",request->msgId); +} /* -------------------------------------------------------------------------- */ #ifdef __cplusplus } diff --git a/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c b/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c index b511f4a4f..9a2f704c7 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c @@ -832,6 +832,78 @@ static uint32_t ln_audio_resume_at(uint8_t *para, uint32_t paraLen, char *strCom return ERRCODE_SUCC; } +/* 哄睡模式开始: AT^LN_SLEEP_MODE_START[=storyTheme] */ +static uint32_t ln_sleep_mode_start_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + VAD_UNUSED(strCommonCmd); + const char *deviceId = uapi_ln_get_device_id(); + const char *id = (deviceId && deviceId[0]) ? deviceId : "DEVICE_LOCAL"; + const char *theme = ""; + if (para != NULL && paraLen > 0) { + uint8_t argv[LN_MAX_ARGC][LN_MAX_ARGV_LEN] = {0}; + uint32_t argc = 0; + (void)ConvertCmdToParam(para, paraLen, argv, &argc); + if (argc >= 1) { theme = (const char*)argv[0]; } + } + + char *json = (char*)malloc(512); + if (json == NULL) { + printf("[LN][SLEEP_START] OOM\n"); + return ERRCODE_FAIL; + } + int n = snprintf(json, 512, + "{\n" + " \"deviceId\": \"%s\",\n" + " \"timestamp\": %u,\n" + " \"messageId\": \"at_msg\",\n" + " \"command\": \"SleepModeStart\",\n" + " \"data\": {\n" + " \"storyTheme\": \"%s\"\n" + " }\n" + "}\n", + id, 0U, theme ? theme : ""); + if (n <= 0 || n >= 512) { + free(json); + printf("[LN][SLEEP_START] build json failed\n"); + return ERRCODE_FAIL; + } + + ln_parse_sleep_mode_start(json, n); + free(json); + return ERRCODE_SUCC; +} + +/* 哄睡模式结束: AT^LN_SLEEP_MODE_END */ +static uint32_t ln_sleep_mode_end_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + VAD_UNUSED(para); + VAD_UNUSED(paraLen); + VAD_UNUSED(strCommonCmd); + const char *deviceId = uapi_ln_get_device_id(); + const char *id = (deviceId && deviceId[0]) ? deviceId : "DEVICE_LOCAL"; + char *json = (char*)malloc(256); + if (json == NULL) { + printf("[LN][SLEEP_END] OOM\n"); + return ERRCODE_FAIL; + } + int n = snprintf(json, 256, + "{\n" + " \"deviceId\": \"%s\",\n" + " \"timestamp\": %u,\n" + " \"messageId\": \"at_msg\",\n" + " \"command\": \"SleepModeEnd\",\n" + " \"data\": {}\n" + "}\n", + id, 0U); + if (n <= 0 || n >= 256) { + free(json); + printf("[LN][SLEEP_END] build json failed\n"); + return ERRCODE_FAIL; + } + ln_parse_sleep_mode_end(json, n); + free(json); + return ERRCODE_SUCC; +} /* ==================== 对话控制相关AT命令实现 ==================== */ /** @@ -1400,7 +1472,8 @@ static const at_cmd_table_t g_ln_api_cmd[] = { {(char *)"AT^LN_SCHEDULE_REMINDER", ln_schedule_reminder_at, (char *)"日程提醒: AT^LN_SCHEDULE_REMINDER[=scheduleName,reminderContent]"}, {(char *)"AT^LN_SCHEDULE_REMINDER_CFG", ln_schedule_reminder_cfg_at, (char *)"日程提醒配置: AT^LN_SCHEDULE_REMINDER_CFG[=scheduleName]"}, {(char *)"AT^LN_CHARACTER_CFG", ln_character_config_change_at, (char *)"角色配置更改: AT^LN_CHARACTER_CFG[=name,eyesShape,hairColor,eyesColor,hairStyle,screenImageAsEmoji]"}, - + {(char *)"AT^LN_SLEEP_MODE_START", ln_sleep_mode_start_at, (char *)"哄睡模式开始: AT^LN_SLEEP_MODE_START[=storyTheme]"}, + {(char *)"AT^LN_SLEEP_MODE_END", ln_sleep_mode_end_at, (char *)"哄睡模式结束: AT^LN_SLEEP_MODE_END"}, /* 内存查看相关AT命令 */ {(char *)"AT^LN_MEMORY_INFO", ln_memory_info_at, (char *)"查看系统内存信息: AT^LN_MEMORY_INFO"}, {(char *)"AT^LN_FOLDER_SIZE", ln_folder_size_at, (char *)"查看文件夹大小: AT^LN_FOLDER_SIZE[=/path/to/folder]"}, diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c index ebdf3408d..698f1bed8 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c @@ -702,7 +702,7 @@ void ln_ws_process_message(const ws_data_msg_t *data_msg, ws_command_t type) printf("[WS] SleepModeStart:哄睡模式开始\n"); if(json_str) { - // ln_parse_sleep_mode_start(json_str, (int)strlen(json_str)); + ln_parse_sleep_mode_start(json_str, (int)strlen(json_str)); } break; } @@ -710,7 +710,7 @@ void ln_ws_process_message(const ws_data_msg_t *data_msg, ws_command_t type) printf("[WS] SleepModeEnd:哄睡模式结束\n"); if(json_str) { - // ln_parse_sleep_mode_end(json_str, (int)strlen(json_str)); + ln_parse_sleep_mode_end(json_str, (int)strlen(json_str)); } break; } diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c index c068f32c2..afc395331 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c @@ -1,6 +1,7 @@ #include "ln_api.h" #include #include +#include "cJSON.h" static void ln_parse_story_random_file(void) { @@ -199,3 +200,45 @@ uint32_t ln_story_random_http(const char *device_id, free(escaped_theme); return ERRCODE_SUCC; } + +/* 解析哄睡模式开始:提取data.storyTheme并触发随机故事 */ +void ln_parse_sleep_mode_start(const char *json_str, int json_len) +{ + printf("[LN][SLEEP_START] parse json\n"); + (void)json_len; + if (json_str == NULL) { + printf("[LN][SLEEP_START] invalid json\n"); + return; + } + printf("[LN][SLEEP_START] parse json\n"); + const char *theme = NULL; + cJSON *root = cJSON_Parse(json_str); + if (root) { + cJSON *data = cJSON_GetObjectItem(root, "data"); + if (data && cJSON_IsObject(data)) { + cJSON *storyTheme = cJSON_GetObjectItem(data, "storyTheme"); + if (storyTheme && cJSON_IsString(storyTheme) && storyTheme->valuestring && storyTheme->valuestring[0]) { + theme = storyTheme->valuestring; + } + } + } + + printf("[LN][SLEEP_START] storyTheme=%s\n", theme); + // 该接口不需要任何参数,系统会自动生成随机主题的故事 + // storyTheme=随机 + if(theme == NULL || theme[0] == '\0') { + theme = "随机"; + } + push_sleep_mode_start_notification(theme); + if (root) cJSON_Delete(root); +} + +/* 解析哄睡模式结束:通知UI并设置结束标志 */ +void ln_parse_sleep_mode_end(const char *json_str, int json_len) +{ + (void)json_str; + (void)json_len; + printf("[LN][SLEEP_END] received\n"); + /* 标记故事结束,供UI状态机使用 */ + push_sleep_mode_end_notification(); +} diff --git a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp index b86054204..75a9806f1 100644 --- a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp +++ b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp @@ -126,7 +126,16 @@ void push_character_config_change_notification(const char* characterId, SendMsgToUIService(HAND_CHARACTER_CONFIG_CHANGE_NOTIFY, 0, (void *)payload, (int32_t)strlen(payload)); } - +//通知ui跳转哄睡界面 +void push_sleep_mode_start_notification(const char *storyTheme) +{ + SendMsgToUIService(HAND_SLEEP_MODE_START_NOTIFY, 0, (void *)storyTheme, (int32_t)strlen(storyTheme)); +} +//通知ui跳转哄睡界面结束 +void push_sleep_mode_end_notification(void) +{ + SendMsgToUIService(HAND_SLEEP_MODE_END_NOTIFY, 0, NULL, 0); +} #ifdef __cplusplus }; #endif \ No newline at end of file diff --git a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h index 4e3c757e4..eabfcfd80 100644 --- a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h +++ b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h @@ -61,6 +61,10 @@ void push_character_config_change_notification( const char *eyesColor, const char *hairStyle, int screenImageAsEmoji); +//通知ui跳转哄睡界面 +void push_sleep_mode_start_notification(const char *storyTheme); +//通知ui跳转哄睡界面结束 +void push_sleep_mode_end_notification(void); #ifdef __cplusplus } #endif -- 2.17.1