![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
OneNet_IoT_demo for ASC platform
Dependencies: Common_lib ESP8266 EdpKit_lib cJSON_lib driver_mbed_HP20x driver_mbed_TH02 wifi_example
Fork of mbed-os-example-esp8266 by
esp8266-driver/ESP8266/ATParser/BufferedSerial/Buffer/MyBuffer.cpp@1:b4a718e62e0b, 2017-01-12 (annotated)
- Committer:
- sarahmarshy
- Date:
- Thu Jan 12 22:05:15 2017 +0000
- Revision:
- 1:b4a718e62e0b
- Parent:
- 0:b887535f68bf
Update esp8266-driver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sarahmarshy | 1:b4a718e62e0b | 1 | |
sarahmarshy | 1:b4a718e62e0b | 2 | /** |
sarahmarshy | 1:b4a718e62e0b | 3 | * @file Buffer.cpp |
sarahmarshy | 1:b4a718e62e0b | 4 | * @brief Software Buffer - Templated Ring Buffer for most data types |
sarahmarshy | 1:b4a718e62e0b | 5 | * @author sam grove |
sarahmarshy | 1:b4a718e62e0b | 6 | * @version 1.0 |
sarahmarshy | 1:b4a718e62e0b | 7 | * @see |
sarahmarshy | 1:b4a718e62e0b | 8 | * |
sarahmarshy | 1:b4a718e62e0b | 9 | * Copyright (c) 2013 |
sarahmarshy | 1:b4a718e62e0b | 10 | * |
sarahmarshy | 1:b4a718e62e0b | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sarahmarshy | 1:b4a718e62e0b | 12 | * you may not use this file except in compliance with the License. |
sarahmarshy | 1:b4a718e62e0b | 13 | * You may obtain a copy of the License at |
sarahmarshy | 1:b4a718e62e0b | 14 | * |
sarahmarshy | 1:b4a718e62e0b | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
sarahmarshy | 1:b4a718e62e0b | 16 | * |
sarahmarshy | 1:b4a718e62e0b | 17 | * Unless required by applicable law or agreed to in writing, software |
sarahmarshy | 1:b4a718e62e0b | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
sarahmarshy | 1:b4a718e62e0b | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sarahmarshy | 1:b4a718e62e0b | 20 | * See the License for the specific language governing permissions and |
sarahmarshy | 1:b4a718e62e0b | 21 | * limitations under the License. |
sarahmarshy | 1:b4a718e62e0b | 22 | */ |
sarahmarshy | 1:b4a718e62e0b | 23 | |
sarahmarshy | 1:b4a718e62e0b | 24 | #include "MyBuffer.h" |
sarahmarshy | 1:b4a718e62e0b | 25 | |
sarahmarshy | 1:b4a718e62e0b | 26 | template <class T> |
sarahmarshy | 1:b4a718e62e0b | 27 | MyBuffer<T>::MyBuffer(uint32_t size) |
sarahmarshy | 1:b4a718e62e0b | 28 | { |
sarahmarshy | 1:b4a718e62e0b | 29 | _buf = new T [size]; |
sarahmarshy | 1:b4a718e62e0b | 30 | _size = size; |
sarahmarshy | 1:b4a718e62e0b | 31 | clear(); |
sarahmarshy | 1:b4a718e62e0b | 32 | |
sarahmarshy | 1:b4a718e62e0b | 33 | return; |
sarahmarshy | 1:b4a718e62e0b | 34 | } |
sarahmarshy | 1:b4a718e62e0b | 35 | |
sarahmarshy | 1:b4a718e62e0b | 36 | template <class T> |
sarahmarshy | 1:b4a718e62e0b | 37 | MyBuffer<T>::~MyBuffer() |
sarahmarshy | 1:b4a718e62e0b | 38 | { |
sarahmarshy | 1:b4a718e62e0b | 39 | delete [] _buf; |
sarahmarshy | 1:b4a718e62e0b | 40 | |
sarahmarshy | 1:b4a718e62e0b | 41 | return; |
sarahmarshy | 1:b4a718e62e0b | 42 | } |
sarahmarshy | 1:b4a718e62e0b | 43 | |
sarahmarshy | 1:b4a718e62e0b | 44 | template <class T> |
sarahmarshy | 1:b4a718e62e0b | 45 | uint32_t MyBuffer<T>::getSize() |
sarahmarshy | 1:b4a718e62e0b | 46 | { |
sarahmarshy | 1:b4a718e62e0b | 47 | return this->_size; |
sarahmarshy | 1:b4a718e62e0b | 48 | } |
sarahmarshy | 1:b4a718e62e0b | 49 | |
sarahmarshy | 1:b4a718e62e0b | 50 | template <class T> |
sarahmarshy | 1:b4a718e62e0b | 51 | void MyBuffer<T>::clear(void) |
sarahmarshy | 1:b4a718e62e0b | 52 | { |
sarahmarshy | 1:b4a718e62e0b | 53 | _wloc = 0; |
sarahmarshy | 1:b4a718e62e0b | 54 | _rloc = 0; |
sarahmarshy | 1:b4a718e62e0b | 55 | memset(_buf, 0, _size); |
sarahmarshy | 1:b4a718e62e0b | 56 | |
sarahmarshy | 1:b4a718e62e0b | 57 | return; |
sarahmarshy | 1:b4a718e62e0b | 58 | } |
sarahmarshy | 1:b4a718e62e0b | 59 | |
sarahmarshy | 1:b4a718e62e0b | 60 | template <class T> |
sarahmarshy | 1:b4a718e62e0b | 61 | uint32_t MyBuffer<T>::peek(char c) |
sarahmarshy | 1:b4a718e62e0b | 62 | { |
sarahmarshy | 1:b4a718e62e0b | 63 | return 1; |
sarahmarshy | 1:b4a718e62e0b | 64 | } |
sarahmarshy | 1:b4a718e62e0b | 65 | |
sarahmarshy | 1:b4a718e62e0b | 66 | // make the linker aware of some possible types |
sarahmarshy | 1:b4a718e62e0b | 67 | template class MyBuffer<uint8_t>; |
sarahmarshy | 1:b4a718e62e0b | 68 | template class MyBuffer<int8_t>; |
sarahmarshy | 1:b4a718e62e0b | 69 | template class MyBuffer<uint16_t>; |
sarahmarshy | 1:b4a718e62e0b | 70 | template class MyBuffer<int16_t>; |
sarahmarshy | 1:b4a718e62e0b | 71 | template class MyBuffer<uint32_t>; |
sarahmarshy | 1:b4a718e62e0b | 72 | template class MyBuffer<int32_t>; |
sarahmarshy | 1:b4a718e62e0b | 73 | template class MyBuffer<uint64_t>; |
sarahmarshy | 1:b4a718e62e0b | 74 | template class MyBuffer<int64_t>; |
sarahmarshy | 1:b4a718e62e0b | 75 | template class MyBuffer<char>; |
sarahmarshy | 1:b4a718e62e0b | 76 | template class MyBuffer<wchar_t>; |