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
Diff: tests/test_TCP_Socket.h
- Revision:
- 115:b26176f23e89
- Parent:
- 96:27bdf4aa3a31
- Child:
- 124:6d964b4343c8
--- a/tests/test_TCP_Socket.h Tue Dec 31 17:32:57 2013 +0000 +++ b/tests/test_TCP_Socket.h Tue Dec 31 21:47:11 2013 +0000 @@ -1,6 +1,8 @@ #ifndef _TEST_TCP_SOCKET_H_ #define _TEST_TCP_SOCKET_H_ +#define CELL_SHIELD 0 // if using a cell shield board, change to 1 + using namespace mts; const char PATTERN_LINE1[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|"; const char PATTERN[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n" @@ -33,8 +35,14 @@ const std::string TEST_SERVER("204.26.122.5"); printf("TCP SOCKET TESTING\r\n"); +#if CELL_SHIELD + Transport::setTransport(Transport::CELLULAR); + MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8); + serial->baud(115200); + Cellular::getInstance()->init(serial); + printf("Setting APN\r\n"); - code = Cellular::getInstance()->setApn("b2b.tmobile.com"); + code = Cellular::getInstance()->setApn("wap.cingular"); if(code == SUCCESS) { printf("Success!\r\n"); } else { @@ -48,16 +56,43 @@ } else { printf("Error setting socket closeable [%d]\r\n", (int)code); } +#else + Transport::setTransport(Transport::WIFI); + MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256); + serial->baud(9600); + Wifi::getInstance()->init(serial); - printf("Establishing PPP Connection\r\n"); - if(Cellular::getInstance()->connect()) { + code = Wifi::getInstance()->setNetwork("Mtech_guest", Wifi::WPA2, "MultiModem2!"); + if(code == SUCCESS) { printf("Success!\r\n"); } else { - printf("Error during PPP connection\r\n"); + printf("Error during network setup [%d]\r\n", (int)code); + } + code = Wifi::getInstance()->setDeviceIP(); + if(code == SUCCESS) { + printf("Success!\r\n"); + } else { + printf("Error during IP setup [%d]\r\n", (int)code); + } +#endif + + printf("Establishing Connection\r\n"); +#if CELL_SHIELD + if(Cellular::getInstance()->connect()) { +#else + if(Wifi::getInstance()->connect()) { +#endif + printf("Success!\r\n"); + } else { + printf("Error during connection\r\n"); } printf("Opening a TCP Socket\r\n"); +#if CELL_SHIELD if(Cellular::getInstance()->open(TEST_SERVER, TEST_PORT, IPStack::TCP)) { +#else + if(Wifi::getInstance()->open(TEST_SERVER, TEST_PORT, IPStack::TCP)) { +#endif printf("Success!\r\n"); } else { printf("Error during TCP socket open [%s:%d]\r\n", TEST_SERVER.c_str(), TEST_PORT); @@ -73,12 +108,20 @@ printf("Closing socket\r\n"); +#if CELL_SHIELD Cellular::getInstance()->close(); +#else + Wifi::getInstance()->close(); +#endif wait(10); printf("Disconnecting\r\n"); +#if CELL_SHIELD Cellular::getInstance()->disconnect(); +#else + Wifi::getInstance()->disconnect(); +#endif } bool testTcpSocketIteration() { @@ -92,7 +135,11 @@ printf("Receiving Data\r\n"); tmr.start(); do { +#if CELL_SHIELD int size = Cellular::getInstance()->read(buffer, bufferSize, 1000); +#else + int size = Wifi::getInstance()->read(buffer, bufferSize, 1000); +#endif if(size != -1) { result.append(buffer, size); } else { @@ -146,21 +193,33 @@ result.clear(); printf("Writing to socket: 2\r\n"); +#if CELL_SHIELD if(Cellular::getInstance()->write("2\r\n", 3, 10000) == 3) { +#else + if(Wifi::getInstance()->write("2\r\n", 3, 10000) == 3) { +#endif printf("Successfully wrote '2'\r\n"); } else { printf("Failed to write '2'\r\n"); return false; } printf("Expecting 'how many ? >:\r\n"); +#if CELL_SHIELD bytesRead = Cellular::getInstance()->read(buffer, bufferSize, 10000); +#else + bytesRead = Wifi::getInstance()->read(buffer, bufferSize, 10000); +#endif if(bytesRead != -1) { result.append(buffer, bytesRead); printf("READ: [%d] [%s]\r\n", bytesRead, result.c_str()); if(result.find("how many") != std::string::npos) { printf("Successfully found 'how many'\r\n"); printf("Writing to socket: 2\r\n"); +#if CELL_SHIELD if(Cellular::getInstance()->write("2\r\n", 3, 10000) == 3) { +#else + if(Wifi::getInstance()->write("2\r\n", 3, 10000) == 3) { +#endif printf("Successfully wrote '2'\r\n"); } else { printf("Failed to write '2'\r\n");