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
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/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。
解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
CBuffer.h@29:1c4419512941, 2013-02-26 (annotated)
- Committer:
- gsfan
- Date:
- Tue Feb 26 02:48:31 2013 +0000
- Revision:
- 29:1c4419512941
- Parent:
- 26:b347ee3a1087
- Child:
- 37:e61ea8267415
add websocket client
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsfan | 29:1c4419512941 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
gsfan | 29:1c4419512941 | 2 | * |
gsfan | 29:1c4419512941 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
gsfan | 29:1c4419512941 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
gsfan | 29:1c4419512941 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
gsfan | 29:1c4419512941 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
gsfan | 29:1c4419512941 | 7 | * furnished to do so, subject to the following conditions: |
gsfan | 29:1c4419512941 | 8 | * |
gsfan | 29:1c4419512941 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
gsfan | 29:1c4419512941 | 10 | * substantial portions of the Software. |
gsfan | 29:1c4419512941 | 11 | * |
gsfan | 29:1c4419512941 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
gsfan | 29:1c4419512941 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
gsfan | 29:1c4419512941 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
gsfan | 29:1c4419512941 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
gsfan | 29:1c4419512941 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
gsfan | 29:1c4419512941 | 17 | */ |
gsfan | 29:1c4419512941 | 18 | |
gsfan | 29:1c4419512941 | 19 | #ifndef CIRCBUFFER_H_ |
gsfan | 29:1c4419512941 | 20 | #define CIRCBUFFER_H_ |
gsfan | 29:1c4419512941 | 21 | |
gsfan | 29:1c4419512941 | 22 | template <class T> |
gsfan | 29:1c4419512941 | 23 | class CircBuffer { |
gsfan | 29:1c4419512941 | 24 | public: |
gsfan | 29:1c4419512941 | 25 | CircBuffer(int length) { |
gsfan | 29:1c4419512941 | 26 | write = 0; |
gsfan | 29:1c4419512941 | 27 | read = 0; |
gsfan | 29:1c4419512941 | 28 | size = length + 1; |
gsfan | 29:1c4419512941 | 29 | buf = (T *)malloc(size * sizeof(T)); |
gsfan | 29:1c4419512941 | 30 | }; |
gsfan | 29:1c4419512941 | 31 | |
gsfan | 29:1c4419512941 | 32 | bool isFull() { |
gsfan | 29:1c4419512941 | 33 | return (((write + 1) % size) == read); |
gsfan | 29:1c4419512941 | 34 | }; |
gsfan | 29:1c4419512941 | 35 | |
gsfan | 29:1c4419512941 | 36 | bool isEmpty() { |
gsfan | 29:1c4419512941 | 37 | return (read == write); |
gsfan | 29:1c4419512941 | 38 | }; |
gsfan | 29:1c4419512941 | 39 | |
gsfan | 29:1c4419512941 | 40 | bool queue(T k) { |
gsfan | 29:1c4419512941 | 41 | if (isFull()) { |
gsfan | 29:1c4419512941 | 42 | // read++; |
gsfan | 29:1c4419512941 | 43 | // read %= size; |
gsfan | 29:1c4419512941 | 44 | return false; |
gsfan | 29:1c4419512941 | 45 | } |
gsfan | 29:1c4419512941 | 46 | buf[write++] = k; |
gsfan | 29:1c4419512941 | 47 | write %= size; |
gsfan | 29:1c4419512941 | 48 | return true; |
gsfan | 29:1c4419512941 | 49 | } |
gsfan | 29:1c4419512941 | 50 | |
gsfan | 29:1c4419512941 | 51 | void flush() { |
gsfan | 29:1c4419512941 | 52 | read = 0; |
gsfan | 29:1c4419512941 | 53 | write = 0; |
gsfan | 29:1c4419512941 | 54 | } |
gsfan | 29:1c4419512941 | 55 | |
gsfan | 29:1c4419512941 | 56 | |
gsfan | 29:1c4419512941 | 57 | uint32_t available() { |
gsfan | 29:1c4419512941 | 58 | return (write >= read) ? write - read : size - read + write; |
gsfan | 29:1c4419512941 | 59 | }; |
gsfan | 29:1c4419512941 | 60 | |
gsfan | 29:1c4419512941 | 61 | bool dequeue(T * c) { |
gsfan | 29:1c4419512941 | 62 | bool empty = isEmpty(); |
gsfan | 29:1c4419512941 | 63 | if (!empty) { |
gsfan | 29:1c4419512941 | 64 | *c = buf[read++]; |
gsfan | 29:1c4419512941 | 65 | read %= size; |
gsfan | 29:1c4419512941 | 66 | } |
gsfan | 29:1c4419512941 | 67 | return(!empty); |
gsfan | 29:1c4419512941 | 68 | }; |
gsfan | 29:1c4419512941 | 69 | |
gsfan | 29:1c4419512941 | 70 | private: |
gsfan | 29:1c4419512941 | 71 | volatile uint32_t write; |
gsfan | 29:1c4419512941 | 72 | volatile uint32_t read; |
gsfan | 29:1c4419512941 | 73 | uint32_t size; |
gsfan | 29:1c4419512941 | 74 | T * buf; |
gsfan | 29:1c4419512941 | 75 | }; |
gsfan | 29:1c4419512941 | 76 | |
gsfan | 29:1c4419512941 | 77 | #endif |