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/

Files at this revision

API Documentation at this revision

Comitter:
gsfan
Date:
Thu Jul 12 13:36:04 2012 +0000
Parent:
1:b127c6c5241d
Child:
3:1345daf4ec1a
Commit message:
fix powerSave

Changed in this revision

GSwifi.cpp Show annotated file Show diff for this revision Revisions of this file
GSwifi.h Show annotated file Show diff for this revision Revisions of this file
dbg.h Show annotated file Show diff for this revision Revisions of this file
--- a/GSwifi.cpp	Thu Jul 12 08:19:50 2012 +0000
+++ b/GSwifi.cpp	Thu Jul 12 13:36:04 2012 +0000
@@ -289,7 +289,9 @@
         // dummy CR+LF
         _gs.printf("\r\n");
         wait_ms(100);
-        while (_gs.readable()) _gs_getc(); // dummy read
+        while (_gs.readable()) {
+            _gs_getc(); // dummy read
+        }
         return 0;
     }
 
@@ -654,6 +656,7 @@
     netmask = _netmask;
     gateway = _gateway;
     nameserver = _nameserver;
+    return 0;
 }
 
 int GSwifi::getHostByName (const char* name, IpAddr &addr) {
@@ -689,18 +692,14 @@
     return command(cmd, GSRES_NORMAL);
 }
 
-int GSwifi::powerSave (int beacon, int association) {
+int GSwifi::powerSave (int active, int save) {
     char cmd[GS_CMD_SIZE];
 
     if (_status != GSSTAT_READY) return -1;
 
-    sprintf(cmd, "AT+WAPSM=%d", association);
+    sprintf(cmd, "AT+WRXACTIVE=%d", active);
     command(cmd, GSRES_NORMAL);
-    if (beacon) {
-        sprintf(cmd, "AT+WRXPS=1,%d", beacon);
-    } else {
-        strcpy(cmd, "AT+WRXPS=0");
-    }
+    sprintf(cmd, "AT+WRXPS=1,%d", save);
     return command(cmd, GSRES_NORMAL);
 }
 
@@ -845,7 +844,7 @@
     }
 }
 
-int GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {
+void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {
     _gs_sock[cid].type = type;
     _gs_sock[cid].protocol = pro;
     _gs_sock[cid].connect = true;
@@ -1096,10 +1095,13 @@
 // for test
 
 void GSwifi::test () {
+/*
     command(NULL, GSRES_NORMAL);
     wait_ms(100);
     command("AT+NCLOSEALL", GSRES_NORMAL);
     _connect = true;
+*/
+    command("AT+WRXACTIVE=1", GSRES_NORMAL);
 }
 
 int GSwifi::getc() {
--- a/GSwifi.h	Thu Jul 12 08:19:50 2012 +0000
+++ b/GSwifi.h	Thu Jul 12 13:36:04 2012 +0000
@@ -121,7 +121,6 @@
     /**
      * send command
      */
-
     int command (char *cmd, GSRESPONCE res, int timeout = GS_TIMEOUT);
     /**
      * recv responce
@@ -130,23 +129,33 @@
     /**
      * associate infrastructure
      * @param sec GSSEC_OPEN, GSSEC_WEP, GSSEC_WPA_PSK, GSSEC_WPA2_PSK, GSSEC_WPS_BUTTON
-     * @param ssid
-     * @param pass
+     * @param ssid SSID
+     * @param pass pass phrase
+     * @param dhcp 0:static ip, 1:dhcp
+     * @retval 0 success
+     * @retval -1 failure
      */
-
     int connect (GSSECURITY sec, char *ssid, char *pass, int dhcp = 1);
     /**
      * adhock
      * @param sec GSSEC_OPEN or GSSEC_WEP
-     * @param ssid
-     * @param pass
+     * @param ssid SSID
+     * @param pass 10 or 26 hexadecimal digits
+     * @param ipaddr my ip address
+     * @param netmask subnet mask
+     * @retval 0 success
+     * @retval -1 failure
      */
     int adhock (GSSECURITY sec, char *ssid, char *pass, IpAddr ipaddr, IpAddr netmask);
     /**
      * limited AP
      * @param sec GSSEC_OPEN or GSSEC_WEP
-     * @param ssid
+     * @param ssid SSID
      * @param pass 10 or 26 hexadecimal digits
+     * @param ipaddr my ip address (dhcp start address)
+     * @param netmask subnet mask
+     * @retval 0 success
+     * @retval -1 failure
      * firmware: s2w-secureweb, s2w-web, s2w-wpsweb
      */
     int limitedap (GSSECURITY sec, char *ssid, char *pass, IpAddr ipaddr, IpAddr netmask);
@@ -169,10 +178,18 @@
     int getAddress (IpAddr &ipaddr, IpAddr &netmask, IpAddr &gateway, IpAddr &nameserver);
     /**
      * resolv hostname
+     * @param name hostname
+     * @param addr resolved ip address
+     * @retval 0 success
+     * @retval -1 failure
      */
     int getHostByName (const char* name, IpAddr &addr);
     /**
      * resolv hostname
+     * @param host.name hostname
+     * @param host.ipaddr resolved ip address
+     * @retval 0 success
+     * @retval -1 failure
      */
     int getHostByName (Host &host);
     /**
@@ -182,8 +199,10 @@
     int setRFPower (int power);
     /**
      * power save mode
+     * @param active 0:switched off, 1:always on
+     * @param save 0:disable, 1:enable
      */
-    int powerSave (int beacon = 10, int association = 1);
+    int powerSave (int active, int save);
     /**
      * standby mode
      * @param msec wakeup after
@@ -205,15 +224,17 @@
     bool isConnected ();
     /**
      * status
+     * @return GSSTATUS
      */
     GSSTATUS getStatus ();
     /**
-     * RSSI dBm
+     * RSSI
+     * @return dBm
      */
     int getRssi ();
 
     /**
-     * polling
+     * main polling
      */
     void poll();
 
@@ -268,7 +289,7 @@
     int x2i (char c);
     char i2x (int i);
     void isr_recv ();
-    int newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive);
+    void newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive);
 
 private:
     Serial _gs;
--- a/dbg.h	Thu Jul 12 08:19:50 2012 +0000
+++ b/dbg.h	Thu Jul 12 13:36:04 2012 +0000
@@ -1,4 +1,4 @@
-//#define DEBUG
+#define DEBUG
 
 #ifdef DEBUG 
 #define DBG(...) printf("" __VA_ARGS__)