Просмотр исходного кода

【增加】SIM800的支持

Signed-off-by: liuxianliang <liuxianliang@rt-thread.com>
liuxianliang 6 лет назад
Родитель
Сommit
a428b4312c
3 измененных файлов с 117 добавлено и 4 удалено
  1. 6 4
      SConscript
  2. 93 0
      class/sim800/ppp_device_sim800.c
  3. 18 0
      class/sim800/ppp_device_sim800.h

+ 6 - 4
SConscript

@@ -3,20 +3,22 @@ from building import *
 cwd = GetCurrentDir()
 path = [cwd + '/inc']
 src  = Glob('src/*.c')
+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')
-    if GetDepend(['PPP_DEVICE_AIR720_SAMPLE']):
-        src += Glob('samples/ppp_sample_air720.c')
 
 # M6312
 if GetDepend(['PPP_DEVICE_USING_M6312']):
     path += [cwd + '/class/m6312']
     src += Glob('class/m6312/ppp_device_m6312.c')
-    if GetDepend(['PPP_DEVICE_M6312_SAMPLE']):
-        src += Glob('samples/ppp_sample_m6312.c')
+
+# SIM800
+if GetDepend(['PPP_DEVICE_USING_SIM800']):
+    path += [cwd + '/class/sim800']
+    src += Glob('class/sim800/ppp_device_sim800.c')
 
 group = DefineGroup('ppp_device', src, depend = ['PKG_USING_PPP_DEVICE'], CPPPATH = path)
 

+ 93 - 0
class/sim800/ppp_device_sim800.c

@@ -0,0 +1,93 @@
+/*
+ * 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 <ppp_device_sim800.h>
+
+#define DBG_TAG    "ppp.sim800"
+
+#ifdef PPP_DEVICE_DEBUG
+#define DBG_LVL   DBG_LOG
+#else
+#define DBG_LVL   DBG_INFO
+#endif
+
+#include <rtdbg.h>
+
+static const struct modem_chat_data mcd[] =
+{
+    {"+++",          MODEM_CHAT_RESP_NOT_NEED,        1,  2, RT_FALSE},
+    {"ATH",          MODEM_CHAT_RESP_OK,              30, 3, RT_TRUE},
+    {"AT",           MODEM_CHAT_RESP_OK,              10, 1, RT_TRUE},
+    {"ATE0",         MODEM_CHAT_RESP_OK,              1,  1, RT_TRUE},
+    {PPP_APN_CMD,    MODEM_CHAT_RESP_OK,              1,  5, RT_TRUE},
+    {PPP_DAIL_CMD,   MODEM_CHAT_RESP_CONNECT,         2, 30, RT_TRUE},
+};
+
+/*
+ * Get into PPP modem,using uart
+ *
+ * @param NULL
+ *
+ * @return  0: execute successful
+ *         -1: send AT commands error
+ *         -5: no memory
+ */
+static rt_err_t ppp_sim800_open(struct ppp_device *device, rt_uint16_t oflag)
+{
+    rt_device_t uart_device = RT_NULL;
+    rt_err_t result = RT_EOK;
+
+    RT_ASSERT(device != RT_NULL);
+
+    uart_device = rt_device_find(device->rely_name);
+    if (uart_device == RT_NULL)
+    {
+        LOG_E("Can't find relying device %s.", device->rely_name);
+        return -RT_ERROR;
+    }
+    result = rt_device_open(uart_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
+    if (result != RT_EOK)
+    {
+        LOG_E("relying device open(%s) fail.", device->rely_name);
+        return RT_NULL;
+    }
+
+    return modem_chat(uart_device, mcd, sizeof(mcd) / sizeof(mcd[0]));
+}
+
+/* ppp_sim800_ops for ppp_device_ops , a common interface */
+static struct ppp_device_ops sim800_ops =
+{
+    ppp_sim800_open,
+};
+
+/*
+ * register sim800 into ppp_device
+ *
+ * @param struct ppp_sim800 *       piont
+ *        const char *              name
+ *        int                       flag
+ *        void *                    resever data
+ * @return  ppp_device function piont
+ *
+ */
+int ppp_sim800_register(struct ppp_sample *sim800, const char *dev_name, const char *uart_name, void *user_data)
+{
+    struct ppp_device *ppp_device = RT_NULL;
+
+    RT_ASSERT(sim800 != RT_NULL);
+
+    ppp_device = &(sim800->device);
+    ppp_device->ops = &sim800_ops;
+
+    LOG_D("ppp sim800 is registering ppp_device");
+
+    return ppp_device_register(ppp_device, dev_name, uart_name, user_data);
+}

+ 18 - 0
class/sim800/ppp_device_sim800.h

@@ -0,0 +1,18 @@
+/*
+ * 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>
+
+extern int ppp_sim800_register(struct ppp_sample *sim800, const char *dev_name, const char *rely_name, void *user_data);
+
+#endif  /* __PPP_AIR720_H__ */