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/
Diff: GSwifi_sock.cpp
- Revision:
- 36:a70b11e1560f
- Parent:
- 34:f5f40c92af00
- Child:
- 37:e61ea8267415
--- a/GSwifi_sock.cpp Fri Jun 21 06:08:37 2013 +0000 +++ b/GSwifi_sock.cpp Mon Jun 24 07:36:48 2013 +0000 @@ -40,7 +40,7 @@ _gs_sock[cid].onGsReceive.detach(); } -int GSwifi::open (Host &host, GSPROTOCOL pro) { +int GSwifi::open (Host &host, GSPROTOCOL pro, int port) { char cmd[GS_CMD_SIZE]; if (! _connect || _status != GSSTAT_READY) return -1; @@ -55,6 +55,9 @@ if (pro == GSPROT_UDP) { sprintf(cmd, "AT+NCUDP=%d.%d.%d.%d,%d", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); + if (port) { + sprintf(&cmd[strlen(cmd)], ",%d", port); + } } else { sprintf(cmd, "AT+NCTCP=%d.%d.%d.%d,%d", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); } @@ -97,8 +100,9 @@ int GSwifi::send (int cid, const char *buf, int len) { int i; + char cmd[GS_CMD_SIZE]; - if (! _gs_sock[cid].connect) return -1; + if ((! _gs_sock[cid].connect) || waitCts()) return -1; if ((_gs_sock[cid].protocol == GSPROT_TCP) || (_gs_sock[cid].protocol == GSPROT_UDP && _gs_sock[cid].type == GSTYPE_CLIENT) || @@ -106,7 +110,8 @@ // TCP Client, TCP Server, UDP Client resetResponse(GSRES_NONE); #ifdef GS_BULK - _gs.printf("\x1bZ%X%04d", cid, len); + sprintf(cmd, "\x1bZ%X%04d", cid, len); + _gs_puts(cmd); for (i = 0; i < len; i ++) { _gs_putc(buf[i]); #ifdef DEBUG_VIEW @@ -114,7 +119,8 @@ #endif } #else - _gs.printf("\x1bS%X", cid); + sprintf(cmd, "\x1bS%X", cid); + _gs_puts(cmd); for (i = 0; i < len; i ++) { if (buf[i] >= 0x20 && buf[i] < 0x7f) { _gs_putc(buf[i]); @@ -134,17 +140,17 @@ } int GSwifi::send (int cid, const char *buf, int len, Host &host) { + char cmd[GS_CMD_SIZE]; int i; - if (! _gs_sock[cid].connect) return -1; + if ((! _gs_sock[cid].connect) || waitCts()) return -1; if ((_gs_sock[cid].protocol == GSPROT_UDP && _gs_sock[cid].type == GSTYPE_SERVER)) { // UDP Server 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()); - _gs.printf("%04d", len); + sprintf(cmd, "\x1bY%X%d.%d.%d.%d:%d:%04d", cid, host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort(), len); + _gs_puts(cmd); for (i = 0; i < len; i ++) { _gs_putc(buf[i]); #ifdef DEBUG_VIEW @@ -152,8 +158,8 @@ #endif } #else - _gs.printf("\x1bU%X", cid); - _gs.printf("%d.%d.%d.%d:%d:", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); + sprintf(cmd, "\x1bU%X%d.%d.%d.%d:%d:", cid, host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); + _gs_puts(cmd); for (i = 0; i < len; i ++) { if (buf[i] >= 0x20 && buf[i] < 0x7f) { _gs_putc(buf[i]);