WIFI library for WIFI Shield of Seeed Studio
Fork of WiflyInterface by
Revision 5:26ae56c7cb3d, committed 2013-12-19
- Comitter:
- yihui
- Date:
- Thu Dec 19 09:56:59 2013 +0000
- Parent:
- 1:fb4494783863
- Commit message:
- for wifi shield of Seeed Studio
Changed in this revision
diff -r fb4494783863 -r 26ae56c7cb3d Wifly/CBuffer.h --- a/Wifly/CBuffer.h Fri Aug 24 13:48:36 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* Copyright (C) 2012 mbed.org, 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. - */ - -#ifndef CIRCBUFFER_H_ -#define CIRCBUFFER_H_ - -template <class T> -class CircBuffer { -public: - CircBuffer(int length) { - write = 0; - read = 0; - size = length + 1; - buf = (T *)malloc(size * sizeof(T)); - }; - - bool isFull() { - return (((write + 1) % size) == read); - }; - - bool isEmpty() { - return (read == write); - }; - - void queue(T k) { - if (isFull()) { - read++; - read %= size; - } - buf[write++] = k; - write %= size; - } - - void flush() { - read = 0; - write = 0; - } - - - uint32_t available() { - return (write >= read) ? write - read : size - read + write; - }; - - bool dequeue(T * c) { - bool empty = isEmpty(); - if (!empty) { - *c = buf[read++]; - read %= size; - } - return(!empty); - }; - -private: - volatile uint32_t write; - volatile uint32_t read; - uint32_t size; - T * buf; -}; - -#endif
diff -r fb4494783863 -r 26ae56c7cb3d Wifly/CircBuffer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Wifly/CircBuffer.h Thu Dec 19 09:56:59 2013 +0000 @@ -0,0 +1,75 @@ +/* Copyright (C) 2012 mbed.org, 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. + */ + +#ifndef CIRCBUFFER_H_ +#define CIRCBUFFER_H_ + +template <class T> +class CircBuffer { +public: + CircBuffer(int length) { + write = 0; + read = 0; + size = length + 1; + buf = (T *)malloc(size * sizeof(T)); + }; + + bool isFull() { + return (((write + 1) % size) == read); + }; + + bool isEmpty() { + return (read == write); + }; + + void queue(T k) { + if (isFull()) { + read++; + read %= size; + } + buf[write++] = k; + write %= size; + } + + void flush() { + read = 0; + write = 0; + } + + + uint32_t available() { + return (write >= read) ? write - read : size - read + write; + }; + + bool dequeue(T * c) { + bool empty = isEmpty(); + if (!empty) { + *c = buf[read++]; + read %= size; + } + return(!empty); + }; + +private: + volatile uint32_t write; + volatile uint32_t read; + uint32_t size; + T * buf; +}; + +#endif
diff -r fb4494783863 -r 26ae56c7cb3d Wifly/Wifly.cpp --- a/Wifly/Wifly.cpp Fri Aug 24 13:48:36 2012 +0000 +++ b/Wifly/Wifly.cpp Thu Dec 19 09:56:59 2013 +0000 @@ -42,8 +42,8 @@ Wifly * Wifly::inst; -Wifly::Wifly( PinName tx, PinName rx, PinName _reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec): - wifi(tx, rx), reset_pin(_reset), tcp_status(tcp_status), buf_wifly(256) +Wifly::Wifly( PinName tx, PinName rx, const char * ssid, const char * phrase, Security sec): + wifi(tx, rx), buf_wifly(256) { memset(&state, 0, sizeof(state)); state.sec = sec; @@ -342,16 +342,13 @@ bool Wifly::is_connected() { - return (tcp_status.read() == 1) ? true : false; + return state.tcp; } void Wifly::reset() { - reset_pin = 0; - wait(0.2); - reset_pin = 1; - wait(0.2); + // Not available } bool Wifly::close()
diff -r fb4494783863 -r 26ae56c7cb3d Wifly/Wifly.h --- a/Wifly/Wifly.h Fri Aug 24 13:48:36 2012 +0000 +++ b/Wifly/Wifly.h Thu Dec 19 09:56:59 2013 +0000 @@ -28,9 +28,9 @@ #define WIFLY_H #include "mbed.h" -#include "CBuffer.h" +#include "CircBuffer.h" -#define DEFAULT_WAIT_RESP_TIMEOUT 500 +#define DEFAULT_WAIT_RESP_TIMEOUT 1500 enum Security { NONE = 0, @@ -52,13 +52,11 @@ * * @param tx mbed pin to use for tx line of Serial interface * @param rx mbed pin to use for rx line of Serial interface - * @param reset reset pin of the wifi module () - * @param tcp_status connection status pin of the wifi module (GPIO 6) * @param ssid ssid of the network * @param phrase WEP or WPA key * @param sec Security type (NONE, WEP_128 or WPA) */ - Wifly( PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec); + Wifly( PinName tx, PinName rx, const char * ssid, const char * phrase, Security sec); /* * Connect the wifi module to the ssid contained in the constructor. @@ -192,8 +190,6 @@ protected: Serial wifi; - DigitalOut reset_pin; - DigitalIn tcp_status; char phrase[30]; char ssid[30]; const char * ip;
diff -r fb4494783863 -r 26ae56c7cb3d WiflyInterface.cpp --- a/WiflyInterface.cpp Fri Aug 24 13:48:36 2012 +0000 +++ b/WiflyInterface.cpp Thu Dec 19 09:56:59 2013 +0000 @@ -1,8 +1,8 @@ #include "WiflyInterface.h" -WiflyInterface::WiflyInterface( PinName tx, PinName rx, PinName reset, PinName tcp_status, - const char * ssid, const char * phrase, Security sec) : - Wifly(tx, rx, reset, tcp_status, ssid, phrase, sec) +WiflyInterface::WiflyInterface( PinName tx, PinName rx, + const char * ssid, const char * phrase, Security sec) : + Wifly(tx, rx, ssid, phrase, sec) { ip_set = false; }
diff -r fb4494783863 -r 26ae56c7cb3d WiflyInterface.h --- a/WiflyInterface.h Fri Aug 24 13:48:36 2012 +0000 +++ b/WiflyInterface.h Thu Dec 19 09:56:59 2013 +0000 @@ -33,13 +33,11 @@ * * \param tx mbed pin to use for tx line of Serial interface * \param rx mbed pin to use for rx line of Serial interface - * \param reset reset pin of the wifi module () - * \param tcp_status connection status pin of the wifi module (GPIO 6) * \param ssid ssid of the network * \param phrase WEP or WPA key * \param sec Security type (NONE, WEP_128 or WPA) */ - WiflyInterface(PinName tx, PinName rx, PinName reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec = NONE); + WiflyInterface(PinName tx, PinName rx, const char * ssid, const char * phrase, Security sec = NONE); /** Initialize the interface with DHCP. * Initialize the interface and configure it to use DHCP (no connection at this point).