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:
58:408f67fa292f
Parent:
39:6e94520a3217
Child:
71:82205735732b
--- a/tests/test_TCP_Socket.h	Fri Dec 20 16:26:10 2013 +0000
+++ b/tests/test_TCP_Socket.h	Fri Dec 20 21:10:13 2013 +0000
@@ -39,9 +39,24 @@
         printf("Error during TCP socket open [%s:%d]\r\n", TEST_SERVER.c_str(), TEST_PORT);
     }
     
-    printf("Reading from socket for 15 seconds\r\n");
-    char data[1024] = { 0 };
-    int bytesRead = Cellular::getInstance()->read(data, 1023, 15000);    //1 less than max
+    printf("Receiving Data (timeout = 15 seconds)\r\n");
+    Timer tmr;
+    int bytesRead = 0;
+    const int size = 1024;
+    char data[size] = { 0 };
+    tmr.start();
+    do {
+        int status = Cellular::getInstance()->read(&data[bytesRead], size - bytesRead, 1000);
+        if(status != -1) {
+            bytesRead += status;
+        } else {
+            printf("Error reading from socket\r\n");
+            data[bytesRead] = '\0';
+            break;
+        }
+        printf("Total bytes read %d\r\n", bytesRead);
+    } while (tmr.read_ms() <= 15000 && bytesRead < size);
+   
     printf("READ: [%d] [%s]\r\n", bytesRead, data);
     
         
@@ -57,13 +72,25 @@
         printf("Failed to write 'q'\r\n");   
     }
     
-    printf("Reading from socket for 15 seconds\r\n");
-    bytesRead = Cellular::getInstance()->read(data, 1023, 15000);    //1 less than max
+    bytesRead = 0;
+    tmr.start();
+    do {
+        int status = Cellular::getInstance()->read(&data[bytesRead], size - bytesRead, 1000);
+        if(status != -1) {
+            bytesRead += status;
+        } else {
+            printf("Error reading from socket\r\n");
+            data[bytesRead] = '\0';
+            break;
+        }
+        printf("Total bytes read %d\r\n", bytesRead);
+    } while (tmr.read_ms() <= 15000 && bytesRead < size);
     printf("READ: [%d] [%s]\r\n", bytesRead, data);
    
     printf("Closing socket\r\n");
     Cellular::getInstance()->close();
     
+    wait(10);
     
     printf("Disconnecting\r\n");
     Cellular::getInstance()->disconnect();