From 093391f5bb61aadde82044fb226f1c0eade2016e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Sun, 14 Sep 2025 00:15:26 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8Dppp=E6=8B=A8=E5=8F=B7=E5=90=8E?= =?utf8?q?=E4=B8=80=E6=AE=B5=E6=97=B6=E9=97=B4=E6=97=A0=E6=B3=95=E8=BE=93?= =?utf8?q?=E5=85=A5=E6=8C=87=E4=BB=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/zhihui/ppp/example/ppp_example.c | 75 +++-------------------- 1 file changed, 7 insertions(+), 68 deletions(-) diff --git a/code/sdk/zhihui/ppp/example/ppp_example.c b/code/sdk/zhihui/ppp/example/ppp_example.c index 6683afd7b..22d2345a9 100644 --- a/code/sdk/zhihui/ppp/example/ppp_example.c +++ b/code/sdk/zhihui/ppp/example/ppp_example.c @@ -89,8 +89,8 @@ int ppp_env_init(void) } /** - * @brief 开始PPP拨号 - * @return 0成功,-1失败 + * @brief 开始PPP拨号(异步版本,不阻塞AT命令线程) + * @return 0成功启动拨号,-1失败 */ int ppp_test_start_dial(void) { @@ -105,7 +105,7 @@ int ppp_test_start_dial(void) return 0; } - PRINT("Starting PPP dial...\r\n"); + PRINT("Starting PPP dial (async mode)...\r\n"); /* 检查PPP模块状态 */ ppp_state_t current_state = ppp_get_state(); @@ -132,72 +132,11 @@ int ppp_test_start_dial(void) return -1; } - /* 等待连接建立或超时 */ - uint32_t timeout = 60000; // 60秒超时 - uint32_t start_time = (uint32_t)osal_get_jiffies(); + PRINT("PPP dial started successfully (async mode)\r\n"); + PRINT("Use AT^PPPSTATUS to check connection status\r\n"); + PRINT("Connection will be established in background\r\n"); - PRINT("Waiting for PPP connection...\r\n"); - while (!g_ppp_connected && (osal_get_jiffies() - start_time) < osal_msecs_to_jiffies(timeout)) { - ppp_state_t state = ppp_get_state(); - - if (state == PPP_STATE_ERROR) { - PRINT("PPP connection failed\r\n"); - /* 连接失败,自动切回AT模式 */ - ppp_error_t serial_ret = ppp_serial_switch_to_at_mode(); - if (serial_ret != PPP_ERR_OK) { - PRINT("Failed to switch back to AT mode: %d\r\n", serial_ret); - } else { - PRINT("Switched back to AT mode after connection failure\r\n"); - } - return -1; - } - - osal_msleep(1000); - } - - if (g_ppp_connected) { - PRINT("PPP connection established successfully!\r\n"); - - /* 获取并显示网络信息 */ - ppp_connection_info_t network_info; - ret = ppp_get_connection_info(&network_info); - if (ret == ERRCODE_SUCC) { - PRINT("Network Information:\r\n"); - PRINT(" Local IP: %u.%u.%u.%u\r\n", - (network_info.local_ip >> 0) & 0xFF, - (network_info.local_ip >> 8) & 0xFF, - (network_info.local_ip >> 16) & 0xFF, - (network_info.local_ip >> 24) & 0xFF); - PRINT(" Remote IP: %u.%u.%u.%u\r\n", - (network_info.remote_ip >> 0) & 0xFF, - (network_info.remote_ip >> 8) & 0xFF, - (network_info.remote_ip >> 16) & 0xFF, - (network_info.remote_ip >> 24) & 0xFF); - PRINT(" Primary DNS: %u.%u.%u.%u\r\n", - (network_info.primary_dns >> 0) & 0xFF, - (network_info.primary_dns >> 8) & 0xFF, - (network_info.primary_dns >> 16) & 0xFF, - (network_info.primary_dns >> 24) & 0xFF); - PRINT(" Secondary DNS: %u.%u.%u.%u\r\n", - (network_info.secondary_dns >> 0) & 0xFF, - (network_info.secondary_dns >> 8) & 0xFF, - (network_info.secondary_dns >> 16) & 0xFF, - (network_info.secondary_dns >> 24) & 0xFF); - PRINT(" MTU: %u\r\n", network_info.mtu); - } - - return 0; - } else { - PRINT("PPP connection timeout\r\n"); - /* 连接超时,自动切回AT模式 */ - ppp_error_t serial_ret = ppp_serial_switch_to_at_mode(); - if (serial_ret != PPP_ERR_OK) { - PRINT("Failed to switch back to AT mode: %d\r\n", serial_ret); - } else { - PRINT("Switched back to AT mode after timeout\r\n"); - } - return -1; - } + return 0; } /** -- 2.17.1