Forked mbed official WiflyInterface (interface for Roving Networks Wifly modules) which includes the possibility to use TCPSocketServer::accept as a non-blocking cal.

Dependents:   WiFlyHTTPServerSample MultiThreadingHTTPServer

Fork of WiflyInterface by mbed official

Revision:
9:4f6f2f35a21a
Parent:
8:ac134ae11893
Child:
10:d84defb718ab
--- a/Wifly/Wifly.cpp	Sun Jun 02 00:26:25 2013 +0000
+++ b/Wifly/Wifly.cpp	Wed Jun 05 23:40:17 2013 +0000
@@ -64,7 +64,7 @@
     }
 
     inst = this;
-    attach_rx(false);
+    attach_rx(false);    
     state.cmd_mode = false;
     
     reset();
@@ -205,7 +205,7 @@
         ERR("Failed to set time zone !");
     }
 
-    sendCommand("time\r", NULL, NULL);
+    sendCommand("time\r", NULL, NULL, 1000);
     
     flush();
         
@@ -230,20 +230,23 @@
 bool Wifly::setBaudRate(int baud)
 {
     char str[35];
-    bool bfound = false;
+    bool bfound = true;
     
     INFO("Trying baudrates.\n");
     sprintf(str, "set uart raw %d\r", baud);
-    for( int i = 0 ; i < sizeof(std_baudrates)/sizeof(int) ; i++) {
-        //  try all standard baudrates until the correct one is found
-        INFO("Trying at %d baud\n", std_baudrates[i]);
-        wifi.baud(std_baudrates[i]);
-        if (sendCommand(str, "AOK")) {
-            bfound = true;
-            break;
+
+    wifi.baud(baud);
+    if (!sendCommand(str, "AOK")) {
+        for( int i = 0 ; i < sizeof(std_baudrates)/sizeof(int) ; i++) {
+            //  try all standard baudrates until the correct one is found
+            INFO("Trying at %d baud\n", std_baudrates[i]);
+            wifi.baud(std_baudrates[i]);
+            if (sendCommand(str, "AOK")) {
+                bfound = true;
+                break;
+            }
         }
     }
-    
     if (bfound) {
         wait(0.05);
         if (!sendCommand("save\r", "STOR"))
@@ -461,7 +464,7 @@
     wait(0.25);
     if (!sendCommand("close\r", "CLOS"))
         return false;
-    exit();
+    exit(false);
 
     state.tcp = false;
     return true;
@@ -475,15 +478,17 @@
 }
 
 
-bool Wifly::exit()
+bool Wifly::exit(bool bflush)
 {
-    flush();
+    if (bflush)
+        flush();
     if (!state.cmd_mode)
         return true;
     if (!sendCommand("exit\r", "EXIT"))
         return false;
     state.cmd_mode = false;
-    flush();
+    if (bflush)
+        flush();
     return true;
 }
 
@@ -506,6 +511,17 @@
     return c;
 }
 
+
+char Wifly::peek()
+{
+    char c;
+    while (!buf_wifly.available())
+        ;
+   buf_wifly.peek(&c);
+   return c;
+}
+
+
 void Wifly::handler_rx(void)
 {
     //read characters
@@ -536,7 +552,10 @@
 
     //We flush the buffer
     while (wifi.readable())
-        wifi.getc();
+    {
+        char c = wifi.getc();
+        INFO("Flushing : %c",c);
+    }
 
     if (!ACK || !strcmp(ACK, "NO")) {
         for (int i = 0; i < len; i++)
@@ -544,7 +563,10 @@
     } else {
         //We flush the buffer
         while (wifi.readable())
-            wifi.getc();
+        {
+            char c = wifi.getc();
+            INFO("Flushing : %c",c);
+        }
 
         tmr.start();
         for (int i = 0; i < len; i++)