A library for talking to Multi-Tech's Cellular SocketModem Devices.

Dependents:   M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more

Revision:
143:c7d8fe37981b
Parent:
141:571e0ef6c8dc
Child:
146:efc4db23a564
--- a/cellular/Cellular.cpp	Sat Jan 04 21:09:13 2014 +0000
+++ b/cellular/Cellular.cpp	Sun Jan 05 05:49:42 2014 +0000
@@ -83,8 +83,13 @@
         dtr->write(0);
     }
     instance->io = io;
-
-    return (test() == SUCCESS);
+    
+    test();
+    // Reset radio to make sure it's in a good state and wait for it to come back
+    reset();
+    test();
+    
+    return SUCCESS;
 }
 
 
@@ -573,24 +578,15 @@
 
 Code Cellular::test()
 {
-    bool basicRadioComms = false;
     Code code;
-    Timer tmr;
-    tmr.start();
-    do {
-        printf("[DEBUG] Attempting basic radio communication\r\n");
-        code = sendBasicCommand("AT", 1000);
-        if(code == SUCCESS) {
-            basicRadioComms = true;
-            break;
-        } else {
-            wait(1);
+    int i = 0;
+    while (sendBasicCommand("AT", 1000) != SUCCESS) {
+        i++;
+        if (i >= 30) {
+            printf("[ERROR] Could not talk to radio after 30 tries\r\n");
+            i = 0;
         }
-    } while(tmr.read() < 15);
-
-    if(!basicRadioComms) {
-        printf("[ERROR] Unable to communicate with the radio\r\n");
-        return FAILURE;
+        wait(1);
     }
 
     return SUCCESS;
@@ -842,14 +838,18 @@
     //Attempt to write command
     if(io->write(command.data(), command.size(), timeoutMillis) != command.size()) {
         //Failed to write command
-        printf("[ERROR] failed to send command to radio within %d milliseconds\r\n", timeoutMillis);
+        if (command != "AT" && command != "at") {
+            printf("[ERROR] failed to send command to radio within %d milliseconds\r\n", timeoutMillis);
+        }
         return "";
     }
 
     //Send Escape Character
     if (esc != 0x00) {
         if(io->write(esc, timeoutMillis) != 1) {
-            printf("[ERROR] failed to send character '%c' (0x%02X) to radio within %d milliseconds\r\n", esc, esc, timeoutMillis);
+            if (command != "AT" && command != "at") {
+                printf("[ERROR] failed to send character '%c' (0x%02X) to radio within %d milliseconds\r\n", esc, esc, timeoutMillis);
+            }
             return "";
         }
     }
@@ -879,7 +879,9 @@
             done =  (result.size() == previous);
         }
         if(timer >= timeoutMillis) {
-            printf("[WARNING] sendCommand [%s] timed out after %d milliseconds\r\n", command.c_str(), timeoutMillis);
+            if (command != "AT" && command != "at") {
+                printf("[WARNING] sendCommand [%s] timed out after %d milliseconds\r\n", command.c_str(), timeoutMillis);
+            }
             done = true;
         }
     } while (!done);