fork BLE_API to add update adv payload API

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Thu Jul 02 09:06:11 2015 +0100
Revision:
714:a6130aaa0fd9
Synchronized with git rev 7e8977d8
Author: Rohit Grover
Release 0.3.8
=============

This is a minor set of enhancements before we yotta-ize BLE_API.

Enhancements
~~~~~~~~~~~~

* Minor rework for class UUID; added a default and copy constructor; and a != operator.

* Added copy constructor and accessors for GapAdvertisingParams.

* GapScanningParams:: remove unnecessary checks for SCAN_TIMEOUT_MAX.

* Add a comment header block to explain why BLEDevice::init() may not be safe
to call from global static context.

* Introduce GattAttribute::INVALID_HANDLE.

* Replace some deprecated uses of Gap::address_t with Gap::Address_t.

Bugfixes
~~~~~~~~

* None.

Who changed what in which revision?

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