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

Committer:
mfiore
Date:
Thu Dec 19 19:49:58 2013 +0000
Revision:
39:6e94520a3217
Parent:
19:38794784e009
Child:
58:408f67fa292f
add mts namespace to files in cellular/, io/, and utils/ directories; prepend CELL_ to some enums in cellular.h to avoid conflict with HTTPClient class; added AxedaWrapper class for sending data to Axeda backend

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sgodinez 19:38794784e009 1 #ifndef _TEST_TCP_SOCKET_H_
sgodinez 19:38794784e009 2 #define _TEST_TCP_SOCKET_H_
sgodinez 19:38794784e009 3
mfiore 39:6e94520a3217 4 using namespace mts;
mfiore 39:6e94520a3217 5
sgodinez 19:38794784e009 6 void testTcpSocket() {
sgodinez 19:38794784e009 7 Cellular::Code code;
sgodinez 19:38794784e009 8 const int TEST_PORT = 7000;
sgodinez 19:38794784e009 9 const std::string TEST_SERVER("204.26.122.5");
sgodinez 19:38794784e009 10
sgodinez 19:38794784e009 11 printf("TCP SOCKET TESTING\r\n");
sgodinez 19:38794784e009 12 printf("Setting APN\r\n");
sgodinez 19:38794784e009 13 code = Cellular::getInstance()->setApn("b2b.tmobile.com");
mfiore 39:6e94520a3217 14 if(code == Cellular::CELL_OK) {
sgodinez 19:38794784e009 15 printf("Success!\r\n");
sgodinez 19:38794784e009 16 } else {
sgodinez 19:38794784e009 17 printf("Error during APN setup [%d]\r\n", (int)code);
sgodinez 19:38794784e009 18 }
sgodinez 19:38794784e009 19
sgodinez 19:38794784e009 20 printf("Setting Socket Closeable\r\n");
sgodinez 19:38794784e009 21 code = Cellular::getInstance()->setSocketCloseable();
mfiore 39:6e94520a3217 22 if(code == Cellular::CELL_OK) {
sgodinez 19:38794784e009 23 printf("Success!\r\n");
sgodinez 19:38794784e009 24 } else {
sgodinez 19:38794784e009 25 printf("Error setting socket closeable [%d]\r\n", (int)code);
sgodinez 19:38794784e009 26 }
sgodinez 19:38794784e009 27
sgodinez 19:38794784e009 28 printf("Establishing PPP Connection\r\n");
sgodinez 19:38794784e009 29 if(Cellular::getInstance()->connect()) {
sgodinez 19:38794784e009 30 printf("Success!\r\n");
sgodinez 19:38794784e009 31 } else {
sgodinez 19:38794784e009 32 printf("Error during PPP connection\r\n");
sgodinez 19:38794784e009 33 }
sgodinez 19:38794784e009 34
sgodinez 19:38794784e009 35 printf("Opening a TCP Socket\r\n");
sgodinez 19:38794784e009 36 if(Cellular::getInstance()->open(TEST_SERVER, TEST_PORT, IPStack::TCP)) {
sgodinez 19:38794784e009 37 printf("Success!\r\n");
sgodinez 19:38794784e009 38 } else {
sgodinez 19:38794784e009 39 printf("Error during TCP socket open [%s:%d]\r\n", TEST_SERVER.c_str(), TEST_PORT);
sgodinez 19:38794784e009 40 }
sgodinez 19:38794784e009 41
sgodinez 19:38794784e009 42 printf("Reading from socket for 15 seconds\r\n");
sgodinez 19:38794784e009 43 char data[1024] = { 0 };
sgodinez 19:38794784e009 44 int bytesRead = Cellular::getInstance()->read(data, 1023, 15000); //1 less than max
sgodinez 19:38794784e009 45 printf("READ: [%d] [%s]\r\n", bytesRead, data);
sgodinez 19:38794784e009 46
sgodinez 19:38794784e009 47
sgodinez 19:38794784e009 48 printf("Waiting 10 seconds\r\n");
sgodinez 19:38794784e009 49 wait(10);
sgodinez 19:38794784e009 50
sgodinez 19:38794784e009 51 printf("Writing to socket\r\n");
sgodinez 19:38794784e009 52 sprintf(data, "3\r\n");
sgodinez 19:38794784e009 53 int bytesWritten = Cellular::getInstance()->write(data, 4, 10000);
sgodinez 19:38794784e009 54 if(bytesWritten == 4) {
sgodinez 19:38794784e009 55 printf("Successfully wrote 'q'\r\n");
sgodinez 19:38794784e009 56 } else {
sgodinez 19:38794784e009 57 printf("Failed to write 'q'\r\n");
sgodinez 19:38794784e009 58 }
sgodinez 19:38794784e009 59
sgodinez 19:38794784e009 60 printf("Reading from socket for 15 seconds\r\n");
sgodinez 19:38794784e009 61 bytesRead = Cellular::getInstance()->read(data, 1023, 15000); //1 less than max
sgodinez 19:38794784e009 62 printf("READ: [%d] [%s]\r\n", bytesRead, data);
sgodinez 19:38794784e009 63
sgodinez 19:38794784e009 64 printf("Closing socket\r\n");
sgodinez 19:38794784e009 65 Cellular::getInstance()->close();
sgodinez 19:38794784e009 66
sgodinez 19:38794784e009 67
sgodinez 19:38794784e009 68 printf("Disconnecting\r\n");
sgodinez 19:38794784e009 69 Cellular::getInstance()->disconnect();
sgodinez 19:38794784e009 70 }
sgodinez 19:38794784e009 71
sgodinez 19:38794784e009 72 #endif