It is the project that wifi run on the rtos

Fork of WiflyInterface by Mbed

Files at this revision

API Documentation at this revision

Comitter:
shiyilei
Date:
Fri Dec 05 02:10:34 2014 +0000
Parent:
9:a27cf731e79a
Commit message:
It is the wifi project run on the rtos

Changed in this revision

Socket/Socket.h Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.h Show annotated file Show diff for this revision Revisions of this file
--- a/Socket/Socket.h	Thu May 08 17:09:48 2014 +0000
+++ b/Socket/Socket.h	Fri Dec 05 02:10:34 2014 +0000
@@ -18,7 +18,7 @@
 #ifndef SOCKET_H_
 #define SOCKET_H_
 
-#include "Wifly.h"
+#include "baseinterface.h"
 
 /** Socket file descriptor and select wrapper
   */
@@ -44,7 +44,7 @@
 protected:
     bool _blocking;
     int _timeout;
-    Wifly * wifi;
+    //Wifly * wifi;
 };
 
 
--- a/Socket/TCPSocketConnection.cpp	Thu May 08 17:09:48 2014 +0000
+++ b/Socket/TCPSocketConnection.cpp	Fri Dec 05 02:10:34 2014 +0000
@@ -17,55 +17,70 @@
  */
 
 #include "TCPSocketConnection.h"
+#include "rtos.h"
 #include <algorithm>
 
 TCPSocketConnection::TCPSocketConnection() {}
 
 int TCPSocketConnection::connect(const char* host, const int port)
 {  
-    if (!wifi->connect(host, port))
-        return -1;
-    wifi->flush();
-    return 0;
+    return (base_level_connect(host,port));
 }
 
 bool TCPSocketConnection::is_connected(void)
 {
-    return wifi->is_connected();
+    return base_level_is_connected();
+
 }
 
 int TCPSocketConnection::send(char* data, int length)
 {
-    Timer tmr;
+//    Timer tmr;
 
-    if (!_blocking) {
-        tmr.start();
-        while (tmr.read_ms() < _timeout) {
-            if (wifi->writeable())
-                break;
-        }
-        if (tmr.read_ms() >= _timeout) {
-            return -1;
-        }
-    }
-    return wifi->send(data, length);
+//    if (!_blocking) {
+//        tmr.start();
+//        while (tmr.read_ms() < _timeout) {
+//            if (wifi->writeable())
+//                break;
+//        }
+//        if (tmr.read_ms() >= _timeout) {
+//            return -1;
+//        }
+//    }
+//    return wifi->send(data, length);
+    
 }
 
 // -1 if unsuccessful, else number of bytes written
 int TCPSocketConnection::send_all(char* data, int length)
 {
+    
     Timer tmr;
     int idx = 0;
+       globaldata.send_length=length; 
+    memcpy(globaldata.send_buffer,data,length);
+     globaldata.send_ready=1;           
     tmr.start();
 
     while ((tmr.read_ms() < _timeout) || _blocking) {
 
-        idx += wifi->send(data, length);
+        //idx += wifi->send(data, length);
 
-        if (idx == length)
-            return idx;
-    }
-    return (idx == 0) ? -1 : idx;
+//        idx+=baselevel_send_data(data,length);
+//        if (idx == length)
+//            return idx;
+     if(globaldata.send_completed==1)
+               { 
+                    globaldata.send_completed=0;
+                    memset(globaldata.send_buffer,0,600*sizeof(char));
+                    if(globaldata.send_length_over==length)
+                                            return length;
+        
+                 }
+    //return (idx == 0) ? -1 : idx;
+                     }
+        return (globaldata.send_length_over==0) ? -1 : globaldata.send_length_over;
+    
 }
 
 // -1 if unsuccessful, else number of bytes received
@@ -73,53 +88,86 @@
 {
     Timer tmr;
     int time = -1;
-    
+    int idx=0;
     
     if (!_blocking) {
+                globaldata.need_receive=length;
+                globaldata.receive_start=1;
         tmr.start();
-        while (time < _timeout + 20) {
-            if (wifi->readable()) {
-                break;
+        while (time < _timeout + 30) {
+            if (globaldata.receive_completed==1) {
+                                    globaldata.receive_completed=0;
+                                globaldata.receive_start=0;
+                            break;
             }
+                    
             time = tmr.read_ms();
         }
-        if (time >= _timeout + 20) {
+        if (time >= _timeout + 30) {
             return -1;
         }
     }
 
 
-    while(!wifi->readable());
-    int nb_available = wifi->readable();
-    for (int i = 0; i < min(nb_available, length); i++) {
-        data[i] = wifi->getc();
-    }
+//    while(!wifi->readable());
+//    int nb_available = wifi->readable();
+//    for (int i = 0; i < min(nb_available, length); i++) {
+//        data[i] = wifi->getc();
+//}
+        //int nb_available=baselevel_receive_data(data, length);
+    
 
-    return min(nb_available, length);
+   // return min(nb_available, length);
+     for(int i=0;i<globaldata.receive_length;i++)
+                   if(globaldata.receive_buffer[i]!=0)
+                                        data[idx++]=globaldata.receive_buffer[i];
+                                        globaldata.receive_completed=0;
+
+            return min(globaldata.receive_length, length);
+
 }
 
 
 // -1 if unsuccessful, else number of bytes received
 int TCPSocketConnection::receive_all(char* data, int length)
 {
-    Timer tmr;
+
+        Timer tmr;
     int idx = 0;
     int time = -1;
-
+    globaldata.receive_start=1;
+    globaldata.need_receive=length;
     tmr.start();
-    
+
     while (time < _timeout || _blocking) {
 
-        int nb_available = wifi->readable();
-        for (int i = 0; i < min(nb_available, length); i++) {
-            data[idx++] = wifi->getc();
+        // int nb_available = wifi->readable();
+        // for (int i = 0; i < min(nb_available, length); i++) {
+        //     data[idx++] = wifi->getc();
+        // }
+        // 
+        // my code:
+         //idx=baselevel_receive_data(data,length);
+
+        // if (idx == length)
+        //     break;
+
+        if(globaldata.receive_completed==1)
+        {
+                for(int i=0;i<globaldata.receive_length;i++)
+                   if(globaldata.receive_buffer[i]!=0)
+                                        data[idx++]=globaldata.receive_buffer[i];
+                                        globaldata.receive_completed=0;
         }
-
-        if (idx == length)
+        if(idx==length)
             break;
 
         time = tmr.read_ms();
     }
 
-    return (idx == 0) ? -1 : idx;
+    //return (idx == 0) ? -1 : idx;
+    return (idx==0) ? -1 : idx;
+    
+    
+    
 }
--- a/Socket/TCPSocketConnection.h	Thu May 08 17:09:48 2014 +0000
+++ b/Socket/TCPSocketConnection.h	Fri Dec 05 02:10:34 2014 +0000
@@ -21,7 +21,7 @@
 
 #include "Socket.h"
 #include "Endpoint.h"
-
+#include "sysinterface.h"
 /**
 TCP socket connection
 */