修复ppp拨号后一段时间无法输入指令问题
author孙春阳 <snickersun@163.com>
Sat, 13 Sep 2025 16:15:26 +0000 (00:15 +0800)
committer孙春阳 <snickersun@163.com>
Sat, 13 Sep 2025 16:15:26 +0000 (00:15 +0800)
code/sdk/zhihui/ppp/example/ppp_example.c

index 6683afd..22d2345 100644 (file)
@@ -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;
 }
 
 /**