* add C027_Support fork

Fork of C027_Support by u-blox

Revision:
62:a02f026bdd7c
Parent:
61:eafa56058398
Child:
65:dd94f920a762
diff -r eafa56058398 -r a02f026bdd7c MDM.cpp
--- a/MDM.cpp	Tue May 13 08:57:04 2014 +0000
+++ b/MDM.cpp	Tue May 13 13:54:05 2014 +0000
@@ -9,6 +9,7 @@
 #define MAX_SIZE        256  // max expected messages
 // some helper 
 #define ISSOCKET(s)     (((s) >= 0) && ((s) < (sizeof(_sockets)/sizeof(*_sockets))))
+#define WAIT_MS(ms)     wait_ms(ms) // you may choose to use Thread::wait(ms)
 
 #ifdef DEBUG
 void dump(const char* buf, int len)
@@ -191,7 +192,7 @@
             }
         }
         // relax a bit
-        wait_ms(10); 
+        WAIT_MS(10); 
     }
     while (timer.read_ms() < timeout_ms);
     timer.stop();
@@ -237,7 +238,7 @@
         if ((netStatus.reg == REG_DENIED) || (i == 0))
             break;;
         i --;
-        wait_ms(1000);
+        WAIT_MS(1000);
     }
     if (dump) dumpNetStatus(&netStatus);
     if ((netStatus.reg == REG_DENIED) || (i == 0))
@@ -252,6 +253,8 @@
 bool MDMParser::init(const char* simpin, DevStatus* status)
 {
     int i = 5;
+    // we should wait some time before 
+    WAIT_MS(1000);
     while (i--) {
         // check interface and disable local echo
         sendFormated("AT\r\n");
@@ -272,7 +275,7 @@
     sendFormated("AT+IPR=115200\r\n");
     if (RESP_OK != waitFinalResp())
         return false;
-    wait_ms(40);
+    WAIT_MS(40);
     // identify the module 
     sendFormated("ATI\r\n");
     if (RESP_OK != waitFinalResp(_cbATI, &_dev.dev))
@@ -323,6 +326,7 @@
         for (int i = 0; (i < 5) && (_dev.sim != SIM_READY); i++) {
             sendFormated("AT+CPIN?\r\n");
             int ret = waitFinalResp(_cbCPIN, &_dev.sim);
+            // having an error here is ok (sim may still be initializing)
             if ((RESP_OK != ret) && (RESP_ERROR != ret))
                 return false;
             // Enter PIN if needed
@@ -334,8 +338,9 @@
                 sendFormated("AT+CPIN=%s\r\n", simpin);
                 if (RESP_OK != waitFinalResp(_cbCPIN, &_dev.sim))
                     return false;
-            } else if (_dev.sim != SIM_READY)
-                wait_ms(1000);
+            } else if (_dev.sim != SIM_READY) {
+                WAIT_MS(1000);
+            }
         }
         if (_dev.sim != SIM_READY)
             return false;
@@ -773,7 +778,7 @@
         sendFormated("AT+USOWR=%d,%d\r\n",socket,len);
         if (RESP_PROMPT != waitFinalResp())
             return SOCKET_ERROR;
-        wait_ms(50);
+        WAIT_MS(50);
         send(buf, len);
         if (RESP_OK != waitFinalResp()) 
             return SOCKET_ERROR;
@@ -788,7 +793,7 @@
         sendFormated("AT+USOWR=%d,\"" IPSTR "\",%d,%d\r\n",socket,IPNUM(ip),port,len);
         if (RESP_PROMPT != waitFinalResp())
             return SOCKET_ERROR;
-        wait_ms(50);
+        WAIT_MS(50);
         send(buf, len);
         if (RESP_OK != waitFinalResp()) 
             return SOCKET_ERROR;