Multi-Hackers / SocketModem

Dependents:   M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more

Revision:
68:c490e4a51778
Parent:
55:56d9a9d98079
Child:
71:82205735732b
--- a/tests/test_TCP_Socket_Echo.h	Mon Dec 23 19:55:31 2013 +0000
+++ b/tests/test_TCP_Socket_Echo.h	Tue Dec 24 01:15:44 2013 +0000
@@ -3,6 +3,7 @@
 
 
 //Setup a netcat server with command: ncat -l 5798 -k -c 'xargs -n1 --null echo'
+bool testTcpSocketEchoLoop();
 
 void testTcpSocketEcho() {
     using namespace mts;
@@ -10,9 +11,6 @@
     Cellular::Code code;
     const int TEST_PORT = 5798;
     const std::string TEST_SERVER("204.26.122.96");
-    const char buffer[] = "*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890*";
-    const int size = sizeof(buffer); 
-    char echoData[size];
     
     printf("TCP SOCKET TESTING\r\n");
     printf("Setting APN\r\n");
@@ -62,6 +60,25 @@
         return;
     }
     
+    int count = 0;
+    while(testTcpSocketEchoLoop()) {
+        count++;  
+        printf("Successful Echos: [%d]\r\n", count);  
+    }
+        
+    printf("Closing socket\r\n");
+    Cellular::getInstance()->close();
+    
+    
+    //printf("Disconnecting\r\n");
+//    Cellular::getInstance()->disconnect();   
+}
+
+bool testTcpSocketEchoLoop() {
+    const char buffer[] = "*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890*";
+    const int size = sizeof(buffer); 
+    char echoData[size];
+    
     printf("Sending buffer\r\n");
     int bytesWritten = Cellular::getInstance()->write(buffer, size, 10000);
     if(bytesWritten == size) {
@@ -69,7 +86,7 @@
     } else {
         printf("Failed to send buffer.  Closing socket and aborting.\r\n");
         Cellular::getInstance()->close();
-        return;
+        return false;
     }
     
     printf("Receiving echo (timeout = 15 seconds)\r\n");
@@ -83,7 +100,7 @@
         } else {
             printf("Error reading from socket.  Closing socket and aborting.\r\n");
             Cellular::getInstance()->close();
-            return;
+            return false;
         }
         printf("Total bytes read %d\r\n", bytesRead);
     } while (tmr.read_ms() <= 15000 && bytesRead < size);
@@ -92,22 +109,16 @@
     //Safely Cap at Max Size
     echoData[size - 1] = '\0';
     printf("Comparing Buffers\r\n");
-    printf("SENT: [%s]\r\n", buffer);
-    printf("RECV: [%s]\r\n", echoData);
+    printf("SENT [%d]: [%s]\r\n", size, buffer);
+    printf("RECV [%d]: [%s]\r\n", bytesRead, echoData);
     
     for(int i = 0; i < size - 1; i++) {
         if(buffer[i] != echoData[i]) {
             printf("Buffers do not match at index %d\r\n", i);
-            break;   
+            return false;   
         }   
-    }
-        
-    printf("Closing socket\r\n");
-    Cellular::getInstance()->close();
-    
-    
-    printf("Disconnecting\r\n");
-    Cellular::getInstance()->disconnect();   
+    }   
+    return true;
 }
 
 #endif