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
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/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。
解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Revision 6:a423f0d197de, committed 2012-08-16
- Comitter:
- gsfan
- Date:
- Thu Aug 16 05:01:19 2012 +0000
- Parent:
- 5:6def1d0df519
- Child:
- 7:b75b7fc144ff
- Commit message:
- bugfix send
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 |
--- a/GSwifi.cpp Fri Jul 13 04:14:14 2012 +0000 +++ b/GSwifi.cpp Thu Aug 16 05:01:19 2012 +0000 @@ -517,6 +517,10 @@ r = command("AT+NDHCP=1", GSRES_DHCP, GS_TIMEOUT2); } break; + default: + DBG("Can't use security\r\n"); + r = -1; + break; } if (r == 0) _connect = true; @@ -595,7 +599,7 @@ command("AT+NDHCP=0", GSRES_NORMAL); setAddress(ipaddr, netmask, ipaddr, ipaddr); command("AT+DHCPSRVR=1", GSRES_NORMAL); - command("AT+DNS=1,gainspan", GSRES_NORMAL); + command("AT+DNS=1,setup", GSRES_NORMAL); switch (sec) { case GSSEC_NONE: @@ -827,6 +831,15 @@ return _time; } +int GSwifi::gpioOut (int port, int out) { + char cmd[GS_CMD_SIZE]; + + if (_status != GSSTAT_READY) return -1; + + sprintf(cmd, "AT+DGPIO=%d,%d", port, out); + return command(cmd, GSRES_NORMAL); +} + void GSwifi::poll() { int i; @@ -968,6 +981,7 @@ int GSwifi::send (int cid, char *buf, int len) { int i; + Timer timeout; if (! _gs_sock[cid].connect) return -1; @@ -996,12 +1010,14 @@ } else { return -1; } - while (!_gs_ok && !_gs_failure); + timeout.start(); + while (!_gs_ok && !_gs_failure && timeout.read_ms() < GS_TIMEOUT); return _gs_ok == 1 ? 0 : -1; } int GSwifi::send (int cid, char *buf, int len, Host &host) { int i; + Timer timeout; if (! _gs_sock[cid].connect) return -1; @@ -1009,7 +1025,6 @@ // UDP Server _gs_ok = 0; _gs_failure = 0; - _gs_putc(0x1b); #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()); @@ -1033,7 +1048,8 @@ } else { return -1; } - while (!_gs_ok && !_gs_failure); + timeout.start(); + while (!_gs_ok && !_gs_failure && timeout.read_ms() < GS_TIMEOUT); return _gs_ok == 1 ? 0 : -1; }
--- a/GSwifi.h Fri Jul 13 04:14:14 2012 +0000 +++ b/GSwifi.h Thu Aug 16 05:01:19 2012 +0000 @@ -181,16 +181,12 @@ * 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); /** @@ -200,8 +196,8 @@ int setRFPower (int power); /** * power save mode - * @param active 0:switched off, 1:always on - * @param save 0:disable, 1:enable + * @param active rx radio 0:switched off, 1:always on + * @param save power save 0:disable, 1:enable */ int powerSave (int active, int save); /** @@ -230,21 +226,31 @@ GSSTATUS getStatus (); /** * RSSI - * @return dBm + * @return RSSI (dBm) */ int getRssi (); /** * set NTP server + * @param host SNTP server + * @param sec time sync interval, 0:one time */ int ntpdate (Host host, int sec = 0); /** - * set RTC time + * set system time + * @param time date time (UTC) */ int setTime (time_t time); - /* + /** * get RTC time + * @return date time (UTC) */ time_t getTime (); + /** + * GPIO output + * @param port 10,11,30,31 + * @param out 0:set(high), 1:reset(low) + */ + int gpioOut (int port, int out); /** * main polling @@ -253,10 +259,12 @@ /** * tcp/udp client + * @return CID, -1:failure */ int open (Host &host, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive = NULL); /** * tcp/udp server + * @return CID, -1:failure */ int listen (int port, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive = NULL); /** @@ -273,10 +281,12 @@ int send (int cid, char *buf, int len, Host &host); /** * recv data tcp(s/c), udp(c) + * @return length */ int recv (int cid, char *buf, int len); /** * recv data udp(s) + * @return length */ int recv (int cid, char *buf, int len, Host &host); /** @@ -286,6 +296,8 @@ /** * http request + * @return CID, -1:failure + * If you use ssl, please set system time. */ int httpGet (Host &host, char *uri, int ssl = 0, onGsReceiveFunc ponGsReceive = NULL); /**