Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: WNC14A2AInterface-httpmodified
Fork of easy-connect by
esp8266-driver/ESP8266/ATParser/BufferedSerial/Buffer/MyBuffer.h@8:54ac58ec99d5, 2017-12-14 (annotated)
- Committer:
- nrithya
- Date:
- Thu Dec 14 00:33:15 2017 +0000
- Revision:
- 8:54ac58ec99d5
- Parent:
- 0:2563b0415d1f
easy connect wnc added to http request with debug mode enabled. traces collected for AT%CGEQOS, AT%MEAS, AT%PCONI
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JMF | 0:2563b0415d1f | 1 | |
| JMF | 0:2563b0415d1f | 2 | /** |
| JMF | 0:2563b0415d1f | 3 | * @file Buffer.h |
| JMF | 0:2563b0415d1f | 4 | * @brief Software Buffer - Templated Ring Buffer for most data types |
| JMF | 0:2563b0415d1f | 5 | * @author sam grove |
| JMF | 0:2563b0415d1f | 6 | * @version 1.0 |
| JMF | 0:2563b0415d1f | 7 | * @see |
| JMF | 0:2563b0415d1f | 8 | * |
| JMF | 0:2563b0415d1f | 9 | * Copyright (c) 2013 |
| JMF | 0:2563b0415d1f | 10 | * |
| JMF | 0:2563b0415d1f | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| JMF | 0:2563b0415d1f | 12 | * you may not use this file except in compliance with the License. |
| JMF | 0:2563b0415d1f | 13 | * You may obtain a copy of the License at |
| JMF | 0:2563b0415d1f | 14 | * |
| JMF | 0:2563b0415d1f | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
| JMF | 0:2563b0415d1f | 16 | * |
| JMF | 0:2563b0415d1f | 17 | * Unless required by applicable law or agreed to in writing, software |
| JMF | 0:2563b0415d1f | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
| JMF | 0:2563b0415d1f | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| JMF | 0:2563b0415d1f | 20 | * See the License for the specific language governing permissions and |
| JMF | 0:2563b0415d1f | 21 | * limitations under the License. |
| JMF | 0:2563b0415d1f | 22 | */ |
| JMF | 0:2563b0415d1f | 23 | |
| JMF | 0:2563b0415d1f | 24 | #ifndef MYBUFFER_H |
| JMF | 0:2563b0415d1f | 25 | #define MYBUFFER_H |
| JMF | 0:2563b0415d1f | 26 | |
| JMF | 0:2563b0415d1f | 27 | #include <stdint.h> |
| JMF | 0:2563b0415d1f | 28 | #include <string.h> |
| JMF | 0:2563b0415d1f | 29 | |
| JMF | 0:2563b0415d1f | 30 | /** A templated software ring buffer |
| JMF | 0:2563b0415d1f | 31 | * |
| JMF | 0:2563b0415d1f | 32 | * Example: |
| JMF | 0:2563b0415d1f | 33 | * @code |
| JMF | 0:2563b0415d1f | 34 | * #include "mbed.h" |
| JMF | 0:2563b0415d1f | 35 | * #include "MyBuffer.h" |
| JMF | 0:2563b0415d1f | 36 | * |
| JMF | 0:2563b0415d1f | 37 | * MyBuffer <char> buf; |
| JMF | 0:2563b0415d1f | 38 | * |
| JMF | 0:2563b0415d1f | 39 | * int main() |
| JMF | 0:2563b0415d1f | 40 | * { |
| JMF | 0:2563b0415d1f | 41 | * buf = 'a'; |
| JMF | 0:2563b0415d1f | 42 | * buf.put('b'); |
| JMF | 0:2563b0415d1f | 43 | * char *head = buf.head(); |
| JMF | 0:2563b0415d1f | 44 | * puts(head); |
| JMF | 0:2563b0415d1f | 45 | * |
| JMF | 0:2563b0415d1f | 46 | * char whats_in_there[2] = {0}; |
| JMF | 0:2563b0415d1f | 47 | * int pos = 0; |
| JMF | 0:2563b0415d1f | 48 | * |
| JMF | 0:2563b0415d1f | 49 | * while(buf.available()) |
| JMF | 0:2563b0415d1f | 50 | * { |
| JMF | 0:2563b0415d1f | 51 | * whats_in_there[pos++] = buf; |
| JMF | 0:2563b0415d1f | 52 | * } |
| JMF | 0:2563b0415d1f | 53 | * printf("%c %c\n", whats_in_there[0], whats_in_there[1]); |
| JMF | 0:2563b0415d1f | 54 | * buf.clear(); |
| JMF | 0:2563b0415d1f | 55 | * error("done\n\n\n"); |
| JMF | 0:2563b0415d1f | 56 | * } |
| JMF | 0:2563b0415d1f | 57 | * @endcode |
| JMF | 0:2563b0415d1f | 58 | */ |
| JMF | 0:2563b0415d1f | 59 | |
| JMF | 0:2563b0415d1f | 60 | template <typename T> |
| JMF | 0:2563b0415d1f | 61 | class MyBuffer |
| JMF | 0:2563b0415d1f | 62 | { |
| JMF | 0:2563b0415d1f | 63 | private: |
| JMF | 0:2563b0415d1f | 64 | T *_buf; |
| JMF | 0:2563b0415d1f | 65 | volatile uint32_t _wloc; |
| JMF | 0:2563b0415d1f | 66 | volatile uint32_t _rloc; |
| JMF | 0:2563b0415d1f | 67 | uint32_t _size; |
| JMF | 0:2563b0415d1f | 68 | |
| JMF | 0:2563b0415d1f | 69 | public: |
| JMF | 0:2563b0415d1f | 70 | /** Create a Buffer and allocate memory for it |
| JMF | 0:2563b0415d1f | 71 | * @param size The size of the buffer |
| JMF | 0:2563b0415d1f | 72 | */ |
| JMF | 0:2563b0415d1f | 73 | MyBuffer(uint32_t size = 0x100); |
| JMF | 0:2563b0415d1f | 74 | |
| JMF | 0:2563b0415d1f | 75 | /** Get the size of the ring buffer |
| JMF | 0:2563b0415d1f | 76 | * @return the size of the ring buffer |
| JMF | 0:2563b0415d1f | 77 | */ |
| JMF | 0:2563b0415d1f | 78 | uint32_t getSize(); |
| JMF | 0:2563b0415d1f | 79 | |
| JMF | 0:2563b0415d1f | 80 | /** Destry a Buffer and release it's allocated memory |
| JMF | 0:2563b0415d1f | 81 | */ |
| JMF | 0:2563b0415d1f | 82 | ~MyBuffer(); |
| JMF | 0:2563b0415d1f | 83 | |
| JMF | 0:2563b0415d1f | 84 | /** Add a data element into the buffer |
| JMF | 0:2563b0415d1f | 85 | * @param data Something to add to the buffer |
| JMF | 0:2563b0415d1f | 86 | */ |
| JMF | 0:2563b0415d1f | 87 | void put(T data); |
| JMF | 0:2563b0415d1f | 88 | |
| JMF | 0:2563b0415d1f | 89 | /** Remove a data element from the buffer |
| JMF | 0:2563b0415d1f | 90 | * @return Pull the oldest element from the buffer |
| JMF | 0:2563b0415d1f | 91 | */ |
| JMF | 0:2563b0415d1f | 92 | T get(void); |
| JMF | 0:2563b0415d1f | 93 | |
| JMF | 0:2563b0415d1f | 94 | /** Get the address to the head of the buffer |
| JMF | 0:2563b0415d1f | 95 | * @return The address of element 0 in the buffer |
| JMF | 0:2563b0415d1f | 96 | */ |
| JMF | 0:2563b0415d1f | 97 | T *head(void); |
| JMF | 0:2563b0415d1f | 98 | |
| JMF | 0:2563b0415d1f | 99 | /** Reset the buffer to 0. Useful if using head() to parse packeted data |
| JMF | 0:2563b0415d1f | 100 | */ |
| JMF | 0:2563b0415d1f | 101 | void clear(void); |
| JMF | 0:2563b0415d1f | 102 | |
| JMF | 0:2563b0415d1f | 103 | /** Determine if anything is readable in the buffer |
| JMF | 0:2563b0415d1f | 104 | * @return 1 if something can be read, 0 otherwise |
| JMF | 0:2563b0415d1f | 105 | */ |
| JMF | 0:2563b0415d1f | 106 | uint32_t available(void); |
| JMF | 0:2563b0415d1f | 107 | |
| JMF | 0:2563b0415d1f | 108 | /** Overloaded operator for writing to the buffer |
| JMF | 0:2563b0415d1f | 109 | * @param data Something to put in the buffer |
| JMF | 0:2563b0415d1f | 110 | * @return |
| JMF | 0:2563b0415d1f | 111 | */ |
| JMF | 0:2563b0415d1f | 112 | MyBuffer &operator= (T data) |
| JMF | 0:2563b0415d1f | 113 | { |
| JMF | 0:2563b0415d1f | 114 | put(data); |
| JMF | 0:2563b0415d1f | 115 | return *this; |
| JMF | 0:2563b0415d1f | 116 | } |
| JMF | 0:2563b0415d1f | 117 | |
| JMF | 0:2563b0415d1f | 118 | /** Overloaded operator for reading from the buffer |
| JMF | 0:2563b0415d1f | 119 | * @return Pull the oldest element from the buffer |
| JMF | 0:2563b0415d1f | 120 | */ |
| JMF | 0:2563b0415d1f | 121 | operator int(void) |
| JMF | 0:2563b0415d1f | 122 | { |
| JMF | 0:2563b0415d1f | 123 | return get(); |
| JMF | 0:2563b0415d1f | 124 | } |
| JMF | 0:2563b0415d1f | 125 | |
| JMF | 0:2563b0415d1f | 126 | uint32_t peek(char c); |
| JMF | 0:2563b0415d1f | 127 | |
| JMF | 0:2563b0415d1f | 128 | }; |
| JMF | 0:2563b0415d1f | 129 | |
| JMF | 0:2563b0415d1f | 130 | template <class T> |
| JMF | 0:2563b0415d1f | 131 | inline void MyBuffer<T>::put(T data) |
| JMF | 0:2563b0415d1f | 132 | { |
| JMF | 0:2563b0415d1f | 133 | _buf[_wloc++] = data; |
| JMF | 0:2563b0415d1f | 134 | _wloc %= (_size-1); |
| JMF | 0:2563b0415d1f | 135 | |
| JMF | 0:2563b0415d1f | 136 | return; |
| JMF | 0:2563b0415d1f | 137 | } |
| JMF | 0:2563b0415d1f | 138 | |
| JMF | 0:2563b0415d1f | 139 | template <class T> |
| JMF | 0:2563b0415d1f | 140 | inline T MyBuffer<T>::get(void) |
| JMF | 0:2563b0415d1f | 141 | { |
| JMF | 0:2563b0415d1f | 142 | T data_pos = _buf[_rloc++]; |
| JMF | 0:2563b0415d1f | 143 | _rloc %= (_size-1); |
| JMF | 0:2563b0415d1f | 144 | |
| JMF | 0:2563b0415d1f | 145 | return data_pos; |
| JMF | 0:2563b0415d1f | 146 | } |
| JMF | 0:2563b0415d1f | 147 | |
| JMF | 0:2563b0415d1f | 148 | template <class T> |
| JMF | 0:2563b0415d1f | 149 | inline T *MyBuffer<T>::head(void) |
| JMF | 0:2563b0415d1f | 150 | { |
| JMF | 0:2563b0415d1f | 151 | T *data_pos = &_buf[0]; |
| JMF | 0:2563b0415d1f | 152 | |
| JMF | 0:2563b0415d1f | 153 | return data_pos; |
| JMF | 0:2563b0415d1f | 154 | } |
| JMF | 0:2563b0415d1f | 155 | |
| JMF | 0:2563b0415d1f | 156 | template <class T> |
| JMF | 0:2563b0415d1f | 157 | inline uint32_t MyBuffer<T>::available(void) |
| JMF | 0:2563b0415d1f | 158 | { |
| JMF | 0:2563b0415d1f | 159 | return (_wloc == _rloc) ? 0 : 1; |
| JMF | 0:2563b0415d1f | 160 | } |
| JMF | 0:2563b0415d1f | 161 | |
| JMF | 0:2563b0415d1f | 162 | #endif |
| JMF | 0:2563b0415d1f | 163 |
