From 505fba7e7e86ec3aabf2fc0d32e958300354cc96 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Tue, 23 Sep 2025 11:56:11 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E9=9B=B7=E9=B8=9F=E4=BA=A7?= =?utf8?q?=E6=B5=8B=E6=A8=A1=E5=BC=8F=EF=BC=8C=E4=B8=8D=E5=90=AF=E5=8A=A8h?= =?utf8?q?ttp=E6=9C=8D=E5=8A=A1=EF=BC=8C=E4=BC=98=E5=8C=96LCD=E3=80=81PPP?= =?utf8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../brandy/brandy_standard/thread_pri_init.c | 6 +- .../leiniao/factory_test/CMakeLists.txt | 6 + .../leiniao/factory_test/LcdTestModel.cpp | 108 ++ .../leiniao/factory_test/LcdTestModel.h | 42 + .../leiniao/factory_test/LcdTestPresenter.cpp | 156 +++ .../leiniao/factory_test/LcdTestPresenter.h | 34 + .../leiniao/factory_test/LcdTestView.cpp | 330 +++-- .../zhihui/leiniao/factory_test/LcdTestView.h | 63 + .../leiniao/factory_test/PPPTestModel.cpp | 324 +++++ .../leiniao/factory_test/PPPTestModel.h | 149 +++ .../leiniao/factory_test/PPPTestPresenter.cpp | 347 +++++ .../leiniao/factory_test/PPPTestPresenter.h | 70 + .../leiniao/factory_test/PPPTestView.cpp | 1131 +++++++---------- .../zhihui/leiniao/factory_test/PPPTestView.h | 93 ++ .../leiniao/factory_test/PPPTestViewC.h | 8 + code/sdk/zhihui/utils/custom_utils.c | 7 +- code/sdk/zhihui/utils/custom_utils.h | 1 + 17 files changed, 2071 insertions(+), 804 deletions(-) create mode 100644 code/sdk/zhihui/leiniao/factory_test/LcdTestModel.cpp create mode 100644 code/sdk/zhihui/leiniao/factory_test/LcdTestModel.h create mode 100644 code/sdk/zhihui/leiniao/factory_test/LcdTestPresenter.cpp create mode 100644 code/sdk/zhihui/leiniao/factory_test/LcdTestPresenter.h create mode 100644 code/sdk/zhihui/leiniao/factory_test/LcdTestView.h create mode 100644 code/sdk/zhihui/leiniao/factory_test/PPPTestModel.cpp create mode 100644 code/sdk/zhihui/leiniao/factory_test/PPPTestModel.h create mode 100644 code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.cpp create mode 100644 code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.h create mode 100644 code/sdk/zhihui/leiniao/factory_test/PPPTestView.h diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index b3ce40c8b..a884919d0 100644 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -631,11 +631,15 @@ static void thread_main(const void *unused) #endif #ifdef CUSTOM_UTILS + custom_check_factory_test_flag(); startup_post_init(); #endif set_startup_finish_flag(); #ifdef SUPPORT_LEINIAO - uapi_ln_http_server_init(); +#ifdef CUSTOM_UTILS + if(!custom_get_factory_test_flag()) +#endif + uapi_ln_http_server_init(); #endif } diff --git a/code/sdk/zhihui/leiniao/factory_test/CMakeLists.txt b/code/sdk/zhihui/leiniao/factory_test/CMakeLists.txt index b73c1b282..77c5895c2 100644 --- a/code/sdk/zhihui/leiniao/factory_test/CMakeLists.txt +++ b/code/sdk/zhihui/leiniao/factory_test/CMakeLists.txt @@ -6,7 +6,11 @@ set(COMPONENT_NAME "AT_factory_test") set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/LcdTestView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/LcdTestPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/LcdTestModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/PPPTestPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PPPTestView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/PPPTestModel.cpp ) @@ -26,6 +30,8 @@ set(PRIVATE_HEADER ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/surface/interfaces/kits ${CMAKE_SOURCE_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits + ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits + code/sdk/zhihui/UI/CustomUIComponentTool/uicomponents/UIComponents.h ) diff --git a/code/sdk/zhihui/leiniao/factory_test/LcdTestModel.cpp b/code/sdk/zhihui/leiniao/factory_test/LcdTestModel.cpp new file mode 100644 index 000000000..47f96e23f --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/LcdTestModel.cpp @@ -0,0 +1,108 @@ +#include "LcdTestModel.h" +#include "gfx_utils/color.h" + +namespace OHOS +{ + // 颜色值定义 + const uint32_t LcdTestModel::COLOR_VALUES[] = { + 0xFF00FF00, // Green + 0xFF0000FF, // Blue + 0xFFFFFF00, // Yellow + 0xFFFF0000, // Red + 0xFFFFFFFF, // White + 0xFF000000 // Black + }; + + // 颜色名称定义 + const char* LcdTestModel::COLOR_NAMES[] = { + "Green", + "Blue", + "Yellow", + "Red", + "White", + "Black" + }; + + static LcdTestModel *g_pLcdTestModel = nullptr; + + LcdTestModel::LcdTestModel() + { + g_pLcdTestModel = this; + } + + LcdTestModel::~LcdTestModel() + { + g_pLcdTestModel = nullptr; + } + + LcdTestModel *LcdTestModel::GetInstance() + { + if (g_pLcdTestModel == nullptr) { + // 懒加载:自动创建实例 + g_pLcdTestModel = new LcdTestModel(); + if (g_pLcdTestModel) { + g_pLcdTestModel->Init(); + } + } + return g_pLcdTestModel; + } + + void LcdTestModel::Init() + { + isTestActive_ = false; + currentColor_ = LcdTestColor::White; + } + + void LcdTestModel::SetTestStatus(bool isActive) + { + isTestActive_ = isActive; + if (!isActive) { + ResetColorIndex(); + } + } + + bool LcdTestModel::GetTestStatus() const + { + return isTestActive_; + } + + void LcdTestModel::SetCurrentColor(LcdTestColor color) + { + currentColor_ = color; + } + + LcdTestColor LcdTestModel::GetCurrentColor() const + { + return currentColor_; + } + + uint32_t LcdTestModel::GetColorValue(LcdTestColor color) const + { + int index = static_cast(color); + if (index >= 0 && index < 6) { + return COLOR_VALUES[index]; + } + return COLOR_VALUES[4]; // 默认返回白色 + } + + const char* LcdTestModel::GetColorName(LcdTestColor color) const + { + int index = static_cast(color); + if (index >= 0 && index < 6) { + return COLOR_NAMES[index]; + } + return "Unknown"; + } + + LcdTestColor LcdTestModel::GetNextColor() const + { + int currentIndex = static_cast(currentColor_); + int nextIndex = (currentIndex + 1) % 6; + return static_cast(nextIndex); + } + + void LcdTestModel::ResetColorIndex() + { + currentColor_ = LcdTestColor::White; + } +} diff --git a/code/sdk/zhihui/leiniao/factory_test/LcdTestModel.h b/code/sdk/zhihui/leiniao/factory_test/LcdTestModel.h new file mode 100644 index 000000000..e65e72dd1 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/LcdTestModel.h @@ -0,0 +1,42 @@ +#ifndef _LCD_TEST_MODEL_H +#define _LCD_TEST_MODEL_H + +#include "LcdTestView.h" + +namespace OHOS +{ + class LcdTestModel + { + public: + LcdTestModel(); + ~LcdTestModel(); + static LcdTestModel *GetInstance(void); + + void Init(); + + // LCD测试状态管理 + void SetTestStatus(bool isActive); + bool GetTestStatus() const; + + void SetCurrentColor(LcdTestColor color); + LcdTestColor GetCurrentColor() const; + + // 颜色相关方法 + uint32_t GetColorValue(LcdTestColor color) const; + const char* GetColorName(LcdTestColor color) const; + + // 测试控制 + LcdTestColor GetNextColor() const; + void ResetColorIndex(); + + private: + bool isTestActive_{false}; + LcdTestColor currentColor_{LcdTestColor::Red}; + + // 颜色定义 + static const uint32_t COLOR_VALUES[]; + static const char* COLOR_NAMES[]; + }; +} + +#endif // _LCD_TEST_MODEL_H diff --git a/code/sdk/zhihui/leiniao/factory_test/LcdTestPresenter.cpp b/code/sdk/zhihui/leiniao/factory_test/LcdTestPresenter.cpp new file mode 100644 index 000000000..e1cc87a25 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/LcdTestPresenter.cpp @@ -0,0 +1,156 @@ +#include "LcdTestPresenter.h" +#include "LcdTestModel.h" +#include "components/ui_label_ext.h" +#include "common/key_code.h" +#include "custom_utils.h" +#include "gfx_utils/mem_check.h" + +namespace OHOS +{ + // 当前Presenter实例指针 + static LcdTestPresenter *g_pLcdTestPresenter = nullptr; + + LcdTestPresenter::LcdTestPresenter() + { + g_pLcdTestPresenter = this; + currentColorIndex_ = 0; + isTestRunning_ = false; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + } + + LcdTestPresenter::~LcdTestPresenter() + { + g_pLcdTestPresenter = nullptr; + isTestRunning_ = false; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + LcdTestPresenter *LcdTestPresenter::GetInstance() + { + if (g_pLcdTestPresenter == nullptr) { + // 懒加载:自动创建实例 + g_pLcdTestPresenter = new LcdTestPresenter(); + if (g_pLcdTestPresenter) { + // 创建View实例并关联 + LcdTestView* view = LcdTestView::GetInstance(); + if (view == nullptr) { + view = new LcdTestView(); + } + if (view) { + g_pLcdTestPresenter->Attach(view); + } + + // 同时创建Model实例 + if (LcdTestModel::GetInstance() == nullptr) { + new LcdTestModel(); + } + // 初始化 + g_pLcdTestPresenter->OnStart(); + } + } + return g_pLcdTestPresenter; + } + + void LcdTestPresenter::OnStart() + { + printf("LcdTestPresenter::OnStart\n"); + // 初始化Model + if (LcdTestModel::GetInstance()) { + LcdTestModel::GetInstance()->Init(); + } + } + + void LcdTestPresenter::OnResume() + { + printf("LcdTestPresenter::OnResume\n"); + } + + void LcdTestPresenter::StartLcdTest() + { + printf("=== 启动LCD测试 ===\n"); + + if (isTestRunning_) { + printf("LCD测试已在运行\n"); + return; + } + + isTestRunning_ = true; + currentColorIndex_ = 4; // 从白色开始 + + // 更新Model状态 + if (LcdTestModel::GetInstance()) { + LcdTestModel::GetInstance()->SetTestStatus(true); + LcdTestModel::GetInstance()->SetCurrentColor(LcdTestColor::White); + } + + // 通知View启动测试 + if (view_) { + view_->StartLcdTest(); + // 立即设置白色 + view_->SetLcdTestColor(LcdTestColor::White); + } + } + + void LcdTestPresenter::StopLcdTest() + { + printf("=== 停止LCD测试 ===\n"); + + if (!isTestRunning_) { + printf("LCD测试未在运行\n"); + return; + } + + isTestRunning_ = false; + + // 更新Model状态 + if (LcdTestModel::GetInstance()) { + LcdTestModel::GetInstance()->SetTestStatus(false); + } + + // 通知View停止测试 + if (view_) { + view_->StopLcdTest(); + } + } + + void LcdTestPresenter::NextColor() + { + if (!isTestRunning_) { + return; + } + + currentColorIndex_ = (currentColorIndex_ + 1) % 6; + SetColor(currentColorIndex_); + } + + void LcdTestPresenter::SetColor(int colorIndex) + { + if (!isTestRunning_ || colorIndex < 0 || colorIndex > 5) { + return; + } + + currentColorIndex_ = colorIndex; + LcdTestColor color = static_cast(colorIndex); + + // 更新Model + if (LcdTestModel::GetInstance()) { + LcdTestModel::GetInstance()->SetCurrentColor(color); + } + + // 更新View + if (view_) { + view_->SetLcdTestColor(color); + } + + // 打印颜色信息 + if (LcdTestModel::GetInstance()) { + const char* colorName = LcdTestModel::GetInstance()->GetColorName(color); + printf("fac:LCD test %s\n", colorName); + } + } + +} diff --git a/code/sdk/zhihui/leiniao/factory_test/LcdTestPresenter.h b/code/sdk/zhihui/leiniao/factory_test/LcdTestPresenter.h new file mode 100644 index 000000000..c89bc3ffd --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/LcdTestPresenter.h @@ -0,0 +1,34 @@ +#ifndef _LCD_TEST_PRESENTER_H +#define _LCD_TEST_PRESENTER_H + +#include "Presenter.h" +#include "LcdTestView.h" +#include "common/key_code.h" + +namespace OHOS +{ + class LcdTestView; + + class LcdTestPresenter : public Presenter + { + public: + LcdTestPresenter(); + virtual ~LcdTestPresenter(); + + void OnStart() override; + void OnResume() override; + static LcdTestPresenter *GetInstance(); + + // LCD测试控制方法 + void StartLcdTest(); + void StopLcdTest(); + void NextColor(); + void SetColor(int colorIndex); + + private: + int currentColorIndex_{0}; + bool isTestRunning_{false}; + }; +} // namespace OHOS + +#endif // _LCD_TEST_PRESENTER_H diff --git a/code/sdk/zhihui/leiniao/factory_test/LcdTestView.cpp b/code/sdk/zhihui/leiniao/factory_test/LcdTestView.cpp index 2c2c251ea..b003737f4 100644 --- a/code/sdk/zhihui/leiniao/factory_test/LcdTestView.cpp +++ b/code/sdk/zhihui/leiniao/factory_test/LcdTestView.cpp @@ -1,16 +1,229 @@ +#include "LcdTestView.h" +#include "LcdTestModel.h" #include "components/ui_scroll_view.h" #include "components/root_view.h" #include "common/screen.h" #include "UiConfig.h" #include "gfx_utils/style.h" #include "graphic_config.h" -#include "View.h" +#include "ui_resource_image.h" -// 全局变量 - 最简单的方式 -static OHOS::UIScrollView* g_lcd_test_view = nullptr; -static OHOS::UIView* g_current_view = nullptr; +namespace OHOS +{ + static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6; + static LcdTestView *g_pLcdTestView = nullptr; + + LcdTestView::LcdTestView() + { + g_pLcdTestView = this; + testView_ = nullptr; + savedCurrentView_ = nullptr; + viewInitStatus_ = false; + isTestActive_ = false; + } + + LcdTestView::~LcdTestView() + { + DeInit(); + g_pLcdTestView = nullptr; + } + + LcdTestView *LcdTestView::GetInstance() + { + if (g_pLcdTestView == nullptr) { + // 懒加载:自动创建实例 + g_pLcdTestView = new LcdTestView(); + if (g_pLcdTestView) { + g_pLcdTestView->OnStart(); + } + } + return g_pLcdTestView; + } + + void LcdTestView::OnStart() + { + printf("LcdTestView::OnStart\n"); + InitView(); + } + + void LcdTestView::InitView() + { + if (viewInitStatus_) { + printf("LcdTestView already initialized\n"); + return; + } + + printf("Initializing LcdTestView\n"); + + // 创建主滚动视图 + if (scrollview_ == nullptr) { + scrollview_ = new UIScrollView(); + if (scrollview_ == nullptr) { + printf("ERROR: Failed to create main scroll view\n"); + return; + } + + scrollview_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scrollview_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollview_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); + scrollview_->SetTouchable(true); + scrollview_->SetDraggable(true); + scrollview_->SetVisible(true); + + // 不需要事件监听器 + } + + viewInitStatus_ = true; + printf("LcdTestView initialized successfully\n"); + } + + void LcdTestView::DeInit() + { + if (!viewInitStatus_) { + return; + } + + printf("Deinitializing LcdTestView\n"); + + // 停止测试(如果正在运行) + if (isTestActive_) { + StopLcdTest(); + } + + // 清理主视图 + if (scrollview_ != nullptr) { + RootView* rootView = RootView::GetInstance(); + if (rootView && scrollview_->GetParent() == rootView) { + rootView->Remove(scrollview_); + } + delete scrollview_; + scrollview_ = nullptr; + } + + viewInitStatus_ = false; + } + + void LcdTestView::PreLoad() + { + printf("LcdTestView::PreLoad\n"); + InitView(); + } + + void LcdTestView::StartLcdTest() + { + if (isTestActive_) { + printf("LCD test already active\n"); + return; + } + + printf("Starting LCD test view\n"); + + RootView* rootView = RootView::GetInstance(); + if (rootView == nullptr) { + printf("ERROR: RootView not initialized\n"); + return; + } + + // 保存当前显示的view + savedCurrentView_ = rootView->GetChildrenHead(); + if (savedCurrentView_ != nullptr && savedCurrentView_ != scrollview_) { + rootView->Remove(savedCurrentView_); + printf("Saved and removed current view for later restore\n"); + } + + // 创建LCD测试view + if (testView_ == nullptr) { + testView_ = new UIScrollView(); + if (testView_ == nullptr) { + printf("ERROR: Failed to create LCD test view\n"); + return; + } + } + + // 设置全屏显示,默认白色 + testView_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + testView_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + testView_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); // 白色 + testView_->SetTouchable(true); + testView_->SetDraggable(true); + testView_->SetVisible(true); + + // 不需要事件监听器 + + // 添加到根视图 + rootView->Add(testView_); + rootView->Invalidate(); + + isTestActive_ = true; + printf("LCD test started - WHITE background\n"); + } + + void LcdTestView::StopLcdTest() + { + if (!isTestActive_) { + printf("LCD test not active\n"); + return; + } + + printf("Stopping LCD test view\n"); + + RootView* rootView = RootView::GetInstance(); + if (rootView != nullptr) { + // 删除LCD测试view + if (testView_ != nullptr) { + rootView->Remove(testView_); + delete testView_; + testView_ = nullptr; + printf("LCD test view removed\n"); + } + + // 恢复原来的view + if (savedCurrentView_ != nullptr) { + printf("Attempting to restore view at address: %p\n", savedCurrentView_); + + if (savedCurrentView_->GetParent() == nullptr) { + rootView->Add(savedCurrentView_); + rootView->Invalidate(); + printf("Original view restored successfully\n"); + } else { + printf("Warning: Original view still has parent, cannot restore\n"); + } + savedCurrentView_ = nullptr; + } else { + printf("No original view to restore\n"); + } + } + + isTestActive_ = false; + } + + void LcdTestView::SetLcdTestColor(LcdTestColor color) + { + if (!isTestActive_ || testView_ == nullptr) { + printf("LCD test not active\n"); + return; + } + + // 获取颜色值 + uint32_t colorValue = 0xffff0000; // 默认红色 + if (LcdTestModel::GetInstance()) { + colorValue = LcdTestModel::GetInstance()->GetColorValue(color); + } + + testView_->SetStyle(STYLE_BACKGROUND_COLOR, colorValue); + RootView::GetInstance()->Invalidate(); + + printf("LCD test color changed\n"); + } + + void LcdTestView::UpdateColorDisplay(LcdTestColor color) + { + SetLcdTestColor(color); + } +} // namespace OHOS +// 保持向后兼容的C接口 #ifdef __cplusplus #if __cplusplus extern "C" @@ -23,43 +236,12 @@ extern "C" */ void start_lcd_test_view(void) { - printf("=== 启动LCD测试 ===\n"); - - OHOS::RootView* rootView = OHOS::RootView::GetInstance(); - if (rootView == nullptr) { - printf("ERROR: RootView not initialized\n"); - return; - } - - // 保存当前显示的view,然后切换到LCD测试view - g_current_view = rootView->GetChildrenHead(); - if (g_current_view != nullptr) { - // 先从rootView中移除,但不删除 - rootView->Remove(g_current_view); - printf("Saved and removed current view for later restore\n"); - } - - // 创建ScrollView用于LCD测试 - g_lcd_test_view = new OHOS::UIScrollView(); - if (g_lcd_test_view == nullptr) { - printf("ERROR: Failed to create LCD test view\n"); - return; + OHOS::LcdTestPresenter* presenter = OHOS::LcdTestPresenter::GetInstance(); + if (presenter) { + presenter->StartLcdTest(); + } else { + printf("ERROR: LcdTestPresenter not initialized\n"); } - - // 设置全屏红色 - printf("fac:LCD test red\n"); - g_lcd_test_view->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); - g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff); - g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xffff0000); // 红色 - g_lcd_test_view->SetTouchable(false); - g_lcd_test_view->SetDraggable(false); - g_lcd_test_view->SetVisible(true); - - // 添加LCD测试view到根视图 - rootView->Add(g_lcd_test_view); - rootView->Invalidate(); - - printf("LCD test started - RED background\n"); } /** @@ -67,34 +249,11 @@ void start_lcd_test_view(void) */ void stop_lcd_test_view(void) { - printf("=== 停止LCD测试 ===\n"); - - OHOS::RootView* rootView = OHOS::RootView::GetInstance(); - if (rootView != nullptr) { - // 删除LCD测试view - if (g_lcd_test_view != nullptr) { - rootView->Remove(g_lcd_test_view); - delete g_lcd_test_view; - g_lcd_test_view = nullptr; - printf("LCD test view removed\n"); - } - - // 恢复原来的view - if (g_current_view != nullptr) { - printf("Attempting to restore view at address: %p\n", g_current_view); - - // 检查view是否还有效 - if (g_current_view->GetParent() == nullptr) { - rootView->Add(g_current_view); - rootView->Invalidate(); - printf("Original view restored successfully\n"); + OHOS::LcdTestPresenter* presenter = OHOS::LcdTestPresenter::GetInstance(); + if (presenter) { + presenter->StopLcdTest(); } else { - printf("Warning: Original view still has parent, cannot restore\n"); - } - g_current_view = nullptr; - } else { - printf("No original view to restore\n"); - } + printf("ERROR: LcdTestPresenter not initialized\n"); } } @@ -104,39 +263,12 @@ void stop_lcd_test_view(void) */ void set_lcd_test_color(int color) { - if (g_lcd_test_view == nullptr) { - printf("LCD test not started\n"); - return; - } - - - switch (color) - { - case 0: - printf("fac:LCD test green\n"); - g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Green().full); - break; - case 1: - printf("fac:LCD test blue\n"); - g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Blue().full); - break; - case 2: - g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Yellow().full); - break; - case 3: - printf("fac:LCD test red\n"); - g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Red().full); - break; - case 4: - g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::White().full); - break; - case 5: - g_lcd_test_view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, OHOS::Color::Black().full); - break; - default: - break; + OHOS::LcdTestPresenter* presenter = OHOS::LcdTestPresenter::GetInstance(); + if (presenter) { + presenter->SetColor(color); + } else { + printf("ERROR: LcdTestPresenter not initialized\n"); } - OHOS::RootView::GetInstance()->Invalidate(); } #ifdef __cplusplus diff --git a/code/sdk/zhihui/leiniao/factory_test/LcdTestView.h b/code/sdk/zhihui/leiniao/factory_test/LcdTestView.h new file mode 100644 index 000000000..6545d7b17 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/LcdTestView.h @@ -0,0 +1,63 @@ +#ifndef _LCD_TEST_VIEW_H +#define _LCD_TEST_VIEW_H + +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_label_button_ext.h" +#include "wearable_log.h" +#include "ohos_types.h" +#include "LcdTestPresenter.h" + +namespace OHOS +{ + enum class LcdTestColor + { + Green = 0, + Blue = 1, + Yellow = 2, + Red = 3, + White = 4, + Black = 5 + }; + + class LcdTestPresenter; + class LcdTestView : public View + { + public: + LcdTestView(); + virtual ~LcdTestView(); + static LcdTestView *GetInstance(void); + + void OnStart() override; + void InitView(); + void DeInit(); + void PreLoad(void); + + // LCD测试相关方法 + void StartLcdTest(); + void StopLcdTest(); + void SetLcdTestColor(LcdTestColor color); + void UpdateColorDisplay(LcdTestColor color); + + // 获取UI组件 + UIScrollView* GetTestView() { return testView_; } + + private: + LcdTestView(LcdTestView &&) = delete; + LcdTestView &operator=(LcdTestView &&) = delete; + + UIScrollView *scrollview_ = nullptr; + UIScrollView *testView_ = nullptr; + UIView *savedCurrentView_ = nullptr; + + bool viewInitStatus_{false}; + bool isTestActive_{false}; + }; +} // namespace OHOS + +#endif // _LCD_TEST_VIEW_H diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestModel.cpp b/code/sdk/zhihui/leiniao/factory_test/PPPTestModel.cpp new file mode 100644 index 000000000..20f1673b7 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestModel.cpp @@ -0,0 +1,324 @@ +#include "PPPTestModel.h" +#include +#include + +namespace OHOS +{ + // 静态常量定义 + const char* PPPTestModel::SIGNAL_LEVEL_NAMES[] = { + "优秀", "良好", "一般", "差", "未知" + }; + + const char* PPPTestModel::NETWORK_TYPE_NAMES[] = { + "未知", "GSM", "GPRS", "EDGE", "UMTS", "HSDPA", "HSUPA", "HSPA", "LTE", "5G" + }; + + const char* PPPTestModel::SIM_STATUS_NAMES[] = { + "未知", "无SIM卡", "PIN锁定", "PUK锁定", "网络锁定", "就绪", "错误" + }; + + static PPPTestModel *g_PPPpTestModel = nullptr; + + PPPTestModel::PPPTestModel() + { + g_PPPpTestModel = this; + memset(&statusInfo_, 0, sizeof(statusInfo_)); + memset(&signalInfo_, 0, sizeof(signalInfo_)); + } + + PPPTestModel::~PPPTestModel() + { + g_PPPpTestModel = nullptr; + } + + PPPTestModel *PPPTestModel::GetInstance() + { + return g_PPPpTestModel; + } + + void PPPTestModel::Init() + { + testStatus_ = PPPTestStatus::Idle; + initCompleted_ = false; + initInProgress_ = false; + initRetryCount_ = 0; + + // 初始化状态信息 + memset(&statusInfo_, 0, sizeof(statusInfo_)); + statusInfo_.isValid = false; + + // 初始化信号信息 + memset(&signalInfo_, 0, sizeof(signalInfo_)); + signalInfo_.level = PPPSignalLevel::Unknown; + signalInfo_.isValid = false; + + printf("PPPTestModel initialized\n"); + } + + void PPPTestModel::SetTestStatus(PPPTestStatus status) + { + testStatus_ = status; + printf("PPP test status changed to: %d\n", static_cast(status)); + } + + PPPTestStatus PPPTestModel::GetTestStatus() const + { + return testStatus_; + } + + void PPPTestModel::SetInitStatus(bool completed, bool inProgress) + { + initCompleted_ = completed; + initInProgress_ = inProgress; + + if (completed) { + printf("PPP initialization completed successfully\n"); + } else if (inProgress) { + printf("PPP initialization in progress\n"); + } + } + + bool PPPTestModel::IsInitCompleted() const + { + return initCompleted_; + } + + bool PPPTestModel::IsInitInProgress() const + { + return initInProgress_; + } + + void PPPTestModel::SetInitRetryCount(int count) + { + initRetryCount_ = count; + printf("PPP init retry count: %d\n", count); + } + + int PPPTestModel::GetInitRetryCount() const + { + return initRetryCount_; + } + + bool PPPTestModel::CanRetryInit() const + { + return initRetryCount_ < MAX_INIT_RETRIES; + } + + void PPPTestModel::UpdateStatusInfo(const PPPStatusInfo& info) + { + statusInfo_ = info; + statusInfo_.isValid = true; + printf("PPP status info updated\n"); + } + + const PPPStatusInfo& PPPTestModel::GetStatusInfo() const + { + return statusInfo_; + } + + void PPPTestModel::UpdateSignalInfo(const PPPSignalInfo& info) + { + signalInfo_ = info; + signalInfo_.isValid = true; + printf("PPP signal info updated - RSRQ: %d, RSRP: %d\n", info.rsrq, info.rsrp); + } + + const PPPSignalInfo& PPPTestModel::GetSignalInfo() const + { + return signalInfo_; + } + + ppp_error_t PPPTestModel::InitializePPPEnvironment() + { + printf("Initializing PPP environment...\n"); +#ifdef SUPPORT_PPP_SERVICE + int result = ppp_env_init(); + + if (result == 0) { + SetInitStatus(true, false); + return PPP_ERR_OK; + } else { + printf("PPP environment initialization failed: %d\n", result); + return PPP_ERR_AT_FAILED; + } +#else + printf("PPP service not supported\n"); + return PPP_ERR_AT_FAILED; +#endif + } + + ppp_error_t PPPTestModel::UpdateRuntimeStatus() + { + printf("Updating PPP runtime status...\n"); +#ifdef SUPPORT_PPP_SERVICE + int result = ppp_api_update_all_runtime_status(); + + if (result == 0) { + // 收集最新的状态信息 + PPPStatusInfo info = CollectStatusInfo(); + UpdateStatusInfo(info); + return PPP_ERR_OK; + } else { + printf("PPP runtime status update failed: %d\n", result); + return PPP_ERR_AT_FAILED; + } +#else + printf("PPP service not supported\n"); + return PPP_ERR_AT_FAILED; +#endif + } + + ppp_error_t PPPTestModel::GetNetworkSignalInfo() + { + printf("Getting network signal info...\n"); +#ifdef SUPPORT_PPP_SERVICE + int result = ppp_get_network_signal_info(); + + if (result == 0) { + // 收集最新的信号信息 + PPPSignalInfo info = CollectSignalInfo(); + UpdateSignalInfo(info); + return PPP_ERR_OK; + } else { + printf("Network signal info retrieval failed: %d\n", result); + return PPP_ERR_AT_FAILED; + } +#else + printf("PPP service not supported\n"); + return PPP_ERR_AT_FAILED; +#endif + } + + PPPStatusInfo PPPTestModel::CollectStatusInfo() + { + PPPStatusInfo info; + memset(&info, 0, sizeof(info)); + +#ifdef SUPPORT_PPP_SERVICE + // 收集CAT1状态信息 + info.powerStatus = (cat1_api_runtime_get_cat1_powerstat() == 1); + info.networkStatus = (cat1_api_runtime_get_cat1_networkstat() == 1); + info.signalStrength = cat1_api_runtime_get_cat1_signal(); + info.simStatus = cat1_api_runtime_get_cat1_simstat(); + info.networkType = cat1_api_runtime_get_cat1_networktype(); + + // 复制字符串信息 + char* operator_str = cat1_api_runtime_get_cat1_operator(); + if (operator_str) { + strncpy(info.operatorName, operator_str, sizeof(info.operatorName) - 1); + } + + char* imei_str = cat1_api_runtime_get_cat1_imei(); + if (imei_str) { + strncpy(info.imei, imei_str, sizeof(info.imei) - 1); + } + + char* iccid_str = cat1_api_runtime_get_cat1_iccid(); + if (iccid_str) { + strncpy(info.iccid, iccid_str, sizeof(info.iccid) - 1); + } + + char* version_str = cat1_api_runtime_get_cat1_modemver(); + if (version_str) { + strncpy(info.modemVersion, version_str, sizeof(info.modemVersion) - 1); + } + + info.isValid = true; +#else + // PPP服务不支持时,返回默认值 + info.powerStatus = false; + info.networkStatus = false; + info.signalStrength = -1; + info.simStatus = 0; + info.networkType = 0; + strncpy(info.operatorName, "不支持", sizeof(info.operatorName) - 1); + strncpy(info.imei, "不支持", sizeof(info.imei) - 1); + strncpy(info.iccid, "不支持", sizeof(info.iccid) - 1); + strncpy(info.modemVersion, "不支持", sizeof(info.modemVersion) - 1); + info.isValid = false; +#endif + + return info; + } + + PPPSignalInfo PPPTestModel::CollectSignalInfo() + { + PPPSignalInfo info; + memset(&info, 0, sizeof(info)); + +#ifdef SUPPORT_PPP_SERVICE + // 获取详细信号信息 + ppp_network_signal_info_t signal_info; + memset(&signal_info, 0, sizeof(signal_info)); + + ppp_error_t result = ppp_at_get_network_signal_info(&signal_info); + if (result == PPP_ERR_OK && signal_info.valid) { + info.rsrq = signal_info.rsrq; + info.rsrp = signal_info.rsrp; + info.rxlev = signal_info.rxlev; + info.ber = signal_info.ber; + info.level = EvaluateSignalLevel(info.rsrq, info.rsrp); + info.isValid = true; + } else { + // 如果详细信号信息获取失败,使用基本信号强度 + info.rxlev = cat1_api_runtime_get_cat1_signal(); + info.rsrq = -1; + info.rsrp = -1; + info.ber = -1; + info.level = PPPSignalLevel::Unknown; + info.isValid = (info.rxlev >= 0); + } +#else + // PPP服务不支持时,返回默认值 + info.rxlev = -1; + info.rsrq = -1; + info.rsrp = -1; + info.ber = -1; + info.level = PPPSignalLevel::Unknown; + info.isValid = false; +#endif + + return info; + } + + PPPSignalLevel PPPTestModel::EvaluateSignalLevel(int16_t rsrq, int16_t rsrp) + { + // 基于RSRQ和RSRP评估信号质量 + if (rsrq >= -10 && rsrp >= -80) { + return PPPSignalLevel::Excellent; + } else if (rsrq >= -15 && rsrp >= -90) { + return PPPSignalLevel::Good; + } else if (rsrq >= -20 && rsrp >= -100) { + return PPPSignalLevel::Fair; + } else if (rsrq >= -30 && rsrp >= -110) { + return PPPSignalLevel::Poor; + } else { + return PPPSignalLevel::Unknown; + } + } + + const char* PPPTestModel::GetSignalLevelName(PPPSignalLevel level) const + { + int index = static_cast(level); + if (index >= 0 && index < 5) { + return SIGNAL_LEVEL_NAMES[index]; + } + return "未知"; + } + + const char* PPPTestModel::GetNetworkTypeName(uint8_t type) const + { + if (type < sizeof(NETWORK_TYPE_NAMES) / sizeof(NETWORK_TYPE_NAMES[0])) { + return NETWORK_TYPE_NAMES[type]; + } + return "未知"; + } + + const char* PPPTestModel::GetSimStatusName(int status) const + { + if (status >= 0 && status < 7) { + return SIM_STATUS_NAMES[status]; + } + return "未知"; + } +} diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestModel.h b/code/sdk/zhihui/leiniao/factory_test/PPPTestModel.h new file mode 100644 index 000000000..a4f186bc8 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestModel.h @@ -0,0 +1,149 @@ +#ifndef _PPP_TEST_MODEL_H +#define _PPP_TEST_MODEL_H + +#include "PPPTestView.h" +#include +#include + +// 前向声明和错误码定义 +typedef int ppp_error_t; + +#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 + +// 网络信号信息结构体 +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; +}; +typedef struct ppp_network_signal_info_s ppp_network_signal_info_t; + +namespace OHOS +{ + // PPP状态信息结构体 + struct PPPStatusInfo { + bool powerStatus; + bool networkStatus; + int signalStrength; + int simStatus; + uint8_t networkType; + char operatorName[64]; + char imei[32]; + char iccid[32]; + char modemVersion[128]; + bool isValid; + }; + + // 信号质量信息结构体 + struct PPPSignalInfo { + int16_t rsrq; + int16_t rsrp; + int16_t rxlev; + int16_t ber; + PPPSignalLevel level; + bool isValid; + }; + + class PPPTestModel + { + public: + PPPTestModel(); + ~PPPTestModel(); + static PPPTestModel *GetInstance(void); + + void Init(); + + // 测试状态管理 + void SetTestStatus(PPPTestStatus status); + PPPTestStatus GetTestStatus() const; + + // 初始化状态管理 + void SetInitStatus(bool completed, bool inProgress); + bool IsInitCompleted() const; + bool IsInitInProgress() const; + + void SetInitRetryCount(int count); + int GetInitRetryCount() const; + bool CanRetryInit() const; + + // 网络状态数据管理 + void UpdateStatusInfo(const PPPStatusInfo& info); + const PPPStatusInfo& GetStatusInfo() const; + + void UpdateSignalInfo(const PPPSignalInfo& info); + const PPPSignalInfo& GetSignalInfo() const; + + // PPP API调用封装 + ppp_error_t InitializePPPEnvironment(); + ppp_error_t UpdateRuntimeStatus(); + ppp_error_t GetNetworkSignalInfo(); + + // 数据获取方法 + PPPStatusInfo CollectStatusInfo(); + PPPSignalInfo CollectSignalInfo(); + + // 信号质量评估 + PPPSignalLevel EvaluateSignalLevel(int16_t rsrq, int16_t rsrp); + const char* GetSignalLevelName(PPPSignalLevel level) const; + const char* GetNetworkTypeName(uint8_t type) const; + const char* GetSimStatusName(int status) const; + + private: + PPPTestStatus testStatus_{PPPTestStatus::Idle}; + bool initCompleted_{false}; + bool initInProgress_{false}; + int initRetryCount_{0}; + + PPPStatusInfo statusInfo_{}; + PPPSignalInfo signalInfo_{}; + + static const int MAX_INIT_RETRIES = 5; + static const char* SIGNAL_LEVEL_NAMES[]; + static const char* NETWORK_TYPE_NAMES[]; + static const char* SIM_STATUS_NAMES[]; + }; +} + +// C API 声明(用于与底层PPP接口交互) +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SUPPORT_PPP_SERVICE +int ppp_env_init(void); +int ppp_api_update_all_runtime_status(void); +ppp_error_t ppp_at_get_network_signal_info(ppp_network_signal_info_t *info); +int 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); +#endif // SUPPORT_PPP_SERVICE + +#ifdef __cplusplus +} +#endif + +#endif // _PPP_TEST_MODEL_H diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.cpp b/code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.cpp new file mode 100644 index 000000000..cb288b2ab --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.cpp @@ -0,0 +1,347 @@ +#include "PPPTestPresenter.h" +#include "PPPTestModel.h" +#include "components/ui_label_ext.h" +#include "common/key_code.h" +#include "custom_utils.h" +#include "gfx_utils/mem_check.h" + +namespace OHOS +{ + // 当前Presenter实例指针 + static PPPTestPresenter *g_pPPPTestPresenter = nullptr; + + // 定时器回调函数声明 + static void InitTimerCallback(void *argument); + static void RefreshTimerCallback(void *argument); + + PPPTestPresenter::PPPTestPresenter() + { + g_pPPPTestPresenter = this; + isTestRunning_ = false; + isInitializing_ = false; + initRetryCount_ = 0; + initTimer_ = nullptr; + refreshTimer_ = nullptr; + +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + } + + PPPTestPresenter::~PPPTestPresenter() + { + DestroyTimers(); + g_pPPPTestPresenter = nullptr; + isTestRunning_ = false; + isInitializing_ = false; + +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + PPPTestPresenter *PPPTestPresenter::GetInstance() + { + return g_pPPPTestPresenter; + } + + void PPPTestPresenter::OnStart() + { + printf("PPPTestPresenter::OnStart\n"); + + // 初始化Model + if (PPPTestModel::GetInstance()) { + PPPTestModel::GetInstance()->Init(); + } + + // 创建定时器 + CreateTimers(); + } + + void PPPTestPresenter::OnResume() + { + printf("PPPTestPresenter::OnResume\n"); + } + + void PPPTestPresenter::StartPPPTest() + { + printf("=== 启动PPP测试 ===\n"); + + if (isTestRunning_) { + printf("PPP测试已在运行\n"); + return; + } + + isTestRunning_ = true; + + // 更新Model状态 + if (PPPTestModel::GetInstance()) { + PPPTestModel::GetInstance()->SetTestStatus(PPPTestStatus::Testing); + } + + // 通知View启动测试 + if (view_) { + view_->StartPPPTest(); + view_->UpdateTestStatus(PPPTestStatus::Testing); + } + + // 开始初始化流程 + StartInitialization(); + } + + void PPPTestPresenter::StopPPPTest() + { + printf("=== 停止PPP测试 ===\n"); + + if (!isTestRunning_) { + printf("PPP测试未在运行\n"); + return; + } + + isTestRunning_ = false; + isInitializing_ = false; + + // 停止定时器 + StopRefreshTimer(); + + // 更新Model状态 + if (PPPTestModel::GetInstance()) { + PPPTestModel::GetInstance()->SetTestStatus(PPPTestStatus::Idle); + } + + // 通知View停止测试 + if (view_) { + view_->StopPPPTest(); + view_->UpdateTestStatus(PPPTestStatus::Idle); + } + } + + void PPPTestPresenter::RefreshPPPData() + { + if (!isTestRunning_) { + printf("PPP测试未运行,无法刷新数据\n"); + return; + } + + printf("刷新PPP测试数据\n"); + + // 更新状态 + if (PPPTestModel::GetInstance()) { + PPPTestModel::GetInstance()->SetTestStatus(PPPTestStatus::Refreshing); + } + + if (view_) { + view_->UpdateTestStatus(PPPTestStatus::Refreshing); + } + + // 更新运行时状态 + if (PPPTestModel::GetInstance()) { + ppp_error_t result = PPPTestModel::GetInstance()->UpdateRuntimeStatus(); + if (result == PPP_ERR_OK) { + // 更新View显示 + if (view_) { + view_->UpdateNetworkInfo(); + view_->UpdateModemInfo(); + } + } + + // 获取信号信息 + result = PPPTestModel::GetInstance()->GetNetworkSignalInfo(); + if (result == PPP_ERR_OK) { + if (view_) { + view_->UpdateSignalInfo(); + } + } + + // 恢复测试状态 + PPPTestModel::GetInstance()->SetTestStatus(PPPTestStatus::Testing); + } + + if (view_) { + view_->UpdateTestStatus(PPPTestStatus::Testing); + } + } + + void PPPTestPresenter::StartInitialization() + { + if (isInitializing_) { + printf("PPP初始化已在进行中\n"); + return; + } + + printf("开始PPP初始化流程\n"); + isInitializing_ = true; + + // 更新状态 + if (PPPTestModel::GetInstance()) { + PPPTestModel::GetInstance()->SetTestStatus(PPPTestStatus::Initializing); + PPPTestModel::GetInstance()->SetInitStatus(false, true); + } + + if (view_) { + view_->UpdateTestStatus(PPPTestStatus::Initializing); + view_->ShowInitProgress(0); + } + + // 启动初始化定时器 + if (initTimer_) { + osTimerStart(initTimer_, INIT_TIMEOUT_MS); + } + + // 执行PPP环境初始化 + if (PPPTestModel::GetInstance()) { + ppp_error_t result = PPPTestModel::GetInstance()->InitializePPPEnvironment(); + if (result == PPP_ERR_OK) { + HandleInitComplete(); + } else { + HandleInitError(); + } + } + } + + void PPPTestPresenter::HandleInitComplete() + { + printf("PPP初始化完成\n"); + isInitializing_ = false; + + // 停止初始化定时器 + if (initTimer_) { + osTimerStop(initTimer_); + } + + // 更新状态 + if (PPPTestModel::GetInstance()) { + PPPTestModel::GetInstance()->SetInitStatus(true, false); + PPPTestModel::GetInstance()->SetTestStatus(PPPTestStatus::Testing); + } + + if (view_) { + view_->ShowInitProgress(100); + view_->UpdateTestStatus(PPPTestStatus::Testing); + } + + // 首次刷新数据 + RefreshPPPData(); + + // 启动定期刷新定时器 + StartRefreshTimer(); + } + + void PPPTestPresenter::HandleInitError() + { + printf("PPP初始化失败\n"); + isInitializing_ = false; + + // 停止初始化定时器 + if (initTimer_) { + osTimerStop(initTimer_); + } + + if (CanRetryInit()) { + RetryInitialization(); + } else { + // 达到最大重试次数,进入错误状态 + if (PPPTestModel::GetInstance()) { + PPPTestModel::GetInstance()->SetTestStatus(PPPTestStatus::Error); + } + + if (view_) { + view_->UpdateTestStatus(PPPTestStatus::Error); + view_->ShowErrorMessage("PPP初始化失败,请检查网络连接"); + } + } + } + + void PPPTestPresenter::RetryInitialization() + { + initRetryCount_++; + printf("重试PPP初始化 (%d/%d)\n", initRetryCount_, MAX_INIT_RETRIES); + + if (PPPTestModel::GetInstance()) { + PPPTestModel::GetInstance()->SetInitRetryCount(initRetryCount_); + } + + // 延迟后重新尝试初始化 + StartInitialization(); + } + + bool PPPTestPresenter::CanRetryInit() const + { + return initRetryCount_ < MAX_INIT_RETRIES; + } + + void PPPTestPresenter::CreateTimers() + { + // 创建初始化超时定时器 + const osTimerAttr_t init_timer_attr = { + .name = "ppp_init_timer" + }; + initTimer_ = osTimerNew(InitTimerCallback, osTimerOnce, this, &init_timer_attr); + + // 创建定期刷新定时器 + const osTimerAttr_t refresh_timer_attr = { + .name = "ppp_refresh_timer" + }; + refreshTimer_ = osTimerNew(RefreshTimerCallback, osTimerPeriodic, this, &refresh_timer_attr); + } + + void PPPTestPresenter::DestroyTimers() + { + if (initTimer_) { + osTimerDelete(initTimer_); + initTimer_ = nullptr; + } + + if (refreshTimer_) { + osTimerDelete(refreshTimer_); + refreshTimer_ = nullptr; + } + } + + void PPPTestPresenter::StartRefreshTimer() + { + if (refreshTimer_ && isTestRunning_) { + osTimerStart(refreshTimer_, REFRESH_INTERVAL_MS); + printf("PPP刷新定时器已启动\n"); + } + } + + void PPPTestPresenter::StopRefreshTimer() + { + if (refreshTimer_) { + osTimerStop(refreshTimer_); + printf("PPP刷新定时器已停止\n"); + } + } + + void PPPTestPresenter::OnInitTimeout() + { + printf("PPP初始化超时\n"); + HandleInitError(); + } + + void PPPTestPresenter::OnRefreshTimer() + { + if (isTestRunning_ && !isInitializing_) { + RefreshPPPData(); + } + } + + + // 定时器回调函数实现 + static void InitTimerCallback(void *argument) + { + PPPTestPresenter* presenter = static_cast(argument); + if (presenter) { + presenter->OnInitTimeout(); + } + } + + static void RefreshTimerCallback(void *argument) + { + PPPTestPresenter* presenter = static_cast(argument); + if (presenter) { + presenter->OnRefreshTimer(); + } + } +} diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.h b/code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.h new file mode 100644 index 000000000..677d966a1 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.h @@ -0,0 +1,70 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-09-22 19:29:47 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-09-22 19:53:00 + * @FilePath: /FD230/code/sdk/zhihui/leiniao/factory_test/PPPTestPresenter.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#ifndef _PPP_TEST_PRESENTER_H +#define _PPP_TEST_PRESENTER_H + +#include "Presenter.h" +#include "PPPTestView.h" +#include "common/key_code.h" +#include "cmsis_os2.h" + +namespace OHOS +{ + class PPPTestView; + + class PPPTestPresenter : public Presenter + { + public: + PPPTestPresenter(); + virtual ~PPPTestPresenter(); + + void OnStart() override; + void OnResume() override; + static PPPTestPresenter *GetInstance(); + + // PPP测试控制方法 + void StartPPPTest(); + void StopPPPTest(); + void RefreshPPPData(); + + // 定时器回调处理 + void OnInitTimeout(); + void OnRefreshTimer(); + + // 初始化状态管理 + void StartInitialization(); + void HandleInitComplete(); + void HandleInitError(); + + private: + // 定时器相关 + void CreateTimers(); + void DestroyTimers(); + void StartRefreshTimer(); + void StopRefreshTimer(); + + // 初始化流程控制 + void RetryInitialization(); + bool CanRetryInit() const; + + bool isTestRunning_{false}; + bool isInitializing_{false}; + int initRetryCount_{0}; + + // 定时器句柄 + osTimerId_t initTimer_{nullptr}; + osTimerId_t refreshTimer_{nullptr}; + + static const int MAX_INIT_RETRIES = 5; + static const uint32_t INIT_TIMEOUT_MS = 5000; + static const uint32_t REFRESH_INTERVAL_MS = 5000; + }; +} // namespace OHOS + +#endif // _PPP_TEST_PRESENTER_H diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp b/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp index 6d567b1ba..8b39ccc90 100644 --- a/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp @@ -1,3 +1,5 @@ +#include "PPPTestView.h" +#include "PPPTestModel.h" #include "components/ui_scroll_view.h" #include "components/root_view.h" #include "components/ui_label.h" @@ -5,723 +7,496 @@ #include "UiConfig.h" #include "gfx_utils/style.h" #include "graphic_config.h" -#include "cmsis_os2.h" - -// C标准库 +#include "ui_resource_image.h" #include #include -#include - -// 预声明必要的类型以避免循环依赖 -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); +namespace OHOS +{ + static const uint32_t BACK_GROUND_COLOR = 0xff000000; // 黑色背景 + static const uint32_t TEXT_COLOR = 0xffffffff; // 白色文字 + static const uint32_t TITLE_COLOR = 0xff00ff00; // 绿色标题 + static PPPTestView *g_pPPPTestView = nullptr; -#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 { + // 标签配置结构体 + struct PPPLabelConfig_t { int left; int top; int width; int height; - uint16_t fontSize; - uint16_t lineHeight; + uint32_t textColor; + uint8_t fontSize; 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; + PPPTestView::PPPTestView() + { + g_pPPPTestView = this; + testView_ = nullptr; + savedCurrentView_ = nullptr; + titleLabel_ = nullptr; + viewInitStatus_ = false; + isTestActive_ = false; + currentStatus_ = PPPTestStatus::Idle; + + // 初始化状态标签数组 + for (int i = 0; i < MAX_STATUS_LABELS; i++) { + statusLabels_[i] = 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; + PPPTestView::~PPPTestView() + { + DeInit(); + g_pPPPTestView = nullptr; } - - printf("=== 更新PPP运行状态显示 ===\n"); - - // 更新所有运行时状态 - #if SUPPORT_PPP_SERVICE - errcode_t ret = ppp_api_update_all_runtime_status(); - #else - errcode_t ret = ERRCODE_SUCC; - #endif - 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++; + + PPPTestView *PPPTestView::GetInstance() + { + return g_pPPPTestView; } - - // 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++; + + void PPPTestView::OnStart() + { + printf("PPPTestView::OnStart\n"); + InitView(); } - - // 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++; + + void PPPTestView::InitView() + { + if (viewInitStatus_) { + printf("PPPTestView already initialized\n"); + return; } - */ - // 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); + printf("Initializing PPPTestView\n"); + + // 创建主滚动视图 + if (scrollview_ == nullptr) { + scrollview_ = new UIScrollView(); + if (scrollview_ == nullptr) { + printf("ERROR: Failed to create main scroll view\n"); + return; + } + + scrollview_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + scrollview_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollview_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); + scrollview_->SetTouchable(true); + scrollview_->SetDraggable(true); + scrollview_->SetVisible(true); + + // 不需要事件监听器 } - g_ppp_status_labels[label_index]->SetText(buffer); - label_index++; + + viewInitStatus_ = true; + printf("PPPTestView initialized successfully\n"); } - - // 清空基本状态部分后面的剩余标签(为信号质量部分预留空间) - 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); // 保持可见,待信号质量更新 + + void PPPTestView::DeInit() + { + if (!viewInitStatus_) { + return; } - } - - // 确保信号质量标签也是可见和可用的 - for (int i = 4; i < 12; i++) { - if (g_ppp_status_labels[i] != nullptr) { - g_ppp_status_labels[i]->SetVisible(true); // 确保信号质量标签可见 + + printf("Deinitializing PPPTestView\n"); + + // 停止测试(如果正在运行) + if (isTestActive_) { + StopPPPTest(); } - } - - 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; - #if SUPPORT_PPP_SERVICE - ppp_error_t ret = ppp_at_get_network_signal_info(&signal_info); - #else - ppp_error_t ret = PPP_ERR_OK; - #endif - if (ret != PPP_ERR_OK) { - printf("获取信号质量信息失败: %d\n", ret); - // 显示错误信息 - if (g_ppp_status_labels[6] != nullptr) { - g_ppp_status_labels[6]->SetText("信号质量获取失败"); + // 清理主视图 + if (scrollview_ != nullptr) { + RootView* rootView = RootView::GetInstance(); + if (rootView && scrollview_->GetParent() == rootView) { + rootView->Remove(scrollview_); + } + delete scrollview_; + scrollview_ = nullptr; } - return; - } - - // 使用malloc动态分配,避免栈溢出 - char* buffer = (char*)malloc(200); - if (buffer == NULL) { - printf("ERROR: Failed to allocate buffer for signal quality display\n"); - return; + + viewInitStatus_ = false; } - - if (!signal_info.valid) { - printf("信号质量信息无效\n"); - if (g_ppp_status_labels[4] != nullptr) { - g_ppp_status_labels[4]->SetText("信号质量信息无效"); - } - free(buffer); - return; + + void PPPTestView::PreLoad() + { + printf("PPPTestView::PreLoad\n"); + InitView(); } - - 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 = "极差"; + + void PPPTestView::StartPPPTest() + { + if (isTestActive_) { + printf("PPP test already active\n"); + return; } + + printf("Starting PPP test view\n"); - // 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 = "极差"; + RootView* rootView = RootView::GetInstance(); + if (rootView == nullptr) { + printf("ERROR: RootView not initialized\n"); + return; } - // 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++; + // 保存当前显示的view + savedCurrentView_ = rootView->GetChildrenHead(); + if (savedCurrentView_ != nullptr && savedCurrentView_ != scrollview_) { + rootView->Remove(savedCurrentView_); + printf("Saved and removed current view for later restore\n"); } - // 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++; + // 创建PPP测试视图 + if (testView_ == nullptr) { + testView_ = new UIScrollView(); + if (testView_ == nullptr) { + printf("ERROR: Failed to create PPP test view\n"); + return; + } } - // 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++; - } + SetupScrollView(); + CreateLabels(); - // 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++; + // 添加到根视图 + rootView->Add(testView_); + rootView->Invalidate(); + + isTestActive_ = true; + printf("PPP test started\n"); + } + + void PPPTestView::StopPPPTest() + { + if (!isTestActive_) { + printf("PPP test not active\n"); + return; } + + printf("Stopping PPP test view\n"); - // 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信号较差"; + RootView* rootView = RootView::GetInstance(); + if (rootView != nullptr) { + // 删除PPP测试view + if (testView_ != nullptr) { + rootView->Remove(testView_); + DestroyLabels(); + delete testView_; + testView_ = nullptr; + printf("PPP test view removed\n"); } - 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); + // 恢复原来的view + if (savedCurrentView_ != nullptr) { + printf("Attempting to restore view at address: %p\n", savedCurrentView_); + + if (savedCurrentView_->GetParent() == nullptr) { + rootView->Add(savedCurrentView_); + rootView->Invalidate(); + printf("Original view restored successfully\n"); + } else { + printf("Warning: Original view still has parent, cannot restore\n"); + } + savedCurrentView_ = nullptr; + } else { + printf("No original view to restore\n"); } } - - printf("LTE参数无效: RSRQ=%d, RSRP=%d\n", signal_info.rsrq, signal_info.rsrp); - } - - printf("信号质量显示更新完成\n"); - - // 释放动态分配的内存 - free(buffer); -} -// 全局变量,避免栈溢出 -static int g_consecutive_failures = 0; + isTestActive_ = false; + currentStatus_ = PPPTestStatus::Idle; + } -// 全局刷新标志,避免在定时器回调中直接操作UI -static volatile bool g_need_refresh = false; + void PPPTestView::RefreshPPPData() + { + if (!isTestActive_) { + printf("PPP test not active, cannot refresh\n"); + return; + } -// 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("Refreshing PPP test data display\n"); + UpdateDisplay(); } - - printf("PPP UI刷新开始 - GraphicEvent安全机制\n"); - - // 使用malloc为buffer分配内存,避免栈溢出 - char* buffer = (char*)malloc(512); - if (buffer == nullptr) { - printf("ERROR: malloc失败,跳过此次刷新\n"); - return; + + void PPPTestView::SetupScrollView() + { + if (testView_ == nullptr) return; + + // 设置PPP测试视图 - 适配360x360圆形LCD + testView_->SetPosition(0, 0, 360, 360); + testView_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + testView_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); + testView_->SetStyle(STYLE_BORDER_RADIUS, 0); + testView_->SetTouchable(true); + testView_->SetDraggable(true); + testView_->SetVisible(true); + testView_->SetYScrollBarVisible(true); + testView_->SetScrollBlankSize(30); + + // 不需要事件监听器 } - - // 安全地更新运行状态显示 - update_ppp_runtime_status_display(); - - // 尝试获取信号质量,但增加容错机制 - #if SUPPORT_PPP_SERVICE - errcode_t ret = ppp_get_network_signal_info(); - #else - errcode_t ret = ERRCODE_SUCC; - #endif - 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); + + void PPPTestView::CreateLabels() + { + if (testView_ == nullptr) return; - // 如果连续失败超过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("(定时器冲突)"); + // 创建标题标签 + PPPLabelConfig_t titleConfig = { + .left = 114, + .top = 10, + .width = 132, + .height = 28, + .textColor = TITLE_COLOR, + .fontSize = 20, + .text = "PPP测试" + }; + + titleLabel_ = new UILabel(); + if (titleLabel_) { + titleLabel_->SetPosition(titleConfig.left, titleConfig.top, + titleConfig.width, titleConfig.height); + titleLabel_->SetText(titleConfig.text); + titleLabel_->SetFont("SourceHanSansSC-Regular.otf", titleConfig.fontSize); + titleLabel_->SetStyle(STYLE_TEXT_COLOR, titleConfig.textColor); + titleLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + testView_->Add(titleLabel_); + } + + // 创建状态标签 + const char* labelTexts[] = { + "状态: 初始化中...", + "电源: 未知", + "网络: 未知", + "信号: 未知", + "SIM: 未知", + "网络类型: 未知", + "运营商: 未知", + "IMEI: 未知", + "ICCID: 未知", + "调制解调器: 未知", + "信号质量: 未知" + }; + + for (int i = 0; i < MAX_STATUS_LABELS - 1 && i < 11; i++) { + statusLabels_[i] = new UILabel(); + if (statusLabels_[i]) { + int yPos = 45 + (i * 32); + statusLabels_[i]->SetPosition(15, yPos, LABEL_WIDTH, LABEL_HEIGHT); + statusLabels_[i]->SetText(labelTexts[i]); + statusLabels_[i]->SetFont("SourceHanSansSC-Regular.otf", 16); + statusLabels_[i]->SetStyle(STYLE_TEXT_COLOR, TEXT_COLOR); + statusLabels_[i]->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT); + testView_->Add(statusLabels_[i]); } } } - - // 释放临时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; + void PPPTestView::DestroyLabels() + { + if (titleLabel_) { + delete titleLabel_; + titleLabel_ = nullptr; + } + + for (int i = 0; i < MAX_STATUS_LABELS; i++) { + if (statusLabels_[i]) { + delete statusLabels_[i]; + statusLabels_[i] = nullptr; + } } } - - // 启动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"); + void PPPTestView::UpdateTestStatus(PPPTestStatus status) + { + currentStatus_ = status; + + if (!isTestActive_ || statusLabels_[0] == nullptr) return; + + const char* statusText = ""; + switch (status) { + case PPPTestStatus::Idle: + statusText = "状态: 空闲"; + break; + case PPPTestStatus::Initializing: + statusText = "状态: 初始化中..."; + break; + case PPPTestStatus::Testing: + statusText = "状态: 测试中"; + break; + case PPPTestStatus::Refreshing: + statusText = "状态: 刷新数据中..."; + break; + case PPPTestStatus::Error: + statusText = "状态: 错误"; + break; + } + + statusLabels_[0]->SetText(statusText); + RootView::GetInstance()->Invalidate(); } -} -// 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; + void PPPTestView::UpdateNetworkInfo() + { + if (!isTestActive_ || !PPPTestModel::GetInstance()) return; + + const PPPStatusInfo& info = PPPTestModel::GetInstance()->GetStatusInfo(); + if (!info.isValid) return; - // 简化状态显示,避免在回调中进行复杂UI操作 - if (g_ppp_status_labels[1] != nullptr) { - g_ppp_status_labels[1]->SetText("PPP初始化失败"); + char buffer[256]; + + // 更新电源状态 + if (statusLabels_[1]) { + snprintf(buffer, sizeof(buffer), "电源: %s", info.powerStatus ? "开启" : "关闭"); + statusLabels_[1]->SetText(buffer); } - 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); + + // 更新网络状态 + if (statusLabels_[2]) { + snprintf(buffer, sizeof(buffer), "网络: %s", info.networkStatus ? "已连接" : "未连接"); + statusLabels_[2]->SetText(buffer); } - // 启动5秒刷新定时器(重试成功) - start_ppp_refresh_timer(); + // 更新信号强度 + if (statusLabels_[3]) { + snprintf(buffer, sizeof(buffer), "信号: %d", info.signalStrength); + statusLabels_[3]->SetText(buffer); + } - // 设置刷新标志,让主线程安全处理UI更新 - g_need_refresh = true; - } else { - printf("PPP环境初始化失败 (重试第%d次): %d\n", g_ppp_init_retry_count, init_ret); + // 更新SIM状态 + if (statusLabels_[4]) { + const char* simStatus = PPPTestModel::GetInstance()->GetSimStatusName(info.simStatus); + snprintf(buffer, sizeof(buffer), "SIM: %s", simStatus); + statusLabels_[4]->SetText(buffer); + } - // 重新启动定时器,等待下次重试 - if (g_ppp_init_timer != NULL) { - osTimerStart(g_ppp_init_timer, PPP_INIT_TIMEOUT_MS); + // 更新网络类型 + if (statusLabels_[5]) { + const char* networkType = PPPTestModel::GetInstance()->GetNetworkTypeName(info.networkType); + snprintf(buffer, sizeof(buffer), "网络类型: %s", networkType); + statusLabels_[5]->SetText(buffer); } + + // 更新运营商 + if (statusLabels_[6]) { + snprintf(buffer, sizeof(buffer), "运营商: %s", info.operatorName[0] ? info.operatorName : "未知"); + statusLabels_[6]->SetText(buffer); + } + + RootView::GetInstance()->Invalidate(); } -} -// 启动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; + void PPPTestView::UpdateSignalInfo() + { + if (!isTestActive_ || !PPPTestModel::GetInstance()) return; + + const PPPSignalInfo& info = PPPTestModel::GetInstance()->GetSignalInfo(); + if (!info.isValid) return; + + char buffer[256]; + + // 更新信号质量 + if (statusLabels_[10]) { + if (info.rsrq != -1 && info.rsrp != -1) { + const char* levelName = PPPTestModel::GetInstance()->GetSignalLevelName(info.level); + snprintf(buffer, sizeof(buffer), "信号质量: RSRQ=%d RSRP=%d (%s)", + info.rsrq, info.rsrp, levelName); + } else { + snprintf(buffer, sizeof(buffer), "信号质量: 基本信号=%d", info.rxlev); + } + statusLabels_[10]->SetText(buffer); } + + RootView::GetInstance()->Invalidate(); } - - // 开始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); + + void PPPTestView::UpdateModemInfo() + { + if (!isTestActive_ || !PPPTestModel::GetInstance()) return; + + const PPPStatusInfo& info = PPPTestModel::GetInstance()->GetStatusInfo(); + if (!info.isValid) return; - // 更新状态显示 - if (g_ppp_status_labels[1] != nullptr) { - g_ppp_status_labels[1]->SetText("PPP初始化失败,5秒后重试..."); + char buffer[256]; + + // 更新IMEI + if (statusLabels_[7]) { + snprintf(buffer, sizeof(buffer), "IMEI: %s", info.imei[0] ? info.imei : "未知"); + statusLabels_[7]->SetText(buffer); + } + + // 更新ICCID + if (statusLabels_[8]) { + snprintf(buffer, sizeof(buffer), "ICCID: %s", info.iccid[0] ? info.iccid : "未知"); + statusLabels_[8]->SetText(buffer); } - // 启动定时器 - osTimerStart(g_ppp_init_timer, PPP_INIT_TIMEOUT_MS); + // 更新调制解调器版本 + if (statusLabels_[9]) { + snprintf(buffer, sizeof(buffer), "调制解调器: %s", + info.modemVersion[0] ? info.modemVersion : "未知"); + statusLabels_[9]->SetText(buffer); + } + + RootView::GetInstance()->Invalidate(); + } + + void PPPTestView::ShowInitProgress(int progress) + { + if (!isTestActive_ || statusLabels_[0] == nullptr) return; + + char buffer[64]; + snprintf(buffer, sizeof(buffer), "状态: 初始化中... %d%%", progress); + statusLabels_[0]->SetText(buffer); + RootView::GetInstance()->Invalidate(); + } + + void PPPTestView::ShowErrorMessage(const char* error) + { + if (!isTestActive_ || statusLabels_[0] == nullptr) return; + + char buffer[128]; + snprintf(buffer, sizeof(buffer), "状态: 错误 - %s", error ? error : "未知错误"); + statusLabels_[0]->SetText(buffer); + RootView::GetInstance()->Invalidate(); } -} -extern "C" { + void PPPTestView::UpdateDisplay() + { + UpdateNetworkInfo(); + UpdateSignalInfo(); + UpdateModemInfo(); + } + + UILabel* PPPTestView::GetStatusLabel(int index) + { + if (index >= 0 && index < MAX_STATUS_LABELS) { + return statusLabels_[index]; + } + return nullptr; + } + +} // namespace OHOS + +// 保持向后兼容的C接口 +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif /* __cplusplus */ +#endif /* __cplusplus */ /** * @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); + OHOS::PPPTestPresenter* presenter = OHOS::PPPTestPresenter::GetInstance(); + if (presenter) { + presenter->StartPPPTest(); } else { - printf("ERROR: PPP标题标签创建失败\n"); + printf("ERROR: PPPTestPresenter not initialized\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(); } /** @@ -729,79 +504,29 @@ void start_ppp_test_view(void) */ 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"); + OHOS::PPPTestPresenter* presenter = OHOS::PPPTestPresenter::GetInstance(); + if (presenter) { + presenter->StopPPPTest(); } else { - printf("Warning: Original view still has parent, cannot restore\n"); - } - g_ppp_saved_view = nullptr; - } else { - printf("No original view to restore\n"); - } + printf("ERROR: PPPTestPresenter not initialized\n"); } - - // 重置PPP状态变量 - g_ppp_init_completed = false; - g_ppp_init_in_progress = false; - g_ppp_init_retry_count = 0; } /** - * @brief 刷新PPP测试数据 - 安全版本,检查定时器刷新请求 + * @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; + OHOS::PPPTestPresenter* presenter = OHOS::PPPTestPresenter::GetInstance(); + if (presenter) { + presenter->RefreshPPPData(); + } else { + printf("ERROR: PPPTestPresenter not initialized\n"); } - - // 使用GraphicEvent进行安全的UI刷新,避免栈溢出 - // UIKit版本: 参数为 回调函数, 用户数据(NULL) - PostGraphicEvent(ppp_refresh_ui_callback, NULL); - - printf("PPP手动刷新请求已发送到GraphicEvent队列\n"); } -} // extern "C" +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestView.h b/code/sdk/zhihui/leiniao/factory_test/PPPTestView.h new file mode 100644 index 000000000..bb5df52a0 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestView.h @@ -0,0 +1,93 @@ +#ifndef _PPP_TEST_VIEW_H +#define _PPP_TEST_VIEW_H + +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_button.h" +#include "components/ui_label_button_ext.h" +#include "wearable_log.h" +#include "ohos_types.h" +#include "PPPTestPresenter.h" + +namespace OHOS +{ + // PPP测试状态枚举 + enum class PPPTestStatus + { + Idle, // 空闲状态 + Initializing, // 初始化中 + Testing, // 测试中 + Refreshing, // 刷新数据中 + Error // 错误状态 + }; + + // PPP信号质量等级 + enum class PPPSignalLevel + { + Excellent, // 优秀 + Good, // 良好 + Fair, // 一般 + Poor, // 差 + Unknown // 未知 + }; + + class PPPTestPresenter; + class PPPTestView : public View + { + public: + PPPTestView(); + virtual ~PPPTestView(); + static PPPTestView *GetInstance(void); + + void OnStart() override; + void InitView(); + void DeInit(); + void PreLoad(void); + + // PPP测试相关方法 + void StartPPPTest(); + void StopPPPTest(); + void RefreshPPPData(); + + // UI更新方法 + void UpdateTestStatus(PPPTestStatus status); + void UpdateNetworkInfo(); + void UpdateSignalInfo(); + void UpdateModemInfo(); + void ShowInitProgress(int progress); + void ShowErrorMessage(const char* error); + + // 获取UI组件 + UIScrollView* GetTestView() { return testView_; } + UILabel* GetStatusLabel(int index); + + private: + PPPTestView(PPPTestView &&) = delete; + PPPTestView &operator=(PPPTestView &&) = delete; + + // UI组件相关 + void CreateLabels(); + void DestroyLabels(); + void SetupScrollView(); + void UpdateDisplay(); + + UIScrollView *scrollview_ = nullptr; + UIScrollView *testView_ = nullptr; + UIView *savedCurrentView_ = nullptr; + UILabel *titleLabel_ = nullptr; + UILabel *statusLabels_[12] = {nullptr}; // 状态标签数组 + + bool viewInitStatus_{false}; + bool isTestActive_{false}; + PPPTestStatus currentStatus_{PPPTestStatus::Idle}; + + static const int MAX_STATUS_LABELS = 12; + static const int LABEL_HEIGHT = 28; + static const int LABEL_WIDTH = 330; + }; +} // namespace OHOS + +#endif // _PPP_TEST_VIEW_H diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h b/code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h index 8065e8aa6..75746f712 100644 --- a/code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-09-19 18:23:09 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-09-22 19:53:08 + * @FilePath: /FD230/code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ /* * @Author: penglei 1624952103@qq.com * @Date: 2024-06-07 11:18:25 diff --git a/code/sdk/zhihui/utils/custom_utils.c b/code/sdk/zhihui/utils/custom_utils.c index 99ed53344..ed55aebdd 100644 --- a/code/sdk/zhihui/utils/custom_utils.c +++ b/code/sdk/zhihui/utils/custom_utils.c @@ -660,7 +660,7 @@ void startup_post_init_task(void) PRINT("startup_post_init_task !\r\n"); #ifdef BOARD_LEINIAO - uapi_get_file_data(FACTORY_TEST_MODE_PATH,&factory_test_flag,1); + // uapi_get_file_data(FACTORY_TEST_MODE_PATH,&factory_test_flag,1); char path[40] = {0}; uint16_t delay_time = 1500; @@ -4567,6 +4567,11 @@ void custom_set_factory_test_flag(uint8_t flag) uapi_save_file_data(FACTORY_TEST_MODE_PATH,&flag,1,"w"); } +void custom_check_factory_test_flag(void) +{ + uapi_get_file_data(FACTORY_TEST_MODE_PATH,&factory_test_flag,1); +} + uint8_t custom_get_factory_test_flag(void) { return factory_test_flag; diff --git a/code/sdk/zhihui/utils/custom_utils.h b/code/sdk/zhihui/utils/custom_utils.h index 08d6558c9..e74aa6065 100644 --- a/code/sdk/zhihui/utils/custom_utils.h +++ b/code/sdk/zhihui/utils/custom_utils.h @@ -493,6 +493,7 @@ errcode_t uapi_create_osThread_custom_with_args(app_task_definition_ext_t *task_ void custom_set_factory_test_flag(uint8_t flag); uint8_t custom_get_factory_test_flag(void); +void custom_check_factory_test_flag(void); #include "custom_utilscpp.h" -- 2.17.1