GainSpan Wi-Fi library see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Fork of GSwifi_old 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/

Information

Please change the baud rate in advance.

  • ATB=115200
  • AT&W0

It may be better and sometimes faster.
GSwifi gs(p13, p14, baud);

Heavily modified new library: http://mbed.org/users/gsfan/code/GSwifi

ゲインスパン Wi-Fi モジュール ライブラリ

ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。

解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Information

モジュールはあらかじめ次のコマンドでボーレートを変更しておく。

  • ATB=115200
  • AT&W0

場合によってはもっと高速の方がいいかもしれない。クラス宣言時にレート設定をする。
GSwifi gs(p13, p14, baud);

大幅に更新された新しいライブラリ: http://mbed.org/users/gsfan/code/GSwifi

Committer:
gsfan
Date:
Mon Jul 09 14:36:06 2012 +0000
Revision:
0:2f6062c6d018
Child:
1:b127c6c5241d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gsfan 0:2f6062c6d018 1 /**
gsfan 0:2f6062c6d018 2 * Gainspan wi-fi module library for mbed
gsfan 0:2f6062c6d018 3 * Copyright (c) 2012 gsfan
gsfan 0:2f6062c6d018 4 * Released under the MIT License: http://mbed.org/license/mit
gsfan 0:2f6062c6d018 5 */
gsfan 0:2f6062c6d018 6
gsfan 0:2f6062c6d018 7 /** @file
gsfan 0:2f6062c6d018 8 * @brief Gainspan wi-fi module library for mbed
gsfan 0:2f6062c6d018 9 * GS1011MIC, GS1011MIP, GainSpan WiFi Breakout, etc.
gsfan 0:2f6062c6d018 10 * module configuration: ATB=115200
gsfan 0:2f6062c6d018 11 */
gsfan 0:2f6062c6d018 12
gsfan 0:2f6062c6d018 13 #include "mbed.h"
gsfan 0:2f6062c6d018 14 #include "RingBuffer.h"
gsfan 0:2f6062c6d018 15 #include "host.h"
gsfan 0:2f6062c6d018 16 #include "ipaddr.h"
gsfan 0:2f6062c6d018 17
gsfan 0:2f6062c6d018 18 #define GS_BAUD 115200
gsfan 0:2f6062c6d018 19
gsfan 0:2f6062c6d018 20 #define GS_BULK
gsfan 0:2f6062c6d018 21
gsfan 0:2f6062c6d018 22 #define GS_TIMEOUT 10000 // ms
gsfan 0:2f6062c6d018 23 #define GS_TIMEOUT2 30000 // ms
gsfan 0:2f6062c6d018 24 #define GS_CMD_SIZE 100
gsfan 0:2f6062c6d018 25 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
gsfan 0:2f6062c6d018 26 #define GS_DATA_SIZE 1500
gsfan 0:2f6062c6d018 27 #elif defined(TARGET_LPC11U24)
gsfan 0:2f6062c6d018 28 #define GS_DATA_SIZE 800
gsfan 0:2f6062c6d018 29 #endif
gsfan 0:2f6062c6d018 30
gsfan 0:2f6062c6d018 31 /**
gsfan 0:2f6062c6d018 32 * Wi-Fi security
gsfan 0:2f6062c6d018 33 */
gsfan 0:2f6062c6d018 34 enum GSSECURITY {
gsfan 0:2f6062c6d018 35 GSSEC_AUTO = 0,
gsfan 0:2f6062c6d018 36 GSSEC_NONE = 0,
gsfan 0:2f6062c6d018 37 GSSEC_OPEN = 1,
gsfan 0:2f6062c6d018 38 GSSEC_WEP = 2,
gsfan 0:2f6062c6d018 39 GSSEC_WPA_PSK = 4,
gsfan 0:2f6062c6d018 40 GSSEC_WPA2_PSK = 8,
gsfan 0:2f6062c6d018 41 GSSEC_WPA_ENT = 16,
gsfan 0:2f6062c6d018 42 GSSEC_WPA2_ENT = 32,
gsfan 0:2f6062c6d018 43 GSSEC_WPS_BUTTON = 64,
gsfan 0:2f6062c6d018 44 };
gsfan 0:2f6062c6d018 45
gsfan 0:2f6062c6d018 46 /**
gsfan 0:2f6062c6d018 47 * TCP/IP protocol
gsfan 0:2f6062c6d018 48 */
gsfan 0:2f6062c6d018 49 enum GSPROTOCOL {
gsfan 0:2f6062c6d018 50 GSPROT_UDP = 0,
gsfan 0:2f6062c6d018 51 GSPROT_TCP = 1,
gsfan 0:2f6062c6d018 52 GSPROT_HTTPGET,
gsfan 0:2f6062c6d018 53 GSPROT_HTTPPOST,
gsfan 0:2f6062c6d018 54 };
gsfan 0:2f6062c6d018 55
gsfan 0:2f6062c6d018 56 /**
gsfan 0:2f6062c6d018 57 * Client/Server
gsfan 0:2f6062c6d018 58 */
gsfan 0:2f6062c6d018 59 enum GSTYPE {
gsfan 0:2f6062c6d018 60 GSTYPE_CLIENT = 0,
gsfan 0:2f6062c6d018 61 GSTYPE_SERVER = 1,
gsfan 0:2f6062c6d018 62 };
gsfan 0:2f6062c6d018 63
gsfan 0:2f6062c6d018 64 enum GSRESPONCE {
gsfan 0:2f6062c6d018 65 GSRES_NORMAL,
gsfan 0:2f6062c6d018 66 GSRES_CONNECT,
gsfan 0:2f6062c6d018 67 GSRES_WPS,
gsfan 0:2f6062c6d018 68 GSRES_MACADDRESS,
gsfan 0:2f6062c6d018 69 GSRES_DHCP,
gsfan 0:2f6062c6d018 70 GSRES_DNSLOOKUP,
gsfan 0:2f6062c6d018 71 GSRES_HTTP,
gsfan 0:2f6062c6d018 72 };
gsfan 0:2f6062c6d018 73
gsfan 0:2f6062c6d018 74 enum GSMODE {
gsfan 0:2f6062c6d018 75 GSMODE_COMMAND,
gsfan 0:2f6062c6d018 76 GSMODE_DATA_RX,
gsfan 0:2f6062c6d018 77 GSMODE_DATA_RXUDP,
gsfan 0:2f6062c6d018 78 GSMODE_DATA_RX_BULK,
gsfan 0:2f6062c6d018 79 GSMODE_DATA_RXUDP_BULK,
gsfan 0:2f6062c6d018 80 GSMODE_DATA_RXHTTP,
gsfan 0:2f6062c6d018 81 };
gsfan 0:2f6062c6d018 82
gsfan 0:2f6062c6d018 83 enum GSSTATUS {
gsfan 0:2f6062c6d018 84 GSSTAT_READY,
gsfan 0:2f6062c6d018 85 GSSTAT_STANDBY,
gsfan 0:2f6062c6d018 86 GSSTAT_WAKEUP,
gsfan 0:2f6062c6d018 87 GSSTAT_DEEPSLEEP,
gsfan 0:2f6062c6d018 88 };
gsfan 0:2f6062c6d018 89
gsfan 0:2f6062c6d018 90 /**
gsfan 0:2f6062c6d018 91 * data receive callback function
gsfan 0:2f6062c6d018 92 */
gsfan 0:2f6062c6d018 93 typedef void (*onGsReceiveFunc)(int cid, int acid, int len);
gsfan 0:2f6062c6d018 94
gsfan 0:2f6062c6d018 95 struct GS_Socket {
gsfan 0:2f6062c6d018 96 GSTYPE type;
gsfan 0:2f6062c6d018 97 GSPROTOCOL protocol;
gsfan 0:2f6062c6d018 98 bool connect;
gsfan 0:2f6062c6d018 99 Host host;
gsfan 0:2f6062c6d018 100 RingBuffer *data;
gsfan 0:2f6062c6d018 101 int acid;
gsfan 0:2f6062c6d018 102 int received;
gsfan 0:2f6062c6d018 103 onGsReceiveFunc onGsReceive;
gsfan 0:2f6062c6d018 104 };
gsfan 0:2f6062c6d018 105
gsfan 0:2f6062c6d018 106 /**
gsfan 0:2f6062c6d018 107 * GSwifi class
gsfan 0:2f6062c6d018 108 */
gsfan 0:2f6062c6d018 109 class GSwifi {
gsfan 0:2f6062c6d018 110 public:
gsfan 0:2f6062c6d018 111 /**
gsfan 0:2f6062c6d018 112 * default constructor
gsfan 0:2f6062c6d018 113 */
gsfan 0:2f6062c6d018 114 GSwifi (PinName p_tx, PinName p_rx);
gsfan 0:2f6062c6d018 115 /**
gsfan 0:2f6062c6d018 116 * Default constructor (with hardware fllow controll)
gsfan 0:2f6062c6d018 117 */
gsfan 0:2f6062c6d018 118 GSwifi (PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts);
gsfan 0:2f6062c6d018 119 /**
gsfan 0:2f6062c6d018 120 * send command
gsfan 0:2f6062c6d018 121 */
gsfan 0:2f6062c6d018 122
gsfan 0:2f6062c6d018 123 int command (char *cmd, GSRESPONCE res, int timeout = GS_TIMEOUT);
gsfan 0:2f6062c6d018 124 /**
gsfan 0:2f6062c6d018 125 * recv responce
gsfan 0:2f6062c6d018 126 */
gsfan 0:2f6062c6d018 127 int cmdResponse (GSRESPONCE res, int ms);
gsfan 0:2f6062c6d018 128 /**
gsfan 0:2f6062c6d018 129 * associate infrastructure
gsfan 0:2f6062c6d018 130 * @param sec GSSEC_OPEN, GSSEC_WEP, GSSEC_WPA_PSK, GSSEC_WPA2_PSK, GSSEC_WPS_BUTTON
gsfan 0:2f6062c6d018 131 * @param ssid
gsfan 0:2f6062c6d018 132 * @param pass
gsfan 0:2f6062c6d018 133 */
gsfan 0:2f6062c6d018 134
gsfan 0:2f6062c6d018 135 int connect (GSSECURITY sec, char *ssid, char *pass, int dhcp = 1);
gsfan 0:2f6062c6d018 136 /**
gsfan 0:2f6062c6d018 137 * adhock
gsfan 0:2f6062c6d018 138 * @param sec GSSEC_OPEN or GSSEC_WEP
gsfan 0:2f6062c6d018 139 * @param ssid
gsfan 0:2f6062c6d018 140 * @param pass
gsfan 0:2f6062c6d018 141 */
gsfan 0:2f6062c6d018 142 int adhock (GSSECURITY sec, char *ssid, char *pass, IpAddr ipaddr, IpAddr netmask);
gsfan 0:2f6062c6d018 143 /**
gsfan 0:2f6062c6d018 144 * limited AP
gsfan 0:2f6062c6d018 145 * @param sec GSSEC_OPEN or GSSEC_WEP
gsfan 0:2f6062c6d018 146 * @param ssid
gsfan 0:2f6062c6d018 147 * @param pass 10 or 26 hexadecimal digits
gsfan 0:2f6062c6d018 148 * firmware: s2w-secureweb, s2w-web, s2w-wpsweb
gsfan 0:2f6062c6d018 149 */
gsfan 0:2f6062c6d018 150 int limitedap (GSSECURITY sec, char *ssid, char *pass, IpAddr ipaddr, IpAddr netmask);
gsfan 0:2f6062c6d018 151 /**
gsfan 0:2f6062c6d018 152 * unassociate
gsfan 0:2f6062c6d018 153 */
gsfan 0:2f6062c6d018 154 int disconnect ();
gsfan 0:2f6062c6d018 155
gsfan 0:2f6062c6d018 156 /**
gsfan 0:2f6062c6d018 157 * use DHCP
gsfan 0:2f6062c6d018 158 */
gsfan 0:2f6062c6d018 159 int setAddress ();
gsfan 0:2f6062c6d018 160 /**
gsfan 0:2f6062c6d018 161 * use static ip address
gsfan 0:2f6062c6d018 162 */
gsfan 0:2f6062c6d018 163 int setAddress (IpAddr ipaddr, IpAddr netmask, IpAddr gateway, IpAddr nameserver);
gsfan 0:2f6062c6d018 164 /**
gsfan 0:2f6062c6d018 165 * resolv hostname
gsfan 0:2f6062c6d018 166 */
gsfan 0:2f6062c6d018 167 int getHostByName (const char* name, IpAddr &addr);
gsfan 0:2f6062c6d018 168 /**
gsfan 0:2f6062c6d018 169 * resolv hostname
gsfan 0:2f6062c6d018 170 */
gsfan 0:2f6062c6d018 171 int getHostByName (Host &host);
gsfan 0:2f6062c6d018 172 /**
gsfan 0:2f6062c6d018 173 * RF power
gsfan 0:2f6062c6d018 174 * @param power 0(high)-7(low)
gsfan 0:2f6062c6d018 175 */
gsfan 0:2f6062c6d018 176 int setRFPower (int power);
gsfan 0:2f6062c6d018 177 /**
gsfan 0:2f6062c6d018 178 * power save mode
gsfan 0:2f6062c6d018 179 */
gsfan 0:2f6062c6d018 180 int powerSave (int beacon = 10, int association = 1);
gsfan 0:2f6062c6d018 181 /**
gsfan 0:2f6062c6d018 182 * standby mode
gsfan 0:2f6062c6d018 183 * @param msec wakeup after
gsfan 0:2f6062c6d018 184 * wakeup after msec or alarm1/2
gsfan 0:2f6062c6d018 185 * core off, save to RTC ram
gsfan 0:2f6062c6d018 186 */
gsfan 0:2f6062c6d018 187 int standby (int msec);
gsfan 0:2f6062c6d018 188 /**
gsfan 0:2f6062c6d018 189 * restore standby
gsfan 0:2f6062c6d018 190 */
gsfan 0:2f6062c6d018 191 int wakeup ();
gsfan 0:2f6062c6d018 192 /**
gsfan 0:2f6062c6d018 193 * deep sleep mode
gsfan 0:2f6062c6d018 194 */
gsfan 0:2f6062c6d018 195 int deepSleep ();
gsfan 0:2f6062c6d018 196 /**
gsfan 0:2f6062c6d018 197 * wifi connected
gsfan 0:2f6062c6d018 198 */
gsfan 0:2f6062c6d018 199 bool isConnected ();
gsfan 0:2f6062c6d018 200 /**
gsfan 0:2f6062c6d018 201 * status
gsfan 0:2f6062c6d018 202 */
gsfan 0:2f6062c6d018 203 GSSTATUS getStatus ();
gsfan 0:2f6062c6d018 204
gsfan 0:2f6062c6d018 205 /**
gsfan 0:2f6062c6d018 206 * polling
gsfan 0:2f6062c6d018 207 */
gsfan 0:2f6062c6d018 208 void poll();
gsfan 0:2f6062c6d018 209
gsfan 0:2f6062c6d018 210 /**
gsfan 0:2f6062c6d018 211 * tcp/udp client
gsfan 0:2f6062c6d018 212 */
gsfan 0:2f6062c6d018 213 int open (Host &host, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive = NULL);
gsfan 0:2f6062c6d018 214 /**
gsfan 0:2f6062c6d018 215 * tcp/udp server
gsfan 0:2f6062c6d018 216 */
gsfan 0:2f6062c6d018 217 int listen (int port, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive = NULL);
gsfan 0:2f6062c6d018 218 /**
gsfan 0:2f6062c6d018 219 * close client/server
gsfan 0:2f6062c6d018 220 */
gsfan 0:2f6062c6d018 221 int close (int cid);
gsfan 0:2f6062c6d018 222 /**
gsfan 0:2f6062c6d018 223 * send data tcp(s/c), udp(c)
gsfan 0:2f6062c6d018 224 */
gsfan 0:2f6062c6d018 225 int send (int cid, char *buf, int len);
gsfan 0:2f6062c6d018 226 /**
gsfan 0:2f6062c6d018 227 * send data udp(s)
gsfan 0:2f6062c6d018 228 */
gsfan 0:2f6062c6d018 229 int send (int cid, char *buf, int len, Host &host);
gsfan 0:2f6062c6d018 230 /**
gsfan 0:2f6062c6d018 231 * recv data tcp(s/c), udp(c)
gsfan 0:2f6062c6d018 232 */
gsfan 0:2f6062c6d018 233 int recv (int cid, char *buf, int len);
gsfan 0:2f6062c6d018 234 /**
gsfan 0:2f6062c6d018 235 * recv data udp(s)
gsfan 0:2f6062c6d018 236 */
gsfan 0:2f6062c6d018 237 int recv (int cid, char *buf, int len, Host &host);
gsfan 0:2f6062c6d018 238 /**
gsfan 0:2f6062c6d018 239 * tcp/udp connected
gsfan 0:2f6062c6d018 240 */
gsfan 0:2f6062c6d018 241 bool isConnected (int cid);
gsfan 0:2f6062c6d018 242
gsfan 0:2f6062c6d018 243 /**
gsfan 0:2f6062c6d018 244 * http request
gsfan 0:2f6062c6d018 245 */
gsfan 0:2f6062c6d018 246 int httpGet (Host &host, char *uri, int ssl = 0, onGsReceiveFunc ponGsReceive = NULL);
gsfan 0:2f6062c6d018 247 /**
gsfan 0:2f6062c6d018 248 * certificate
gsfan 0:2f6062c6d018 249 */
gsfan 0:2f6062c6d018 250 int certAdd (char *name, char *cert, int len);
gsfan 0:2f6062c6d018 251
gsfan 0:2f6062c6d018 252 void test ();
gsfan 0:2f6062c6d018 253 int getc();
gsfan 0:2f6062c6d018 254 void putc(char c);
gsfan 0:2f6062c6d018 255 int readable();
gsfan 0:2f6062c6d018 256
gsfan 0:2f6062c6d018 257 protected:
gsfan 0:2f6062c6d018 258 int x2i (char c);
gsfan 0:2f6062c6d018 259 char i2x (int i);
gsfan 0:2f6062c6d018 260 void isr_recv ();
gsfan 0:2f6062c6d018 261
gsfan 0:2f6062c6d018 262 private:
gsfan 0:2f6062c6d018 263 Serial _gs;
gsfan 0:2f6062c6d018 264 bool _rts;
gsfan 0:2f6062c6d018 265 volatile bool _connect;
gsfan 0:2f6062c6d018 266 volatile GSSTATUS _status;
gsfan 0:2f6062c6d018 267 volatile int _gs_ok, _gs_failure, _gs_enter;
gsfan 0:2f6062c6d018 268 GSMODE _gs_mode;
gsfan 0:2f6062c6d018 269 int _escape;
gsfan 0:2f6062c6d018 270 int _cid;
gsfan 0:2f6062c6d018 271 IpAddr _ipaddr, _netmask, _gateway, _nameserver, _resolv;
gsfan 0:2f6062c6d018 272 Host _from, _to;
gsfan 0:2f6062c6d018 273 char mac[6];
gsfan 0:2f6062c6d018 274 RingBuffer _buf_cmd;
gsfan 0:2f6062c6d018 275 struct GS_Socket _gs_sock[16];
gsfan 0:2f6062c6d018 276 };