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:
124:6d964b4343c8
Parent:
115:b26176f23e89
Child:
141:571e0ef6c8dc
--- a/tests/test_TCP_Socket.h	Tue Dec 31 23:41:59 2013 +0000
+++ b/tests/test_TCP_Socket.h	Thu Jan 02 18:11:25 2014 +0000
@@ -1,7 +1,12 @@
 #ifndef _TEST_TCP_SOCKET_H_
 #define _TEST_TCP_SOCKET_H_
 
-#define CELL_SHIELD 0 // if using a cell shield board, change to 1
+// 0 for shield board with wifi
+// 1 for shield board with cellular
+#define CELL_SHIELD 0
+
+/* test TCP socket communication
+ * will keep talking to server until data doesn't match expected */
 
 using namespace mts;
 const char PATTERN_LINE1[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|";
@@ -15,7 +20,6 @@
                         "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n"
                         "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}*";
                         
-                        
 const char MENU[] =     "1       send ascii pattern until keypress\r\n"
                         "2       send ascii pattern (numbered)\r\n"
                         "3       send pattern and close socket\r\n"
@@ -31,11 +35,16 @@
 
 void testTcpSocket() {
     Code code;
+    /* this test is set up to interact with a server listening at the following address and port */
     const int TEST_PORT = 7000;
-    const std::string TEST_SERVER("204.26.122.5");
+    const std::string TEST_SERVER("204.26.122.5";
     
     printf("TCP SOCKET TESTING\r\n");
 #if CELL_SHIELD
+    for (int i = 30; i >= 0; i = i - 2) {
+        wait(2);
+        printf("Waiting %d seconds...\n\r", i);
+    }  
     Transport::setTransport(Transport::CELLULAR);
     MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
     serial->baud(115200);
@@ -48,21 +57,17 @@
     } else {
         printf("Error during APN setup [%d]\r\n", (int)code);
     }
-    
-    printf("Setting Socket Closeable\r\n");
-    code = Cellular::getInstance()->setSocketCloseable();
-    if(code == SUCCESS) {
-        printf("Success!\r\n");
-    } else {
-        printf("Error setting socket closeable [%d]\r\n", (int)code);
-    }
 #else
+    for (int i = 6; i >= 0; i = i - 2) {
+        wait(2);
+        printf("Waiting %d seconds...\n\r", i);
+    }  
     Transport::setTransport(Transport::WIFI);
     MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256);
     serial->baud(9600);
     Wifi::getInstance()->init(serial);
     
-    code = Wifi::getInstance()->setNetwork("Mtech_guest", Wifi::WPA2, "MultiModem2!");
+    code = Wifi::getInstance()->setNetwork("your wireless network" /* SSID of wireless */, Wifi::WPA2 /* security type of wireless */, "your wireless network password" /* password for wireless */);
     if(code == SUCCESS) {
         printf("Success!\r\n");
     } else {
@@ -106,7 +111,6 @@
         printf("Successful Iterations: %d\r\n", count);
     }
     
-    
     printf("Closing socket\r\n");
 #if CELL_SHIELD
     Cellular::getInstance()->close();
@@ -125,7 +129,6 @@
 }
 
 bool testTcpSocketIteration() {
-    
     Timer tmr;
     int bytesRead = 0;
     const int bufferSize = 1024;
@@ -188,8 +191,6 @@
         }
     }
     
-    
-
     result.clear();
     
     printf("Writing to socket: 2\r\n");
@@ -233,9 +234,7 @@
         return false;
     }
     
-    
     return true;
 }
 
-
-#endif
+#endif
\ No newline at end of file