From 07c73261588d4b6409447fe6c9dbbb68188c81fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BD=AD=E7=A3=8A?= <1624952103@qq.com> Date: Fri, 19 Sep 2025 08:36:08 +0000 Subject: [PATCH] Merge #2318 into sdk650pathc0423 from refs/changes/2318/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 彭磊 * refs/changes/2318/head: (2 commits squashed) - 增加ppp测试UI,完善AT产测流程与功能 - Merge branch 'sdk650pathc0423' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650pathc0423 Signed-off-by: aliyun6865282430 <1624952103@qq.com> Merged-by: aliyun6865282430 <1624952103@qq.com> CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/2318 --- .../nativeui/include/lcdtest/PPPTestView.h | 37 + .../thunderbird/src/ThunderBirdPresenter.cpp | 13 +- .../config/target_config/brandy/config.py | 1 + .../sample/wrapper/audio_capture_wrapper.cpp | 15 +- .../sample/wrapper/audio_capture_wrapper.h | 10 + code/sdk/zhihui/leiniao/CMakeLists.txt | 3 +- .../leiniao/factory_test/CMakeLists.txt | 67 ++ .../leiniao/factory_test}/LcdTestView.cpp | 0 .../leiniao/factory_test/LcdTestViewC.h | 28 + .../leiniao/factory_test/PPPTestView.cpp | 796 ++++++++++++++++++ .../leiniao/factory_test/PPPTestViewC.h | 28 + .../services/gnss/src/gnss_http_server.c | 26 +- code/sdk/zhihui/utils/custom_utils.c | 92 +- code/sdk/zhihui/utils/custom_utils.h | 4 + code/sdk/zhihui/utils/custom_utils_at_cmd.c | 200 ++++- 15 files changed, 1258 insertions(+), 62 deletions(-) create mode 100644 code/sdk/application/wearable/ln/nativeapp/nativeui/include/lcdtest/PPPTestView.h create mode 100644 code/sdk/zhihui/leiniao/factory_test/CMakeLists.txt rename code/sdk/{application/wearable/ln/nativeapp/nativeui/lcdtest/src => zhihui/leiniao/factory_test}/LcdTestView.cpp (100%) create mode 100644 code/sdk/zhihui/leiniao/factory_test/LcdTestViewC.h create mode 100644 code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp create mode 100644 code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/include/lcdtest/PPPTestView.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/include/lcdtest/PPPTestView.h new file mode 100644 index 000000000..05faad76b --- /dev/null +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/include/lcdtest/PPPTestView.h @@ -0,0 +1,37 @@ +#ifndef PPP_TEST_VIEW_H +#define PPP_TEST_VIEW_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 启动PPP测试视图 + * 进入该界面后会执行以下操作: + * 1. 执行ppp_env_init初始化PPP环境 + * 2. 等待初始化完成后执行ppp_api_update_all_runtime_status + * 3. 显示所有运行状态信息(电源、网络、信号、SIM、运营商等) + * 4. 执行ppp_get_network_signal_info获取信号质量信息 + * 5. 显示RSRQ/RSRP信息及评级 + */ +void start_ppp_test_view(void); + +/** + * @brief 停止PPP测试视图 + * 清理PPP测试相关资源并恢复原界面 + */ +void stop_ppp_test_view(void); + +/** + * @brief 刷新PPP测试数据 + * 重新获取并更新显示的PPP状态和信号质量信息 + */ +void refresh_ppp_test_data(void); + +#ifdef __cplusplus +} +#endif + +#endif // PPP_TEST_VIEW_H diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp index ac3ab303b..e46e794f3 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp @@ -1,8 +1,8 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-16 14:36:45 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-18 15:19:37 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-09-19 15:30:21 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/ThunderBird/src/ThunderBirdPresenter.cpp */ #include "thunderbird/include/ThunderBirdPresenter.h" @@ -29,6 +29,10 @@ #include "wearable_log.h" #include "ln_api.h" + +#ifdef CUSTOM_UTILS +#include "custom_utils.h" +#endif namespace OHOS { static int i=0;//版本临时变量 @@ -120,7 +124,10 @@ namespace OHOS void ThunderBirdPresenter::Notify() { - +#ifdef CUSTOM_UTILS + if(custom_get_factory_test_flag()) + return; +#endif //如果在二维码界面 判断是否绑定 if(ThunderBirdMainView::GetInstance() != nullptr) { diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index e95859f5b..3459924b8 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -1334,6 +1334,7 @@ target = { # "mag_service", # "cywee_dml", #"cyweeBleService", + 'AT_factory_test', "-:alipay_soc", "-:alipay_soc_adapt", "-:alipay_service", diff --git a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp index ca7b1fb26..8c1a54be2 100644 --- a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp +++ b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.cpp @@ -71,6 +71,13 @@ const uint32_t OPUS_ENCODE_HEADER_SIZE = 8; const uint32_t OPUS_OPUSTAGS_LEN = 12; const uint32_t OPUS_SAMPLERATE = 48000; +static AudioStreamType g_streamType = AUDIO_STREAM_VOICE_ASSISTANT; + +void factory_set_recoder_streamType(void) +{ + g_streamType = AUDIO_STREAM_VOICE_RECORD; +} + typedef struct { size_t framesize; uint8_t *buffer; @@ -559,8 +566,8 @@ static int32_t ActivateAudioInterrupt(AudioSession &sessionId) } MEDIA_INFO_LOG("sessionId:%d", sessionId); g_captureInterruptListener = std::make_shared(); - // g_sample.interrupt = { AUDIO_STREAM_VOICE_RECORD, sessionId, g_captureInterruptListener }; - g_sample.interrupt = { AUDIO_STREAM_VOICE_ASSISTANT, sessionId, g_captureInterruptListener }; + g_sample.interrupt = { g_streamType, sessionId, g_captureInterruptListener }; + // g_sample.interrupt = { AUDIO_STREAM_VOICE_ASSISTANT, sessionId, g_captureInterruptListener }; if (g_amInstance.ActivateAudioInterrupt(g_sample.interrupt) == INTERRUPT_FAILED) { @@ -627,8 +634,8 @@ int32_t AudioCaptureSample(int32_t argc, const char **argv) } audioCapturerInfo.sessionID = sessionId; audioCapturerInfo.inputSource = AUDIO_MIC; - // audioCapturerInfo.streamType = AUDIO_STREAM_VOICE_RECORD; - audioCapturerInfo.streamType = AUDIO_STREAM_VOICE_ASSISTANT; + audioCapturerInfo.streamType = g_streamType; + // audioCapturerInfo.streamType = AUDIO_STREAM_VOICE_ASSISTANT; ret = AudioCaptureSetInfo(audioCapturerInfo); if (ret != 0) { MEDIA_ERR_LOG("AudioCapture set failed"); diff --git a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h index fbc42bd57..e455d259f 100644 --- a/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h +++ b/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-05-23 17:54:44 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-09-18 21:06:48 + * @FilePath: /FD230/code/sdk/middleware/services/media/foundation/sample/wrapper/audio_capture_wrapper.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ /* * Copyright (c) CompanyNameMagicTag. 2021-2021. All rights reserved. * Description: audio capture wrapper @@ -18,6 +26,8 @@ int32_t AudioCaptureSample(int32_t argc, const char *argv[]); int32_t streamingRecordAndSend_AI(int type); +void factory_set_recoder_streamType(void); + #ifdef __cplusplus }; #endif diff --git a/code/sdk/zhihui/leiniao/CMakeLists.txt b/code/sdk/zhihui/leiniao/CMakeLists.txt index 03ce15ec1..009b37b5e 100644 --- a/code/sdk/zhihui/leiniao/CMakeLists.txt +++ b/code/sdk/zhihui/leiniao/CMakeLists.txt @@ -1 +1,2 @@ -add_subdirectory_if_exist(imsl_ln) \ No newline at end of file +add_subdirectory_if_exist(imsl_ln) +add_subdirectory_if_exist(factory_test) \ No newline at end of file diff --git a/code/sdk/zhihui/leiniao/factory_test/CMakeLists.txt b/code/sdk/zhihui/leiniao/factory_test/CMakeLists.txt new file mode 100644 index 000000000..b73c1b282 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/CMakeLists.txt @@ -0,0 +1,67 @@ +#=============================================================================== +# @brief imsl_ln component cmake file +# Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. +#=============================================================================== +set(COMPONENT_NAME "AT_factory_test") + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/LcdTestView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/PPPTestView.cpp + +) + +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} +) + +set(PUBLIC_DEFINES +) + +set(PRIVATE_HEADER + ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/utils/interfaces/kits + ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits + ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/proprietary/include/components + ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/components + ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/proprietary/include + ${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 +) + + +set(PRIVATE_DEFINES + +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -std=c++11 + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + -Wno-c++11-narrowing + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +install_sdk(${CMAKE_CURRENT_SOURCE_DIR} "*") + +# 构建组件 +build_component() \ No newline at end of file diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/lcdtest/src/LcdTestView.cpp b/code/sdk/zhihui/leiniao/factory_test/LcdTestView.cpp similarity index 100% rename from code/sdk/application/wearable/ln/nativeapp/nativeui/lcdtest/src/LcdTestView.cpp rename to code/sdk/zhihui/leiniao/factory_test/LcdTestView.cpp diff --git a/code/sdk/zhihui/leiniao/factory_test/LcdTestViewC.h b/code/sdk/zhihui/leiniao/factory_test/LcdTestViewC.h new file mode 100644 index 000000000..5c4cd55f0 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/LcdTestViewC.h @@ -0,0 +1,28 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-06-07 11:18:25 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-09-19 10:08:07 + * @FilePath: /FD230/code/sdk/application/wearable/fd230/nativeapp/nativeui/producttest/include/testLCDC.h + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ +#ifndef LCD_TEST_VIEW_C_H +#define LCD_TEST_VIEW_C_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif + void start_lcd_test_view(void); + void stop_lcd_test_view(void); + void set_lcd_test_color(int color); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp b/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp new file mode 100644 index 000000000..c452f9965 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp @@ -0,0 +1,796 @@ +#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 +#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); + +#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" diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h b/code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h new file mode 100644 index 000000000..8065e8aa6 --- /dev/null +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestViewC.h @@ -0,0 +1,28 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-06-07 11:18:25 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-09-19 10:09:05 + * @FilePath: /FD230/code/sdk/application/wearable/fd230/nativeapp/nativeui/producttest/include/testLCDC.h + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ +#ifndef PPP_TEST_VIEW_C_H +#define PPP_TEST_VIEW_C_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif + void start_ppp_test_view(void); + void stop_ppp_test_view(void); + void refresh_ppp_test_data(void); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif diff --git a/code/sdk/zhihui/services/gnss/src/gnss_http_server.c b/code/sdk/zhihui/services/gnss/src/gnss_http_server.c index 6efcbd393..4b7b4b10d 100644 --- a/code/sdk/zhihui/services/gnss/src/gnss_http_server.c +++ b/code/sdk/zhihui/services/gnss/src/gnss_http_server.c @@ -149,14 +149,16 @@ static void agnss_download_result_handler(const char *filename, HTTPC_RESULT res if (result == HTTP_SUCCESS && response_code == 200) { // 更新状态为下载中 g_download_status = 1; // 开始下载进度 10% - printf("Status: 1 (开始处理数据 10%%)\n"); + printf("Status: 1 (开始处理数据 10%%) - 异步发送到处理队列\n"); - // 处理接收到的数据 + // 异步发送有效数据到接收任务进行处理 if (data_len > 0 && response_data) { - agnss_accumulate_data(response_data, data_len); + printf("发送 %d 字节数据到异步处理队列\n", data_len); + do_gnss_http_server_recv_data(GNSS_HTTP_SERVICE_CMD_AGNSS_RECV, response_data, data_len); } // 发送完成信号到接收任务 + printf("发送数据接收完成信号\n"); do_gnss_http_server_recv_data(GNSS_HTTP_SERVICE_CMD_AGNSS_RECV, NULL, 0); } else { // HTTP请求失败,设置失败状态 @@ -603,7 +605,7 @@ static int download_agnss_file_with_url(const char *filename, const char *downlo return 0; } -// AGNSS数据处理函数 +// AGNSS数据异步累积函数 - 优化为高性能非阻塞处理 static void agnss_accumulate_data(const char *data, size_t len) { // 验证输入数据 @@ -612,6 +614,8 @@ static void agnss_accumulate_data(const char *data, size_t len) return; } + printf("异步累积数据: %zu bytes (当前缓冲区: %zu bytes)\n", len, g_agnss_response_size); + // 检查数据是否以JSON开始(简单验证) if (g_agnss_response_size == 0) { // 第一个数据包,检查是否以 { 开始 @@ -1730,13 +1734,19 @@ static void gnss_http_server_recv_task(void const *arg) { if (mail.data == NULL) { // 数据接收完成,处理完整的响应 - printf("AGNSS data reception completed, processing response...\n"); + printf("=== AGNSS数据接收完成,开始异步处理完整响应 ===\n"); agnss_process_complete_response(); } else { - // 接收数据片段 - printf("AGNSS data received via queue: %d bytes\n", mail.len); + // 异步处理接收到的数据片段 + printf("=== 异步处理AGNSS数据片段: %d bytes ===\n", mail.len); + + // 快速累积数据,避免阻塞接收队列 agnss_accumulate_data(mail.data, mail.len); - free(mail.data); // 释放数据内存 + + // 释放消息队列中的数据内存 + free(mail.data); + + printf("数据片段处理完成,继续等待更多数据或完成信号\n"); } } } diff --git a/code/sdk/zhihui/utils/custom_utils.c b/code/sdk/zhihui/utils/custom_utils.c index 06e26aa2f..f780b892a 100644 --- a/code/sdk/zhihui/utils/custom_utils.c +++ b/code/sdk/zhihui/utils/custom_utils.c @@ -151,6 +151,15 @@ extern time_t __tm_to_secs(const struct tm *tm); #include #include "audio_service.h" #include "lcd_common.h" +#include "input_app.h" + + +#ifdef BOARD_LEINIAO +#include "PPPTestViewC.h" +#include "audio_capture_wrapper.h" +#endif + +static uint8_t factory_test_flag = 0; errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg) { @@ -609,6 +618,38 @@ void a5133_demo_msg_change_callback(void) a5133_demo_msg_send_index = 0; } +#ifdef BOARD_LEINIAO + +static uint8_t k2_flag = 0; +static uint8_t k3_flag = 0; + +static void key2_enter_ppp_testView_callback(void) +{ + printf("111 key2_enter_ppp_testView_callback\n"); + k2_flag = 1; + if(k3_flag && k2_flag) + { + printf("222 key2_enter_ppp_testView_callback\n"); + start_ppp_test_view(); + k2_flag = 0; + k3_flag = 0; + } +} + +static void key3_enter_ppp_testView_callback(void) +{ + printf("111 key3_enter_ppp_testView_callback\n"); + k3_flag = 1; + if(k3_flag && k2_flag) + { + printf("222 key3_enter_ppp_testView_callback\n"); + start_ppp_test_view(); + k2_flag = 0; + k3_flag = 0; + } +} + +#endif void startup_post_init_task(void) { @@ -618,7 +659,21 @@ void startup_post_init_task(void) PRINT("startup_post_init_task !\r\n"); #ifdef BOARD_LEINIAO - custom_play_audio("/user/music/PowerOn.mp3",100); + + uapi_get_file_data(FACTORY_TEST_MODE_PATH,&factory_test_flag,1); + + char path[40] = {0}; + + if(factory_test_flag) + { + factory_set_recoder_streamType(); + snprintf(path, 40, "/user/music/FactoryMode.mp3"); + } + + else + snprintf(path, 40, "/user/music/PowerOn.mp3"); + + custom_play_audio(path,100); LOS_Msleep(1500); custom_stop_play_audio(); #endif @@ -715,7 +770,8 @@ if ( cm_poweron_cat1_on_bootup_flag() ) #ifdef BOARD_LEINIAO extern int ppp_env_init(void); - ppp_env_init(); + if(!custom_get_factory_test_flag()) + ppp_env_init(); #endif #endif @@ -729,6 +785,23 @@ if ( cm_poweron_cat1_on_bootup_flag() ) send_a5133_cmd_msg(A5133_SERVICE_CMD_TYPE_RUN_SLAVE); #endif +#ifdef BOARD_LEINIAO + + // uapi_button_unregister_event_cb(BUTTON2_LONGPRESS_5S_OVER); + // uapi_button_unregister_event_cb(BUTTON3_LONGPRESS_5S_OVER); + + ret = uapi_button_register_event_cb(key2_enter_ppp_testView_callback, BUTTON2_LONGPRESS_5S_OVER); + if (ret != ERRCODE_SUCC) + printf("key2_enter_ppp_testView_callback error, ret = %d \n", ret); + else + printf("key2_enter_ppp_testView_callback succed\n"); + + ret = uapi_button_register_event_cb(key3_enter_ppp_testView_callback, BUTTON3_LONGPRESS_5S_OVER); + if (ret != ERRCODE_SUCC) + printf("key3_enter_ppp_testView_callback error, ret = %d\n", ret); + else + printf("key3_enter_ppp_testView_callback succed\n"); +#endif } void startup_post_init(void) @@ -2929,7 +3002,11 @@ void uapi_cywee_time_sync(void) void uapi_cywee_get_id(uint8_t *id) { +#ifdef BOARD_LEINIAO + custom_i2c_read_regs(0x62,0x01,1,id,1,I2C_BUS_2); +#else custom_i2c_read_regs(0x19,0x0FU,1,id,1,I2C_BUS_2); +#endif } @@ -4439,3 +4516,14 @@ void uapi_lcd_backlight_on(uint8_t brightness) printf("Brightness: %u%% → Fall Edge: %u → LED Current: %.1fmA\n", brightness, fall_edge_cnt, 20.0 - (2.5 * fall_edge_cnt)); } + + +void custom_set_factory_test_flag(uint8_t flag) +{ + uapi_save_file_data(FACTORY_TEST_MODE_PATH,&flag,1,"w"); +} + +uint8_t custom_get_factory_test_flag(void) +{ + return factory_test_flag; +} \ No newline at end of file diff --git a/code/sdk/zhihui/utils/custom_utils.h b/code/sdk/zhihui/utils/custom_utils.h index 7936ef9ab..3672dff61 100644 --- a/code/sdk/zhihui/utils/custom_utils.h +++ b/code/sdk/zhihui/utils/custom_utils.h @@ -25,6 +25,8 @@ extern "C" { #define EXC_TAR_PATH "/user/tar" #endif +#define FACTORY_TEST_MODE_PATH "/user/system/fac.bin" + #define TASK_PRIORITY_APP (osPriority_t)(17) #define TASK_PRIORITY_LOG (osPriority_t)(18) #define TASK_PRIORITY_CMD (osPriority_t)(17) @@ -489,6 +491,8 @@ typedef struct { */ errcode_t uapi_create_osThread_custom_with_args(app_task_definition_ext_t *task_cfg); +void custom_set_factory_test_flag(uint8_t flag); +uint8_t custom_get_factory_test_flag(void); #include "custom_utilscpp.h" diff --git a/code/sdk/zhihui/utils/custom_utils_at_cmd.c b/code/sdk/zhihui/utils/custom_utils_at_cmd.c index 0f3891720..edfbc3ec1 100644 --- a/code/sdk/zhihui/utils/custom_utils_at_cmd.c +++ b/code/sdk/zhihui/utils/custom_utils_at_cmd.c @@ -33,6 +33,10 @@ #include "battery_service.h" #endif +#ifdef BOARD_LEINIAO +#include "PPPTestViewC.h" +#include "LcdTestViewC.h" +#endif // #include "msg_center_customerC.h" #ifdef SUPPORT_A5133_SERVICE @@ -150,6 +154,11 @@ static uint32_t lcd_test_control(uint8_t *para, uint32_t paraLen, char *strCommo 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"); @@ -159,57 +168,128 @@ static uint32_t lcd_test_control(uint8_t *para, uint32_t paraLen, char *strCommo 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; } @@ -394,10 +474,10 @@ static uint32_t custom_battery_getpower(uint8_t *para, uint32_t paraLen, char *s { 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; @@ -568,7 +648,7 @@ static uint32_t custom_get_cywee_id(uint8_t *para, uint32_t paraLen, char *strCo 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; } @@ -1699,6 +1779,36 @@ static uint32_t custom_audio_test(uint8_t *para, uint32_t paraLen, char *strComm 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 *)" " }, @@ -1794,12 +1904,14 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { // { (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 *)" " }, }; -- 2.17.1