GainSpan Wi-Fi library see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Dependents:   GSwifi_httpd GSwifi_websocket GSwifi_tcpclient GSwifi_tcpserver ... more

Fork of GSwifi by gs fan

GainSpan Wi-Fi library

The GS1011 is an ultra low power 802.11b wireless module from GainSpan.

see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

/media/uploads/gsfan/gs_im_002.jpg /media/uploads/gsfan/gs1011m_2.jpg

ゲインスパン Wi-Fi モジュール ライブラリ

ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。

解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Revision:
26:b347ee3a1087
Parent:
25:f6e5622d2930
Child:
28:fbba4c58d14c
--- a/GSwifi_sock.cpp	Mon Feb 11 06:01:46 2013 +0000
+++ b/GSwifi_sock.cpp	Fri Feb 22 01:05:10 2013 +0000
@@ -25,7 +25,8 @@
 #include "GSwifi.h"
 
 
-void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {
+//void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {
+void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro) {
     _gs_sock[cid].type = type;
     _gs_sock[cid].protocol = pro;
     _gs_sock[cid].connect = true;
@@ -35,8 +36,7 @@
         _gs_sock[cid].data->flush();
     }
     _gs_sock[cid].lcid = 0;
-    _gs_sock[cid].received = 0;
-    _gs_sock[cid].onGsReceive = ponGsReceive;
+    _gs_sock[cid].received = false;
 }
 
 int GSwifi::open (Host &host, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {
@@ -91,7 +91,6 @@
 
 int GSwifi::send (int cid, const char *buf, int len) {
     int i;
-    Timer timeout;
 
     if (! _gs_sock[cid].connect) return -1;
 
@@ -99,8 +98,7 @@
       (_gs_sock[cid].protocol == GSPROT_UDP && _gs_sock[cid].type == GSTYPE_CLIENT) ||
       (_gs_sock[cid].protocol == GSPROT_HTTPD)) {
         // TCP Client, TCP Server, UDP Client
-        _gs_ok = 0;
-        _gs_failure = 0;
+        resetResponse(GSRES_NONE);
 #ifdef GS_BULK
         _gs.printf("\x1bZ%X%04d", cid, len);
         for (i = 0; i < len; i ++) {
@@ -125,21 +123,18 @@
     } else {
         return -1;
     }
-    timeout.start();
-    while (!_gs_ok && !_gs_failure && timeout.read_ms() < GS_TIMEOUT);
-    return _gs_ok == 1 ? 0 : -1;
+    
+    return waitResponse(GS_TIMEOUT);
 }
 
 int GSwifi::send (int cid, const char *buf, int len, Host &host) {
     int i;
-    Timer timeout;
 
     if (! _gs_sock[cid].connect) return -1;
 
     if ((_gs_sock[cid].protocol == GSPROT_UDP && _gs_sock[cid].type == GSTYPE_SERVER)) {
         // UDP Server
-        _gs_ok = 0;
-        _gs_failure = 0;
+        resetResponse(GSRES_NONE);
 #ifdef GS_BULK
         _gs.printf("\x1bY%X", cid);
         _gs.printf("%d.%d.%d.%d:%d:", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort());
@@ -167,9 +162,8 @@
     } else {
         return -1;
     }
-    timeout.start();
-    while (!_gs_ok && !_gs_failure && timeout.read_ms() < GS_TIMEOUT);
-    return _gs_ok == 1 ? 0 : -1;
+
+    return waitResponse(GS_TIMEOUT);
 }
 
 int GSwifi::recv (int cid, char *buf, int len) {
@@ -179,7 +173,7 @@
     if (_gs_sock[cid].data == NULL) return 0;
 
     timeout.start();
-    while (_gs_sock[cid].data->use() == 0) {
+    while (_gs_sock[cid].data->isEmpty()) {
         if (timeout.read_ms() > GS_TIMEOUT) return 0;
     }
     timeout.stop();
@@ -197,7 +191,7 @@
     if (_gs_sock[cid].data == NULL) return 0;
 
     timeout.start();
-    while (_gs_sock[cid].data->use() == 0) {
+    while (_gs_sock[cid].data->isEmpty()) {
         if (timeout.read_ms() > GS_TIMEOUT) return 0;
     }
     timeout.stop();