Explorar el Código

Merge pull request #10 from xiangxistu/master

【修改】直接使用ppp_device注册
朱天龙 (Armink) hace 6 años
padre
commit
334038dcd4

+ 3 - 6
SConscript

@@ -7,18 +7,15 @@ src += Glob('samples/ppp_sample.c')
 
 # Air720
 if GetDepend(['PPP_DEVICE_USING_AIR720']):
-    path += [cwd + '/class/air720']
-    src += Glob('class/air720/ppp_device_air720.c')
+    src += Glob('class/ppp_device_air720.c')
 
 # M6312
 if GetDepend(['PPP_DEVICE_USING_M6312']):
-    path += [cwd + '/class/m6312']
-    src += Glob('class/m6312/ppp_device_m6312.c')
+    src += Glob('class/ppp_device_m6312.c')
 
 # SIM800
 if GetDepend(['PPP_DEVICE_USING_SIM800']):
-    path += [cwd + '/class/sim800']
-    src += Glob('class/sim800/ppp_device_sim800.c')
+    src += Glob('class/ppp_device_sim800.c')
 
 group = DefineGroup('ppp_device', src, depend = ['PKG_USING_PPP_DEVICE'], CPPPATH = path)
 

+ 0 - 28
class/air720/ppp_device_air720.h

@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2006-2019, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date           Author         Notes
- * 2019-08-15    xiangxistu      the first version
- */
-
-#ifndef __PPP_AIR720_H__
-#define __PPP_AIR720_H__
-
-#include <ppp_device.h>
-
-#define AIR720_WARTING_TIME_BASE 500
-
-/* ppp_device base from ppp_device */
-struct ppp_air720
-{
-    struct ppp_device  device;          /* ppp_device struct in ppp_air720 */
-    enum ppp_trans_type type;           /* the type is used to establish a ppp connection */
-    rt_base_t power_pin;                /* power pin, if device need hardware reset */
-};
-
-extern int ppp_air720_register(void);
-
-#endif  /* __PPP_AIR720_H__ */

+ 0 - 28
class/m6312/ppp_device_m6312.h

@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2006-2019, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date           Author         Notes
- * 2019-09-24     xiaofao        the first version
- */
-
-#ifndef __PPP_M6312_H__
-#define __PPP_M6312_H__
-
-#include <ppp_device.h>
-
-#define M6312_WARTING_TIME_BASE 500
-
-/* ppp_device base from ppp_device */
-struct ppp_m6312
-{
-    struct ppp_device  device;          /* ppp_device struct in ppp_m6312 */
-    enum ppp_trans_type type;           /* the type is used to establish a ppp connection */
-    rt_base_t power_pin;                /* power pin, if device need hardware reset */
-};
-
-extern int ppp_m6312_register(void);
-
-#endif  /* __PPP_M6312_H__ */

+ 13 - 15
class/air720/ppp_device_air720.c → class/ppp_device_air720.c

@@ -8,7 +8,7 @@
  * 2019-08-15    xiangxistu      the first version
  */
 
-#include <ppp_device_air720.h>
+#include <ppp_device.h>
 #include <ppp_chat.h>
 #include <rtdevice.h>
 
@@ -27,6 +27,8 @@
 #define AIR720_POWER_PIN -1
 #endif
 
+#define AIR720_WARTING_TIME_BASE 500
+
 static const struct modem_chat_data rst_mcd[] =
 {
     {"+++",          MODEM_CHAT_RESP_NOT_NEED,        30, 1, RT_TRUE},
@@ -43,12 +45,11 @@ static const struct modem_chat_data mcd[] =
 
 static rt_err_t ppp_air720_prepare(struct ppp_device *device)
 {
-    struct ppp_air720 *air720 = (struct ppp_air720*)device;
-    if (air720->power_pin >= 0)
+    if (device->power_pin >= 0)
     {
-        rt_pin_write(air720->power_pin, AIR720_POWER_OFF);
+        rt_pin_write(device->power_pin, AIR720_POWER_OFF);
         rt_thread_mdelay(AIR720_WARTING_TIME_BASE);
-        rt_pin_write(air720->power_pin, AIR720_POWER_ON);
+        rt_pin_write(device->power_pin, AIR720_POWER_ON);
     }
     else
     {
@@ -75,23 +76,20 @@ static struct ppp_device_ops air720_ops =
 int ppp_air720_register(void)
 {
     struct ppp_device *ppp_device = RT_NULL;
-    struct ppp_air720 *air720 = RT_NULL;
 
-    air720 = rt_malloc(sizeof(struct ppp_air720));
-    if(air720 == RT_NULL)
+    ppp_device = rt_malloc(sizeof(struct ppp_device));
+    if(ppp_device == RT_NULL)
     {
-        LOG_E("No memory for struct air720.");
+        LOG_E("No memory for air720 ppp_device.");
         return -RT_ENOMEM;
     }
 
-    air720->power_pin = AIR720_POWER_PIN;
-    if (air720->power_pin >= 0)
+    ppp_device->power_pin = AIR720_POWER_PIN;
+    if (ppp_device->power_pin >= 0)
     {
-        rt_pin_mode(air720->power_pin, PIN_MODE_OUTPUT);
-        rt_pin_write(air720->power_pin, AIR720_POWER_OFF);
+        rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
+        rt_pin_write(ppp_device->power_pin, AIR720_POWER_OFF);
     }
-
-    ppp_device = &(air720->device);
     ppp_device->ops = &air720_ops;
 
     LOG_D("ppp air720 is registering ppp_device");

+ 12 - 14
class/m6312/ppp_device_m6312.c → class/ppp_device_m6312.c

@@ -8,7 +8,7 @@
  * 2019-09-24     xiaofao        the first version
  */
 
-#include <ppp_device_m6312.h>
+#include <ppp_device.h>
 #include <ppp_chat.h>
 #include <rtdevice.h>
 
@@ -27,6 +27,7 @@
 #define M6312_POWER_PIN -1
 #endif
 
+#define M6312_WARTING_TIME_BASE 500
 
 static const struct modem_chat_data rst_mcd[] =
 {
@@ -45,12 +46,11 @@ static const struct modem_chat_data mcd[] =
 
 static rt_err_t ppp_m6312_prepare(struct ppp_device *device)
 {
-    struct ppp_m6312 *m6312 = (struct ppp_m6312*)device;
-    if (m6312->power_pin >= 0)
+    if (device->power_pin >= 0)
     {
-        rt_pin_write(m6312->power_pin, M6312_POWER_OFF);
+        rt_pin_write(device->power_pin, M6312_POWER_OFF);
         rt_thread_mdelay(M6312_WARTING_TIME_BASE);
-        rt_pin_write(m6312->power_pin, M6312_POWER_ON);
+        rt_pin_write(device->power_pin, M6312_POWER_ON);
     }
     else
     {
@@ -77,23 +77,21 @@ static struct ppp_device_ops m6312_ops =
 int ppp_m6312_register(void)
 {
     struct ppp_device *ppp_device = RT_NULL;
-    struct ppp_m6312 *m6312 = RT_NULL;
 
-    m6312 = rt_malloc(sizeof(struct ppp_m6312));
-    if(m6312 == RT_NULL)
+    ppp_device = rt_malloc(sizeof(struct ppp_device));
+    if(ppp_device == RT_NULL)
     {
-        LOG_E("No memory for struct m6312.");
+        LOG_E("No memory for struct m6312 ppp_device.");
         return -RT_ENOMEM;
     }
 
-    m6312->power_pin = M6312_POWER_PIN;
-    if (m6312->power_pin >= 0)
+    ppp_device->power_pin = M6312_POWER_PIN;
+    if (ppp_device->power_pin >= 0)
     {
-        rt_pin_mode(m6312->power_pin, PIN_MODE_OUTPUT);
-        rt_pin_write(m6312->power_pin, M6312_POWER_OFF);
+        rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
+        rt_pin_write(ppp_device->power_pin, M6312_POWER_OFF);
     }
 
-    ppp_device = &(m6312->device);
     ppp_device->ops = &m6312_ops;
     LOG_D("ppp m6312 is registering ppp_device");
     return ppp_device_register(ppp_device, PPP_DEVICE_NAME, RT_NULL, RT_NULL);

+ 13 - 14
class/sim800/ppp_device_sim800.c → class/ppp_device_sim800.c

@@ -8,7 +8,7 @@
  * 2019-08-15    xiangxistu      the first version
  */
 
-#include <ppp_device_sim800.h>
+#include <ppp_device.h>
 #include <ppp_chat.h>
 #include <rtdevice.h>
 
@@ -27,6 +27,8 @@
 #define SIM800_POWER_PIN -1
 #endif
 
+#define SIM800_WARTING_TIME_BASE 500
+
 static const struct modem_chat_data rst_mcd[] =
 {
     {"+++",          MODEM_CHAT_RESP_NOT_NEED,        30, 1, RT_TRUE},
@@ -43,12 +45,11 @@ static const struct modem_chat_data mcd[] =
 
 static rt_err_t ppp_sim800_prepare(struct ppp_device *device)
 {
-    struct ppp_sim800 *sim800 = (struct ppp_sim800*)device;
-    if (sim800->power_pin >= 0)
+    if (device->power_pin >= 0)
     {
-        rt_pin_write(sim800->power_pin, SIM800_POWER_OFF);
+        rt_pin_write(device->power_pin, SIM800_POWER_OFF);
         rt_thread_mdelay(SIM800_WARTING_TIME_BASE);
-        rt_pin_write(sim800->power_pin, SIM800_POWER_ON);
+        rt_pin_write(device->power_pin, SIM800_POWER_ON);
     }
     else
     {
@@ -75,23 +76,21 @@ static struct ppp_device_ops sim800_ops =
 int ppp_sim800_register(void)
 {
     struct ppp_device *ppp_device = RT_NULL;
-    struct ppp_sim800 *sim800 = RT_NULL;
 
-    sim800 = rt_malloc(sizeof(struct ppp_sim800));
-    if(sim800 == RT_NULL)
+    ppp_device = rt_malloc(sizeof(struct ppp_device));
+    if(ppp_device == RT_NULL)
     {
-        LOG_E("No memory for struct sim800.");
+        LOG_E("No memory for struct sim800 ppp_device.");
         return -RT_ENOMEM;
     }
 
-    sim800->power_pin = SIM800_POWER_PIN;
-    if (sim800->power_pin >= 0)
+    ppp_device->power_pin = SIM800_POWER_PIN;
+    if (ppp_device->power_pin >= 0)
     {
-        rt_pin_mode(sim800->power_pin, PIN_MODE_OUTPUT);
-        rt_pin_write(sim800->power_pin, SIM800_POWER_OFF);
+        rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
+        rt_pin_write(ppp_device->power_pin, SIM800_POWER_OFF);
     }
 
-    ppp_device = &(sim800->device);
     ppp_device->ops = &sim800_ops;
 
     LOG_D("ppp sim800 is registering ppp_device");

+ 0 - 28
class/sim800/ppp_device_sim800.h

@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2006-2019, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date           Author         Notes
- * 2019-08-15    xiangxistu      the first version
- */
-
-#ifndef __PPP_AIR720_H__
-#define __PPP_AIR720_H__
-
-#include <ppp_device.h>
-
-#define SIM800_WARTING_TIME_BASE 500
-
-/* ppp_device base from ppp_device */
-struct ppp_sim800
-{
-    struct ppp_device  device;          /* ppp_device struct in ppp_sim800 */
-    enum ppp_trans_type type;           /* the type is used to establish a ppp connection */
-    rt_base_t power_pin;                /* power pin, if device need hardware reset */
-};
-
-extern int ppp_sim800_register(void);
-
-#endif  /* __PPP_AIR720_H__ */

+ 1 - 0
inc/ppp_device.h

@@ -67,6 +67,7 @@ struct ppp_device
     rt_device_t uart;                           /* low-level uart device object */
     const struct ppp_device_ops *ops;           /* ppp device ops interface */
     enum ppp_conn_type conn_type;               /* using usb or uart */
+    rt_base_t power_pin;                        /* power pin, if device need hardware reset */
 
     ppp_pcb *pcb;                               /* ppp protocol control block */
     struct netif pppif;