Explorar el Código

Merge pull request #18 from xiangxistu/master

【update】v2.0.0
朱天龙 (Armink) hace 5 años
padre
commit
821de9245a
Se han modificado 6 ficheros con 52 adiciones y 9 borrados
  1. 11 1
      class/ppp_device_air720.c
  2. 11 0
      class/ppp_device_sim800.c
  3. 6 2
      inc/ppp_device.h
  4. 2 0
      samples/ppp_sample.c
  5. 9 0
      src/ppp_chat.c
  6. 13 6
      src/ppp_device.c

+ 11 - 1
class/ppp_device_air720.c

@@ -26,9 +26,9 @@
 #ifndef AIR720_POWER_PIN
 #define AIR720_POWER_PIN -1
 #endif
-
 #define AIR720_WARTING_TIME_BASE 2000
 
+#ifndef PKG_USING_CMUX
 static const struct modem_chat_data rst_mcd[] =
 {
     {"+++",          MODEM_CHAT_RESP_NOT_NEED,        30, 1, RT_TRUE},
@@ -42,9 +42,18 @@ static const struct modem_chat_data mcd[] =
     {PPP_APN_CMD,    MODEM_CHAT_RESP_OK,              1,  5, RT_FALSE},
     {PPP_DAIL_CMD,   MODEM_CHAT_RESP_CONNECT,         1, 30, RT_FALSE},
 };
+#else
+static const struct modem_chat_data mcd[] =
+{
+    {"AT",           MODEM_CHAT_RESP_NOT_NEED,        10, 1, RT_FALSE},
+    {PPP_APN_CMD,    MODEM_CHAT_RESP_NOT_NEED,        1,  5, RT_FALSE},
+    {PPP_DAIL_CMD,   MODEM_CHAT_RESP_NOT_NEED,        1, 30, RT_FALSE},
+};
+#endif
 
 static rt_err_t ppp_air720_prepare(struct ppp_device *device)
 {
+#ifndef PKG_USING_CMUX
     if (device->power_pin >= 0)
     {
         rt_pin_write(device->power_pin, AIR720_POWER_OFF);
@@ -59,6 +68,7 @@ static rt_err_t ppp_air720_prepare(struct ppp_device *device)
         if (err)
             return err;
     }
+#endif
     return modem_chat(device->uart, mcd, sizeof(mcd) / sizeof(mcd[0]));
 }
 

+ 11 - 0
class/ppp_device_sim800.c

@@ -29,6 +29,7 @@
 
 #define SIM800_WARTING_TIME_BASE 500
 
+#ifndef PKG_USING_CMUX
 static const struct modem_chat_data rst_mcd[] =
 {
     {"+++",          MODEM_CHAT_RESP_NOT_NEED,        30, 1, RT_TRUE},
@@ -42,9 +43,18 @@ static const struct modem_chat_data mcd[] =
     {PPP_APN_CMD,    MODEM_CHAT_RESP_OK,              1,  5, RT_FALSE},
     {PPP_DAIL_CMD,   MODEM_CHAT_RESP_CONNECT,         1, 30, RT_FALSE},
 };
+#else
+static const struct modem_chat_data mcd[] =
+{
+    {"AT",           MODEM_CHAT_RESP_NOT_NEED,        10, 1, RT_FALSE},
+    {PPP_APN_CMD,    MODEM_CHAT_RESP_NOT_NEED,        1,  5, RT_FALSE},
+    {PPP_DAIL_CMD,   MODEM_CHAT_RESP_NOT_NEED,        1, 30, RT_FALSE},
+};
+#endif
 
 static rt_err_t ppp_sim800_prepare(struct ppp_device *device)
 {
+#ifndef PKG_USING_CMUX
     if (device->power_pin >= 0)
     {
         rt_pin_write(device->power_pin, SIM800_POWER_OFF);
@@ -58,6 +68,7 @@ static rt_err_t ppp_sim800_prepare(struct ppp_device *device)
         if (err)
             return err;
     }
+#endif
     return modem_chat(device->uart, mcd, sizeof(mcd) / sizeof(mcd[0]));
 }
 

+ 6 - 2
inc/ppp_device.h

@@ -24,6 +24,9 @@
 #endif
 
 #define PPP_DAIL_CMD         "ATD*99#"                                  /* common dailing cmd */
+#ifndef USING_PUBLIC_APN
+#define PPP_APN_CMD          "AT+CGDCONT=1,\"IP\","PPP_PRIVATE_APN
+#else
 #ifdef  PPP_APN_CMCC
 #define PPP_APN_CMD          "AT+CGDCONT=1,\"IP\",\"CMNET\""            /* China Mobile Communication Company */
 #endif
@@ -33,6 +36,7 @@
 #ifdef  PPP_APN_CTCC
 #define PPP_APN_CMD          "AT+CGDCONT=1,\"IP\",\"CTNET\""            /* China Telecom Communication Company */
 #endif
+#endif
 #define PPP_CTL_GET_CSQ      1
 #define PPP_CTL_GET_IEMI     2
 #define PPP_CTL_GET_TYPE     3
@@ -42,8 +46,8 @@
 #define PPP_DROP_BUF        PPP_FRAME_MAX
 
 
-#define PPP_DEVICE_SW_VERSION           "1.0.1"
-#define PPP_DEVICE_SW_VERSION_NUM       0x10001
+#define PPP_DEVICE_SW_VERSION           "1.1.0"
+#define PPP_DEVICE_SW_VERSION_NUM       0x10100
 
 enum ppp_trans_type
 {

+ 2 - 0
samples/ppp_sample.c

@@ -39,7 +39,9 @@ int ppp_sample_start(void)
     }
     return RT_EOK;
 }
+#ifndef PKG_USING_CMUX
 INIT_APP_EXPORT(ppp_sample_start);
+#endif
 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 */

+ 9 - 0
src/ppp_chat.c

@@ -9,7 +9,12 @@
  */
 
 #include "ppp_chat.h"
+
+#ifndef PKG_USING_CMUX
 #define DBG_TAG    "ppp.chat"
+#else
+#define DBG_TAG    "chat"
+#endif
 
 #ifdef PPP_DEVICE_DEBUG
 #define DBG_LVL   DBG_LOG
@@ -248,6 +253,10 @@ rt_err_t modem_chat(rt_device_t serial, const struct modem_chat_data *data, rt_s
     }
 
     serial->rx_indicate = old_rx_ind;
+#ifdef PKG_USING_CMUX
+    LOG_D("(%s) has control by cmux.", serial->parent.name);
+#else
     LOG_D("(%s) has control by ppp_device.", serial->parent.name);
+#endif
     return err;
 }

+ 13 - 6
src/ppp_device.c

@@ -22,6 +22,13 @@
 
 #include <rtdbg.h>
 
+#ifdef PPP_DEVICE_DEBUG
+#define PPP_THREAD_STACK_SIZE 2048
+#else
+#define PPP_THREAD_STACK_SIZE 768
+#endif
+#define PPP_THREAD_PRIORITY   9
+
 enum
 {
     PPP_STATE_PREPARE,
@@ -56,10 +63,10 @@ static struct ppp_device *_g_ppp_device = RT_NULL;
 #ifdef PPP_DEVICE_DEBUG
 static void ppp_debug_hexdump(const void *data, size_t len)
 {
-    const size_t maxlen = 16;
+    rt_uint16_t maxlen = 16;
     rt_uint32_t offset = 0;
     size_t curlen = 0, i = 0;
-    char line[maxlen * 4 + 3] = {0};
+    char line[16 * 4 + 3] = {0};
     char *p = RT_NULL;
     const unsigned char *src = data;
 
@@ -464,8 +471,8 @@ static int ppp_recv_entry_creat(struct ppp_device *device)
     device->recv_tid = rt_thread_create("ppp_recv",
                                         (void (*)(void *parameter))ppp_recv_entry,
                                         device,
-                                        768,
-                                        8,
+                                        PPP_THREAD_STACK_SIZE,
+                                        PPP_THREAD_PRIORITY,
                                         20);
     if (device->recv_tid == RT_NULL)
     {
@@ -579,10 +586,10 @@ static rt_err_t ppp_device_open(struct rt_device *device, rt_uint16_t oflag)
     ppp_set_usepeerdns(ppp_device->pcb, 1);
     LOG_D("ppp_set_usepeerdns has set a dns number.");
 
-#ifdef USING_PPP_AUTHORIZE
+#ifdef USING_PRIVATE_APN
     /* set authorize */
  #if PAP_SUPPORT
-     ppp_set_auth(ppp_device->pcb , PPPAUTHTYPE_PAP, ppp_device->config.user_name, ppp_device->config.user_name);
+     ppp_set_auth(ppp_device->pcb , PPPAUTHTYPE_PAP, PRIVATE_APN_ACCOUNT, PRIVATE_APN_PASSWORD);
  #elif CHAP_SUPPORT
      ppp_set_auth(ppp_device->pcb, PPPAUTHTYPE_CHAP, ppp_device->config.user_name, ppp_device->config.user_name);
  #else