Simple detection for LE910-NA1 modules

Fork of MTS-Cellular by MultiTech

Revision:
35:257eb41405e1
Parent:
26:2b769ed8de4f
Child:
36:948d06b3e23c
--- a/Cellular/Cellular.cpp	Wed Jul 16 15:05:10 2014 +0000
+++ b/Cellular/Cellular.cpp	Mon Jul 21 20:14:18 2014 +0000
@@ -197,7 +197,9 @@
             return "";
         }
     }
-
+    int time_done = 0;
+    //Time in 100s of milliseconds maximum between character transmissions
+    const int MAX_INPUT_DELAY = 2;
     int timer = 0;
     size_t previous = 0;
     char tmp[256];
@@ -207,7 +209,7 @@
     do {
         wait(0.1);
         timer += 100;
-
+        
         previous = result.size();
         //Make a non-blocking read call by passing timeout of zero
         int size = io->read(tmp,255,0);    //1 less than allocated (timeout is instant)
@@ -220,7 +222,16 @@
                 started = true;
             }
         } else {
-            done =  (result.size() == previous);
+            //Uses an timer to make sure no characters are received
+            //within a period of time after the last recevied character.
+            if(result.size() == previous) {
+                time_done++;
+                if(time_done > MAX_INPUT_DELAY) {
+                    done = true;
+                }
+            } else {
+                time_done = 0;
+            }
         }
         if(timer >= timeoutMillis) {
             if (command != "AT" && command != "at") {
@@ -257,9 +268,9 @@
         logError("CSMP failed [%s]", getRadioNames(type).c_str());
         return code;
     }
-    string cmd = "AT+CMGS=\"+";
+    string cmd = "AT+CMGS=\"";
     cmd.append(phoneNumber);
-    cmd.append("\",145");
+    cmd.append("\"");
     for (int i = 0; i < 5; i++) {
         string response1 = sendCommand(cmd, 1000);
         if (response1.find('>') != string::npos) {
@@ -295,7 +306,7 @@
         return vSms;
     }
     
-    received = sendCommand("AT+CMGL=\"ALL\"", 4000);
+    received = sendCommand("AT+CMGL=\"ALL\"", 5000);
     pos = received.find("+CMGL: ");
 
     while (pos != std::string::npos) {
@@ -304,7 +315,6 @@
         if(line.find("+CMGL: ") == std::string::npos) {
             continue;
         }
-
         //Start of SMS message
         std::vector<std::string> vSmsParts = Text::split(line, ',');
         if (type == MTSMC_H5_IP || type == MTSMC_H5) {
@@ -349,7 +359,6 @@
             //This must be the last SMS message
             bodyEnd = received.find("\r\n\r\nOK", pos);
         }
-
         //Safety check that we found the boundary of this current SMS message
         if(bodyEnd != std::string::npos) {
             sms.message = received.substr(pos, bodyEnd - pos);