增加调试窗口 2766/1 2766/head 2767/target/1
authorxue <2144439972@qq.com>
Wed, 19 Nov 2025 04:07:38 +0000 (12:07 +0800)
committerxue <2144439972@qq.com>
Wed, 19 Nov 2025 04:07:38 +0000 (12:07 +0800)
code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_cmd.cpp
code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/ws_net_task.cpp [new file with mode: 0644]
code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/ws_net_task.h [new file with mode: 0644]
code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c

index b0e2bd3..9938972 100644 (file)
@@ -24,6 +24,7 @@
 #include "components/ui_view.h"
 #include "common/screen.h"
 #include "dfx/fps_task.h"
+#include "dfx/ws_net_task.h"
 #include "engines/gfx/lite_m_gfx_engine.h"
 #include "gfx_utils/mem_check.h"
 #include "gfx_utils/image_info.h"
@@ -434,6 +435,38 @@ void PrintFPS(int argc, char *argv[])
     }
 }
 
+extern "C" void ShowWSNet(int argc, char *argv[])
+{
+    if (argc == 0) {
+        WSNetTask::GetInstance()->ShowWSNet();
+        return;
+    }
+
+    if ((argc == 1) && (strcmp(argv[0], "-h") == 0)) {
+        printf("---GUI showws [-p] [position]---\n");
+        printf("   -h: help, GUI showws descriptions.\n");
+        printf("   -p: position, where ws/net info are shown on screen, eg. showws -p x,y\n");
+        return;
+    }
+
+    if ((argc == 2) && (strcmp(argv[0], "-p") == 0)) { // 2: param num
+        uint16_t left = 0;
+        uint16_t top = 0;
+        char* temp = nullptr;
+        if (!ConvertToInt(strtok_r(argv[1], ",", &temp), left) ||
+            !ConvertToInt(strtok_r(nullptr, ",", &temp), top)) {
+            GRAPHIC_LOGE("Please input position in correct value: x,y");
+            return;
+        }
+        WSNetTask::GetInstance()->ShowWSNet(left, top);
+    }
+}
+
+extern "C" void HideWSNet(int argc, char *argv[])
+{
+    WSNetTask::GetInstance()->HideWSNet();
+}
+
 #if defined (SUPPORT_DIAL_DEBUG)
 void PrintWatchDialInfo(const watch_dial_info &info)
 {
@@ -715,6 +748,8 @@ struct DfxCmd g_dfxCmdList[] = {{"screencap", OHOS::ScreencapCmd},
     {"printfps", OHOS::PrintFPS},
     {"hidefps", OHOS::HideFPS},
     {"showfps", OHOS::ShowFPS},
+    {"showws", OHOS::ShowWSNet},
+    {"hidews", OHOS::HideWSNet},
     {"showtime", OHOS::ShowTime},
     {"refresh", OHOS::ForceRefresh},
 #if defined (SUPPORT_DIAL_DEBUG)
diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/ws_net_task.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/ws_net_task.cpp
new file mode 100644 (file)
index 0000000..3fe0858
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2022 CompanyNameMagicTag.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dfx/ws_net_task.h"
+#if ENABLE_DFX_CMD
+#include <cmath>
+#include <string>
+#include <cstdio>
+#include "graphic_config.h"
+#include "common/screen.h"
+#include "common/text.h"
+#include "components/root_view.h"
+#include "dfx/ws_net_task.h"
+#include "hal_tick.h"
+
+#ifdef SUPPORT_CAT1_SERVICE
+#include "custom_runtime.h"
+#endif
+
+// 前向声明,避免循环依赖
+#ifdef __cplusplus
+extern "C" {
+#endif
+// WebSocket连接状态函数声明
+const char* ln_ws_get_connection_state_string(void);
+#ifdef __cplusplus
+}
+#endif
+
+namespace OHOS {
+static constexpr int16_t WS_NET_LABEL_FONT_SIZE = 20;
+static constexpr int16_t WS_NET_LABEL_WIDTH = 200;
+static constexpr int16_t WS_NET_LABEL_HEIGHT = 120;
+static constexpr int16_t DEFAULT_WS_NET_LABEL_LEFT = 100;
+static constexpr int16_t DEFAULT_WS_NET_LABEL_TOP = 100;
+static constexpr uint32_t SHOW_TIME_PERIOD = 1000; // in ms
+
+void WSNetTask::Callback()
+{
+    if (needShow_) {
+        if (wsNetLabel_ == nullptr) {
+            return;
+        }
+        // always ensure that wsNetLabel is on the top
+        if (RootView::GetInstance()->GetChildrenTail() != wsNetLabel_) {
+            if (isAdded_) {
+                RootView::GetInstance()->Remove(wsNetLabel_);
+            }
+            RootView::GetInstance()->Add(wsNetLabel_);
+            isAdded_ = true;
+        }
+        uint32_t showElapse = HALTick::GetInstance().GetElapseTime(showStartTime_);
+        if (showElapse >= (SHOW_TIME_PERIOD * showCount_)) {
+            showCount_++;
+            
+            // 获取WebSocket连接状态
+            const char* wsState = "未知";
+            // 直接调用函数,函数已通过前向声明保证存在
+            wsState = ln_ws_get_connection_state_string();
+            
+            // 获取网络参数
+            int simStatus = 0;
+            int cat1PowerStatus = 0;
+            int signalStrength = 0;
+            int networkStatus = 0;
+            int networkType = 0;
+            
+#ifdef SUPPORT_CAT1_SERVICE
+            simStatus = uapi_dev_runtime_get_cat1_simstat();
+            cat1PowerStatus = uapi_dev_runtime_get_cat1_powerstat();
+            signalStrength = uapi_dev_runtime_get_cat1_signal();
+            networkStatus = uapi_dev_runtime_get_cat1_networkstat();
+            networkType = uapi_dev_runtime_get_cat1_networtype();
+#endif
+            
+            // 格式化显示文本
+            snprintf(textBuffer_, sizeof(textBuffer_),
+                "WS:%s\n"
+                "SIM:%d PWR:%d\n"
+                "SIG:%d NET:%d\n"
+                "TYPE:%d",
+                wsState,
+                simStatus, cat1PowerStatus,
+                signalStrength, networkStatus,
+                networkType);
+            
+            wsNetLabel_->SetText(textBuffer_);
+            wsNetLabel_->SetPosition(left_, top_);
+            wsNetLabel_->Invalidate();
+        }
+    } else {
+        if (isAdded_) {
+            RootView::GetInstance()->Remove(wsNetLabel_);
+            RootView::GetInstance()->InvalidateRect(wsNetLabel_->GetRect());
+            isAdded_ = false;
+        }
+    }
+}
+
+void WSNetTask::ShowWSNet(int left, int top)
+{
+    if (wsNetLabel_ == nullptr) {
+        wsNetLabel_ = new UILabel();
+        wsNetLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, WS_NET_LABEL_FONT_SIZE);
+        wsNetLabel_->SetTextColor(Color::Red());
+        wsNetLabel_->SetWidth(WS_NET_LABEL_WIDTH);
+        wsNetLabel_->SetHeight(WS_NET_LABEL_HEIGHT);
+        wsNetLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT,
+            UITextLanguageAlignment::TEXT_ALIGNMENT_TOP);
+        wsNetLabel_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+        wsNetLabel_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+    }
+    if (isFirstShow_) {
+        left_ = ((left <= 0 || left >= Screen::GetInstance().GetWidth()) ? DEFAULT_WS_NET_LABEL_LEFT : left);
+        top_ = ((top <= 0 || top >=  Screen::GetInstance().GetHeight()) ? DEFAULT_WS_NET_LABEL_TOP : top);
+        isFirstShow_ = false;
+    }
+    showCount_ = 0;
+    showStartTime_ = HALTick::GetInstance().GetTime();
+    needShow_ = true;
+}
+
+void WSNetTask::HideWSNet()
+{
+    needShow_ = false;
+}
+}
+#endif
+
diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/ws_net_task.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/ws_net_task.h
new file mode 100644 (file)
index 0000000..b1a19f9
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2022 CompanyNameMagicTag.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WS_NET_TASK_H
+#define WS_NET_TASK_H
+
+#include "graphic_config.h"
+#if ENABLE_DFX_CMD
+#include <atomic>
+#include "common/task_manager.h"
+#include "components/ui_label.h"
+
+namespace OHOS {
+class WSNetTask : public Task {
+public:
+    static WSNetTask *GetInstance()
+    {
+        static WSNetTask instance;
+        instance.Init();
+        return &instance;
+    }
+
+    void Callback() override;
+    void ShowWSNet(int left = 0, int top = 0);
+    void HideWSNet();
+
+private:
+    UILabel *wsNetLabel_ = nullptr;
+    bool isFirstShow_ = true;
+    bool isAdded_ = false;
+    bool needShow_ = false;
+    uint32_t showStartTime_ = 0;
+    uint32_t showCount_ = 0;
+    int16_t left_ = 0;
+    int16_t top_ = 0;
+    char textBuffer_[256];
+};
+}
+#endif // ENABLE_DFX_CMD
+#endif  // WS_NET_TASK_H
+
index e5264bd..8bacb6d 100644 (file)
@@ -27,6 +27,7 @@
 /* 对话控制相关AT命令函数声明 */
 static uint32_t ln_conversation_flag_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
 static uint32_t ln_push_text_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
+static uint32_t ln_timeline_status_change_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
 
 //恢复出厂设置相关AT命令函数声明
 static uint32_t ln_factory_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
@@ -42,6 +43,10 @@ static uint32_t ln_switch_expression_at(uint8_t *para, uint32_t paraLen, char *s
 static uint32_t ln_set_fps_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
 static uint32_t ln_get_fps_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
 
+//WS状态和网络参数显示相关AT命令函数声明
+static uint32_t ln_show_ws_net_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
+static uint32_t ln_hide_ws_net_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
+
 //网络检测相关AT命令函数声明
 static uint32_t ln_check_internet_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
 static uint32_t ln_check_dns_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd);
@@ -756,6 +761,52 @@ static uint32_t ln_push_text_at(uint8_t *para, uint32_t paraLen, char *strCommon
     return ERRCODE_SUCC;
 }
 
+/**
+ * @brief 推送时间线状态变化通知的AT命令
+ * @param para 参数字符串
+ * @param paraLen 参数长度  
+ * @param strCommonCmd 命令字符串
+ * @return 错误码
+ * 
+ * 用法: AT^LN_TIMELINE_STATUS_CHANGE=状态描述,表情
+ *      AT^LN_TIMELINE_STATUS_CHANGE="今天天气不错","happy"
+ */
+static uint32_t ln_timeline_status_change_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    LN_UNUSED(strCommonCmd);
+    
+    uint8_t argv[LN_MAX_ARGC][LN_MAX_ARGV_LEN] = {0};
+    uint32_t argc = 0;
+    
+    // 解析参数
+    if (ConvertCmdToParam(para, paraLen, argv, &argc) != LN_SUCCESS) {
+        printf("ERROR: Failed to parse parameters\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc < 1) {
+        printf("ERROR: Missing description parameter\n");
+        printf("Usage: AT^LN_TIMELINE_STATUS_CHANGE=description,emotion\n");
+        return ERRCODE_FAIL;
+    }
+
+    const char *emotion = (char*)argv[0];
+    // const char *emotion = (argc >= 2 && argv[1][0]) ? (char*)argv[1] : "";
+    
+
+    // 检查参数长度限制
+    if (strlen(emotion) > 256) {
+        printf("ERROR: Emotion too long (max 256 characters)\n");
+        return ERRCODE_FAIL;
+    }
+
+    // 推送时间线状态变化通知
+    push_timeline_status_change_notification("表情测试", emotion);
+    printf("+LN_TIMELINE_STATUS_CHANGE: OK\n");
+    
+    return ERRCODE_SUCC;
+}
+
 /* 恢复出厂设置: AT^LN_FACTORY */
 static uint32_t ln_factory_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
@@ -1224,6 +1275,87 @@ static uint32_t ln_get_fps_at(uint8_t *para, uint32_t paraLen, char *strCommonCm
     return ERRCODE_SUCC;
 }
 
+/* AT^LN_SHOW_WS_NET[=-p x,y] */
+/* 显示WebSocket连接状态和网络参数 */
+static uint32_t ln_show_ws_net_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    LN_UNUSED(strCommonCmd);
+    
+    // 前向声明C++函数(在OHOS命名空间中)
+    #ifdef __cplusplus
+    extern "C" {
+    #endif
+    void ShowWSNet(int argc, char *argv[]);
+    #ifdef __cplusplus
+    }
+    #endif
+    
+    uint8_t argv[LN_MAX_ARGC][LN_MAX_ARGV_LEN] = {0};
+    uint32_t argc = 0;
+    char *c_argv[LN_MAX_ARGC] = {0};
+    
+    printf("[LN][SHOW_WS_NET] Showing WebSocket and network status...\n");
+    
+    // 如果没有参数,直接显示
+    if (para == NULL || paraLen == 0) {
+        ShowWSNet(0, NULL);
+        printf("[LN][SHOW_WS_NET] Display enabled at default position\n");
+        return ERRCODE_SUCC;
+    }
+    
+    // 解析参数
+    if (ConvertCmdToParam(para, paraLen, argv, &argc) != LN_SUCCESS) {
+        printf("[LN][SHOW_WS_NET] ERROR: Failed to parse parameters\n");
+        printf("Usage: AT^LN_SHOW_WS_NET or AT^LN_SHOW_WS_NET=-p x,y\n");
+        return ERRCODE_FAIL;
+    }
+    
+    // 转换参数为char*数组
+    for (uint32_t i = 0; i < argc && i < LN_MAX_ARGC; i++) {
+        c_argv[i] = (char*)argv[i];
+    }
+    
+    // 检查是否是位置参数 -p x,y
+    if (argc == 2 && strcmp((char*)argv[0], "-p") == 0) {
+        ShowWSNet(argc, c_argv);
+        printf("[LN][SHOW_WS_NET] Display enabled at position: %s\n", (char*)argv[1]);
+    } else if (argc == 1 && strcmp((char*)argv[0], "-h") == 0) {
+        printf("---LN showws [-p] [position]---\n");
+        printf("   -h: help, LN showws descriptions.\n");
+        printf("   -p: position, where ws/net info are shown on screen, eg. -p x,y\n");
+        printf("   Example: AT^LN_SHOW_WS_NET=-p 100,100\n");
+    } else {
+        printf("[LN][SHOW_WS_NET] ERROR: Invalid parameters\n");
+        printf("Usage: AT^LN_SHOW_WS_NET or AT^LN_SHOW_WS_NET=-p x,y\n");
+        return ERRCODE_FAIL;
+    }
+    
+    return ERRCODE_SUCC;
+}
+
+/* AT^LN_HIDE_WS_NET */
+/* 隐藏WebSocket连接状态和网络参数显示 */
+static uint32_t ln_hide_ws_net_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    LN_UNUSED(para);
+    LN_UNUSED(paraLen);
+    LN_UNUSED(strCommonCmd);
+    
+    // 前向声明C++函数(在OHOS命名空间中)
+    #ifdef __cplusplus
+    extern "C" {
+    #endif
+    void HideWSNet(int argc, char *argv[]);
+    #ifdef __cplusplus
+    }
+    #endif
+    
+    printf("[LN][HIDE_WS_NET] Hiding WebSocket and network status display...\n");
+    HideWSNet(0, NULL);
+    printf("[LN][HIDE_WS_NET] Display disabled\n");
+    return ERRCODE_SUCC;
+}
+
 /* AT^LN_DOWNLOAD_EMOJI */
 static uint32_t ln_download_emoji_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
@@ -1377,10 +1509,11 @@ static uint32_t ln_switch_expression_at(uint8_t *para, uint32_t paraLen, char *s
         printf("ERROR: Empty video path parameter\n");
         return ERRCODE_FAIL;
     }
-    
+
     // 拼接完整路径:/user/userdata/leiniao/emoji + 用户输入的路径
     char full_path[512];
-    const char *base_path = "/user/userdata/leiniao/emoji";
+    // const char *base_path = "/user/userdata/leiniao/emoji";
+    const char *base_path = "/user/res/video/Default";
     
     // 检查总路径长度限制
     if (strlen(base_path) + strlen(video_path) + 1 > sizeof(full_path)) {
@@ -1576,6 +1709,7 @@ static const at_cmd_table_t g_ln_api_cmd[] = {
     {(char *)"AT^LN_API_ERROR", ln_api_error_at, (char *)"推送协议错误: AT^LN_API_ERROR[=message]"},
     {(char *)"AT^LN_NOTIFY_BIND_AND_UNBIND", ln_notify_bind_and_unbind_at, (char *)"通知用户绑定或解绑: AT^LN_NOTIFY_BIND_AND_UNBIND=1/0"},
     {(char *)"AT^LN_NOTIFY_DOWNLOAD_SUCCESS", ln_download_success_notification_at, (char *)"通知切换屏保: AT^LN_NOTIFY_DOWNLOAD_SUCCESS=0/1"},
+    {(char *)"AT^LN_TIMELINE_STATUS_CHANGE", ln_timeline_status_change_at, (char *)"推送时间线状态变化: AT^LN_TIMELINE_STATUS_CHANGE[=description,emotion]"},
     
     
     /* 内存查看相关AT命令 */
@@ -1595,6 +1729,10 @@ static const at_cmd_table_t g_ln_api_cmd[] = {
     //帧率控制
     {(char *)"AT^LN_SET_FPS", ln_set_fps_at, (char *)"设置帧率: AT^LN_SET_FPS=<fps_value>"},
     {(char *)"AT^LN_GET_FPS", ln_get_fps_at, (char *)"获取当前帧率: AT^LN_GET_FPS"},
+    
+    //WS状态和网络参数显示
+    {(char *)"AT^LN_SHOW_WS_NET", ln_show_ws_net_at, (char *)"显示WS连接状态和网络参数: AT^LN_SHOW_WS_NET[=-p x,y]"},
+    {(char *)"AT^LN_HIDE_WS_NET", ln_hide_ws_net_at, (char *)"隐藏WS连接状态和网络参数显示: AT^LN_HIDE_WS_NET"},
 };