From c1e74041d2d3a4dc514f42cb24fe3302c290459f Mon Sep 17 00:00:00 2001 From: cheng Date: Thu, 18 Sep 2025 16:30:10 +0800 Subject: [PATCH] =?utf8?q?=E6=8F=90=E4=BE=9Bota=E7=9B=B8=E5=85=B3=E6=96=87?= =?utf8?q?=E4=BB=B6=E7=BB=99ui=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../thunderbird/include/ThunderBirdModel.h | 2 +- code/sdk/zhihui/leiniao/imsl_ln/ln_api.c | 81 ++++++++----------- code/sdk/zhihui/leiniao/imsl_ln/ln_api.h | 21 ++--- .../zhihui/leiniao/ln_api_cpp/CMakeLists.txt | 1 + .../leiniao/ln_api_cpp/ln_api_interface.cpp | 16 ++++ .../leiniao/ln_api_cpp/ln_api_interface.h | 16 ++++ 6 files changed, 80 insertions(+), 57 deletions(-) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h index 7f9e91699..85ad1d32d 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h @@ -10,7 +10,7 @@ #include #include #include "AppViewIDs.h" -#include "UiConfig.h" +// #include "UiConfig.h" namespace OHOS { diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c index ebecb72bb..e93d2a753 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c @@ -12,7 +12,7 @@ #include #include "stdio.h" #include "audio_stream_player.h" -#include "ln_api_interface.h" + #ifdef BOARD_N9 #include "leiniao/include/ln_story_player_simple.h" @@ -337,14 +337,12 @@ static void ln_handle_ota_task_response(const char *json_buf, int json_len) { /* 强制升级:直接触发下载 */ printf("[OTA] force upgrade: trigger download(强制升级:直接触发下载)\n"); - do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_OTA_DOWNLOAD, NULL, 0); + push_ota_status(OTA_UI_STATUS_START); } else if (ut == 0) { - /* 可选升级:此处仅提示,实际是否下载由上层UI决定(例如用户确认后再触发)*/ printf("[OTA] optional upgrade: waiting for user confirmation(可选升级:等待用户确认)\n"); - /* 如需自动下载,可取消下面注释 */ - // do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_OTA_DOWNLOAD, NULL, 0); + push_ota_status(OTA_UI_STATUS_START); } else { @@ -429,6 +427,7 @@ static void handle_ota_download_msg(const OtaDownloadMsg *msg) switch (msg->status) { case OTA_DOWNLOAD_STATUS_PROGRESS: printf("[OTA_DOWNLOAD] 下载进度: %d%%\n", msg->progress); + push_ota_progress(msg->progress); break; case OTA_DOWNLOAD_STATUS_COMPLETED: printf("[OTA_DOWNLOAD] 下载完成,文件路径: %s\n", msg->file_path); @@ -437,11 +436,14 @@ static void handle_ota_download_msg(const OtaDownloadMsg *msg) int md5_ok = ln_ota_is_md5_ok(msg->file_path, msg->md5); if (md5_ok == 1) { printf("[OTA_DOWNLOAD] MD5校验成功,准备重启升级\n"); + push_ota_status(OTA_UI_STATUS_SUCCESS); /* 外部可在此触发升级动作 */ } else if (md5_ok == 0) { printf("[OTA_DOWNLOAD] MD5校验失败,建议重新下载\n"); + push_ota_status(OTA_UI_STATUS_FAILED); } else { printf("[OTA_DOWNLOAD] MD5校验出错\n"); + push_ota_status(OTA_UI_STATUS_FAILED); } } break; @@ -460,10 +462,16 @@ static void handle_ota_download_msg(const OtaDownloadMsg *msg) /* ============================ WebSocket 业务消息 上层处理 ============================ */ void ln_ws_process_message(int cmd, const char *json_str) { - if (!json_str) return; + if (!json_str) + { + printf("[WS] invalid json string\n"); + return; + } + cJSON *root = cJSON_Parse(json_str); - if (!root) { - printf("[WS] invalid json\n"); + if (!root) + { + printf("[WS] parse json failed\n"); return; } const cJSON *msgId = cJSON_GetObjectItem(root, "messageId"); @@ -471,68 +479,47 @@ void ln_ws_process_message(int cmd, const char *json_str) const char *message_id = (msgId && cJSON_IsString(msgId)) ? msgId->valuestring : NULL; const char *cmd_str = (command && cJSON_IsString(command)) ? command->valuestring : ""; + printf("[WS] cmd=%d message_id=%s cmd_str=%s\n", cmd, message_id, cmd_str); + switch (cmd) { case LN_WS_RECV_CHARACTER_CHANGE: { - const cJSON *data = cJSON_GetObjectItem(root, "data"); - const cJSON *name = data ? cJSON_GetObjectItem(data, "characterName") : NULL; - const cJSON *cid = data ? cJSON_GetObjectItem(data, "characterId") : NULL; - printf("[WS] CharacterChange: name=%s id=%s\n", - (name && cJSON_IsString(name)) ? name->valuestring : "", - (cid && cJSON_IsString(cid)) ? cid->valuestring : ""); + printf("[WS] CharacterChange:角色切换\n"); break; } case LN_WS_RECV_CHARACTER_CONFIG_CHANGE: { - printf("[WS] CharacterConfigChange\n"); + printf("[WS] CharacterConfigChange:角色配置更改\n"); break; } case LN_WS_RECV_SLEEP_MODE_START: { - const cJSON *data = cJSON_GetObjectItem(root, "data"); - const cJSON *theme = data ? cJSON_GetObjectItem(data, "storyTheme") : NULL; - const char *device_id = uapi_ln_get_device_id(); - const char *token = uapi_ln_get_device_token(); - if (device_id && token) { - ln_story_random_http(device_id, token, - (theme && cJSON_IsString(theme)) ? theme->valuestring : NULL); - } - printf("[WS] SleepModeStart: storyTheme=%s\n", - (theme && cJSON_IsString(theme)) ? theme->valuestring : ""); + printf("[WS] SleepModeStart:哄睡模式开始\n"); break; } case LN_WS_RECV_SLEEP_MODE_END: { - const char *device_id = uapi_ln_get_device_id(); - const char *token = uapi_ln_get_device_token(); - if (device_id && token) { - ln_story_finish_http(device_id, token); - } - printf("[WS] SleepModeEnd\n"); + printf("[WS] SleepModeEnd:哄睡模式结束\n"); break; } case LN_WS_RECV_DEVICE_BIND: { - const cJSON *data = cJSON_GetObjectItem(root, "data"); - const cJSON *userId = data ? cJSON_GetObjectItem(data, "userId") : NULL; - printf("[WS] DeviceBind: userId=%s\n", - (userId && cJSON_IsString(userId)) ? userId->valuestring : ""); + printf("[WS] DeviceBind:设备绑定\n"); break; } case LN_WS_RECV_DEVICE_UNBIND: { - const cJSON *data = cJSON_GetObjectItem(root, "data"); - const cJSON *userId = data ? cJSON_GetObjectItem(data, "userId") : NULL; - printf("[WS] DeviceUnbind: userId=%s\n", - (userId && cJSON_IsString(userId)) ? userId->valuestring : ""); + printf("[WS] DeviceUnbind:设备解绑\n"); break; } case LN_WS_RECV_SCHEDULE_REMINDER: { - const cJSON *data = cJSON_GetObjectItem(root, "data"); - const cJSON *name = data ? cJSON_GetObjectItem(data, "scheduleName") : NULL; - printf("[WS] ScheduleReminder: %s\n", - (name && cJSON_IsString(name)) ? name->valuestring : ""); + printf("[WS] ScheduleReminder:日程提醒\n"); break; } case LN_WS_RECV_SCHEDULE_REMINDER_CFG: { - const cJSON *data = cJSON_GetObjectItem(root, "data"); - const cJSON *name = data ? cJSON_GetObjectItem(data, "scheduleName") : NULL; - printf("[WS] ScheduleReminderConfig: %s\n", - (name && cJSON_IsString(name)) ? name->valuestring : ""); + printf("[WS] ScheduleReminderConfig:日程提醒配置\n"); + break; + } + case LN_WS_RECV_DOWNLOAD_EMOJI: { + printf("[WS] DownloadEmoji:下载表情\n"); + break; + } + case LN_WS_RECV_DELETE_EMOJI: { + printf("[WS] DeleteEmoji:删除表情\n"); break; } default: { diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.h b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.h index e4b3742ab..e9917c502 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.h +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.h @@ -12,6 +12,7 @@ extern "C" #include "netstack/http/include/httpclient.h" #include #include "wearable_log.h" +#include "ln_api_interface.h" // 产品名称:Amby Box // 产品型号:AB101 @@ -83,15 +84,17 @@ typedef struct /* WebSocket 业务消息接收命令(供 WS 回调上报分类使用)*/ -#define LN_WS_RECV_UNKNOWN 0x70 -#define LN_WS_RECV_CHARACTER_CHANGE 0x71 -#define LN_WS_RECV_CHARACTER_CONFIG_CHANGE 0x72 -#define LN_WS_RECV_SLEEP_MODE_START 0x73 -#define LN_WS_RECV_SLEEP_MODE_END 0x74 -#define LN_WS_RECV_DEVICE_BIND 0x75 -#define LN_WS_RECV_DEVICE_UNBIND 0x76 -#define LN_WS_RECV_SCHEDULE_REMINDER 0x77 -#define LN_WS_RECV_SCHEDULE_REMINDER_CFG 0x78 +#define LN_WS_RECV_UNKNOWN 0x70 /* 未知命令 */ +#define LN_WS_RECV_CHARACTER_CHANGE 0x71 /* 角色切换 (CharacterChange) */ +#define LN_WS_RECV_CHARACTER_CONFIG_CHANGE 0x72 /* 角色配置更改 (CharacterConfigChange) */ +#define LN_WS_RECV_SLEEP_MODE_START 0x73 /* 哄睡模式开始 (SleepModeStart) */ +#define LN_WS_RECV_SLEEP_MODE_END 0x74 /* 哄睡模式结束 (SleepModeEnd) */ +#define LN_WS_RECV_DEVICE_BIND 0x75 /* 设备绑定 (DeviceBind) */ +#define LN_WS_RECV_DEVICE_UNBIND 0x76 /* 设备解绑 (DeviceUnbind) */ +#define LN_WS_RECV_SCHEDULE_REMINDER 0x77 /* 日程提醒 (ScheduleReminder) */ +#define LN_WS_RECV_SCHEDULE_REMINDER_CFG 0x78 /* 日程提醒配置 (ScheduleReminderConfig) */ +#define LN_WS_RECV_DOWNLOAD_EMOJI 0x79 /* 下载表情 (DownloadEmoji) */ +#define LN_WS_RECV_DELETE_EMOJI 0x7A /* 删除表情 (DeleteEmoji) */ /* 音频播放相关命令 */ #define LN_HTTP_SERVICE_CMD_AUDIO_PLAY 0x1001 /* 播放音频 */ diff --git a/code/sdk/zhihui/leiniao/ln_api_cpp/CMakeLists.txt b/code/sdk/zhihui/leiniao/ln_api_cpp/CMakeLists.txt index b7c826419..3db202a2e 100644 --- a/code/sdk/zhihui/leiniao/ln_api_cpp/CMakeLists.txt +++ b/code/sdk/zhihui/leiniao/ln_api_cpp/CMakeLists.txt @@ -15,6 +15,7 @@ ${ROOT_DIR}/middleware/services/media/foundation/audiomanager/interfaces/kits/au ${ROOT_DIR}/middleware/services/media/foundation/audiomanager/frameworks/audiostream/include ${ROOT_DIR}/middleware/services/media/foundation/sample/wrapper ${ROOT_DIR}/middleware/services/media/foundation/utils/include +${ROOT_DIR}/application/wearable/ln/nativeapp/nativeui/ ) set(AI_SOURCES 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 c001866b6..7388bfdb1 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 @@ -1,4 +1,5 @@ #include "ln_api_interface.h" +#include "thunderbird/include/ThunderBirdModel.h" #ifdef __cplusplus extern "C" @@ -6,14 +7,29 @@ extern "C" #endif #include +#include // 推送文本给ui void push_text_to_ui(const char *text) { + OHOS::ThunderBirdModel::GetInstance()->SetTextStr(text); +} +void push_ota_status(int status) +{ + printf("push_ota_status: %d\n", status); } +void push_ota_progress(int progress) +{ + printf("push_ota_progress: %d\n", progress); +} +void do_restore_factory_setting(void) +{ + printf("do_restore_factory_setting\n"); + OHOS::ThunderBirdModel::GetInstance()->restore_factory_settings(); +} #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 8f733b8a9..265585395 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 @@ -8,6 +8,22 @@ extern "C" // 推送文本给ui void push_text_to_ui(const char *text); +/* +ota升级状态 +*/ +typedef enum { + OTA_UI_STATUS_NOT_START = 0, /* 未开始 */ + OTA_UI_STATUS_START, /* 开始 */ + OTA_UI_STATUS_FAILED, /* 失败 */ + OTA_UI_STATUS_SUCCESS, /* 成功 */ +} ota_ui_status_t; + +void push_ota_status(int status); +void push_ota_progress(int progress); + +//恢复出厂操作 +void do_restore_factory_setting(void); + #ifdef __cplusplus } #endif -- 2.17.1