GSwifiInterface library (interface for GainSpan Wi-Fi GS1011 modules) Please see https://mbed.org/users/gsfan/notebook/GSwifiInterface/
Dependents: GSwifiInterface_HelloWorld GSwifiInterface_HelloServo GSwifiInterface_UDPEchoServer GSwifiInterface_UDPEchoClient ... more
Fork of WiflyInterface by
GainSpan Wi-Fi library
The GS1011/GS2100 is an ultra low power 802.11b wireless module from GainSpan.
mbed RTOS supported.
- about this library: http://mbed.org/users/gsfan/notebook/GSwifiInterface/
- about Wi-Fi module: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011/GS2100 シリーズ用のライブラリです。
mbed RTOS に対応しています。(mbed2.0)
- このライブラリについて: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
- Wi-FIモジュールについて: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
- UARTコマンド、SPIデータインターフェースに対応しました。(2019/09)
Diff: GSwifi/GSwifi_msg.cpp
- Revision:
- 11:71d67fea5ace
- Parent:
- 8:64184a968e3b
- Child:
- 12:057089026a20
--- a/GSwifi/GSwifi_msg.cpp Thu Oct 31 08:34:45 2013 +0000 +++ b/GSwifi/GSwifi_msg.cpp Fri Nov 15 04:20:14 2013 +0000 @@ -18,13 +18,13 @@ #include "GSwifi.h" -#ifdef RTOS_H +#ifdef CFG_ENABLE_RTOS #undef DBG #define DBG(x, ...) #endif void GSwifi::recvData (char c) { - static int sub, len, count; + static int cid, sub, len, count; #ifdef DEBUG_DUMP if (c < 0x20) { @@ -111,7 +111,7 @@ switch (sub) { case 0: // cid - _state.cid = x2i(c); + cid = x2i(c); sub ++; count = 0; if (_state.mode == MODE_DATA_RX) { @@ -121,18 +121,18 @@ case 1: // ip if ((c >= '0' && c <= '9') || c == '.') { - _con[_state.cid].ip[count] = c; + _con[cid].ip[count] = c; count ++; } else { - _con[_state.cid].ip[count] = 0; - _con[_state.cid].port = 0; + _con[cid].ip[count] = 0; + _con[cid].port = 0; sub ++; } break; case 2: // port if (c >= '0' && c <= '9') { - _con[_state.cid].port = (_con[_state.cid].port * 10) + (c - '0'); + _con[cid].port = (_con[cid].port * 10) + (c - '0'); } else { sub ++; count = 0; @@ -142,13 +142,13 @@ // data if (_state.escape) { if (c == 'E') { - DBG("recv ascii %d %d/a\r\n", _state.cid, count); - _con[_state.cid].received = true; + DBG("recv ascii %d %d/a\r\n", cid, count); + _con[cid].received = true; _state.mode = MODE_COMMAND; } else { - if (_con[_state.cid].buf != NULL) { - _con[_state.cid].buf->queue(0x1b); - _con[_state.cid].buf->queue(c); + if (_con[cid].buf != NULL) { + _con[cid].buf->queue(0x1b); + _con[cid].buf->queue(c); } count += 2; } @@ -157,11 +157,11 @@ if (c == 0x1b) { _state.escape = true; } else { - if (_con[_state.cid].buf != NULL) { - _con[_state.cid].buf->queue(c); - if (_con[_state.cid].buf->available() > CFG_DATA_SIZE - 16) { + if (_con[cid].buf != NULL) { + _con[cid].buf->queue(c); + if (_con[cid].buf->available() > CFG_DATA_SIZE - 16) { setRts(false); - _con[_state.cid].received = true; + _con[cid].received = true; } } count ++; @@ -176,7 +176,7 @@ switch (sub) { case 0: // cid - _state.cid = x2i(c); + cid = x2i(c); sub ++; len = 0; count = 0; @@ -187,18 +187,18 @@ case 1: // ip if ((c >= '0' && c <= '9') || c == '.') { - _con[_state.cid].ip[count] = c; + _con[cid].ip[count] = c; count ++; } else { - _con[_state.cid].ip[count] = 0; - _con[_state.cid].port = 0; + _con[cid].ip[count] = 0; + _con[cid].port = 0; sub ++; } break; case 2: // port if (c >= '0' && c <= '9') { - _con[_state.cid].port = (_con[_state.cid].port * 10) + (c - '0'); + _con[cid].port = (_con[cid].port * 10) + (c - '0'); } else { sub ++; count = 0; @@ -215,17 +215,17 @@ break; default: // data - if (_con[_state.cid].buf != NULL) { - _con[_state.cid].buf->queue(c); - if (_con[_state.cid].buf->available() > CFG_DATA_SIZE - 16) { + if (_con[cid].buf != NULL) { + _con[cid].buf->queue(c); + if (_con[cid].buf->available() > CFG_DATA_SIZE - 16) { setRts(false); - _con[_state.cid].received = true; + _con[cid].received = true; } } count ++; if (count >= len) { - DBG("recv bulk %d %d/%d\r\n", _state.cid, count, len); - _con[_state.cid].received = true; + DBG("recv bulk %d %d/%d\r\n", cid, count, len); + _con[cid].received = true; _state.mode = MODE_COMMAND; } break; @@ -304,6 +304,9 @@ void GSwifi::msgOk (const char *buf) { _state.ok = true; + if (_state.status == STAT_DEEPSLEEP) { + _state.status = STAT_READY; + } } void GSwifi::msgError (const char *buf) { @@ -312,42 +315,44 @@ void GSwifi::msgConnect (const char *buf) { int i, count; + int cid, acid; if (buf[8] < '0' || buf[8] > 'F' || buf[9] != ' ') return; - _state.cid = x2i(buf[8]); - _state.acid = x2i(buf[10]); - DBG("connect %d -> %d\r\n", _state.cid, _state.acid); + cid = x2i(buf[8]); + acid = x2i(buf[10]); + DBG("forked %d -> %d\r\n", cid, acid); // ip count = 0; for (i = 12; i < strlen(buf); i ++) { if ((buf[i] >= '0' && buf[i] <= '9') || buf[i] == '.') { - _con[_state.acid].ip[count] = buf[i]; + _con[acid].ip[count] = buf[i]; count ++; } else { - _con[_state.acid].ip[count] = 0; + _con[acid].ip[count] = 0; break; } } // port - _con[_state.acid].port = 0; + _con[acid].port = 0; count = 0; for (; i < strlen(buf); i ++) { if (buf[i] >= '0' && buf[i] <= '9') { - _con[_state.acid].port = (_con[_state.acid].port * 10) + (buf[i] - '0'); + _con[acid].port = (_con[acid].port * 10) + (buf[i] - '0'); } else { break; } } - _con[_state.acid].protocol = _con[_state.cid].protocol; - _con[_state.acid].type = _con[_state.cid].type; - _con[_state.acid].parent = _state.cid; - _con[_state.acid].accept = true; - if (_con[_state.acid].buf == NULL) - _con[_state.acid].buf = new CircBuffer<char>(CFG_DATA_SIZE); - _con[_state.acid].buf->flush(); - _con[_state.acid].connected = true; + // initalize + _con[acid].protocol = _con[cid].protocol; + _con[acid].type = _con[cid].type; + _con[acid].parent = cid; + _con[acid].accept = true; + if (_con[acid].buf == NULL) + _con[acid].buf = new CircBuffer<char>(CFG_DATA_SIZE); + _con[acid].buf->flush(); + _con[acid].connected = true; } void GSwifi::msgDisconnect (const char *buf) { @@ -367,36 +372,52 @@ for (i = 0; i < 16; i ++) { _con[i].connected = false; } -#ifdef RTOS_H +#ifdef CFG_ENABLE_RTOS if (_threadPoll) _threadPoll->signal_set(1); #endif } void GSwifi::msgReset (const char *buf) { + DBG("reset\r\n"); + _state.initialized = false; _state.mode = MODE_COMMAND; _state.status = STAT_READY; msgDisassociated(NULL); + clearFlags(); +#ifdef CFG_ENABLE_RTOS + if (_threadPoll) { + _threadPoll->terminate(); + delete _threadPoll; + } +#endif } void GSwifi::msgOutofStandby (const char *buf) { + DBG("OutofStandby\r\n"); _state.status = STAT_WAKEUP; } void GSwifi::msgOutofDeepsleep (const char *buf) { + DBG("OutofDeepsleep\r\n"); _state.status = STAT_READY; } void GSwifi::resConnect (const char *buf) { + int cid; + + // udp/tcp listen socket if (strncmp(buf, "CONNECT ", 8) == 0 && buf[9] == 0) { - _state.cid = x2i(buf[8]); - DBG("connect %d\r\n", _state.cid); - _con[_state.cid].parent = -1; - _con[_state.cid].accept = false; - if (_con[_state.cid].buf == NULL) - _con[_state.cid].buf = new CircBuffer<char>(CFG_DATA_SIZE); - _con[_state.cid].buf->flush(); - _con[_state.cid].connected = true; + cid = x2i(buf[8]); + DBG("connect %d\r\n", cid); + // initalize + _con[cid].parent = -1; + _con[cid].accept = false; + if (_con[cid].buf == NULL) + _con[cid].buf = new CircBuffer<char>(CFG_DATA_SIZE); + _con[cid].buf->flush(); + _con[cid].connected = true; + _state.cid = cid; _state.res = RES_NULL; return; } @@ -414,6 +435,7 @@ strncpy(_state.pass, &buf[11], sizeof(_state.pass)); _state.n ++; _state.res = RES_NULL; + DBG("wps %s %s\r\n", _state.ssid, _state.pass); } } @@ -422,7 +444,7 @@ strncpy(_state.mac, buf, sizeof(_state.mac)); _state.mac[17] = 0; _state.res = RES_NULL; - DBG("mac: %s", _state.mac); + DBG("mac %s\r\n", _state.mac); } } @@ -451,7 +473,7 @@ if (strncmp(buf, "IP:", 3) == 0) { strncpy(_state.resolv, &buf[3], sizeof(_state.resolv)); _state.res = RES_NULL; - DBG("resolv: %s", _state.resolv); + DBG("resolv: %s\r\n", _state.resolv); } } @@ -459,7 +481,7 @@ if (buf[0] == '-' || (buf[0] >= '0' && buf[0] <= '9')) { _state.rssi = atoi(buf); _state.res = RES_NULL; - DBG("rssi: %d", _state.rssi); + DBG("rssi: %d\r\n", _state.rssi); } }