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/

Revision:
25:f6e5622d2930
Parent:
24:5c350ae2e703
Child:
26:b347ee3a1087
--- a/GSwifi.h	Wed Jan 23 07:41:23 2013 +0000
+++ b/GSwifi.h	Mon Feb 11 06:01:46 2013 +0000
@@ -1,13 +1,23 @@
-/**
- * Gainspan wi-fi module library for mbed
- * Copyright (c) 2012 gsfan
- * Released under the MIT License: http://mbed.org/license/mit
+/* Copyright (C) 2013 gsfan, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-
 /** @file
  * @brief Gainspan wi-fi module library for mbed
  * GS1011MIC, GS1011MIP, GainSpan WiFi Breakout, etc.
- * module configuration: ATB=115200
  */
 
 #ifndef _GSWIFI_H_
@@ -15,17 +25,19 @@
 
 #include "mbed.h"
 #include "GSwifi_net.h"
-#include "RingBuffer.h"
+#include "CBuffer.h"
 #include "host.h"
 #include "ipaddr.h"
+#include <ctype.h>
 
-#define GS_BAUD 115200
+
+#define GS_BAUD 9600
 
 #define GS_UART_DIRECT
 #define GS_BULK
 
 #define GS_DNSNAME "setup.local"
-#define GS_WREGDOMAIN "2" // 0:FCC, 1:ETSI, 2:TELEC
+#define GS_WREGDOMAIN 2 // 0:FCC, 1:ETSI, 2:TELEC
 
 #define GS_TIMEOUT 10000 // ms
 #define GS_TIMEOUT2 30000 // ms
@@ -51,6 +63,12 @@
 #endif
 
 /**
+ * GSwifi class
+ */
+class GSwifi {
+public:
+
+/**
  * Wi-Fi security
  */
 enum GSSECURITY {
@@ -123,25 +141,25 @@
     GSPROTOCOL protocol;
     bool connect;
     Host host;
-    RingBuffer *data;
+    CircBuffer<char> *data;
     int lcid;
     int received;
     onGsReceiveFunc onGsReceive;
 };
 
-/**
- * GSwifi class
- */
-class GSwifi {
-public:
+    // ----- GSwifi.cpp -----
     /**
      * default constructor
      */
-    GSwifi (PinName p_tx, PinName p_rx, int baud = GS_BAUD);
+    GSwifi (PinName p_tx, PinName p_rx, PinName p_reset, PinName p_alarm = NC, int baud = GS_BAUD);
     /**
      * Default constructor (with hardware fllow controll)
      */
-    GSwifi (PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts, int baud = GS_BAUD);
+    GSwifi (PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts, PinName p_reset, PinName p_alarm = NC, int baud = GS_BAUD);
+    /**
+     * reset module
+     */
+    void reset ();
     /**
      * send command
      */
@@ -275,12 +293,28 @@
      * @param out 0:set(high), 1:reset(low)
      */
     int gpioOut (int port, int out);
-
     /**
      * main polling
      */
     void poll();
+    /**
+     * Web server
+     */
+    int provisioning (char *user, char *pass);
+    /**
+     * change baud rate
+     */
+    int setBaud (int baud);
+    /**
+     * change radio region
+     */
+    int setRegion (int reg = GS_WREGDOMAIN);
+    /**
+     * certificate 
+     */
+    int certAdd (const char *name, const char *cert, int len);
 
+// ----- GSwifi_sock.cpp -----
     /**
      * tcp/udp client
      * @return CID, -1:failure
@@ -326,6 +360,7 @@
      */
     bool isConnected (int cid);
 
+// ----- GSwifi_http.cpp -----
     /**
      * http request (GET method)
      */
@@ -338,11 +373,20 @@
     int httpPost (Host &host, const char *uri, const char *body, int ssl = 0, onGsReceiveFunc ponGsReceive = NULL);
 
     /**
-     * certificate 
+     * base64 encode
+     */
+    int base64encode (char *input, int length, char *output, int len);
+    /**
+     * url encode
      */
-    int certAdd (const char *name, const char *cert, int len);
+    int urlencode (char *str, char *buf, int len);
+    /**
+     * url decode
+     */
+    int urldecode (char *str, char *buf, int len);
 
 #ifdef GS_USE_SMTP
+// ----- GSwifi_smtp.cpp -----
     /**
      * send mail (smtp)
      * @param host SMTP server
@@ -359,6 +403,7 @@
 #endif
 
 #ifdef GS_USE_HTTPD
+// ----- GSwifi_httpd.cpp -----
     /**
      * start http server
      * @param port
@@ -381,27 +426,6 @@
 #endif
 #endif
 
-    /**
-     * Web server
-     */
-    int provisioning (char *user, char *pass);
-    /**
-     * change baud rate
-     */
-    int setBaud (int baud);
-    /**
-     * base64 encode
-     */
-    int base64encode (char *input, int length, char *output, int len);
-    /**
-     * url encode
-     */
-    int urlencode (char *str, char *buf, int len);
-    /**
-     * url decode
-     */
-    int urldecode (char *str, char *buf, int len);
-
 #ifdef DEBUG
     void dump ();
     void test ();
@@ -415,10 +439,11 @@
     int x2i (char c);
     char i2x (int i);
     void isr_recv ();
-    void newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive);
     int from_hex (int ch);
     int to_hex (int code);
 
+    void newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive);
+
 #ifdef GS_USE_SMTP
     int wait_smtp (int cid, int code);
 #endif
@@ -433,6 +458,8 @@
 private:
     Serial _gs;
     bool _rts;
+    DigitalOut _reset;
+    DigitalOut *_alarm;
     volatile bool _connect;
     volatile GSSTATUS _status;
     volatile int _gs_ok, _gs_failure, _gs_enter;
@@ -443,7 +470,7 @@
     IpAddr _ipaddr, _netmask, _gateway, _nameserver, _resolv;
     Host _from, _to;
     char _mac[6];
-    RingBuffer _buf_cmd;
+    CircBuffer<char> _buf_cmd;
     struct GS_Socket _gs_sock[16];
     time_t _time;
     char *_ssid;