From: 孙春阳 Date: Fri, 26 Sep 2025 12:04:51 +0000 (+0800) Subject: 添加 ppp 设置波特率at指令,优化tcp test 发送线程 X-Git-Tag: V1.0.9_20251128_194606_LN~312 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=4b7174cb349e643840def7a51047f822d16a7ced;p=mirrors%2FFD230.git 添加 ppp 设置波特率at指令,优化tcp test 发送线程 --- diff --git a/code/sdk/zhihui/config/include/ConfigModel.h b/code/sdk/zhihui/config/include/ConfigModel.h index 97f1749a2..abe249c6d 100644 --- a/code/sdk/zhihui/config/include/ConfigModel.h +++ b/code/sdk/zhihui/config/include/ConfigModel.h @@ -44,6 +44,7 @@ namespace OHOS CONFIGMODEL_ITEM_CAT1_IMEI, //Cat1 imei CONFIGMODEL_ITEM_CAT1_MODEMVER, //Cat1 modem version CONFIGMODEL_ITEM_CAT1_PYVER, //Cat1 Python app version + CONFIGMODEL_ITEM_PPP_BAUDRATE, //PPP 波特率 CONFIGMODEL_ITEM_LANGUAGE_ID, //语言ID int id CONFIGMODEL_ITEM_LANGUAGE_CODE, //语言Code string "zh","en" CONFIGMODEL_ITEM_TIMEZONE, //单位刻钟 默认+8 小时 = 8*4 = 32 刻钟 @@ -320,6 +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", "115200" },//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/config/include/ConfigModelC.h b/code/sdk/zhihui/config/include/ConfigModelC.h index 9f60a0155..58ae27aaf 100644 --- a/code/sdk/zhihui/config/include/ConfigModelC.h +++ b/code/sdk/zhihui/config/include/ConfigModelC.h @@ -148,6 +148,16 @@ int get_save_runtime_log_switch(void); bool cm_getisFirstTimeStart(void); + + +/* PPP 波特率 */ +void set_ppp_baudrate_from_config_model(uint32_t value); +/* PPP 波特率 */ +uint32_t get_ppp_baudrate_from_config_model(void); + + + + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/zhihui/config/src/ConfigModel.cpp b/code/sdk/zhihui/config/src/ConfigModel.cpp index e459c1bdb..a23dcf2e2 100644 --- a/code/sdk/zhihui/config/src/ConfigModel.cpp +++ b/code/sdk/zhihui/config/src/ConfigModel.cpp @@ -1635,7 +1635,7 @@ void cm_set_HFP_switch(bool value) OHOS::ConfigModel::GetInstance()->set_condigData_Bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_HFP,value); } - void cm_set_A2DP_switch(bool value) +void cm_set_A2DP_switch(bool value) { OHOS::ConfigModel::GetInstance()->set_condigData_Bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_A2DP,value); } @@ -1659,6 +1659,17 @@ int get_save_runtime_log_switch(void) { return OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SAVE_RUNTIMR_LOG_STATUS); } + +void set_ppp_baudrate_from_config_model(uint32_t value) +{ + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_PPP_BAUDRATE,value); +} + +uint32_t get_ppp_baudrate_from_config_model(void) +{ + return OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_PPP_BAUDRATE); +} + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c index 755842d1f..8442a88fd 100644 --- a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c +++ b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c @@ -17,6 +17,7 @@ #include "zhihui_tcp_test.h" #include "ppp_example.h" #include "uart.h" +#include "ConfigModelC.h" @@ -2344,6 +2345,84 @@ static errcode_t at_demo_test_stats(uint8_t *para, uint32_t paraLen, char *strCo return ERRCODE_SUCC; } +/** + * @brief AT^PPPSETBAUD - 设置PPP波特率到配置模型 + * @param para 参数: 波特率值 + * @param paraLen 参数长度 + */ +static errcode_t at_ppp_set_config_baudrate(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + if (!para || paraLen == 0) { + ppp_print_err("PPP SET BAUDRATE: Missing baudrate parameter\n"); + return ERRCODE_FAIL; + } + + 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 || argc != 1) { + ppp_print_err("PPP SET BAUDRATE: Invalid parameter format, usage: AT^PPPSETBAUD=baudrate\n"); + return ERRCODE_FAIL; + } + + uint32_t baudrate = atoi((char*)argv[0]); + + // 检查波特率是否为支持的值 + if (baudrate != 9600 && baudrate != 19200 && baudrate != 38400 && + baudrate != 57600 && baudrate != 115200 && baudrate != 230400 && + baudrate != 460800 && baudrate != 921600 && baudrate != 1000000 && baudrate != 2000000) { + ppp_print_err("PPP SET BAUDRATE: Invalid baudrate %d\n", baudrate); + ppp_print_err("PPP SET BAUDRATE: Supported values: 9600,19200,38400,57600,115200,230400,460800,921600,1000000,2000000\n"); + return ERRCODE_FAIL; + } + + // 获取当前配置的波特率 + uint32_t current_baudrate = get_ppp_baudrate_from_config_model(); + + if (current_baudrate == baudrate) { + ppp_print_info("PPP SET BAUDRATE: Baudrate already set to %d, no change needed\n", baudrate); + return ERRCODE_SUCC; + } + + // 设置新的波特率到配置模型 + set_ppp_baudrate_from_config_model(baudrate); + + 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); + ppp_print_info("PPP SET BAUDRATE: Successfully set PPP baudrate to %d, ret: %d\n ", baudrate,rett); + return ERRCODE_SUCC; +} + +/** + * @brief AT^PPPGETBAUD - 获取PPP波特率配置 + */ +static errcode_t at_ppp_get_config_baudrate(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(para); + UNUSED(paraLen); + UNUSED(strCommonCmd); + + uint32_t config_baudrate = get_ppp_baudrate_from_config_model(); + uint32_t current_baudrate = ppp_at_get_current_baudrate(); + + ppp_print_info("PPP GET BAUDRATE: Config model baudrate: %d\n", config_baudrate); + ppp_print_info("PPP GET BAUDRATE: Current runtime baudrate: %d\n", current_baudrate); + + if (config_baudrate != current_baudrate) { + ppp_print_warning("PPP GET BAUDRATE: Warning - Config and runtime baudrates differ!\n"); + ppp_print_warning("PPP GET BAUDRATE: Consider restarting PPP module to sync baudrates\n"); + } else { + ppp_print_info("PPP GET BAUDRATE: Config and runtime baudrates are synchronized\n"); + } + + return ERRCODE_SUCC; +} + static const at_cmd_table_t g_ppp_cmd[] = { { (char *)"AT^CAT1POWER", cat1_power, (char *)"1" }, { (char *)"AT^CAT1GETSIGNAL", at_cat1_getsignal, (char *)"1" }, @@ -2404,6 +2483,9 @@ static const at_cmd_table_t g_ppp_cmd[] = { { (char *)"AT^DEMOTEST", at_demo_serial_test, (char *)"[interval_ms],[duration_sec],[baudrate]" }, { (char *)"AT^DEMOSTOP", at_demo_test_stop, (char *)" " }, { (char *)"AT^DEMOSTATS", at_demo_test_stats, (char *)" " }, + /* PPP配置模型波特率管理指令 */ + { (char *)"AT^PPPSETBAUD", at_ppp_set_config_baudrate, (char *)"baudrate" }, + { (char *)"AT^PPPGETBAUD", at_ppp_get_config_baudrate, (char *)" " }, }; at_cmd_table_t *get_ppp_cmd_table(uint32_t *cmd_count) diff --git a/code/sdk/zhihui/ppp/example/ppp_example.c b/code/sdk/zhihui/ppp/example/ppp_example.c index 34d4b119b..d3078d3ce 100644 --- a/code/sdk/zhihui/ppp/example/ppp_example.c +++ b/code/sdk/zhihui/ppp/example/ppp_example.c @@ -24,7 +24,7 @@ static void network_monitor_task(void *arg); static bool g_ppp_connected = false; static osal_task *g_monitor_task = NULL; static bool g_ppp_env_initialized = false; - +static uint32_t g_ppp_baudrate = PPP_UART_BAUDRATE; /** * @brief PPP环境初始化 * @return 0成功,-1失败 @@ -43,7 +43,7 @@ int ppp_env_init(void) .apn = "CMIOTZSZCGRE.GD", // 中国移动APN cmnet .username = "", // 用户名(通常为空) .password = "", // 密码(通常为空) - .baudrate = PPP_UART_BAUDRATE, // 2M波特率 + .baudrate = g_ppp_baudrate, // 2M波特率 .auto_baudrate = true, // 启用自动波特率检测 .dial_timeout = 30000, // 30秒拨号超时 .retry_count = 3 // 重试3次 @@ -78,7 +78,14 @@ int ppp_env_init(void) } - +uint32_t get_ppp_baudrate(void) +{ + return g_ppp_baudrate; +} +void set_ppp_baudrate(uint32_t value) +{ + g_ppp_baudrate = value; +} int ppp_env_init_monitor_task(void) { /* 4. 创建网络监控任务 */ diff --git a/code/sdk/zhihui/ppp/include/ppp_config.h b/code/sdk/zhihui/ppp/include/ppp_config.h index 77e972c54..d4c15cf66 100644 --- a/code/sdk/zhihui/ppp/include/ppp_config.h +++ b/code/sdk/zhihui/ppp/include/ppp_config.h @@ -27,7 +27,7 @@ extern "C" { #define SIO_UART_IRQ_NUM UART_0_IRQN // UART IRQ引脚 #endif -#define PPP_UART_BAUDRATE 2000000 +#define PPP_UART_BAUDRATE 115200 /* 支持的波特率列表(自适应模式) */ #define PPP_BAUDRATE_AUTO_LIST {9600, 57600, 115200} diff --git a/code/sdk/zhihui/ppp/include/ppp_example.h b/code/sdk/zhihui/ppp/include/ppp_example.h index e4c4fbf2e..6d521e470 100644 --- a/code/sdk/zhihui/ppp/include/ppp_example.h +++ b/code/sdk/zhihui/ppp/include/ppp_example.h @@ -70,6 +70,20 @@ int ppp_env_deinit(void); */ int ppp_env_init_monitor_task(void); +/** + * @brief 获取PPP波特率 + * + * @return 波特率 + */ +uint32_t get_ppp_baudrate(void); + +/** + * @brief 设置PPP波特率 + * + * @param value 波特率 + */ +void set_ppp_baudrate(uint32_t value); + #ifdef __cplusplus } diff --git a/code/sdk/zhihui/ppp/src/ppp_at_handler.c b/code/sdk/zhihui/ppp/src/ppp_at_handler.c index 8a609e286..8e8673556 100644 --- a/code/sdk/zhihui/ppp/src/ppp_at_handler.c +++ b/code/sdk/zhihui/ppp/src/ppp_at_handler.c @@ -17,6 +17,7 @@ static struct { bool initialized; uint8_t uart_bus; uint32_t current_baudrate; + uint32_t target_baudrate; bool auto_baudrate_mode; ppp_at_response_t last_response; osal_mutex at_mutex; // 改为结构体,不是指针 @@ -104,12 +105,9 @@ ppp_error_t ppp_at_baudrate_handshake(void) return PPP_ERR_INVALID_PARAM; } - PPP_DEBUG_INFO("Starting baudrate handshake (prove 1000000 not working, then try auto handshake)"); + PPP_DEBUG_INFO("Starting baudrate handshake (prove %d not working, then try auto handshake)",g_at_ctx.current_baudrate); - // 1. 先reset模组,证明1000000没有正常工作 - PPP_DEBUG_DEBUG("Resetting module to prove 1000000 baudrate is not working..."); - ppp_power_reset_cat1(); - osal_msleep(5000); + // uint8_t dummy_buffer[256]={0}; // 2. 依次尝试自动波特率列表 for (int i = 0; i < PPP_BAUDRATE_AUTO_COUNT; i++) { @@ -130,15 +128,15 @@ ppp_error_t ppp_at_baudrate_handshake(void) PPP_DEBUG_DEBUG("UART configured for baudrate %u", baudrate); // 清空接收缓冲区 - PPP_DEBUG_DEBUG("Clearing UART RX buffer before AT test..."); - uint8_t dummy_buffer[256]; - int clear_cnt = 0; - while (uapi_uart_read(g_at_ctx.uart_bus, dummy_buffer, sizeof(dummy_buffer), 100) > 0) { - clear_cnt++; - } - if (clear_cnt > 0) { - PPP_DEBUG_DEBUG("Cleared %d RX buffer rounds", clear_cnt); - } + // PPP_DEBUG_DEBUG("Clearing UART RX buffer before AT test..."); + // int clear_cnt = 0; + // memset(dummy_buffer,0,sizeof(dummy_buffer)); + // while (uapi_uart_read(g_at_ctx.uart_bus, dummy_buffer, sizeof(dummy_buffer), 100) > 0) { + // clear_cnt++; + // } + // if (clear_cnt > 0) { + // PPP_DEBUG_DEBUG("Cleared %d RX buffer rounds", clear_cnt); + // } // 3次重试AT ppp_error_t ret = PPP_ERR_AT_FAILED; @@ -146,7 +144,8 @@ ppp_error_t ppp_at_baudrate_handshake(void) PPP_DEBUG_DEBUG("--- AT Test at %u baud, retry %d/3 ---", baudrate, retry + 1); // 再次清空缓冲区,防止上次残留 - while (uapi_uart_read(g_at_ctx.uart_bus, dummy_buffer, sizeof(dummy_buffer), 100) > 0) {} + // memset(dummy_buffer,0,sizeof(dummy_buffer)); + // while (uapi_uart_read(g_at_ctx.uart_bus, dummy_buffer, sizeof(dummy_buffer), 100) > 0) {} ppp_at_response_t response; ret = ppp_at_send_command("AT", "OK", 1000, &response); @@ -155,18 +154,23 @@ ppp_error_t ppp_at_baudrate_handshake(void) PPP_DEBUG_INFO("AT command successful at baudrate %u", baudrate); // 在当前波特率下,设置AT+IPR=1000000 - ppp_at_set_baudrate(PPP_UART_BAUDRATE); - ppp_at_set_baudrate(PPP_UART_BAUDRATE); - + ret = ppp_at_set_baudrate(g_at_ctx.current_baudrate); + if (ret != PPP_ERR_OK) { + ret = ppp_at_set_baudrate(g_at_ctx.current_baudrate); + if (ret != PPP_ERR_OK) { + PPP_DEBUG_ERROR("Failed to set baudrate %u", g_at_ctx.current_baudrate); + return ret; + } + } // 再次reset模组,让其自动工作在1000000波特率下 - PPP_DEBUG_DEBUG("Resetting module again to switch to baudrate %d...",PPP_UART_BAUDRATE); - ppp_power_reset_cat1(); - osal_msleep(5000); + PPP_DEBUG_DEBUG("Resetting module again to switch to baudrate %d...",g_at_ctx.current_baudrate); + // ppp_power_reset_cat1(); + // osal_msleep(5000); ret = ppp_at_send_command("AT", "OK", 1000, &response); if(ret != PPP_ERR_OK) { - PPP_DEBUG_INFO("Baudrate handshake failed, now at %d baud",PPP_UART_BAUDRATE); + PPP_DEBUG_INFO("Baudrate handshake failed, now at %d baud",g_at_ctx.current_baudrate); }else{ - PPP_DEBUG_INFO("Baudrate handshake successful, now at %d baud",PPP_UART_BAUDRATE); + PPP_DEBUG_INFO("Baudrate handshake successful, now at %d baud",g_at_ctx.current_baudrate); } return PPP_ERR_OK; } else { diff --git a/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c b/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c index 27d4568c4..a59c7567f 100644 --- a/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c +++ b/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c @@ -404,8 +404,7 @@ static void* tcp_test_send_worker(void *arg) uint32_t current_time = tcp_test_get_time_ms(); // 检查是否可以发送 - bool can_send = (send_interval_ms == 0) || - (current_time - last_send_time >= send_interval_ms); + bool can_send = true;// (send_interval_ms == 0) || (current_time - last_send_time >= send_interval_ms); if (can_send) { // 生成固定模式数据 @@ -456,7 +455,8 @@ static void* tcp_test_send_worker(void *arg) conn->last_activity_time = tcp_test_get_time_ms(); // 短暂延迟避免CPU占用过高 - TCP_SLEEP_MS(send_interval_ms > 0 ? 1 : 0); + // TCP_SLEEP_MS(send_interval_ms > 0 ? 1 : 0); + TCP_SLEEP_MS(send_interval_ms ); } free(send_buffer); @@ -586,7 +586,7 @@ static void* tcp_test_recv_worker(void *arg) conn->last_activity_time = tcp_test_get_time_ms(); // 短暂延迟 - TCP_SLEEP_MS(1); + TCP_SLEEP_MS(20); } // 处理剩余不完整数据 diff --git a/code/sdk/zhihui/utils/custom_utils.c b/code/sdk/zhihui/utils/custom_utils.c index b7379566f..4958fffcb 100644 --- a/code/sdk/zhihui/utils/custom_utils.c +++ b/code/sdk/zhihui/utils/custom_utils.c @@ -699,6 +699,9 @@ void startup_post_init_task(void) #ifdef SUPPORT_PPP_SERVICE + uint32_t baudrate = get_ppp_baudrate_from_config_model(); + if(baudrate != 0) + set_ppp_baudrate(baudrate); ppp_env_init(); #endif