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