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