Răsfoiți Sursa

【优化】attach 和 detach 的逻辑

Signed-off-by: liuxianliang <liuxianliang@rt-thread.com>
liuxianliang 6 ani în urmă
părinte
comite
c98357bf64
1 a modificat fișierele cu 16 adăugiri și 2 ștergeri
  1. 16 2
      samples/ppp_sample.c

+ 16 - 2
samples/ppp_sample.c

@@ -25,7 +25,14 @@
 /* if you want connect network again, you can use this function to create a new ppp link */
 int ppp_sample_start(void)
 {
-    if(ppp_device_attach(PPP_DEVICE_NAME, PPP_CLIENT_NAME, RT_NULL) != RT_EOK)
+    rt_device_t device = RT_NULL;
+    device = rt_device_find(PPP_DEVICE_NAME);
+    if(device == RT_NULL)
+    {
+        LOG_E("Can't find device (%s).", PPP_DEVICE_NAME);
+        return -RT_ERROR;
+    }
+    if(ppp_device_attach((struct ppp_device *)device, PPP_CLIENT_NAME, RT_NULL) != RT_EOK)
     {
         LOG_E("ppp_device_attach execute failed.");
         return -RT_ERROR;
@@ -38,7 +45,14 @@ MSH_CMD_EXPORT_ALIAS(ppp_sample_start, ppp_start, a sample of ppp device  for da
 /* close ppp link ,turn off modem form network */
 int ppp_sample_stop(void)
 {
-    if(ppp_device_detach(PPP_DEVICE_NAME) != RT_EOK)
+    rt_device_t device = RT_NULL;
+    device = rt_device_find(PPP_DEVICE_NAME);
+    if(device == RT_NULL)
+    {
+        LOG_E("Can't find device (%s).", PPP_DEVICE_NAME);
+        return -RT_ERROR;
+    }
+    if(ppp_device_detach((struct ppp_device *)device) != RT_EOK)
     {
         LOG_E("ppp_device_detach execute failed.");
         return -RT_ERROR;