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.cpp
- Revision:
- 23:a783c62c36d0
- Parent:
- 22:9b077e2823ce
- Child:
- 24:5c350ae2e703
--- a/GSwifi.cpp Wed Dec 26 08:41:43 2012 +0000 +++ b/GSwifi.cpp Mon Jan 21 05:58:28 2013 +0000 @@ -15,24 +15,12 @@ #include "GSwifi.h" #include <ctype.h> -#ifdef GS_UART_DIRECT -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) -#define _gs_getc() LPC_UART1->RBR -#define _gs_putc(c) while(!(LPC_UART1->LSR & (1<<5))); LPC_UART1->THR = c -#elif defined(TARGET_LPC11U24) -#define _gs_getc() LPC_USART->RBR -#define _gs_putc(c) while(!(LPC_USART->LSR & (1<<5))); LPC_USART->THR = c -#endif -#else -#define _gs_getc() _gs.getc() -#define _gs_putc(c) _gs.putc(c) -#endif GSwifi::GSwifi (PinName p_tx, PinName p_rx, int baud) : _gs(p_tx, p_rx), _buf_cmd(GS_CMD_SIZE) { _connect = false; _status = GSSTAT_READY; _escape = 0; - _response = 1; + _response = GSRES_NONE; _gs_mode = GSMODE_COMMAND; _gs.baud(baud); @@ -44,7 +32,7 @@ _connect = false; _status = GSSTAT_READY; _escape = 0; - _response = 1; + _response = GSRES_NONE; _gs_mode = GSMODE_COMMAND; _gs.baud(baud); @@ -95,8 +83,16 @@ dat = _gs_getc(); if (flg & ((1 << 7)|(1 << 3)|(1 << 4))) return; +#ifdef DEBUG_VIEW // DBG("%02x_", dat); - +#endif +/* + if (dat >= 0x20 && dat < 0x7f) { + DBG("_%c", dat); + } else { + DBG("_%02x", dat); + } +*/ switch (_gs_mode) { case GSMODE_COMMAND: // command responce if (_escape) { @@ -145,7 +141,11 @@ _buf_cmd.put(dat); if (dat == '\n') { _gs_enter ++; - if (!_response && _connect) poll_cmd(); + DBG("* %d %d *", _response, _connect); + if (_response == GSRES_NONE && _connect) { + DBG("poll_cmd\r\n"); + poll_cmd(); + } } } } @@ -317,7 +317,7 @@ return 0; } - _response = 1; + _response = res; _buf_cmd.clear(); _gs_ok = 0; _gs_failure = 0; @@ -329,11 +329,11 @@ _gs_putc('\n'); DBG("command: %s\r\n", cmd); if (strlen(cmd) == 0) return 0; - wait_ms(10); +// wait_ms(10); if (timeout) { r = cmdResponse(res, timeout); } - _response = 0; + _response = GSRES_NONE; return r; } @@ -883,7 +883,7 @@ // received "\n" char buf[GS_CMD_SIZE]; - wait_ms(10); +// wait_ms(10); _gs_enter --; i = 0; while (_buf_cmd.use() && i < sizeof(buf)) { @@ -894,7 +894,7 @@ i ++; } buf[i] = 0; - DBG("poll: %s\r\n", buf); + DBG("poll: %d %s\r\n", _gs_enter, buf); if (i == 0) { } else @@ -1049,8 +1049,8 @@ if (! _gs_sock[cid].connect) return -1; _gs_sock[cid].connect = false; - delete _gs_sock[cid].data; - _gs_sock[cid].data = NULL; +// delete _gs_sock[cid].data; +// _gs_sock[cid].data = NULL; sprintf(cmd, "AT+NCLOSE=%X", cid); return command(cmd, GSRES_NORMAL); } @@ -1071,14 +1071,18 @@ _gs.printf("\x1bZ%X%04d", cid, len); for (i = 0; i < len; i ++) { _gs_putc(buf[i]); -// DBG("%c", buf[i]); +#ifdef DEBUG_VIEW + DBG("%c", buf[i]); +#endif } #else _gs.printf("\x1bS%X", cid); for (i = 0; i < len; i ++) { if (buf[i] >= 0x20 && buf[i] < 0x7f) { _gs_putc(buf[i]); -// DBG("%c", buf[i]); +#ifdef DEBUG_VIEW + DBG("%c", buf[i]); +#endif } } _gs_putc(0x1b); @@ -1108,7 +1112,9 @@ _gs.printf("%04d", len); for (i = 0; i < len; i ++) { _gs_putc(buf[i]); -// DBG("%c", buf[i]); +#ifdef DEBUG_VIEW + DBG("%c", buf[i]); +#endif } #else _gs.printf("\x1bU%X", cid); @@ -1116,7 +1122,9 @@ for (i = 0; i < len; i ++) { if (buf[i] >= 0x20 && buf[i] < 0x7f) { _gs_putc(buf[i]); -// DBG("%c", buf[i]); +#ifdef DEBUG_VIEW + DBG("%c", buf[i]); +#endif } } _gs_putc(0x1b); @@ -1303,7 +1311,6 @@ } int GSwifi::setBaud (int baud) { - char cmd[GS_CMD_SIZE]; if (_status != GSSTAT_READY) return -1; @@ -1418,9 +1425,19 @@ return 0; } - #ifdef DEBUG // for test +void GSwifi::dump () { + int i; + + DBG("GS mode=%d, escape=%d, cid=%d\r\n", _gs_mode, _escape, _cid); + for (i = 0; i < 16; i ++) { + DBG("%d: connect=%d, type=%d, protocol=%d, len=%d\r\n", i, _gs_sock[i].connect, _gs_sock[i].type, _gs_sock[i].protocol, _gs_sock[i].data->use()); + if (_gs_sock[i].protocol == GSPROT_HTTPD) { + DBG(" mode=%d, type=%d, len=%d\r\n", i, _httpd[i].mode, _httpd[i].type, _httpd[i].len); + } + } +} void GSwifi::test () { /*