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

Files at this revision

API Documentation at this revision

Comitter:
jengbrecht
Date:
Mon Dec 30 22:54:55 2013 +0000
Parent:
99:eba6b99bc80c
Child:
102:914226a5e530
Child:
103:da58d27c15d7
Commit message:
Got all Wifi commands working in a stable way, except reset. Was able to perform a successful loopback test.

Changed in this revision

wifi/Wifi.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/wifi/Wifi.cpp	Mon Dec 30 20:04:50 2013 +0000
+++ b/wifi/Wifi.cpp	Mon Dec 30 22:54:55 2013 +0000
@@ -129,9 +129,10 @@
         printf("[ERROR] Failed in disconnecting from network.  Continuing ...\r\n");
     }
 
-    std::string response = sendCommand("leave", 20000);
-    printf("Response: %s\n\r", response.c_str());
-    if (response.find("DeAuth") != string::npos) {
+    std::string response = sendCommand("leave", 10000, "<4.00>");
+    response = sendCommand("show net", 5000, "Links");
+    //printf("Response: %s\n\r", response.c_str());
+    if (response.find("Assoc=FAIL") != string::npos) {
         printf("[DEBUG] Successfully disconnected from network\r\n");
     } else {
         printf("[ERROR] Failed in disconnecting from network.  Continuing ...\r\n");
@@ -254,10 +255,8 @@
         printf("[ERROR] Host address could not be set\r\n");
     }
 
-    if(sendBasicCommand("set ip host " + address, 1000) == SUCCESS) {
-        host_address = address;
-    } else {
-        printf("[ERROR] Host address could not be set\r\n");
+    if(sendBasicCommand("set ip protocol 8", 1000) != SUCCESS) {
+        printf("[ERROR] Failed to set TCP mode\r\n");
     }
 
     // Try and Connect
@@ -267,15 +266,15 @@
         sOpenSocketCmd = "open";
         sMode = "TCP";
     } else {
-        sOpenSocketCmd = "AT#OUDP";
-        sMode = "UDP";
+        //TODO
+        //sOpenSocketCmd = "AT#OUDP";
+        //sMode = "UDP";
     }
-    string response = sendCommand(sOpenSocketCmd, 20000, "OPEN");
-    printf("Open Response: %s\n\r", response.c_str());
+    string response = sendCommand(sOpenSocketCmd, 10000, "OPEN");
     if (response.find("OPEN") != string::npos) {
         printf("[INFO] Opened %s Socket [%s:%d]\r\n", sMode.c_str(), address.c_str(), port);
         socketOpened = true;
-        cmdOn = false; //Need to make sure that this is true...
+        cmdOn = false;
     } else {
         printf("[WARNING] Unable to open %s Socket [%s:%d]\r\n", sMode.c_str(),  address.c_str(), port);
         socketOpened = false;
@@ -343,48 +342,6 @@
         bytesRead = io->read(data, max);
     }
 
-    if(bytesRead > 0 && socketCloseable) {
-        //Remove escape characters
-        int index = 0;
-        bool escapeFlag = false;
-        for(int i = 0; i < bytesRead; i++) {
-            if(data[i] == DLE || data[i] == ETX) {
-                if(escapeFlag == true) {
-                    //This character has been escaped
-                    escapeFlag = false;
-                } else if(data[bytesRead] == DLE) {
-                    //Found escape character
-                    escapeFlag = true;
-                    continue;
-                } else {
-                    //ETX sent without escape -> Socket closed
-                    printf("[INFO] Read ETX character without DLE escape. Socket closed\r\n");
-                    socketOpened = false;
-                    continue;
-                }
-            }
-
-            if(index != i) {
-                data[index] = data[i];
-            }
-            index++;
-        }
-        bytesRead = index;
-    }
-
-    //Scan for socket closed message
-    for(size_t i = 0; i < bytesRead; i++) {
-        if(data[i] == 'O') {
-            if(strstr(&data[i], "Ok_Info_SocketClosed")) {
-                printf("[INFO] Found socket closed message. Socket closed\r\n");
-                //Close socket and Cut Off End of Message
-                socketOpened = false;
-                data[i] = '\0';
-                bytesRead = i;
-                break;
-            }
-        }
-    }
     return bytesRead;
 }
 
@@ -407,22 +364,13 @@
     }
 
     int bytesWritten = 0;
+    
     if(timeout >= 0) {
-        Timer tmr;
-        tmr.start();
-        do {
-            int available = io->writeable();
-            if (available > 0) {
-                int size = MIN(available, length - bytesWritten);
-                bytesWritten += io->write(&data[bytesWritten], size);
-            } else {
-                wait(0.05);
-            }
-        } while (tmr.read_ms() <= timeout && bytesWritten < length);
+        bytesWritten = io->write(data, length, static_cast<unsigned int>(timeout));
     } else {
-        bytesWritten = io->write(&data[bytesWritten], length - bytesWritten);
+        bytesWritten = io->write(data, length);
     }
-
+    
     return bytesWritten;
 }
 
@@ -594,7 +542,7 @@
         printf("[ERROR] MTSBufferedIO not set\r\n");
         return "";
     }
-    if(socketOpened && command.compare("$$") != 0 && command.compare("exit") != 0) {
+    if(socketOpened && command.compare("$$") != 0 && command.compare("exit") != 0 && command.compare("close") != 0) {
         printf("[ERROR] socket is open. Can not send AT commands\r\n");
         return "";
     }