Add a bunch of APNs

Fork of C027_Support by Xinlei Cao

Revision:
23:05a1aeeb5fd9
Parent:
22:29322c22577e
Child:
24:0e287a85ac9e
--- a/MDM.cpp	Tue Apr 08 09:17:50 2014 +0000
+++ b/MDM.cpp	Tue Apr 08 11:11:20 2014 +0000
@@ -2,7 +2,7 @@
 #include <ctype.h>
 #include "MDM.h"
 
-#define TRACE           (1)?:printf
+#define TRACE           (0)?:printf
 //#define DEBUG           
 #define PROFILE         "0"   // this is the psd profile used
 #define MAX_SIZE        256  // max expected messages
@@ -32,6 +32,7 @@
     _net     = NET_UNKNOWN;
     _ip      = 0;
     _rssi    = 0;
+    *_num    = '\0';
     for (int socket = 0; socket < sizeof(_sockets)/sizeof(*_sockets); socket++) {
         _sockets[socket].state = SOCK_FREE;
         _sockets[socket].pending = 0;
@@ -81,11 +82,11 @@
             if (type == TYPE_PLUS) {
                 const char* cmd = buf+3;
                 int a, b, c, d;
-                char s[8];
+                char s[32];
 
                 // +CSQ: <rssi>,<qual>
                 if (sscanf(cmd, "CSQ: %d,%d",&a,&b) == 2) {
-                    if (a != 99) _rssi = -113 - 2*a;  // 0: -113 1: -111 ... 30: -53 dBm with 2 dBm steps
+                    if (a != 99) _rssi = -113 + 2*a;  // 0: -113 1: -111 ... 30: -53 dBm with 2 dBm steps
                     //if (b != 99) int qual = b;  // 
                 // Socket Specific Command ---------------------------------
                 // +UUSORD: <socket>,<length>
@@ -145,8 +146,11 @@
                     //  if      (a == 0) ;                    // 0: GSM, 
                     //  else if (a == 2) ;                    // 2: UTRAN
                     // +CPIN: <code>
-                    } else if (sscanf(cmd, "CPIN: %8s",s) == 1) {
+                    } else if (sscanf(cmd, "CPIN: %7s",s) == 1) {
                         _sim = (strcmp("READY", s) == 0) ? SIM_READY : SIM_UNKNOWN;
+                    // +CNUM: <code>
+                    } else if (sscanf(cmd, "CNUM: \"My Number\",\"%31[^\"]\",%d", s, &a) == 2) {
+                        if ((a == 129) || (a == 145)) strncpy(_num, s, sizeof(_num));
                     // +UPSND=<profile_id>,<param_tag>[,<dynamic_param_val>]
                     } else if (sscanf(cmd, "UPSND: " PROFILE ",0,\"" IPSTR "\"", &a,&b,&c,&d) == 4) {
                         _ip = IPADR(a,b,c,d);
@@ -313,6 +317,10 @@
     sendFormated("AT+CSQ\r\n");
     if (OK != waitFinalResp())
         return false;
+    if (*_num)
+        TRACE("Phone number: \"%s\"\n", _num);
+    if (_rssi)
+        TRACE("Signal Strength: %d dBm\n", _rssi);
     return true;
 }
 
@@ -392,7 +400,7 @@
     }
     if (!_ip)
         return false;
-    printf("Got IP address: " IPSTR "\n",  IPNUM(_ip));
+    TRACE("Got IP address: " IPSTR "\n",  IPNUM(_ip));
     return true;
 }