BLE_API_Tiny_BLE
Fork of BLE_API by
public/GapAdvertisingParams.h@329:2e082a9c7c13, 2015-04-15 (annotated)
- Committer:
- rgrover1
- Date:
- Wed Apr 15 09:05:10 2015 +0100
- Revision:
- 329:2e082a9c7c13
- Parent:
- 260:ea7f9f14cc15
Synchronized with git rev 995d4797
Author: Rohit Grover
merge GapAdvertisingParams.cpp into GapAdvertisingParams.h;
also get rid of the empty virtual destructor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 260:ea7f9f14cc15 | 1 | /* mbed Microcontroller Library |
rgrover1 | 260:ea7f9f14cc15 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 260:ea7f9f14cc15 | 3 | * |
rgrover1 | 260:ea7f9f14cc15 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 260:ea7f9f14cc15 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 260:ea7f9f14cc15 | 6 | * You may obtain a copy of the License at |
rgrover1 | 260:ea7f9f14cc15 | 7 | * |
rgrover1 | 260:ea7f9f14cc15 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 260:ea7f9f14cc15 | 9 | * |
rgrover1 | 260:ea7f9f14cc15 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 260:ea7f9f14cc15 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 260:ea7f9f14cc15 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 260:ea7f9f14cc15 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 260:ea7f9f14cc15 | 14 | * limitations under the License. |
rgrover1 | 260:ea7f9f14cc15 | 15 | */ |
rgrover1 | 260:ea7f9f14cc15 | 16 | |
rgrover1 | 260:ea7f9f14cc15 | 17 | #ifndef __GAP_ADVERTISING_PARAMS_H__ |
rgrover1 | 260:ea7f9f14cc15 | 18 | #define __GAP_ADVERTISING_PARAMS_H__ |
rgrover1 | 260:ea7f9f14cc15 | 19 | |
rgrover1 | 260:ea7f9f14cc15 | 20 | /**************************************************************************/ |
rgrover1 | 260:ea7f9f14cc15 | 21 | /*! |
rgrover1 | 260:ea7f9f14cc15 | 22 | \brief |
rgrover1 | 260:ea7f9f14cc15 | 23 | This class provides a wrapper for the core advertising parameters, |
rgrover1 | 260:ea7f9f14cc15 | 24 | including the advertising type (Connectable Undirected, |
rgrover1 | 260:ea7f9f14cc15 | 25 | Non Connectable Undirected, etc.), as well as the advertising and |
rgrover1 | 260:ea7f9f14cc15 | 26 | timeout intervals. |
rgrover1 | 260:ea7f9f14cc15 | 27 | |
rgrover1 | 260:ea7f9f14cc15 | 28 | \par |
rgrover1 | 260:ea7f9f14cc15 | 29 | See the following for more information on advertising types: |
rgrover1 | 260:ea7f9f14cc15 | 30 | |
rgrover1 | 260:ea7f9f14cc15 | 31 | \li \c Bluetooth Core Specification 4.0 (Vol. 6), Part B, Section 2.3.1 |
rgrover1 | 260:ea7f9f14cc15 | 32 | \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 9.3 |
rgrover1 | 260:ea7f9f14cc15 | 33 | */ |
rgrover1 | 260:ea7f9f14cc15 | 34 | /**************************************************************************/ |
rgrover1 | 260:ea7f9f14cc15 | 35 | class GapAdvertisingParams { |
rgrover1 | 260:ea7f9f14cc15 | 36 | public: |
rgrover1 | 260:ea7f9f14cc15 | 37 | static const unsigned GAP_ADV_PARAMS_INTERVAL_MIN = 0x0020; |
rgrover1 | 260:ea7f9f14cc15 | 38 | static const unsigned GAP_ADV_PARAMS_INTERVAL_MIN_NONCON = 0x00A0; |
rgrover1 | 260:ea7f9f14cc15 | 39 | static const unsigned GAP_ADV_PARAMS_INTERVAL_MAX = 0x4000; |
rgrover1 | 260:ea7f9f14cc15 | 40 | static const unsigned GAP_ADV_PARAMS_TIMEOUT_MAX = 0x3FFF; |
rgrover1 | 260:ea7f9f14cc15 | 41 | |
rgrover1 | 260:ea7f9f14cc15 | 42 | /**************************************************************************/ |
rgrover1 | 260:ea7f9f14cc15 | 43 | /*! |
rgrover1 | 260:ea7f9f14cc15 | 44 | \brief |
rgrover1 | 260:ea7f9f14cc15 | 45 | Encapsulates the peripheral advertising modes, which determine how |
rgrover1 | 260:ea7f9f14cc15 | 46 | the device appears to other central devices in hearing range |
rgrover1 | 260:ea7f9f14cc15 | 47 | |
rgrover1 | 260:ea7f9f14cc15 | 48 | \par |
rgrover1 | 260:ea7f9f14cc15 | 49 | See the following for more information on advertising types: |
rgrover1 | 260:ea7f9f14cc15 | 50 | |
rgrover1 | 260:ea7f9f14cc15 | 51 | \li \c Bluetooth Core Specification 4.0 (Vol. 6), Part B, Section 2.3.1 |
rgrover1 | 260:ea7f9f14cc15 | 52 | \li \c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 9.3 |
rgrover1 | 260:ea7f9f14cc15 | 53 | */ |
rgrover1 | 260:ea7f9f14cc15 | 54 | /**************************************************************************/ |
rgrover1 | 260:ea7f9f14cc15 | 55 | enum AdvertisingType { |
rgrover1 | 260:ea7f9f14cc15 | 56 | ADV_CONNECTABLE_UNDIRECTED, /**< Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1 */ |
rgrover1 | 260:ea7f9f14cc15 | 57 | ADV_CONNECTABLE_DIRECTED, /**< Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2 */ |
rgrover1 | 260:ea7f9f14cc15 | 58 | ADV_SCANNABLE_UNDIRECTED, /**< Include support for Scan Response payloads, see Vol 6, Part B, Section 2.3.1.4 */ |
rgrover1 | 260:ea7f9f14cc15 | 59 | ADV_NON_CONNECTABLE_UNDIRECTED /**< Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3 */ |
rgrover1 | 260:ea7f9f14cc15 | 60 | }; |
rgrover1 | 260:ea7f9f14cc15 | 61 | |
rgrover1 | 260:ea7f9f14cc15 | 62 | public: |
rgrover1 | 260:ea7f9f14cc15 | 63 | GapAdvertisingParams(AdvertisingType advType = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED, |
rgrover1 | 260:ea7f9f14cc15 | 64 | uint16_t interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON, |
rgrover1 | 329:2e082a9c7c13 | 65 | uint16_t timeout = 0) : _advType(advType), _interval(interval), _timeout(timeout) { |
rgrover1 | 329:2e082a9c7c13 | 66 | /* Interval checks */ |
rgrover1 | 329:2e082a9c7c13 | 67 | if (_advType == ADV_CONNECTABLE_DIRECTED) { |
rgrover1 | 329:2e082a9c7c13 | 68 | /* Interval must be 0 in directed connectable mode */ |
rgrover1 | 329:2e082a9c7c13 | 69 | _interval = 0; |
rgrover1 | 329:2e082a9c7c13 | 70 | } else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) { |
rgrover1 | 329:2e082a9c7c13 | 71 | /* Min interval is slightly larger than in other modes */ |
rgrover1 | 329:2e082a9c7c13 | 72 | if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) { |
rgrover1 | 329:2e082a9c7c13 | 73 | _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON; |
rgrover1 | 329:2e082a9c7c13 | 74 | } |
rgrover1 | 329:2e082a9c7c13 | 75 | if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) { |
rgrover1 | 329:2e082a9c7c13 | 76 | _interval = GAP_ADV_PARAMS_INTERVAL_MAX; |
rgrover1 | 329:2e082a9c7c13 | 77 | } |
rgrover1 | 329:2e082a9c7c13 | 78 | } else { |
rgrover1 | 329:2e082a9c7c13 | 79 | /* Stay within interval limits */ |
rgrover1 | 329:2e082a9c7c13 | 80 | if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) { |
rgrover1 | 329:2e082a9c7c13 | 81 | _interval = GAP_ADV_PARAMS_INTERVAL_MIN; |
rgrover1 | 329:2e082a9c7c13 | 82 | } |
rgrover1 | 329:2e082a9c7c13 | 83 | if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) { |
rgrover1 | 329:2e082a9c7c13 | 84 | _interval = GAP_ADV_PARAMS_INTERVAL_MAX; |
rgrover1 | 329:2e082a9c7c13 | 85 | } |
rgrover1 | 329:2e082a9c7c13 | 86 | } |
rgrover1 | 329:2e082a9c7c13 | 87 | |
rgrover1 | 329:2e082a9c7c13 | 88 | /* Timeout checks */ |
rgrover1 | 329:2e082a9c7c13 | 89 | if (timeout) { |
rgrover1 | 329:2e082a9c7c13 | 90 | /* Stay within timeout limits */ |
rgrover1 | 329:2e082a9c7c13 | 91 | if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) { |
rgrover1 | 329:2e082a9c7c13 | 92 | _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX; |
rgrover1 | 329:2e082a9c7c13 | 93 | } |
rgrover1 | 329:2e082a9c7c13 | 94 | } |
rgrover1 | 329:2e082a9c7c13 | 95 | } |
rgrover1 | 260:ea7f9f14cc15 | 96 | |
rgrover1 | 260:ea7f9f14cc15 | 97 | AdvertisingType getAdvertisingType(void) const {return _advType; } |
rgrover1 | 260:ea7f9f14cc15 | 98 | uint16_t getInterval(void) const {return _interval;} |
rgrover1 | 260:ea7f9f14cc15 | 99 | uint16_t getTimeout(void) const {return _timeout; } |
rgrover1 | 260:ea7f9f14cc15 | 100 | |
rgrover1 | 260:ea7f9f14cc15 | 101 | void setAdvertisingType(AdvertisingType newAdvType) {_advType = newAdvType; } |
rgrover1 | 260:ea7f9f14cc15 | 102 | void setInterval(uint16_t newInterval) {_interval = newInterval;} |
rgrover1 | 260:ea7f9f14cc15 | 103 | void setTimeout(uint16_t newTimeout) {_timeout = newTimeout; } |
rgrover1 | 260:ea7f9f14cc15 | 104 | |
rgrover1 | 260:ea7f9f14cc15 | 105 | private: |
rgrover1 | 260:ea7f9f14cc15 | 106 | AdvertisingType _advType; |
rgrover1 | 260:ea7f9f14cc15 | 107 | uint16_t _interval; |
rgrover1 | 260:ea7f9f14cc15 | 108 | uint16_t _timeout; |
rgrover1 | 260:ea7f9f14cc15 | 109 | |
rgrover1 | 260:ea7f9f14cc15 | 110 | private: |
rgrover1 | 260:ea7f9f14cc15 | 111 | /* disallow copy constructor */ |
rgrover1 | 260:ea7f9f14cc15 | 112 | GapAdvertisingParams(const GapAdvertisingParams &); |
rgrover1 | 260:ea7f9f14cc15 | 113 | }; |
rgrover1 | 260:ea7f9f14cc15 | 114 | |
rgrover1 | 260:ea7f9f14cc15 | 115 | #endif // ifndef __GAP_ADVERTISING_PARAMS_H__ |