From f29093380898c12901e0f4c5b65a22bbbbfe2eca Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Tue, 14 Oct 2025 20:31:33 +0800 Subject: [PATCH] =?utf8?q?=E9=BB=98=E8=AE=A4ppp=E6=B3=A2=E7=89=B9=E7=8E=87?= =?utf8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA2000000?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/zhihui/config/include/ConfigModel.h | 2 +- code/sdk/zhihui/ppp/example/ppp_at_cmd.c | 2 +- code/sdk/zhihui/ppp/include/ppp_api.h | 7 ++ code/sdk/zhihui/ppp/src/ppp_api.c | 80 ++++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/code/sdk/zhihui/config/include/ConfigModel.h b/code/sdk/zhihui/config/include/ConfigModel.h index 6f88f31e1..13bcfbc41 100644 --- a/code/sdk/zhihui/config/include/ConfigModel.h +++ b/code/sdk/zhihui/config/include/ConfigModel.h @@ -321,7 +321,7 @@ namespace OHOS {ConfigDataType::DATATYPE_STRING, "cat1_imei", "pls poweron 4G first" },//CONFIGMODEL_ITEM_CAT1_IMEI, {ConfigDataType::DATATYPE_STRING, "cat1_modemver", "pls poweron 4G first" },//CONFIGMODEL_ITEM_CAT1_MODEMVER, {ConfigDataType::DATATYPE_STRING, "cat1_pyver", "pls poweron 4G first" },//CONFIGMODEL_ITEM_CAT1_PYVER, - {ConfigDataType::DATATYPE_INT, "ppp_baudrate", "1000000" },//CONFIGMODEL_ITEM_PPP_BAUDRATE, + {ConfigDataType::DATATYPE_INT, "ppp_baudrate", "2000000" },//CONFIGMODEL_ITEM_PPP_BAUDRATE, {ConfigDataType::DATATYPE_INT, "language_id", "0" },//CONFIGMODEL_ITEM_LANGUAGE_ID, //默认选择中文 {ConfigDataType::DATATYPE_STRING, "language_code", "zh" },//CONFIGMODEL_ITEM_LANGUAGE_CODE, //默认没有选择语言 {ConfigDataType::DATATYPE_INT, "timezone", "32" },//CONFIGMODEL_ITEM_TIMEZONE, //单位刻钟 默认+8 小时 = 4*8 = 32 刻钟 diff --git a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c index 45bc06fc1..50f867d49 100644 --- a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c +++ b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c @@ -2464,7 +2464,7 @@ static errcode_t at_ppp_set_config_baudrate(uint8_t *para, uint32_t paraLen, cha ppp_print_info("PPP SET BAUDRATE: Successfully set PPP baudrate from %d to %d in config model\n", current_baudrate, baudrate); ppp_print_info("PPP SET BAUDRATE: Note: This change will take effect after PPP module restart\n"); - errcode_t rett = ppp_at_set_baudrate(baudrate); + errcode_t rett = ppp_api_set_baudrate_in_all_mode(baudrate); ppp_print_info("PPP SET BAUDRATE: Successfully set PPP baudrate to %d, ret: %d\n ", baudrate,rett); return ERRCODE_SUCC; } diff --git a/code/sdk/zhihui/ppp/include/ppp_api.h b/code/sdk/zhihui/ppp/include/ppp_api.h index 69eee3620..c70a86fd5 100644 --- a/code/sdk/zhihui/ppp/include/ppp_api.h +++ b/code/sdk/zhihui/ppp/include/ppp_api.h @@ -62,6 +62,13 @@ errcode_t ppp_ppp_mode_pause(void); */ errcode_t ppp_ppp_mode_resume(void); +/** + * @brief 设置PPP波特率 + * @param baudrate 波特率 + * @return 错误码 + */ +errcode_t ppp_api_set_baudrate_in_all_mode(uint32_t baudrate); + /* PPP数据接收线程函数已移至ppp_lwip_thread.c */ /** diff --git a/code/sdk/zhihui/ppp/src/ppp_api.c b/code/sdk/zhihui/ppp/src/ppp_api.c index c5cdd1e14..e5a4b8ca7 100644 --- a/code/sdk/zhihui/ppp/src/ppp_api.c +++ b/code/sdk/zhihui/ppp/src/ppp_api.c @@ -1904,6 +1904,86 @@ errcode_t ppp_api_get_default_netif(char* netif_name, uint32_t buffer_size) return ERRCODE_SUCC; } +errcode_t ppp_api_set_baudrate_in_all_mode(uint32_t baudrate) +{ + errcode_t ret = ERRCODE_SUCC; + uint8_t need_resume = 0; + uint8_t need_deinit_at = 0; + + // 1. 如果在 PPP 模式,先暂停 + if(ppp_serial_get_mode() == PPP_SERIAL_MODE_PPP_DATA) { + PPP_DEBUG_INFO("In PPP mode, pausing..."); + if (ppp_ppp_mode_pause() != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to pause PPP mode"); + return ERRCODE_FAIL; + } + need_resume = 1; + + // 2. 暂停后需要初始化 AT handler 才能执行 AT 命令 + PPP_DEBUG_INFO("Initializing AT handler for command execution..."); + ppp_error_t at_ret = ppp_at_handler_init(SIO_UART_BUS, g_ppp_config.baudrate, true); + if (at_ret != PPP_ERR_OK) { + PPP_DEBUG_ERROR("Failed to initialize AT handler: %d", at_ret); + // 尝试恢复 PPP 模式 + ppp_ppp_mode_resume(); + return ERRCODE_FAIL; + } + need_deinit_at = 1; + } else { + PPP_DEBUG_INFO("Already in AT mode"); + need_resume = 0; + need_deinit_at = 0; + } + + // 3. 执行 AT 命令更新信息 + PPP_DEBUG_CRITICAL("Starting baudrate set... %u",baudrate); + if(ppp_at_set_baudrate(baudrate) != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to set baudrate"); + ret = ERRCODE_FAIL; + } + + // 4. 如果需要,去初始化 AT handler 并恢复 PPP 模式 + if (need_resume) { + // 先去初始化 AT handler + if (need_deinit_at) { + PPP_DEBUG_INFO("Deinitializing AT handler..."); + ppp_at_handler_deinit(); + } + + // 然后恢复 PPP 模式 + PPP_DEBUG_INFO("Resuming PPP mode..."); + errcode_t resume_ret = ppp_ppp_mode_resume(); + if (resume_ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to resume PPP mode: %d", resume_ret); + PPP_DEBUG_ERROR("Forcing PPP mode recovery..."); + + // 强制恢复到 PPP 模式 + ppp_serial_switch_to_ppp_mode(); + + #if PPP_USE_INTERRUPT_MODE + ppp_error_t int_ret = ppp_interrupt_enable(); + if (int_ret != PPP_ERR_OK) { + PPP_DEBUG_ERROR("Failed to enable interrupt after forced recovery: %d", int_ret); + } else { + PPP_DEBUG_INFO("PPP interrupt mode re-enabled after forced recovery"); + } + #else + ppp_error_t thread_ret = ppp_lwip_start_receive_thread(); + if (thread_ret != PPP_ERR_OK) { + PPP_DEBUG_ERROR("Failed to start receive thread after forced recovery: %d", thread_ret); + } else { + PPP_DEBUG_INFO("PPP receive thread restarted after forced recovery"); + } + #endif + + PPP_DEBUG_WARN("PPP mode forcefully recovered, but connection may be unstable"); + ret = ERRCODE_FAIL; + } + } + + return ret; +} + errcode_t ppp_api_update_netinfo_in_all_mode(void) { errcode_t ret = ERRCODE_SUCC; -- 2.17.1