NetworkServices with NUCLEO-L476RG and W5500 by SeeedStudio stack.
Dependents: coap-example Borsch coap-example
Fork of NetworkServices by
HTTPD/CBuffer.h@17:c976088bf39d, 2017-07-05 (annotated)
- Committer:
- sgnezdov
- Date:
- Wed Jul 05 18:34:39 2017 +0000
- Revision:
- 17:c976088bf39d
- Parent:
- 15:14382459c8b7
Changed setup interface to take MAC address, because W5500 may use software defined MAC when obtaining IP.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dgriffin65 | 15:14382459c8b7 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
dgriffin65 | 15:14382459c8b7 | 2 | * |
dgriffin65 | 15:14382459c8b7 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
dgriffin65 | 15:14382459c8b7 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
dgriffin65 | 15:14382459c8b7 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
dgriffin65 | 15:14382459c8b7 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
dgriffin65 | 15:14382459c8b7 | 7 | * furnished to do so, subject to the following conditions: |
dgriffin65 | 15:14382459c8b7 | 8 | * |
dgriffin65 | 15:14382459c8b7 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
dgriffin65 | 15:14382459c8b7 | 10 | * substantial portions of the Software. |
dgriffin65 | 15:14382459c8b7 | 11 | * |
dgriffin65 | 15:14382459c8b7 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
dgriffin65 | 15:14382459c8b7 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
dgriffin65 | 15:14382459c8b7 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
dgriffin65 | 15:14382459c8b7 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dgriffin65 | 15:14382459c8b7 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
dgriffin65 | 15:14382459c8b7 | 17 | */ |
dgriffin65 | 15:14382459c8b7 | 18 | |
dgriffin65 | 15:14382459c8b7 | 19 | #ifndef CIRCBUFFER_H_ |
dgriffin65 | 15:14382459c8b7 | 20 | #define CIRCBUFFER_H_ |
dgriffin65 | 15:14382459c8b7 | 21 | |
dgriffin65 | 15:14382459c8b7 | 22 | template <class T> |
dgriffin65 | 15:14382459c8b7 | 23 | class CircBuffer { |
dgriffin65 | 15:14382459c8b7 | 24 | public: |
dgriffin65 | 15:14382459c8b7 | 25 | CircBuffer(int length) { |
dgriffin65 | 15:14382459c8b7 | 26 | write = 0; |
dgriffin65 | 15:14382459c8b7 | 27 | read = 0; |
dgriffin65 | 15:14382459c8b7 | 28 | size = length + 1; |
dgriffin65 | 15:14382459c8b7 | 29 | buf = (T *)malloc(size * sizeof(T)); |
dgriffin65 | 15:14382459c8b7 | 30 | }; |
dgriffin65 | 15:14382459c8b7 | 31 | |
dgriffin65 | 15:14382459c8b7 | 32 | bool isFull() { |
dgriffin65 | 15:14382459c8b7 | 33 | return (((write + 1) % size) == read); |
dgriffin65 | 15:14382459c8b7 | 34 | }; |
dgriffin65 | 15:14382459c8b7 | 35 | |
dgriffin65 | 15:14382459c8b7 | 36 | bool isEmpty() { |
dgriffin65 | 15:14382459c8b7 | 37 | return (read == write); |
dgriffin65 | 15:14382459c8b7 | 38 | }; |
dgriffin65 | 15:14382459c8b7 | 39 | |
dgriffin65 | 15:14382459c8b7 | 40 | void queue(T k) { |
dgriffin65 | 15:14382459c8b7 | 41 | if (isFull()) { |
dgriffin65 | 15:14382459c8b7 | 42 | read++; |
dgriffin65 | 15:14382459c8b7 | 43 | read %= size; |
dgriffin65 | 15:14382459c8b7 | 44 | } |
dgriffin65 | 15:14382459c8b7 | 45 | buf[write++] = k; |
dgriffin65 | 15:14382459c8b7 | 46 | write %= size; |
dgriffin65 | 15:14382459c8b7 | 47 | } |
dgriffin65 | 15:14382459c8b7 | 48 | |
dgriffin65 | 15:14382459c8b7 | 49 | void flush() { |
dgriffin65 | 15:14382459c8b7 | 50 | read = 0; |
dgriffin65 | 15:14382459c8b7 | 51 | write = 0; |
dgriffin65 | 15:14382459c8b7 | 52 | } |
dgriffin65 | 15:14382459c8b7 | 53 | |
dgriffin65 | 15:14382459c8b7 | 54 | |
dgriffin65 | 15:14382459c8b7 | 55 | uint32_t available() { |
dgriffin65 | 15:14382459c8b7 | 56 | return (write >= read) ? write - read : size - read + write; |
dgriffin65 | 15:14382459c8b7 | 57 | }; |
dgriffin65 | 15:14382459c8b7 | 58 | |
dgriffin65 | 15:14382459c8b7 | 59 | bool dequeue(T * c) { |
dgriffin65 | 15:14382459c8b7 | 60 | bool empty = isEmpty(); |
dgriffin65 | 15:14382459c8b7 | 61 | if (!empty) { |
dgriffin65 | 15:14382459c8b7 | 62 | *c = buf[read++]; |
dgriffin65 | 15:14382459c8b7 | 63 | read %= size; |
dgriffin65 | 15:14382459c8b7 | 64 | } |
dgriffin65 | 15:14382459c8b7 | 65 | return(!empty); |
dgriffin65 | 15:14382459c8b7 | 66 | }; |
dgriffin65 | 15:14382459c8b7 | 67 | |
dgriffin65 | 15:14382459c8b7 | 68 | private: |
dgriffin65 | 15:14382459c8b7 | 69 | volatile uint32_t write; |
dgriffin65 | 15:14382459c8b7 | 70 | volatile uint32_t read; |
dgriffin65 | 15:14382459c8b7 | 71 | uint32_t size; |
dgriffin65 | 15:14382459c8b7 | 72 | T * buf; |
dgriffin65 | 15:14382459c8b7 | 73 | }; |
dgriffin65 | 15:14382459c8b7 | 74 | |
dgriffin65 | 15:14382459c8b7 | 75 | #endif |