Forráskód Böngészése

【优化】sample文件统一处理
【修改】MSH命令变更

Signed-off-by: liuxianliang <liuxianliang@rt-thread.com>

liuxianliang 6 éve
szülő
commit
aeefb39d41

+ 1 - 8
class/air720/ppp_device_air720.h

@@ -13,13 +13,6 @@
 
 #include <ppp_device.h>
 
-/* Air720  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 */
-};
-
-extern int ppp_air720_register(struct ppp_air720 *air720, const char *dev_name, const char *rely_name, void *user_data);
+extern int ppp_air720_register(struct ppp_sample *air720, const char *dev_name, const char *rely_name, void *user_data);
 
 #endif  /* __PPP_AIR720_H__ */

+ 1 - 8
class/m6312/ppp_device_m6312.h

@@ -13,13 +13,6 @@
 
 #include <ppp_device.h>
 
-/* M6312  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 */
-};
-
-extern int ppp_m6312_register(struct ppp_m6312 *m6312, const char *dev_name, const char *rely_name, void *user_data);
+extern int ppp_m6312_register(struct ppp_sample *m6312, const char *dev_name, const char *rely_name, void *user_data);
 
 #endif  /* __PPP_M6312_H__ */

+ 7 - 3
inc/ppp_device.h

@@ -72,12 +72,16 @@ struct ppp_device
     void *user_data;                            /* reserve */
 };
 
+/* ppp_device base from ppp_device */
+struct ppp_sample
+{
+    struct ppp_device  device;          /* ppp_device struct in ppp_air720 */
+    enum ppp_trans_type type;           /* the type is used to establish a ppp connection */
+};
+
 struct ppp_device_ops
 {
-    rt_err_t  (*init)   (struct ppp_device *dev);
     rt_err_t  (*open)   (struct ppp_device *dev, rt_uint16_t oflag);
-    rt_err_t  (*close)  (struct ppp_device *dev);
-    rt_err_t  (*control)(struct ppp_device *dev, int cmd, void *args);
 };
 
 /* store at_client rx_callback function */

+ 103 - 0
samples/ppp_sample.c

@@ -0,0 +1,103 @@
+/*
+ * 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
+ */
+
+#include<rtthread.h>
+#include<ppp_device.h>
+
+
+#define DBG_TAG    "ppp.sample"
+
+#ifdef PPP_DEVICE_DEBUG
+#define DBG_LVL   DBG_LOG
+#else
+#define DBG_LVL   DBG_INFO
+#endif
+
+#include <rtdbg.h>
+
+#ifdef PPP_DEVICE_USING_AIR720
+#include "ppp_device_air720.h"
+#endif
+#ifdef PPP_DEVICE_USING_M6312
+#include "ppp_device_m6312.h"
+#endif
+#ifdef PPP_DEVICE_USING_SIM800
+#include "ppp_device_sim800.h"
+#endif
+
+static struct ppp_sample sample;
+
+/* register device into rt_device frame */
+int ppp_sample_register(void)
+{
+    int result = RT_EOK;
+
+#ifdef PPP_DEVICE_USING_AIR720
+    result = ppp_air720_register(&sample, PPP_DEVICE_NAME, PPP_CLIENT_NAME, RT_NULL);
+#endif
+#ifdef PPP_DEVICE_USING_M6312
+    result = ppp_m6312_register(&sample, PPP_DEVICE_NAME, PPP_CLIENT_NAME, RT_NULL);
+#endif
+#ifdef PPP_DEVICE_USING_SIM800
+    result = ppp_sim800_register(&sample, PPP_DEVICE_NAME, PPP_CLIENT_NAME, RT_NULL);
+#endif
+    if (result != RT_EOK)
+    {
+        LOG_E("%s registered failed, please try again.", PPP_DEVICE_NAME);
+    }
+
+    return result;
+}
+INIT_ENV_EXPORT(ppp_sample_register);
+
+/* if you want connect network again, you can use this function to create a new ppp link */
+int ppp_sample_start(void)
+{
+    rt_device_t device = RT_NULL;
+
+    device = rt_device_find(PPP_DEVICE_NAME);
+    if (device == RT_NULL)
+    {
+        LOG_E("Cann't find device %s, execute failed", PPP_DEVICE_NAME);
+        return -RT_ERROR;
+    }
+
+    if (rt_device_open(device, 0) != RT_EOK)
+    {
+        LOG_E("Cann't open device %s, execute failed", PPP_DEVICE_NAME);
+        return -RT_ERROR;
+    }
+
+    return RT_EOK;
+}
+INIT_APP_EXPORT(ppp_sample_start);
+MSH_CMD_EXPORT_ALIAS(ppp_sample_start, ppp_start, a sample of ppp device  for dailing to network);
+
+/* close ppp link ,turn off modem form network */
+int ppp_sample_stop(void)
+{
+    rt_device_t device = RT_NULL;
+
+    device = rt_device_find(PPP_DEVICE_NAME);
+    if (device == RT_NULL)
+    {
+        LOG_E("Cann't find device %s, execute failed", PPP_DEVICE_NAME);
+        return -RT_ERROR;
+    }
+
+    if (rt_device_close(device) != RT_EOK)
+    {
+        LOG_E("Cann't close device %s, execute failed", PPP_DEVICE_NAME);
+        return -RT_ERROR;
+    }
+
+    return RT_EOK;
+}
+MSH_CMD_EXPORT_ALIAS(ppp_sample_stop, ppp_stop, a sample of ppp device for turning off network);

+ 0 - 102
samples/ppp_sample_air720.c

@@ -1,102 +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
- */
-
-#include<rtthread.h>
-#include<ppp_device_air720.h>
-
-
-#define DBG_TAG    "air720.sample"
-
-#ifdef PPP_DEVICE_DEBUG
-#define DBG_LVL   DBG_LOG
-#else
-#define DBG_LVL   DBG_INFO
-#endif
-
-#include <rtdbg.h>
-
-static struct ppp_air720 air720;
-
-/*
- * init air720 mode
- *
- * @param NULL
- *
- *
- * @return  RT_EOK      successful
- *          -RT_ERROR   failed
- *
- */
-
-int air720_ppp_register(void)
-{
-    int result = RT_EOK;
-
-    result = ppp_air720_register(&air720, PPP_AIR720_DEVICE_NAME, PPP_AIR720_CLIENT_NAME, RT_NULL);
-    if (result != RT_EOK)
-    {
-        LOG_E("%s registered failed, please try again.", PPP_AIR720_DEVICE_NAME);
-    }
-
-    return result;
-}
-INIT_ENV_EXPORT(air720_ppp_register);
-
-int ppp_air720_start(void)
-{
-    rt_device_t device = RT_NULL;
-
-    device = rt_device_find(PPP_AIR720_DEVICE_NAME);
-    if (device == RT_NULL)
-    {
-        LOG_E("Cann't find device %s, execute failed", PPP_AIR720_DEVICE_NAME);
-        return -RT_ERROR;
-    }
-
-    if (rt_device_open(device, 0) != RT_EOK)
-    {
-        LOG_E("Cann't open device %s, execute failed", PPP_AIR720_DEVICE_NAME);
-        return -RT_ERROR;
-    }
-
-    return RT_EOK;
-}
-INIT_APP_EXPORT(ppp_air720_start);
-MSH_CMD_EXPORT(ppp_air720_start, a sample create air720 for dail to network);
-/*
- * close air720 ppp mode, hang up from network
- *
- * @param NULL
- *
- *
- * @return  NULL
- *
- */
-int ppp_air720_stop(void)
-{
-    rt_device_t device = RT_NULL;
-
-    device = rt_device_find(PPP_AIR720_DEVICE_NAME);
-    if (device == RT_NULL)
-    {
-        LOG_E("Cann't find device %s, execute failed", PPP_AIR720_DEVICE_NAME);
-        return -RT_ERROR;
-    }
-
-    if (rt_device_close(device) != RT_EOK)
-    {
-        LOG_E("Cann't close device %s, execute failed", PPP_AIR720_DEVICE_NAME);
-        return -RT_ERROR;
-    }
-
-    return RT_EOK;
-}
-MSH_CMD_EXPORT(ppp_air720_stop, a sample stop air720 for dail to network);
-

+ 0 - 102
samples/ppp_sample_m6312.c

@@ -1,102 +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
- */
-
-#include<rtthread.h>
-#include<ppp_device_m6312.h>
-
-
-#define DBG_TAG    "m6312.sample"
-
-#ifdef PPP_DEVICE_DEBUG
-#define DBG_LVL   DBG_LOG
-#else
-#define DBG_LVL   DBG_INFO
-#endif
-
-#include <rtdbg.h>
-
-static struct ppp_m6312 m6312;
-
-/*
- * init m6312 mode
- *
- * @param NULL
- *
- *
- * @return  RT_EOK      successful
- *          -RT_ERROR   failed
- *
- */
-
-int ppp_m6312_init(void)
-{
-    int result = RT_EOK;
-
-    result = ppp_m6312_register(&m6312, PPP_M6312_DEVICE_NAME, PPP_M6312_CLIENT_NAME, RT_NULL);
-    if (result != RT_EOK)
-    {
-        LOG_E("%s registered failed, please try again.", PPP_M6312_DEVICE_NAME);
-    }
-
-    return result;
-}
-INIT_ENV_EXPORT(ppp_m6312_init);
-
-int ppp_m6312_start(void)
-{
-    rt_device_t device = RT_NULL;
-
-    device = rt_device_find(PPP_M6312_DEVICE_NAME);
-    if (device == RT_NULL)
-    {
-        LOG_E("Cann't find device %s, execute failed", PPP_M6312_DEVICE_NAME);
-        return -RT_ERROR;
-    }
-
-    if (rt_device_open(device, 0) != RT_EOK)
-    {
-        LOG_E("Cann't open device %s, execute failed", PPP_M6312_DEVICE_NAME);
-        return -RT_ERROR;
-    }
-
-    return RT_EOK;
-}
-INIT_APP_EXPORT(ppp_m6312_start);
-MSH_CMD_EXPORT(ppp_m6312_start, a sample create m6312 for dail to network);
-/*
- * close m6312 ppp mode, hang up from network
- *
- * @param NULL
- *
- *
- * @return  NULL
- *
- */
-int ppp_m6312_stop(void)
-{
-    rt_device_t device = RT_NULL;
-
-    device = rt_device_find(PPP_M6312_DEVICE_NAME);
-    if (device == RT_NULL)
-    {
-        LOG_E("Cann't find device %s, execute failed", PPP_M6312_DEVICE_NAME);
-        return -RT_ERROR;
-    }
-
-    if (rt_device_close(device) != RT_EOK)
-    {
-        LOG_E("Cann't close device %s, execute failed", PPP_M6312_DEVICE_NAME);
-        return -RT_ERROR;
-    }
-
-    return RT_EOK;
-}
-MSH_CMD_EXPORT(ppp_m6312_stop, a sample stop m6312 for dail to network);
-