Generic Pelion Device Management example for various Advantech modules.
This example is known to work great on the following platforms:
- WISE-1530 WiFi Module using DB-1505 carrier board and external SD card reader.
Example Functionality
This example showcases the following device functionality:
- On timer button increment, simulate Pelion LWM2M button resource change
Use this example with Mbed CLI
1. Import the application into your desktop:
mbed import https://os.mbed.com/teams/Advantech/code/pelion-example-common cd pelion-example-common
2. Download your developer certificate from pelion portal
3. Compile the program
mbed compile -t <toolchain> -m <TARGET_BOARD>
(supported toolchains : GCC_ARM / ARM / IAR)
4. Copy the binary file pelion-example-common.bin to your mbed device.
drivers/network/COMPONENT_WIFI_ISM43362/ISM43362/ATParser/BufferedSpi/Buffer/MyBuffer.cpp@0:43ff9e3bc244, 2019-03-12 (annotated)
- Committer:
- chuanga
- Date:
- Tue Mar 12 13:48:39 2019 +0800
- Revision:
- 0:43ff9e3bc244
copying sources from github repository
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chuanga | 0:43ff9e3bc244 | 1 | |
| chuanga | 0:43ff9e3bc244 | 2 | /** |
| chuanga | 0:43ff9e3bc244 | 3 | * @file Buffer.cpp |
| chuanga | 0:43ff9e3bc244 | 4 | * @brief Software Buffer - Templated Ring Buffer for most data types |
| chuanga | 0:43ff9e3bc244 | 5 | * @author sam grove |
| chuanga | 0:43ff9e3bc244 | 6 | * @version 1.0 |
| chuanga | 0:43ff9e3bc244 | 7 | * @see |
| chuanga | 0:43ff9e3bc244 | 8 | * |
| chuanga | 0:43ff9e3bc244 | 9 | * Copyright (c) 2013 |
| chuanga | 0:43ff9e3bc244 | 10 | * |
| chuanga | 0:43ff9e3bc244 | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| chuanga | 0:43ff9e3bc244 | 12 | * you may not use this file except in compliance with the License. |
| chuanga | 0:43ff9e3bc244 | 13 | * You may obtain a copy of the License at |
| chuanga | 0:43ff9e3bc244 | 14 | * |
| chuanga | 0:43ff9e3bc244 | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
| chuanga | 0:43ff9e3bc244 | 16 | * |
| chuanga | 0:43ff9e3bc244 | 17 | * Unless required by applicable law or agreed to in writing, software |
| chuanga | 0:43ff9e3bc244 | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
| chuanga | 0:43ff9e3bc244 | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| chuanga | 0:43ff9e3bc244 | 20 | * See the License for the specific language governing permissions and |
| chuanga | 0:43ff9e3bc244 | 21 | * limitations under the License. |
| chuanga | 0:43ff9e3bc244 | 22 | */ |
| chuanga | 0:43ff9e3bc244 | 23 | |
| chuanga | 0:43ff9e3bc244 | 24 | #include "MyBuffer.h" |
| chuanga | 0:43ff9e3bc244 | 25 | |
| chuanga | 0:43ff9e3bc244 | 26 | template <class T> |
| chuanga | 0:43ff9e3bc244 | 27 | MyBuffer<T>::MyBuffer(uint32_t size) |
| chuanga | 0:43ff9e3bc244 | 28 | { |
| chuanga | 0:43ff9e3bc244 | 29 | _buf = new T [size]; |
| chuanga | 0:43ff9e3bc244 | 30 | _size = size; |
| chuanga | 0:43ff9e3bc244 | 31 | clear(); |
| chuanga | 0:43ff9e3bc244 | 32 | |
| chuanga | 0:43ff9e3bc244 | 33 | return; |
| chuanga | 0:43ff9e3bc244 | 34 | } |
| chuanga | 0:43ff9e3bc244 | 35 | |
| chuanga | 0:43ff9e3bc244 | 36 | template <class T> |
| chuanga | 0:43ff9e3bc244 | 37 | MyBuffer<T>::~MyBuffer() |
| chuanga | 0:43ff9e3bc244 | 38 | { |
| chuanga | 0:43ff9e3bc244 | 39 | delete [] _buf; |
| chuanga | 0:43ff9e3bc244 | 40 | |
| chuanga | 0:43ff9e3bc244 | 41 | return; |
| chuanga | 0:43ff9e3bc244 | 42 | } |
| chuanga | 0:43ff9e3bc244 | 43 | |
| chuanga | 0:43ff9e3bc244 | 44 | template <class T> |
| chuanga | 0:43ff9e3bc244 | 45 | uint32_t MyBuffer<T>::getSize() |
| chuanga | 0:43ff9e3bc244 | 46 | { |
| chuanga | 0:43ff9e3bc244 | 47 | return this->_size; |
| chuanga | 0:43ff9e3bc244 | 48 | } |
| chuanga | 0:43ff9e3bc244 | 49 | |
| chuanga | 0:43ff9e3bc244 | 50 | template <class T> |
| chuanga | 0:43ff9e3bc244 | 51 | uint32_t MyBuffer<T>::getNbAvailable() |
| chuanga | 0:43ff9e3bc244 | 52 | { |
| chuanga | 0:43ff9e3bc244 | 53 | if (_wloc >= _rloc) { |
| chuanga | 0:43ff9e3bc244 | 54 | return (_wloc - _rloc); |
| chuanga | 0:43ff9e3bc244 | 55 | } else { |
| chuanga | 0:43ff9e3bc244 | 56 | return (_size - _rloc + _wloc); |
| chuanga | 0:43ff9e3bc244 | 57 | } |
| chuanga | 0:43ff9e3bc244 | 58 | } |
| chuanga | 0:43ff9e3bc244 | 59 | |
| chuanga | 0:43ff9e3bc244 | 60 | template <class T> |
| chuanga | 0:43ff9e3bc244 | 61 | void MyBuffer<T>::clear(void) |
| chuanga | 0:43ff9e3bc244 | 62 | { |
| chuanga | 0:43ff9e3bc244 | 63 | _wloc = 0; |
| chuanga | 0:43ff9e3bc244 | 64 | _rloc = 0; |
| chuanga | 0:43ff9e3bc244 | 65 | memset(_buf, 0, _size); |
| chuanga | 0:43ff9e3bc244 | 66 | |
| chuanga | 0:43ff9e3bc244 | 67 | return; |
| chuanga | 0:43ff9e3bc244 | 68 | } |
| chuanga | 0:43ff9e3bc244 | 69 | |
| chuanga | 0:43ff9e3bc244 | 70 | template <class T> |
| chuanga | 0:43ff9e3bc244 | 71 | uint32_t MyBuffer<T>::peek(char c) |
| chuanga | 0:43ff9e3bc244 | 72 | { |
| chuanga | 0:43ff9e3bc244 | 73 | return 1; |
| chuanga | 0:43ff9e3bc244 | 74 | } |
| chuanga | 0:43ff9e3bc244 | 75 | |
| chuanga | 0:43ff9e3bc244 | 76 | // make the linker aware of some possible types |
| chuanga | 0:43ff9e3bc244 | 77 | template class MyBuffer<uint8_t>; |
| chuanga | 0:43ff9e3bc244 | 78 | template class MyBuffer<int8_t>; |
| chuanga | 0:43ff9e3bc244 | 79 | template class MyBuffer<uint16_t>; |
| chuanga | 0:43ff9e3bc244 | 80 | template class MyBuffer<int16_t>; |
| chuanga | 0:43ff9e3bc244 | 81 | template class MyBuffer<uint32_t>; |
| chuanga | 0:43ff9e3bc244 | 82 | template class MyBuffer<int32_t>; |
| chuanga | 0:43ff9e3bc244 | 83 | template class MyBuffer<uint64_t>; |
| chuanga | 0:43ff9e3bc244 | 84 | template class MyBuffer<int64_t>; |
| chuanga | 0:43ff9e3bc244 | 85 | template class MyBuffer<char>; |
| chuanga | 0:43ff9e3bc244 | 86 | template class MyBuffer<wchar_t>; |