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:
Fri Jul 13 04:14:14 2012 +0000
Parent:
4:a8d38857f3fd
Child:
6:a423f0d197de
Commit message:
added setTime, getTime

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 14:40:02 2012 +0000
+++ b/GSwifi.cpp	Fri Jul 13 04:14:14 2012 +0000
@@ -214,7 +214,7 @@
 
     case GSMODE_DATA_RX_BULK:
     case GSMODE_DATA_RXUDP_BULK:
-        DBG("%c", dat);
+//        DBG("%c", dat);
         if (mode == 0) {
             // cid
             _cid = x2i(dat);
@@ -264,7 +264,9 @@
         } else
         if (mode == 4) {
             // data
-            _gs_sock[_cid].data->put(dat);
+            if (_gs_sock[_cid].data != NULL) {
+                _gs_sock[_cid].data->put(dat);
+            }
             len  --;
             if (len == 0) {
                 DBG("recv binary %d\r\n", _cid);
@@ -291,7 +293,7 @@
         _gs.printf("\r\n");
         wait_ms(100);
         while (_gs.readable()) {
-            _gs_getc(); // dummy read
+            i = _gs_getc(); // dummy read
         }
         return 0;
     }
@@ -425,6 +427,21 @@
                 flg = 1;
             }
             break;
+        case GSRES_TIME:
+            if (buf[0] >= '0' && buf[0] <= '9') {
+                int year, month, day, hour, min, sec;
+                struct tm t;
+                sscanf(buf, "%d/%d/%d,%d:%d,%d", &day, &month, &year, &hour, &min, &sec);
+                t.tm_sec = sec;
+                t.tm_min = min;
+                t.tm_hour = hour;
+                t.tm_mday = day;
+                t.tm_mon = month - 1;
+                t.tm_year = year - 1900;   
+                _time = mktime(&t);            
+                flg = 1;
+            }
+            break;
         }
         
         if ((flg && _gs_ok) || _gs_failure) break;
@@ -770,6 +787,46 @@
     return _rssi;
 }
 
+int GSwifi::ntpdate (Host host, int sec) {
+    char cmd[GS_CMD_SIZE];
+
+    if (! _connect || _status != GSSTAT_READY) return -1;
+
+    if (host.getIp().isNull()) {
+        if (getHostByName(host)) {
+            if (getHostByName(host)) return -1;
+        }
+    }
+
+    if (sec) {
+        sprintf(cmd, "AT+NTIMESYNC=1,%d.%d.%d.%d,%d,1,%d", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3],
+          GS_TIMEOUT / 1000, sec);
+    } else {
+        sprintf(cmd, "AT+NTIMESYNC=1,%d.%d.%d.%d,%d,0", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3],
+          GS_TIMEOUT / 1000);
+    }
+    return command(cmd, GSRES_NORMAL);
+}
+
+int GSwifi::setTime (time_t time) {
+    char cmd[GS_CMD_SIZE];
+    struct tm *t;
+
+    if (_status != GSSTAT_READY) return -1;
+
+    t = localtime(&time);
+    sprintf(cmd, "AT+SETTIME=%d/%d/%d,%d:%d:%d", t->tm_mday, t->tm_mon + 1, t->tm_year + 1900, t->tm_hour, t->tm_min, t->tm_sec);
+    return command(cmd, GSRES_NORMAL);
+}
+
+time_t GSwifi::getTime () {
+
+    if (command("AT+GETTIME=?", GSRES_TIME)) {
+        return 0;
+    }
+    return _time;
+}
+
 void GSwifi::poll() {
     int i;
 
--- a/GSwifi.h	Thu Jul 12 14:40:02 2012 +0000
+++ b/GSwifi.h	Fri Jul 13 04:14:14 2012 +0000
@@ -71,6 +71,7 @@
     GSRES_DNSLOOKUP,
     GSRES_HTTP,
     GSRES_RSSI,
+    GSRES_TIME,
 };
 
 enum GSMODE {
@@ -232,6 +233,18 @@
      * @return dBm
      */
     int getRssi ();
+    /**
+     * set NTP server
+     */
+    int ntpdate (Host host, int sec = 0);
+    /**
+     * set RTC time
+     */
+    int setTime (time_t time);
+    /*
+     * get RTC time
+     */
+    time_t getTime ();
 
     /**
      * main polling
@@ -305,4 +318,5 @@
     char _mac[6];
     RingBuffer _buf_cmd;
     struct GS_Socket _gs_sock[16];
+    time_t _time;
 };
--- a/dbg.h	Thu Jul 12 14:40:02 2012 +0000
+++ b/dbg.h	Fri Jul 13 04:14:14 2012 +0000
@@ -1,4 +1,4 @@
-#define DEBUG
+//#define DEBUG
 
 #ifdef DEBUG 
 #define DBG(...) printf("" __VA_ARGS__)