优化ppptestview内容显示,产测模式下不开启ln websocket 2526/1 2526/head 2527/target/1
authorpenglei <1624952103@qq.com>
Wed, 15 Oct 2025 10:17:44 +0000 (18:17 +0800)
committerpenglei <1624952103@qq.com>
Wed, 15 Oct 2025 10:17:44 +0000 (18:17 +0800)
code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp
code/sdk/zhihui/leiniao/imsl_ln/ln_api.c

index 8c32288..2001cc0 100644 (file)
@@ -15,6 +15,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <time.h>
+#include "osal_task.h"
+#include "cmsis_os2.h"
 
 namespace OHOS
 {
@@ -501,6 +503,15 @@ static OHOS::UIView* g_saved_current_view = nullptr;
 static OHOS::UILabel* g_ppp_status_labels[12] = {nullptr}; // 支持12个状态标签
 static bool g_ppp_init_completed = false;
 
+// 定时器相关变量
+static osTimerId_t g_ppp_update_timer_handle = nullptr;
+static bool g_ppp_timer_running = false;
+
+// 前向声明
+extern "C" {
+    int ppp_test_stop_dial(void);
+}
+
 // 更新信号质量信息显示 - 统一格式结构
 static void update_signal_quality_display() {
     if (!g_ppp_init_completed) {
@@ -524,10 +535,10 @@ static void update_signal_quality_display() {
     if (ret != PPP_ERR_OK) {
         printf("获取信号质量信息失败: %d\n", ret);
         // 显示错误信息
-        if (g_ppp_status_labels[4] != nullptr) {
-            g_ppp_status_labels[4]->SetText("信号质量获取失败");
-            g_ppp_status_labels[4]->SetVisible(true);
-            g_ppp_status_labels[4]->Invalidate();
+        if (g_ppp_status_labels[2] != nullptr) {
+            g_ppp_status_labels[2]->SetText("信号质量获取失败");
+            g_ppp_status_labels[2]->SetVisible(true);
+            g_ppp_status_labels[2]->Invalidate();
         }
         return;
     }
@@ -541,13 +552,13 @@ static void update_signal_quality_display() {
         
     if (!signal_info.valid) {
         printf("信号质量信息无效\n");
-        if (g_ppp_status_labels[4] != nullptr) {
-            g_ppp_status_labels[4]->SetText("信号质量: 信息无效");
-            g_ppp_status_labels[4]->SetVisible(true);
-            g_ppp_status_labels[4]->Invalidate();
+        if (g_ppp_status_labels[2] != nullptr) {
+            g_ppp_status_labels[2]->SetText("信号质量: 信息无效");
+            g_ppp_status_labels[2]->SetVisible(true);
+            g_ppp_status_labels[2]->Invalidate();
         }
         // 清空其他信号质量标签
-        for (int i = 5; i < 12; i++) {
+        for (int i = 3; i < 12; i++) {
             if (g_ppp_status_labels[i] != nullptr) {
                 g_ppp_status_labels[i]->SetText("");
                 g_ppp_status_labels[i]->SetVisible(false);
@@ -557,7 +568,7 @@ static void update_signal_quality_display() {
         return;
     }
     
-    int label_index = 4; // 从第4个标签开始显示信号质量信息(去掉状态行后调整)
+    int label_index = 2; // 从第2个标签开始显示信号质量信息(去掉状态、信号、SIM行后调整)
     
     // 检查LTE信号参数有效性
     if (signal_info.rsrq != 255 && signal_info.rsrp != 255 && 
@@ -743,6 +754,124 @@ static void update_imei_iccid_display() {
     free(buffer);
 }
 
+// 切换到AT模式并继续后续操作
+static void switch_to_at_mode_and_continue() {
+    printf("=== 开始切换到AT模式 ===\n");
+    
+    // 调用ppp_test_stop_dial函数切换到AT模式
+    int ret = ppp_test_stop_dial();
+    if (ret == 0) {
+        printf("PPP STOP DIAL: 成功切换到AT模式\n");
+        
+        // 等待一段时间确保模式切换完成
+        osal_msleep(1000);
+        
+        // 设置AT通信标志为true(解决之前的问题)
+        extern void set_at_communication_and_baudrate_flag(bool flag);
+        set_at_communication_and_baudrate_flag(true);
+        printf("AT通信标志已设置为true\n");
+        
+    } else {
+        printf("PPP STOP DIAL: 切换到AT模式失败,错误码: %d\n", ret);
+        
+        // 即使失败也尝试设置AT标志
+        extern void set_at_communication_and_baudrate_flag(bool flag);
+        set_at_communication_and_baudrate_flag(true);
+        printf("强制设置AT通信标志为true\n");
+    }
+    
+    printf("=== AT模式切换完成 ===\n");
+}
+
+// 定时器回调函数 - 定期更新信号质量
+static void ppp_update_timer_callback(void* arg) {
+    (void)arg;  // 未使用的参数
+    
+    if (!g_ppp_init_completed || !g_ppp_timer_running) {
+        return;
+    }
+    
+    printf("=== 定时器触发:更新信号质量 ===\n");
+    
+    // 确保在AT模式下
+    extern void set_at_communication_and_baudrate_flag(bool flag);
+    set_at_communication_and_baudrate_flag(true);
+    
+    // 更新IMEI和ICCID信息(偶尔更新)
+    static int update_counter = 0;
+    if (update_counter % 10 == 0) {  // 每10次更新一次IMEI/ICCID
+        update_imei_iccid_display();
+    }
+    
+    // 更新信号质量显示
+    update_signal_quality_display();
+    
+    // 刷新UI
+    OHOS::RootView* rootView = OHOS::RootView::GetInstance();
+    if (rootView != nullptr) {
+        rootView->Invalidate();
+    }
+    
+    update_counter++;
+    printf("定时器更新完成,计数器: %d\n", update_counter);
+}
+
+// 启动定时器
+static void start_ppp_update_timer() {
+    if (g_ppp_timer_running) {
+        printf("PPP更新定时器已经在运行\n");
+        return;
+    }
+    
+    printf("=== 启动PPP信号质量更新定时器 ===\n");
+    
+    // 创建定时器,每3秒更新一次
+    g_ppp_update_timer_handle = osTimerNew((osTimerFunc_t)ppp_update_timer_callback, 
+                                           osTimerPeriodic, 
+                                           nullptr, 
+                                           nullptr);
+    
+    if (g_ppp_update_timer_handle != nullptr) {
+        osStatus_t status = osTimerStart(g_ppp_update_timer_handle, 3000);  // 3秒间隔
+        if (status == osOK) {
+            g_ppp_timer_running = true;
+            printf("PPP更新定时器启动成功,间隔3秒\n");
+        } else {
+            printf("PPP更新定时器启动失败: %d\n", status);
+            osTimerDelete(g_ppp_update_timer_handle);
+            g_ppp_update_timer_handle = nullptr;
+        }
+    } else {
+        printf("PPP更新定时器创建失败\n");
+        g_ppp_update_timer_handle = nullptr;
+    }
+}
+
+// 停止定时器
+static void stop_ppp_update_timer() {
+    if (!g_ppp_timer_running || g_ppp_update_timer_handle == nullptr) {
+        printf("PPP更新定时器未运行\n");
+        return;
+    }
+    
+    printf("=== 停止PPP信号质量更新定时器 ===\n");
+    
+    osStatus_t status = osTimerStop(g_ppp_update_timer_handle);
+    if (status == osOK) {
+        status = osTimerDelete(g_ppp_update_timer_handle);
+        if (status == osOK) {
+            printf("PPP更新定时器停止成功\n");
+        } else {
+            printf("PPP更新定时器删除失败: %d\n", status);
+        }
+    } else {
+        printf("PPP更新定时器停止失败: %d\n", status);
+    }
+    
+    g_ppp_timer_running = false;
+    g_ppp_update_timer_handle = nullptr;
+}
+
 // 获取并更新PPP显示信息
 static void update_ppp_display_info(void)
 {
@@ -883,8 +1012,6 @@ static void simple_ppp_test_start(void)
     const char* labelTexts[] = {
         "IMEI: 未知",
         "ICCID: 未知", 
-        "信号: 未知",
-        "SIM: 未知",
         "信号质量: 未知",
         "",  // RSRQ
         "",  // RSRP
@@ -892,6 +1019,8 @@ static void simple_ppp_test_start(void)
         "",  // 预留
         "",  // 预留
         "",  // 预留
+        "",  // 预留
+        "",  // 预留
         ""   // 预留
     };
     
@@ -905,7 +1034,7 @@ static void simple_ppp_test_start(void)
             g_ppp_status_labels[i]->SetFont("SourceHanSansSC-Regular.otf", 14);
             g_ppp_status_labels[i]->SetStyle(OHOS::STYLE_TEXT_COLOR, 0xffffffff); // 白色文字
             g_ppp_status_labels[i]->SetAlign(OHOS::UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT);
-            g_ppp_status_labels[i]->SetVisible(i < 5); // 前5个标签默认可见(去掉状态行后调整)
+            g_ppp_status_labels[i]->SetVisible(i < 3); // 前3个标签默认可见(去掉状态、信号、SIM行后调整)
             g_simple_ppp_container->Add(g_ppp_status_labels[i]);
         }
     }
@@ -913,6 +1042,10 @@ static void simple_ppp_test_start(void)
     // 设置初始化完成标志
     g_ppp_init_completed = true;
     
+    // 首先切换到AT模式
+    printf("=== PPP测试启动:切换到AT模式 ===\n");
+    switch_to_at_mode_and_continue();
+    
     // 获取并显示实际的PPP信息
     update_ppp_display_info();
     
@@ -922,10 +1055,13 @@ static void simple_ppp_test_start(void)
     // 更新详细的信号质量显示
     update_signal_quality_display();
     
+    // 启动定时器进行周期性更新
+    start_ppp_update_timer();
+    
     // 添加容器到根视图
     rootView->Add(g_simple_ppp_container);
     rootView->Invalidate();
-    
+
     printf("Simple PPP UI created and displayed with detailed signal info\n");
 }
 
@@ -951,6 +1087,9 @@ void stop_ppp_test_view(void)
     ScreenAlwaysOnCtr(0);
     printf("PPP test: Screen always on disabled\n");
     
+    // 停止定时器
+    stop_ppp_update_timer();
+    
     // 设置初始化完成标志为false
     g_ppp_init_completed = false;
     
@@ -1002,6 +1141,11 @@ void refresh_ppp_test_data(void)
     
     // 更新UI显示
     if (g_simple_ppp_container != nullptr && g_ppp_init_completed) {
+        // 确保在AT模式下进行刷新
+        printf("=== 刷新数据:确保AT模式 ===\n");
+        extern void set_at_communication_and_baudrate_flag(bool flag);
+        set_at_communication_and_baudrate_flag(true);
+        
         // 重新获取最新的PPP信息
         update_ppp_display_info();
         
index 2be4e97..3bd57c4 100644 (file)
@@ -17,7 +17,9 @@
 #include "lwip/netdb.h"
 #include "lwip/sockets.h"
 #include "lwip/inet.h"
-
+#ifdef CUSTOM_UTILS
+#include "custom_utils.h"
+#endif
 // 声明播放器消息处理函数
 
 static app_task_definition_t ln_send_taskcfg = {0};
@@ -1631,6 +1633,12 @@ static void ln_init_required_dirs(void)
 */
 errcode_t uapi_ln_ws_start(void)
 {
+
+#ifdef CUSTOM_UTILS
+    if(custom_get_factory_test_flag())
+        return ERRCODE_SUCC;
+#endif
+
     ln_ws_start(ln_ws_process_message,2000);
     return ERRCODE_SUCC;
 }