Improve readability with getHandle inline

Fork of BLE_API by Bluetooth Low Energy

Committer:
schilit
Date:
Mon Jan 12 14:49:53 2015 -0800
Revision:
257:6be2b4b0cd71
Parent:
106:a20be740075d
Merged the BLE_API from upstream

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rohit Grover 106:a20be740075d 1 /* mbed Microcontroller Library
Rohit Grover 106:a20be740075d 2 * Copyright (c) 2006-2013 ARM Limited
Rohit Grover 106:a20be740075d 3 *
Rohit Grover 106:a20be740075d 4 * Licensed under the Apache License, Version 2.0 (the "License");
Rohit Grover 106:a20be740075d 5 * you may not use this file except in compliance with the License.
Rohit Grover 106:a20be740075d 6 * You may obtain a copy of the License at
Rohit Grover 106:a20be740075d 7 *
Rohit Grover 106:a20be740075d 8 * http://www.apache.org/licenses/LICENSE-2.0
Rohit Grover 106:a20be740075d 9 *
Rohit Grover 106:a20be740075d 10 * Unless required by applicable law or agreed to in writing, software
Rohit Grover 106:a20be740075d 11 * distributed under the License is distributed on an "AS IS" BASIS,
Rohit Grover 106:a20be740075d 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Rohit Grover 106:a20be740075d 13 * See the License for the specific language governing permissions and
Rohit Grover 106:a20be740075d 14 * limitations under the License.
Rohit Grover 106:a20be740075d 15 */
Rohit Grover 106:a20be740075d 16
Rohit Grover 106:a20be740075d 17 #include <stdio.h>
Rohit Grover 106:a20be740075d 18 #include <string.h>
Rohit Grover 106:a20be740075d 19
Rohit Grover 106:a20be740075d 20 #include "blecommon.h"
Rohit Grover 106:a20be740075d 21 #include "GapAdvertisingParams.h"
Rohit Grover 106:a20be740075d 22
Rohit Grover 106:a20be740075d 23 /**************************************************************************/
Rohit Grover 106:a20be740075d 24 /*!
Rohit Grover 106:a20be740075d 25 \brief
Rohit Grover 106:a20be740075d 26 Instantiates a new GapAdvertisingParams instance
Rohit Grover 106:a20be740075d 27
Rohit Grover 106:a20be740075d 28 \param[in] advType
Rohit Grover 106:a20be740075d 29 The GAP advertising mode to use for this device. Valid
Rohit Grover 106:a20be740075d 30 values are defined in AdvertisingType:
Rohit Grover 106:a20be740075d 31
Rohit Grover 106:a20be740075d 32 \par ADV_NON_CONNECTABLE_UNDIRECTED
Rohit Grover 106:a20be740075d 33 All connections to the peripheral device will be refused.
Rohit Grover 106:a20be740075d 34
Rohit Grover 106:a20be740075d 35 \par ADV_CONNECTABLE_DIRECTED
Rohit Grover 106:a20be740075d 36 Only connections from a pre-defined central device will be
Rohit Grover 106:a20be740075d 37 accepted.
Rohit Grover 106:a20be740075d 38
Rohit Grover 106:a20be740075d 39 \par ADV_CONNECTABLE_UNDIRECTED
Rohit Grover 106:a20be740075d 40 Any central device can connect to this peripheral.
Rohit Grover 106:a20be740075d 41
Rohit Grover 106:a20be740075d 42 \par ADV_SCANNABLE_UNDIRECTED
Rohit Grover 106:a20be740075d 43 Any central device can connect to this peripheral, and
Rohit Grover 106:a20be740075d 44 the secondary Scan Response payload will be included or
Rohit Grover 106:a20be740075d 45 available to central devices.
Rohit Grover 106:a20be740075d 46
Rohit Grover 106:a20be740075d 47 \par
Rohit Grover 106:a20be740075d 48 See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
Rohit Grover 106:a20be740075d 49 Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
Rohit Grover 106:a20be740075d 50 Section 2.3.1 for further information on GAP connection
Rohit Grover 106:a20be740075d 51 modes
Rohit Grover 106:a20be740075d 52
Rohit Grover 106:a20be740075d 53 \param[in] interval
Rohit Grover 106:a20be740075d 54 Advertising interval between 0x0020 and 0x4000 in 0.625ms units
Rohit Grover 106:a20be740075d 55 (20ms to 10.24s). If using non-connectable mode
Rohit Grover 106:a20be740075d 56 (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is 0x00A0
Rohit Grover 106:a20be740075d 57 (100ms). To reduce the likelihood of collisions, the link layer
Rohit Grover 106:a20be740075d 58 perturbs this interval by a pseudo-random delay with a range of
Rohit Grover 106:a20be740075d 59 0 ms to 10 ms for each advertising event.
Rohit Grover 106:a20be740075d 60
Rohit Grover 106:a20be740075d 61 \par
Rohit Grover 106:a20be740075d 62 Decreasing this value will allow central devices to detect
Rohit Grover 106:a20be740075d 63 your peripheral faster at the expense of more power being
Rohit Grover 106:a20be740075d 64 used by the radio due to the higher data transmit rate.
Rohit Grover 106:a20be740075d 65
Rohit Grover 106:a20be740075d 66 \par
Rohit Grover 106:a20be740075d 67 This field must be set to 0 if connectionMode is equal
Rohit Grover 106:a20be740075d 68 to ADV_CONNECTABLE_DIRECTED
Rohit Grover 106:a20be740075d 69
Rohit Grover 106:a20be740075d 70 \par
Rohit Grover 106:a20be740075d 71 See Bluetooth Core Specification, Vol 3., Part C,
Rohit Grover 106:a20be740075d 72 Appendix A for suggested advertising intervals.
Rohit Grover 106:a20be740075d 73
Rohit Grover 106:a20be740075d 74 \param[in] timeout
Rohit Grover 106:a20be740075d 75 Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
Rohit Grover 106:a20be740075d 76 in seconds. Enter 0 to disable the advertising timeout.
Rohit Grover 106:a20be740075d 77
Rohit Grover 106:a20be740075d 78 \par EXAMPLE
Rohit Grover 106:a20be740075d 79
Rohit Grover 106:a20be740075d 80 \code
Rohit Grover 106:a20be740075d 81
Rohit Grover 106:a20be740075d 82 \endcode
Rohit Grover 106:a20be740075d 83 */
Rohit Grover 106:a20be740075d 84 /**************************************************************************/
Rohit Grover 106:a20be740075d 85 GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout)
Rohit Grover 106:a20be740075d 86 {
Rohit Grover 106:a20be740075d 87 _advType = advType;
Rohit Grover 106:a20be740075d 88 _interval = interval;
Rohit Grover 106:a20be740075d 89 _timeout = timeout;
Rohit Grover 106:a20be740075d 90
Rohit Grover 106:a20be740075d 91 /* Interval checks */
Rohit Grover 106:a20be740075d 92 if (_advType == ADV_CONNECTABLE_DIRECTED) {
Rohit Grover 106:a20be740075d 93 /* Interval must be 0 in directed connectable mode */
Rohit Grover 106:a20be740075d 94 _interval = 0;
Rohit Grover 106:a20be740075d 95 } else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
Rohit Grover 106:a20be740075d 96 /* Min interval is slightly larger than in other modes */
Rohit Grover 106:a20be740075d 97 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
Rohit Grover 106:a20be740075d 98 _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
Rohit Grover 106:a20be740075d 99 }
Rohit Grover 106:a20be740075d 100 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
Rohit Grover 106:a20be740075d 101 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
Rohit Grover 106:a20be740075d 102 }
Rohit Grover 106:a20be740075d 103 } else {
Rohit Grover 106:a20be740075d 104 /* Stay within interval limits */
Rohit Grover 106:a20be740075d 105 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) {
Rohit Grover 106:a20be740075d 106 _interval = GAP_ADV_PARAMS_INTERVAL_MIN;
Rohit Grover 106:a20be740075d 107 }
Rohit Grover 106:a20be740075d 108 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
Rohit Grover 106:a20be740075d 109 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
Rohit Grover 106:a20be740075d 110 }
Rohit Grover 106:a20be740075d 111 }
Rohit Grover 106:a20be740075d 112
Rohit Grover 106:a20be740075d 113 /* Timeout checks */
Rohit Grover 106:a20be740075d 114 if (timeout) {
Rohit Grover 106:a20be740075d 115 /* Stay within timeout limits */
Rohit Grover 106:a20be740075d 116 if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) {
Rohit Grover 106:a20be740075d 117 _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
Rohit Grover 106:a20be740075d 118 }
Rohit Grover 106:a20be740075d 119 }
Rohit Grover 106:a20be740075d 120 }
Rohit Grover 106:a20be740075d 121
Rohit Grover 106:a20be740075d 122 /**************************************************************************/
Rohit Grover 106:a20be740075d 123 /*!
Rohit Grover 106:a20be740075d 124 Destructor
Rohit Grover 106:a20be740075d 125 */
Rohit Grover 106:a20be740075d 126 /**************************************************************************/
Rohit Grover 106:a20be740075d 127 GapAdvertisingParams::~GapAdvertisingParams(void)
Rohit Grover 106:a20be740075d 128 {
Rohit Grover 106:a20be740075d 129 }