提供ota相关文件给ui层 2297/1
authorcheng <chengyf@zhihuishixun.com>
Thu, 18 Sep 2025 08:30:10 +0000 (16:30 +0800)
committercheng <chengyf@zhihuishixun.com>
Thu, 18 Sep 2025 08:30:10 +0000 (16:30 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h
code/sdk/zhihui/leiniao/imsl_ln/ln_api.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api.h
code/sdk/zhihui/leiniao/ln_api_cpp/CMakeLists.txt
code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp
code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h

index ebecb72..e93d2a7 100644 (file)
@@ -12,7 +12,7 @@
 #include <soc_osal.h>
 #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 : "<null>");
+            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: {
index e4b3742..e9917c5 100644 (file)
@@ -12,6 +12,7 @@ extern "C"
 #include "netstack/http/include/httpclient.h"
 #include <unistd.h>
 #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 /* 播放音频 */
index b7c8264..3db202a 100644 (file)
@@ -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
index c001866..7388bfd 100644 (file)
@@ -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 <stdlib.h>
+#include <cstdio>
 
 // 推送文本给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
index 8f733b8..2655853 100644 (file)
@@ -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