--- /dev/null
+#include "components/ui_scroll_view.h"
+#include "components/root_view.h"
+#include "components/ui_label.h"
+#include "common/screen.h"
+#include "UiConfig.h"
+#include "gfx_utils/style.h"
+#include "graphic_config.h"
+#include "cmsis_os2.h"
+
+// C标准库
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+// 预声明必要的类型以避免循环依赖
+typedef int ppp_error_t;
+
+// PPP错误码常量
+#define PPP_ERR_OK 0
+#define PPP_ERR_TIMEOUT 1
+#define PPP_ERR_AT_FAILED 2
+#define PPP_ERR_DIAL_FAILED 3
+#define PPP_ERR_NO_CARRIER 4
+#define PPP_ERR_BUSY 5
+#define PPP_ERR_NO_DIALTONE 6
+#define PPP_ERR_INVALID_PARAM 7
+#define PPP_ERR_MEMORY 8
+#define PPP_ERR_UART 9
+#define PPP_ERR_INVALID_STATE 10
+#define PPP_ERR_UNKNOWN 11
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// 仅包含必要的头文件
+#include "errcode.h"
+#include "service/graphic_service_wrapper.h"
+
+// 确保有这些常量定义(如果errcode.h没有定义的话)
+#ifndef ERRCODE_SUCC
+#define ERRCODE_SUCC 0
+#endif
+#ifndef ERRCODE_FAIL
+#define ERRCODE_FAIL 1
+#endif
+
+// 前向声明结构体
+struct ppp_network_signal_info_s;
+typedef struct ppp_network_signal_info_s ppp_network_signal_info_t;
+
+// 声明需要使用的函数
+int ppp_env_init(void);
+errcode_t ppp_api_update_all_runtime_status(void);
+ppp_error_t ppp_at_get_network_signal_info(ppp_network_signal_info_t *info);
+errcode_t ppp_get_network_signal_info(void);
+
+// CAT1 API 声明
+uint8_t cat1_api_runtime_get_cat1_powerstat(void);
+uint8_t cat1_api_runtime_get_cat1_networkstat(void);
+int cat1_api_runtime_get_cat1_signal(void);
+int cat1_api_runtime_get_cat1_simstat(void);
+uint8_t cat1_api_runtime_get_cat1_networktype(void);
+char* cat1_api_runtime_get_cat1_operator(void);
+char* cat1_api_runtime_get_cat1_imei(void);
+char* cat1_api_runtime_get_cat1_iccid(void);
+char* cat1_api_runtime_get_cat1_modemver(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+// 定义信号信息结构体(避免包含完整头文件)
+struct ppp_network_signal_info_s {
+ int16_t rxlev;
+ int16_t ber;
+ int16_t rscp;
+ int16_t ecno;
+ int16_t rsrq;
+ int16_t rsrp;
+ bool valid;
+};
+
+// 全局变量
+static OHOS::UIScrollView* g_ppp_test_view = nullptr;
+static OHOS::UIView* g_ppp_saved_view = nullptr;
+static OHOS::UILabel* g_ppp_status_labels[12] = {nullptr}; // 增加到12个标签:标题+11个状态(VER占两行)
+static OHOS::UILabel* g_ppp_title_label = nullptr;
+
+// PPP初始化状态
+static bool g_ppp_init_completed = false;
+static bool g_ppp_init_in_progress = false;
+static int g_ppp_init_retry_count = 0;
+static const int MAX_PPP_INIT_RETRIES = 5;
+
+// 定时器相关
+static osTimerId_t g_ppp_init_timer = NULL;
+static osTimerId_t g_ppp_refresh_timer = NULL;
+static const uint32_t PPP_INIT_TIMEOUT_MS = 5000; // 5秒超时
+static const uint32_t PPP_REFRESH_INTERVAL_MS = 5000; // 5秒刷新间隔(减少定时器冲突)
+
+// 标签配置结构体 - 参考testCAT1的设计
+typedef struct {
+ int left;
+ int top;
+ int width;
+ int height;
+ uint16_t fontSize;
+ uint16_t lineHeight;
+ const char* text;
+ OHOS::UILabel::LineBreakMode lineBreakMode;
+} PPPLabelConfig_t;
+
+// 创建标签的辅助函数 - 优化为圆形LCD布局
+static OHOS::UILabel* create_ppp_label(const PPPLabelConfig_t& config) {
+ OHOS::UILabel* label = new OHOS::UILabel();
+ if (label == nullptr) {
+ return nullptr;
+ }
+
+ label->SetPosition(config.left, config.top, config.width, config.height);
+ label->SetText(config.text);
+ label->SetFont(OHOS::DEFAULT_VECTOR_FONT_FILENAME, config.fontSize);
+ label->SetStyle(OHOS::STYLE_TEXT_COLOR, OHOS::Color::White().full);
+ label->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0);
+ label->SetStyle(OHOS::STYLE_TEXT_FONT, config.fontSize);
+ label->SetStyle(OHOS::STYLE_LINE_HEIGHT, config.lineHeight);
+ label->SetAlign(OHOS::TEXT_ALIGNMENT_LEFT);
+ label->SetLineBreakMode(config.lineBreakMode);
+
+
+ return label;
+}
+
+// 更新PPP运行状态显示 - 简化版本
+static void update_ppp_runtime_status_display() {
+ if (!g_ppp_init_completed) {
+ return;
+ }
+
+ printf("=== 更新PPP运行状态显示 ===\n");
+
+ // 更新所有运行时状态
+ errcode_t ret = ppp_api_update_all_runtime_status();
+ if (ret != ERRCODE_SUCC) {
+ printf("更新PPP运行状态失败: %d\n", ret);
+ return;
+ }
+
+ // 使用malloc动态分配,避免栈溢出
+ char* buffer = (char*)malloc(128);
+ if (buffer == NULL) {
+ printf("ERROR: Failed to allocate buffer for PPP status display\n");
+ return;
+ }
+
+ int label_index = 1; // 跳过标题,从索引1开始
+
+ // 1. SIM卡插入状态 (临时屏蔽)
+ /*
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ snprintf(buffer, sizeof(buffer), "SIM状态: %s",
+ cat1_api_runtime_get_cat1_simstat() ? "已插入" : "未插入");
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ label_index++;
+ }
+ */
+
+ // 2. IMEI
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ char* imei = cat1_api_runtime_get_cat1_imei();
+ snprintf(buffer, 128, "IMEI: %s",
+ (imei && strlen(imei) > 0) ? imei : "未知");
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ label_index++;
+ }
+
+ // 3. ICCID
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ char* iccid = cat1_api_runtime_get_cat1_iccid();
+ snprintf(buffer, 128, "ICCID: %s",
+ (iccid && strlen(iccid) > 0) ? iccid : "未知");
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ label_index++;
+ }
+
+ // 4. 版本信息 (临时屏蔽)
+ /*
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ char* version = cat1_api_runtime_get_cat1_modemver();
+ if (version && strlen(version) > 0) {
+ // 使用换行符在一个标签中显示VER和版本号
+ snprintf(buffer, sizeof(buffer), "VER:\n%s", version);
+ } else {
+ snprintf(buffer, sizeof(buffer), "VER:\n未知");
+ }
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ label_index++;
+ }
+ */
+
+ // 4. 信号强度
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ int signal = cat1_api_runtime_get_cat1_signal();
+ if (signal == 99) {
+ snprintf(buffer, 128, "信号强度: 无信号");
+ } else {
+ snprintf(buffer, 128, "信号强度: %d", signal);
+ }
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ label_index++;
+ }
+
+ // 清空基本状态部分后面的剩余标签(为信号质量部分预留空间)
+ for (int i = label_index; i < 4; i++) {
+ if (g_ppp_status_labels[i] != nullptr) {
+ g_ppp_status_labels[i]->SetText("");
+ g_ppp_status_labels[i]->SetVisible(true); // 保持可见,待信号质量更新
+ }
+ }
+
+ // 确保信号质量标签也是可见和可用的
+ for (int i = 4; i < 12; i++) {
+ if (g_ppp_status_labels[i] != nullptr) {
+ g_ppp_status_labels[i]->SetVisible(true); // 确保信号质量标签可见
+ }
+ }
+
+ printf("PPP运行状态显示更新完成\n");
+
+ // 释放动态分配的内存
+ free(buffer);
+}
+
+// 更新信号质量信息显示
+static void update_signal_quality_display() {
+ if (!g_ppp_init_completed) {
+ return;
+ }
+
+ printf("=== 更新信号质量显示 ===\n");
+
+ // 使用直接的API获取信号信息
+ ppp_network_signal_info_t signal_info;
+ ppp_error_t ret = ppp_at_get_network_signal_info(&signal_info);
+
+ if (ret != PPP_ERR_OK) {
+ printf("获取信号质量信息失败: %d\n", ret);
+ // 显示错误信息
+ if (g_ppp_status_labels[6] != nullptr) {
+ g_ppp_status_labels[6]->SetText("信号质量获取失败");
+ }
+ return;
+ }
+
+ // 使用malloc动态分配,避免栈溢出
+ char* buffer = (char*)malloc(200);
+ if (buffer == NULL) {
+ printf("ERROR: Failed to allocate buffer for signal quality display\n");
+ return;
+ }
+
+ if (!signal_info.valid) {
+ printf("信号质量信息无效\n");
+ if (g_ppp_status_labels[4] != nullptr) {
+ g_ppp_status_labels[4]->SetText("信号质量信息无效");
+ }
+ free(buffer);
+ return;
+ }
+
+ int label_index = 4; // 从第4个标签开始显示信号质量信息(SIM和VER都被屏蔽)
+
+ // 检查LTE信号参数有效性
+ if (signal_info.rsrq != 255 && signal_info.rsrp != 255 &&
+ signal_info.rsrq >= 0 && signal_info.rsrq <= 49 &&
+ signal_info.rsrp >= 0 && signal_info.rsrp <= 97) {
+
+ // 使用正确的转换公式
+ float rsrq_db = (signal_info.rsrq - 94) / 10.0f; // (rsrq - 94)/10
+ float rsrp_dbm = signal_info.rsrp - 140.0f; // rsrp - 140
+
+ // RSRQ评级
+ const char* rsrq_rating;
+ if (rsrq_db >= -7.0) {
+ rsrq_rating = "极佳";
+ } else if (rsrq_db >= -12.0) {
+ rsrq_rating = "良好";
+ } else if (rsrq_db >= -19.5) {
+ rsrq_rating = "较差";
+ } else {
+ rsrq_rating = "极差";
+ }
+
+ // RSRP评级
+ const char* rsrp_rating;
+ if (rsrp_dbm >= -85) {
+ rsrp_rating = "极好";
+ } else if (rsrp_dbm >= -100) {
+ rsrp_rating = "良好";
+ } else if (rsrp_dbm >= -110) {
+ rsrp_rating = "较弱";
+ } else {
+ rsrp_rating = "极差";
+ }
+
+ // 6. RSRQ信息 - 带评级显示
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ snprintf(buffer, 200, "RSRQ: %d (%.1fdB)",
+ signal_info.rsrq, rsrq_db);
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ g_ppp_status_labels[label_index]->SetVisible(true);
+ g_ppp_status_labels[label_index]->Invalidate();
+ printf("设置RSRQ标签[%d]: %s\n", label_index, buffer);
+ label_index++;
+ }
+
+ // 7. RSRQ评级
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ snprintf(buffer, 200, "RSRQ评级: %s", rsrq_rating);
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ g_ppp_status_labels[label_index]->SetVisible(true);
+ g_ppp_status_labels[label_index]->Invalidate();
+ printf("设置RSRQ评级标签[%d]: %s\n", label_index, buffer);
+ label_index++;
+ }
+
+ // 8. RSRP信息 - 带评级显示
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ snprintf(buffer, 200, "RSRP: %d (%.0fdBm)",
+ signal_info.rsrp, rsrp_dbm);
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ g_ppp_status_labels[label_index]->SetVisible(true);
+ g_ppp_status_labels[label_index]->Invalidate();
+ printf("设置RSRP标签[%d]: %s\n", label_index, buffer);
+ label_index++;
+ }
+
+ // 9. RSRP评级
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ snprintf(buffer, 200, "RSRP评级: %s", rsrp_rating);
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ g_ppp_status_labels[label_index]->SetVisible(true);
+ g_ppp_status_labels[label_index]->Invalidate();
+ printf("设置RSRP评级标签[%d]: %s\n", label_index, buffer);
+ label_index++;
+ }
+
+ // 10. 综合LTE信号质量评估
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ const char* overall_quality;
+ // 根据RSRQ和RSRP的评级综合评估
+ if ((rsrq_db >= -7.0 && rsrp_dbm >= -85) ||
+ (rsrq_db >= -12.0 && rsrp_dbm >= -100)) {
+ overall_quality = "LTE信号优秀";
+ } else if ((rsrq_db >= -12.0 && rsrp_dbm >= -110) ||
+ (rsrq_db >= -19.5 && rsrp_dbm >= -100)) {
+ overall_quality = "LTE信号良好";
+ } else if (rsrq_db >= -19.5 && rsrp_dbm >= -110) {
+ overall_quality = "LTE信号一般";
+ } else {
+ overall_quality = "LTE信号较差";
+ }
+
+ snprintf(buffer, 200, "Overall LTE Quality: %s", overall_quality);
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ g_ppp_status_labels[label_index]->SetVisible(true);
+ g_ppp_status_labels[label_index]->Invalidate();
+ printf("设置Overall Quality标签[%d]: %s\n", label_index, buffer);
+ label_index++;
+ }
+
+ // 清空剩余未使用的标签
+ for (int i = label_index; i < 12; i++) {
+ if (g_ppp_status_labels[i] != nullptr) {
+ g_ppp_status_labels[i]->SetText("");
+ g_ppp_status_labels[i]->SetVisible(false);
+ }
+ }
+
+ printf("LTE信号质量更新: RSRQ=%d(%.1fdB)[%s], RSRP=%d(%.0fdBm)[%s]\n",
+ signal_info.rsrq, rsrq_db, rsrq_rating, signal_info.rsrp, rsrp_dbm, rsrp_rating);
+ } else {
+ // 显示无效的LTE参数
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ snprintf(buffer, 200, "RSRQ: 无效(%d)", signal_info.rsrq);
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ label_index++;
+ }
+ if (g_ppp_status_labels[label_index] != nullptr) {
+ snprintf(buffer, 200, "RSRP: 无效(%d)", signal_info.rsrp);
+ g_ppp_status_labels[label_index]->SetText(buffer);
+ label_index++;
+ }
+
+ // 清空剩余未使用的标签
+ for (int i = label_index; i < 12; i++) {
+ if (g_ppp_status_labels[i] != nullptr) {
+ g_ppp_status_labels[i]->SetText("");
+ g_ppp_status_labels[i]->SetVisible(false);
+ }
+ }
+
+ printf("LTE参数无效: RSRQ=%d, RSRP=%d\n", signal_info.rsrq, signal_info.rsrp);
+ }
+
+ printf("信号质量显示更新完成\n");
+
+ // 释放动态分配的内存
+ free(buffer);
+}
+
+// 全局变量,避免栈溢出
+static int g_consecutive_failures = 0;
+
+// 全局刷新标志,避免在定时器回调中直接操作UI
+static volatile bool g_need_refresh = false;
+
+// UI刷新回调函数 - 通过GraphicEvent在主UI线程中安全执行,避免栈溢出
+static void ppp_refresh_ui_callback(void* userData) {
+ (void)userData; // 未使用的参数
+
+ if (!g_ppp_init_completed || g_ppp_test_view == nullptr) {
+ return; // 如果PPP未初始化完成或view已销毁,不执行刷新
+ }
+
+ printf("PPP UI刷新开始 - GraphicEvent安全机制\n");
+
+ // 使用malloc为buffer分配内存,避免栈溢出
+ char* buffer = (char*)malloc(512);
+ if (buffer == nullptr) {
+ printf("ERROR: malloc失败,跳过此次刷新\n");
+ return;
+ }
+
+ // 安全地更新运行状态显示
+ update_ppp_runtime_status_display();
+
+ // 尝试获取信号质量,但增加容错机制
+ errcode_t ret = ppp_get_network_signal_info();
+ if (ret == ERRCODE_SUCC) {
+ g_consecutive_failures = 0; // 重置失败计数
+ update_signal_quality_display();
+ printf("PPP信号质量更新成功\n");
+ } else {
+ g_consecutive_failures++;
+ printf("PPP信号质量获取失败 (%d次)\n", g_consecutive_failures);
+
+ // 如果连续失败超过3次,暂停信号质量查询,只更新基本状态
+ if (g_consecutive_failures >= 3) {
+ if (g_ppp_status_labels[5] != nullptr) {
+ g_ppp_status_labels[5]->SetText("信号查询暂停");
+ }
+ if (g_ppp_status_labels[6] != nullptr) {
+ g_ppp_status_labels[6]->SetText("(定时器冲突)");
+ }
+ }
+ }
+
+ // 释放临时buffer
+ free(buffer);
+
+ // 刷新UI显示
+ OHOS::RootView::GetInstance()->Invalidate();
+ printf("PPP UI刷新完成\n");
+}
+
+// PPP刷新定时器回调函数 - 使用GraphicEvent避免栈溢出
+static void ppp_refresh_timer_callback(void *arg) {
+ (void)arg;
+
+ if (!g_ppp_init_completed || g_ppp_test_view == nullptr) {
+ return; // 如果PPP未初始化完成或view已销毁,不执行刷新
+ }
+
+ // 使用GraphicEvent将UI更新操作投递到主UI线程,避免栈溢出
+ // UIKit版本: 参数为 回调函数, 用户数据(NULL)
+ PostGraphicEvent(ppp_refresh_ui_callback, NULL);
+
+ printf("PPP定时器回调 - 已投递GraphicEvent\n");
+}
+
+// 启动PPP刷新定时器
+static void start_ppp_refresh_timer() {
+ if (g_ppp_refresh_timer == NULL) {
+ g_ppp_refresh_timer = osTimerNew(ppp_refresh_timer_callback, osTimerPeriodic, NULL, NULL);
+ if (g_ppp_refresh_timer == NULL) {
+ printf("ERROR: Failed to create PPP refresh timer\n");
+ return;
+ }
+ }
+
+ // 启动5秒周期定时器
+ osTimerStart(g_ppp_refresh_timer, PPP_REFRESH_INTERVAL_MS);
+ printf("PPP刷新定时器启动 (5秒周期,避免定时器冲突)\n");
+}
+
+// 停止PPP刷新定时器
+static void stop_ppp_refresh_timer() {
+ if (g_ppp_refresh_timer != NULL) {
+ osTimerStop(g_ppp_refresh_timer);
+ osTimerDelete(g_ppp_refresh_timer);
+ g_ppp_refresh_timer = NULL;
+ printf("PPP刷新定时器停止\n");
+ }
+}
+
+// PPP初始化定时器回调函数
+static void ppp_init_timer_callback(void *arg) {
+ (void)arg;
+
+ printf("=== PPP初始化超时,准备重试 ===\n");
+
+ if (g_ppp_init_retry_count >= MAX_PPP_INIT_RETRIES) {
+ printf("PPP初始化达到最大重试次数(%d),停止重试\n", MAX_PPP_INIT_RETRIES);
+ g_ppp_init_in_progress = false;
+
+ // 简化状态显示,避免在回调中进行复杂UI操作
+ if (g_ppp_status_labels[1] != nullptr) {
+ g_ppp_status_labels[1]->SetText("PPP初始化失败");
+ }
+ return;
+ }
+
+ // 增加重试计数
+ g_ppp_init_retry_count++;
+ printf("开始第%d次PPP初始化重试\n", g_ppp_init_retry_count);
+
+ // 简化状态显示
+ if (g_ppp_status_labels[1] != nullptr) {
+ g_ppp_status_labels[1]->SetText("PPP初始化重试中...");
+ }
+
+ // 重新开始PPP初始化
+ printf("执行ppp_env_init (重试)...\n");
+ int init_ret = ppp_env_init();
+ if (init_ret == 0) {
+ printf("PPP环境初始化成功 (重试第%d次)\n", g_ppp_init_retry_count);
+ g_ppp_init_completed = true;
+ g_ppp_init_in_progress = false;
+
+ // 停止定时器
+ if (g_ppp_init_timer != NULL) {
+ osTimerStop(g_ppp_init_timer);
+ }
+
+ // 启动5秒刷新定时器(重试成功)
+ start_ppp_refresh_timer();
+
+ // 设置刷新标志,让主线程安全处理UI更新
+ g_need_refresh = true;
+ } else {
+ printf("PPP环境初始化失败 (重试第%d次): %d\n", g_ppp_init_retry_count, init_ret);
+
+ // 重新启动定时器,等待下次重试
+ if (g_ppp_init_timer != NULL) {
+ osTimerStart(g_ppp_init_timer, PPP_INIT_TIMEOUT_MS);
+ }
+ }
+}
+
+// 启动PPP初始化和定时器
+static void start_ppp_init_with_timer() {
+ printf("=== 启动PPP初始化和定时器 ===\n");
+
+ // 重置状态
+ g_ppp_init_completed = false;
+ g_ppp_init_in_progress = true;
+ g_ppp_init_retry_count = 0;
+
+ // 创建定时器
+ if (g_ppp_init_timer == NULL) {
+ g_ppp_init_timer = osTimerNew(ppp_init_timer_callback, osTimerOnce, NULL, NULL);
+ if (g_ppp_init_timer == NULL) {
+ printf("ERROR: Failed to create PPP init timer\n");
+ return;
+ }
+ }
+
+ // 开始PPP初始化
+ printf("执行ppp_env_init...\n");
+ int init_ret = ppp_env_init();
+ if (init_ret == 0) {
+ printf("PPP环境初始化成功\n");
+ g_ppp_init_completed = true;
+ g_ppp_init_in_progress = false;
+
+ // 启动5秒刷新定时器
+ start_ppp_refresh_timer();
+
+ // 设置刷新标志,让主线程安全处理UI更新
+ g_need_refresh = true;
+ } else {
+ printf("PPP环境初始化失败: %d,启动定时器等待重试\n", init_ret);
+
+ // 更新状态显示
+ if (g_ppp_status_labels[1] != nullptr) {
+ g_ppp_status_labels[1]->SetText("PPP初始化失败,5秒后重试...");
+ }
+
+ // 启动定时器
+ osTimerStart(g_ppp_init_timer, PPP_INIT_TIMEOUT_MS);
+ }
+}
+
+extern "C" {
+
+/**
+ * @brief 启动PPP测试视图
+ */
+void start_ppp_test_view(void)
+{
+ printf("=== 启动PPP测试 ===\n");
+
+ OHOS::RootView* rootView = OHOS::RootView::GetInstance();
+ if (rootView == nullptr) {
+ printf("ERROR: RootView not initialized\n");
+ return;
+ }
+
+ // 保存当前显示的view
+ g_ppp_saved_view = rootView->GetChildrenHead();
+ if (g_ppp_saved_view != nullptr) {
+ rootView->Remove(g_ppp_saved_view);
+ printf("Saved and removed current view for later restore\n");
+ }
+
+ // 创建ScrollView用于PPP测试
+ g_ppp_test_view = new OHOS::UIScrollView();
+ if (g_ppp_test_view == nullptr) {
+ printf("ERROR: Failed to create PPP test view\n");
+ return;
+ }
+
+ // 设置PPP测试视图 - 适配360x360圆形LCD,支持大字体滚动
+ g_ppp_test_view->SetPosition(0, 0, 360, 360);
+ g_ppp_test_view->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
+ g_ppp_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff000000); // 黑色背景
+ g_ppp_test_view->SetStyle(OHOS::STYLE_BORDER_RADIUS, 0);
+ g_ppp_test_view->SetTouchable(true);
+ g_ppp_test_view->SetDraggable(true);
+ g_ppp_test_view->SetVisible(true);
+ g_ppp_test_view->SetYScrollBarVisible(true);
+ g_ppp_test_view->SetScrollBlankSize(30); // 增加滚动空白,适应大字体
+
+ // 创建标题标签 - 居中布局,适配圆形显示,右移3个字体大小距离
+ PPPLabelConfig_t titleConfig = {
+ .left = 114, // 右移3个字体大小:60 + (18×3) = 114
+ .top = 20, // 顶部留白进一步减少:25->20
+ .width = 240, // 标题宽度增加容纳中文:180->240
+ .height = 30, // 标题高度增加适应18px字体:25->30
+ .fontSize = 18, // 字体大小调大:16->18
+ .lineHeight = 30,// 行高与标签高度一致:25->30
+ .text = "PPP网络测试", // 去掉空格,节省空间
+ .lineBreakMode = OHOS::UILabel::LINE_BREAK_ADAPT
+ };
+ g_ppp_title_label = create_ppp_label(titleConfig);
+ if (g_ppp_title_label != nullptr) {
+ g_ppp_status_labels[0] = g_ppp_title_label;
+
+ // 强制设置标题样式,确保显示正常
+ g_ppp_title_label->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER);
+ g_ppp_title_label->SetStyle(OHOS::STYLE_TEXT_COLOR, 0xFFFFFFFF); // 白色
+ g_ppp_title_label->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0); // 透明背景
+ g_ppp_title_label->SetVisible(true);
+ g_ppp_title_label->Invalidate();
+
+ g_ppp_test_view->Add(g_ppp_title_label);
+ printf("PPP标题标签创建成功: 位置(%d,%d) 尺寸(%dx%d) 文字='%s'\n",
+ titleConfig.left, titleConfig.top, titleConfig.width, titleConfig.height, titleConfig.text);
+ } else {
+ printf("ERROR: PPP标题标签创建失败\n");
+ }
+
+ // 创建状态显示标签 - 圆形LCD优化布局,大字体不重叠
+ int y_start = 70; // 标题高度30px + top 20px + 间距 = 70px
+ int label_height = 26; // 进一步增加高度适应大字体:22->26
+ int label_spacing = 30; // 大幅增加间距避免重叠:25->30
+
+ for (int i = 1; i < 12; i++) {
+ // 为不同标签设置不同的初始文本
+ const char* initial_text;
+ if (i <= 4) {
+ initial_text = "初始化中..."; // 基本状态信息(1-4,VER被屏蔽)
+ } else {
+ initial_text = ""; // 信号质量信息初始为空(5-11)
+ }
+
+ PPPLabelConfig_t labelConfig = {
+ .left = 30, // 右移10px,更好适配圆形显示区域
+ .top = y_start + (i - 1) * label_spacing,
+ .width = 300, // 相应调整宽度
+ .height = label_height,
+ .fontSize = 15, // 字体大小调大:12->15,配合大间距
+ .lineHeight = label_height,
+ .text = initial_text,
+ .lineBreakMode = OHOS::UILabel::LINE_BREAK_WRAP
+ };
+
+ g_ppp_status_labels[i] = create_ppp_label(labelConfig);
+ if (g_ppp_status_labels[i] != nullptr) {
+ g_ppp_test_view->Add(g_ppp_status_labels[i]);
+ }
+ }
+
+ // 添加到根视图
+ rootView->Add(g_ppp_test_view);
+ rootView->Invalidate();
+
+ printf("PPP test view created, starting initialization with timer...\n");
+
+ // 使用定时器启动PPP初始化
+ start_ppp_init_with_timer();
+}
+
+/**
+ * @brief 停止PPP测试视图
+ */
+void stop_ppp_test_view(void)
+{
+ printf("=== 停止PPP测试 ===\n");
+
+ OHOS::RootView* rootView = OHOS::RootView::GetInstance();
+ if (rootView != nullptr) {
+ // 停止并删除定时器
+ if (g_ppp_init_timer != NULL) {
+ osTimerStop(g_ppp_init_timer);
+ osTimerDelete(g_ppp_init_timer);
+ g_ppp_init_timer = NULL;
+ printf("PPP init timer stopped and deleted\n");
+ }
+
+ // 停止刷新定时器
+ stop_ppp_refresh_timer();
+
+ // 删除PPP测试view
+ if (g_ppp_test_view != nullptr) {
+ rootView->Remove(g_ppp_test_view);
+
+ // 清理所有标签
+ for (int i = 0; i < 12; i++) {
+ if (g_ppp_status_labels[i] != nullptr) {
+ delete g_ppp_status_labels[i];
+ g_ppp_status_labels[i] = nullptr;
+ }
+ }
+ g_ppp_title_label = nullptr;
+
+ delete g_ppp_test_view;
+ g_ppp_test_view = nullptr;
+ printf("PPP test view removed\n");
+ }
+
+ // 恢复原来的view
+ if (g_ppp_saved_view != nullptr) {
+ printf("Attempting to restore view at address: %p\n", g_ppp_saved_view);
+
+ if (g_ppp_saved_view->GetParent() == nullptr) {
+ rootView->Add(g_ppp_saved_view);
+ rootView->Invalidate();
+ printf("Original view restored successfully\n");
+ } else {
+ printf("Warning: Original view still has parent, cannot restore\n");
+ }
+ g_ppp_saved_view = nullptr;
+ } else {
+ printf("No original view to restore\n");
+ }
+ }
+
+ // 重置PPP状态变量
+ g_ppp_init_completed = false;
+ g_ppp_init_in_progress = false;
+ g_ppp_init_retry_count = 0;
+}
+
+/**
+ * @brief 刷新PPP测试数据 - 安全版本,检查定时器刷新请求
+ */
+void refresh_ppp_test_data(void)
+{
+ printf("=== 刷新PPP测试数据(手动) ===\n");
+
+ if (!g_ppp_init_completed || g_ppp_test_view == nullptr) {
+ printf("PPP未初始化或view已销毁,无法刷新数据\n");
+ return;
+ }
+
+ // 使用GraphicEvent进行安全的UI刷新,避免栈溢出
+ // UIKit版本: 参数为 回调函数, 用户数据(NULL)
+ PostGraphicEvent(ppp_refresh_ui_callback, NULL);
+
+ printf("PPP手动刷新请求已发送到GraphicEvent队列\n");
+}
+
+} // extern "C"
#include "battery_service.h"
#endif
+#ifdef BOARD_LEINIAO
+#include "PPPTestViewC.h"
+#include "LcdTestViewC.h"
+#endif
// #include "msg_center_customerC.h"
#ifdef SUPPORT_A5133_SERVICE
if(cmd == 1)
{
// 进入LCD测试界面
+#ifdef BOARD_LEINIAO
+ start_lcd_test_view();
+ wstp_print("LCDTEST ATCMD Enter LCD test interface (LcdTestView)\n");
+ wstp_print("Use AT^LCDTEST=3-8 to change colors: 3=Green, 4=Blue, 5=Yellow, 6=Red, 7=White, 8=Black\n");
+#else
uint8_t lcd_cmd = 1;
do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_LCD_TEST, &lcd_cmd, sizeof(lcd_cmd));
wstp_print("LCDTEST ATCMD Enter LCD test interface\n");
LOS_Msleep(2000);
do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_LCD_COLOR_TEST, &i, 1);
}
+#endif
}
else if(cmd == 2)
{
// 退出LCD测试界面
+#ifdef BOARD_LEINIAO
+ stop_lcd_test_view();
+ wstp_print("LCDTEST ATCMD Exit LCD test interface (LcdTestView)\n");
+#else
+ // 其他板:使用原有的消息机制
uint8_t lcd_cmd = 0;
do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_LCD_TEST, &lcd_cmd, sizeof(lcd_cmd));
wstp_print("LCDTEST ATCMD Exit LCD test interface\n");
+#endif
}
- // else if(cmd >= 3 && cmd <= 7)
- // {
-
- // // 改变LCD屏幕颜色
- // uint8_t color_cmd = cmd - 2; // 转换为颜色命令 (1-5)
+ else if(cmd >= 3 && cmd <= 8)
+ {
+ // 改变LCD屏幕颜色
+ int color_index = cmd - 3; // 转换为颜色索引 (0-5)
+#ifdef BOARD_LEINIAO
+ // 雷鸟板:使用 LcdTestView 设置颜色
+ set_lcd_test_color(color_index);
- // // 根据命令打印对应的颜色信息
- // switch(color_cmd)
- // {
- // case 1:
- // wstp_print("LCDTEST ATCMD Set LCD color: Red\n");
- // break;
- // case 2:
- // wstp_print("LCDTEST ATCMD Set LCD color: Green\n");
- // break;
- // case 3:
- // wstp_print("LCDTEST ATCMD Set LCD color: Blue\n");
- // break;
- // case 4:
- // wstp_print("LCDTEST ATCMD Set LCD color: White\n");
- // break;
- // case 5:
- // wstp_print("LCDTEST ATCMD Set LCD color: Black\n");
- // break;
- // default:
- // wstp_print("LCDTEST ATCMD Set LCD color: Unknown\n");
- // break;
- // }
- // }
- // else
- // {
- // wstp_print("LCDTEST ATCMD Unknown command %d\n", cmd);
- // wstp_print("LCDTEST ATCMD Usage:\n");
- // wstp_print(" AT^LCDTEST=1 - Enter LCD test interface\n");
- // wstp_print(" AT^LCDTEST=2 - Exit LCD test interface\n");
- // wstp_print(" AT^LCDTEST=3 - Set LCD color: Red\n");
- // wstp_print(" AT^LCDTEST=4 - Set LCD color: Green\n");
- // wstp_print(" AT^LCDTEST=5 - Set LCD color: Blue\n");
- // wstp_print(" AT^LCDTEST=6 - Set LCD color: White\n");
- // wstp_print(" AT^LCDTEST=7 - Set LCD color: Black\n");
- // return ERRCODE_FAIL;
- // }
+ // 根据 LcdTestView 的颜色索引打印对应的颜色信息
+ switch(color_index)
+ {
+ case 0:
+ wstp_print("LCDTEST ATCMD Set LCD color: Green\n");
+ break;
+ case 1:
+ wstp_print("LCDTEST ATCMD Set LCD color: Blue\n");
+ break;
+ case 2:
+ wstp_print("LCDTEST ATCMD Set LCD color: Yellow\n");
+ break;
+ case 3:
+ wstp_print("LCDTEST ATCMD Set LCD color: Red\n");
+ break;
+ case 4:
+ wstp_print("LCDTEST ATCMD Set LCD color: White\n");
+ break;
+ case 5:
+ wstp_print("LCDTEST ATCMD Set LCD color: Black\n");
+ break;
+ default:
+ wstp_print("LCDTEST ATCMD Set LCD color: Unknown\n");
+ break;
+ }
+#else
+ // 其他板:使用原有的消息机制
+ uint8_t color_cmd = color_index + 1;
+ do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_LCD_COLOR_TEST, &color_cmd, 1);
+ wstp_print("LCDTEST ATCMD Set LCD color: %d\n", color_cmd);
+#endif
+ }
+ return ERRCODE_SUCC;
+}
+
+// PPP测试AT指令实现
+static uint32_t ppp_test_control(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+ UNUSED(strCommonCmd);
+ uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
+ uint32_t argc = 0;
+
+ int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+ if (ret != CUSTOM_UTILS_SUCCESS) {
+ wstp_print("PPPTEST ATCMD Convert Command Failed\n");
+ return ERRCODE_FAIL;
+ }
+
+ if (argc != 1) {
+ wstp_print("PPPTEST ATCMD Set Parameter Failed argc %d, should be AT^PPPTEST=cmd\n", argc);
+ return ERRCODE_FAIL;
+ }
+
+ uint8_t cmd = (uint8_t)atoi((char*)argv[0]);
+
+ if(cmd == 1)
+ {
+ // 进入PPP测试界面
+#ifdef BOARD_LEINIAO
+ // 雷鸟板:使用 PPPTestView 进行PPP测试
+ start_ppp_test_view();
+ wstp_print("PPPTEST ATCMD Enter PPP test interface (PPPTestView)\n");
+ wstp_print("Use AT^PPPTEST=2 to exit, AT^PPPTEST=3 to refresh data\n");
+#else
+ wstp_print("PPPTEST ATCMD PPP test not supported on this board\n");
+#endif
+ }
+ else if(cmd == 2)
+ {
+ // 退出PPP测试界面
+#ifdef BOARD_LEINIAO
+ // 雷鸟板:停止 PPPTestView
+ stop_ppp_test_view();
+ wstp_print("PPPTEST ATCMD Exit PPP test interface (PPPTestView)\n");
+#else
+ wstp_print("PPPTEST ATCMD PPP test not supported on this board\n");
+#endif
+ }
+ else if(cmd == 3)
+ {
+ // 刷新PPP测试数据
+#ifdef BOARD_LEINIAO
+ // 雷鸟板:刷新 PPPTestView 数据
+ refresh_ppp_test_data();
+ wstp_print("PPPTEST ATCMD Refresh PPP test data\n");
+#else
+ wstp_print("PPPTEST ATCMD PPP test not supported on this board\n");
+#endif
+ }
+ else
+ {
+ wstp_print("PPPTEST ATCMD Unknown command %d\n", cmd);
+ wstp_print("PPPTEST ATCMD Usage:\n");
+ wstp_print(" AT^PPPTEST=1 - Enter PPP test interface\n");
+ wstp_print(" AT^PPPTEST=2 - Exit PPP test interface\n");
+ wstp_print(" AT^PPPTEST=3 - Refresh PPP test data\n");
+ return ERRCODE_FAIL;
+ }
return ERRCODE_SUCC;
}
{
UNUSED(strCommonCmd);
- #ifdef FD230_650
+ #ifdef SUPPORT_BATTERY_SERVICE
float vol = 0;
uint8_t percent = battery_get_voltage(&vol);
- wstp_print("voltage : %f , percent %02D\%\r\n",vol,percent);
+ printf("fac:voltage : %.3f , percent %d\r\n",vol,percent);
#endif
return ERRCODE_SUCC;
UNUSED(strCommonCmd);
uint8_t id;
uapi_cywee_get_id(&id);
- printf("id : 0x%x\n",id);
+ printf("fac:gsensor id : 0x%x\n",id);
return ERRCODE_SUCC;
}
return ERRCODE_SUCC;
}
+// 录音相关AT指令实现
+static uint32_t custom_enter_factory_test_mode(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+ UNUSED(strCommonCmd);
+ uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
+ uint32_t argc = 0;
+
+ int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+ if (ret != CUSTOM_UTILS_SUCCESS) {
+ wstp_print("AUDIO TEST ATCMD Convert Command Failed\n");
+ return ERRCODE_FAIL;
+ }
+
+ if (argc != 1) {
+ wstp_print("AUDIO TEST ATCMD Set Parameter Failed argc %d\n", argc);
+ wstp_print("Usage: AT^AUDIOTEST=cmd\n");
+ wstp_print(" cmd: 1=start record, 2=stop record, 3=start play, 4=stop play\n");
+ return ERRCODE_FAIL;
+ }
+
+ uint8_t cmd = (uint8_t)atoi((char*)argv[0]);
+
+ custom_set_factory_test_flag(cmd);
+
+ uapi_reboot_device();
+
+ return ERRCODE_SUCC;
+}
+
+
static const at_cmd_table_t g_custom_utils_cmd[] = {
{ (char *)"AT^CUSTOM_SN", custom_utils_setsn, (char *)"123456789ABCDEF2345678" },
{ (char *)"AT^CUSTOM_SN_REQ", custom_utils_getsn, (char *)" " },
// { (char *)"AT^CROWNKEYTEST", crown_test_control, (char *)" " },
{ (char *)"AT^LCDTEST", lcd_test_control, (char *)" " },
+ { (char *)"AT^PPPTESTVIEW", ppp_test_control, (char *)" " },
// { (char *)"AT^TPTEST", tp_test_control, (char *)" " },
{ (char *)"AT^BTTESTSTART", custom_factory_bt_test_start, (char *)" " },
{ (char *)"AT^BTTESTSTOP", custom_factory_bt_test_stop, (char *)" " },
// 录音相关AT指令
{ (char *)"AT^AUDIOTEST", custom_audio_test, (char *)" " },
+ { (char *)"AT^FACTORY", custom_enter_factory_test_mode, (char *)" " },
};