see http://mbed.org/users/okini3939/notebook/wattmeter-shield-on-mbed/

Dependencies:   mbed

Fork of GSwifi_xively by gs fan

Committer:
okini3939
Date:
Wed Nov 27 08:18:45 2013 +0000
Revision:
4:9a2415f2ab07
update GSwifiInterface library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 4:9a2415f2ab07 1 /* Copyright (C) 2012 mbed.org, MIT License
okini3939 4:9a2415f2ab07 2 *
okini3939 4:9a2415f2ab07 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
okini3939 4:9a2415f2ab07 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
okini3939 4:9a2415f2ab07 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
okini3939 4:9a2415f2ab07 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
okini3939 4:9a2415f2ab07 7 * furnished to do so, subject to the following conditions:
okini3939 4:9a2415f2ab07 8 *
okini3939 4:9a2415f2ab07 9 * The above copyright notice and this permission notice shall be included in all copies or
okini3939 4:9a2415f2ab07 10 * substantial portions of the Software.
okini3939 4:9a2415f2ab07 11 *
okini3939 4:9a2415f2ab07 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
okini3939 4:9a2415f2ab07 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
okini3939 4:9a2415f2ab07 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
okini3939 4:9a2415f2ab07 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
okini3939 4:9a2415f2ab07 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
okini3939 4:9a2415f2ab07 17 */
okini3939 4:9a2415f2ab07 18 /* Copyright (C) 2013 gsfan, MIT License
okini3939 4:9a2415f2ab07 19 * port to the GainSpan Wi-FI module GS1011
okini3939 4:9a2415f2ab07 20 */
okini3939 4:9a2415f2ab07 21
okini3939 4:9a2415f2ab07 22 #include "Socket.h"
okini3939 4:9a2415f2ab07 23 #include <cstring>
okini3939 4:9a2415f2ab07 24
okini3939 4:9a2415f2ab07 25 Socket::Socket() {
okini3939 4:9a2415f2ab07 26 _wifi = GSwifi::getInstance();
okini3939 4:9a2415f2ab07 27 if (_wifi == NULL)
okini3939 4:9a2415f2ab07 28 error("Socket constructor error: no wifly instance available!\r\n");
okini3939 4:9a2415f2ab07 29 _blocking = true;
okini3939 4:9a2415f2ab07 30 _timeout = 1500;
okini3939 4:9a2415f2ab07 31
okini3939 4:9a2415f2ab07 32 _server = false;
okini3939 4:9a2415f2ab07 33 _cid = -1;
okini3939 4:9a2415f2ab07 34 _port = 0;
okini3939 4:9a2415f2ab07 35 }
okini3939 4:9a2415f2ab07 36
okini3939 4:9a2415f2ab07 37 void Socket::set_blocking(bool blocking, unsigned int timeout) {
okini3939 4:9a2415f2ab07 38 _blocking = blocking;
okini3939 4:9a2415f2ab07 39 _timeout = timeout;
okini3939 4:9a2415f2ab07 40 }
okini3939 4:9a2415f2ab07 41
okini3939 4:9a2415f2ab07 42 int Socket::close() {
okini3939 4:9a2415f2ab07 43 if (_cid < 0) return 0;
okini3939 4:9a2415f2ab07 44
okini3939 4:9a2415f2ab07 45 _wifi->close(_cid);
okini3939 4:9a2415f2ab07 46 _cid = -1;
okini3939 4:9a2415f2ab07 47 return 0;
okini3939 4:9a2415f2ab07 48 }
okini3939 4:9a2415f2ab07 49
okini3939 4:9a2415f2ab07 50 Socket::~Socket() {
okini3939 4:9a2415f2ab07 51 close(); //Don't want to leak
okini3939 4:9a2415f2ab07 52 }