Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
GapAdvertisingParams.cpp@18:86fe1e247a54, 2013-12-18 (annotated)
- Committer:
- ktownsend
- Date:
- Wed Dec 18 19:39:19 2013 +0000
- Revision:
- 18:86fe1e247a54
- Parent:
- 14:6ea5d1012a64
- Child:
- 19:a6f33421746c
Doxygen Cleanup
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ktownsend | 2:ffc5216bd2cc | 1 | #include <stdio.h> |
| ktownsend | 2:ffc5216bd2cc | 2 | #include <string.h> |
| ktownsend | 2:ffc5216bd2cc | 3 | |
| ktownsend | 4:50a31ff5f974 | 4 | #include "blecommon.h" |
| ktownsend | 2:ffc5216bd2cc | 5 | #include "GapAdvertisingParams.h" |
| ktownsend | 2:ffc5216bd2cc | 6 | |
| ktownsend | 2:ffc5216bd2cc | 7 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 8 | /*! |
| ktownsend | 18:86fe1e247a54 | 9 | \brief |
| ktownsend | 18:86fe1e247a54 | 10 | Instantiates a new GapAdvertisingParams instance |
| ktownsend | 4:50a31ff5f974 | 11 | |
| ktownsend | 18:86fe1e247a54 | 12 | \param[in] advType |
| ktownsend | 6:425638944835 | 13 | The GAP advertising mode to use for this device. Valid |
| ktownsend | 18:86fe1e247a54 | 14 | values are defined in AdvertisingType |
| ktownsend | 2:ffc5216bd2cc | 15 | |
| ktownsend | 18:86fe1e247a54 | 16 | \par ADV_NON_CONNECTABLE_UNDIRECTED |
| ktownsend | 18:86fe1e247a54 | 17 | All connections to the peripheral device will be refused. |
| ktownsend | 4:50a31ff5f974 | 18 | |
| ktownsend | 18:86fe1e247a54 | 19 | \par ADV_CONNECTABLE_DIRECTED |
| ktownsend | 18:86fe1e247a54 | 20 | Only connections from a pre-defined central device will be |
| ktownsend | 18:86fe1e247a54 | 21 | accepted. |
| ktownsend | 4:50a31ff5f974 | 22 | |
| ktownsend | 18:86fe1e247a54 | 23 | \par ADV_CONNECTABLE_UNDIRECTED |
| ktownsend | 18:86fe1e247a54 | 24 | Any central device can connect to this peripheral. |
| ktownsend | 6:425638944835 | 25 | |
| ktownsend | 18:86fe1e247a54 | 26 | \par ADV_SCANNABLE_UNDIRECTED |
| ktownsend | 18:86fe1e247a54 | 27 | Any central device can connect to this peripheral, and |
| ktownsend | 18:86fe1e247a54 | 28 | the secondary Scan Response payload will be included or |
| ktownsend | 18:86fe1e247a54 | 29 | available to central devices. |
| ktownsend | 18:86fe1e247a54 | 30 | |
| ktownsend | 18:86fe1e247a54 | 31 | \note |
| ktownsend | 4:50a31ff5f974 | 32 | |
| ktownsend | 18:86fe1e247a54 | 33 | See Bluetooth Core Specification 4.0 (Vol. 3), Part C, |
| ktownsend | 18:86fe1e247a54 | 34 | Section 9.3 and Core Specification 4.0 (Vol. 6), Part B, |
| ktownsend | 18:86fe1e247a54 | 35 | Section 2.3.1 for further information on GAP connection |
| ktownsend | 18:86fe1e247a54 | 36 | modes |
| ktownsend | 4:50a31ff5f974 | 37 | |
| ktownsend | 18:86fe1e247a54 | 38 | \param[in] interval |
| ktownsend | 14:6ea5d1012a64 | 39 | Advertising interval between 0x0020 and 0x4000 in 0.625ms |
| ktownsend | 14:6ea5d1012a64 | 40 | units (20ms to 10.24s). If using non-connectable mode |
| ktownsend | 18:86fe1e247a54 | 41 | (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is |
| ktownsend | 14:6ea5d1012a64 | 42 | 0x00A0 (100ms). |
| ktownsend | 4:50a31ff5f974 | 43 | |
| ktownsend | 18:86fe1e247a54 | 44 | \par |
| ktownsend | 4:50a31ff5f974 | 45 | Increasing this value will allow central devices to detect |
| ktownsend | 4:50a31ff5f974 | 46 | your peripheral faster at the expense of more power being |
| ktownsend | 4:50a31ff5f974 | 47 | used by the radio due to the higher data transmit rate. |
| ktownsend | 4:50a31ff5f974 | 48 | |
| ktownsend | 18:86fe1e247a54 | 49 | \note |
| ktownsend | 18:86fe1e247a54 | 50 | This field must be set to 0 if connectionMode is equal |
| ktownsend | 18:86fe1e247a54 | 51 | to ADV_CONNECTABLE_DIRECTED |
| ktownsend | 14:6ea5d1012a64 | 52 | |
| ktownsend | 18:86fe1e247a54 | 53 | \note |
| ktownsend | 18:86fe1e247a54 | 54 | See Bluetooth Core Specification, Vol 3., Part C, |
| ktownsend | 14:6ea5d1012a64 | 55 | Appendix A for suggested advertising intervals: |
| ktownsend | 14:6ea5d1012a64 | 56 | |
| ktownsend | 18:86fe1e247a54 | 57 | \param[in] timeout |
| ktownsend | 4:50a31ff5f974 | 58 | Advertising timeout between 0x1 and 0x3FFF (1 and 16383) |
| ktownsend | 4:50a31ff5f974 | 59 | in seconds. Enter 0 to disable the advertising timeout. |
| ktownsend | 4:50a31ff5f974 | 60 | |
| ktownsend | 18:86fe1e247a54 | 61 | \par EXAMPLE |
| ktownsend | 2:ffc5216bd2cc | 62 | |
| ktownsend | 18:86fe1e247a54 | 63 | \code |
| ktownsend | 2:ffc5216bd2cc | 64 | |
| ktownsend | 18:86fe1e247a54 | 65 | \endcode |
| ktownsend | 2:ffc5216bd2cc | 66 | */ |
| ktownsend | 2:ffc5216bd2cc | 67 | /**************************************************************************/ |
| ktownsend | 6:425638944835 | 68 | GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout) |
| ktownsend | 2:ffc5216bd2cc | 69 | { |
| ktownsend | 6:425638944835 | 70 | _advType = advType; |
| ktownsend | 2:ffc5216bd2cc | 71 | _interval = interval; |
| ktownsend | 2:ffc5216bd2cc | 72 | _timeout = timeout; |
| ktownsend | 4:50a31ff5f974 | 73 | |
| ktownsend | 4:50a31ff5f974 | 74 | /* Interval checks */ |
| ktownsend | 6:425638944835 | 75 | if (_advType == ADV_CONNECTABLE_DIRECTED) |
| ktownsend | 4:50a31ff5f974 | 76 | { |
| ktownsend | 4:50a31ff5f974 | 77 | /* Interval must be 0 in directed connectable mode */ |
| ktownsend | 4:50a31ff5f974 | 78 | _interval = 0; |
| ktownsend | 4:50a31ff5f974 | 79 | } |
| ktownsend | 14:6ea5d1012a64 | 80 | else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) |
| ktownsend | 14:6ea5d1012a64 | 81 | { |
| ktownsend | 14:6ea5d1012a64 | 82 | /* Min interval is slightly larger than in other modes */ |
| ktownsend | 14:6ea5d1012a64 | 83 | if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) |
| ktownsend | 14:6ea5d1012a64 | 84 | { |
| ktownsend | 14:6ea5d1012a64 | 85 | _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON; |
| ktownsend | 14:6ea5d1012a64 | 86 | } |
| ktownsend | 14:6ea5d1012a64 | 87 | if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) |
| ktownsend | 14:6ea5d1012a64 | 88 | { |
| ktownsend | 14:6ea5d1012a64 | 89 | _interval = GAP_ADV_PARAMS_INTERVAL_MAX; |
| ktownsend | 14:6ea5d1012a64 | 90 | } |
| ktownsend | 14:6ea5d1012a64 | 91 | } |
| ktownsend | 4:50a31ff5f974 | 92 | else |
| ktownsend | 4:50a31ff5f974 | 93 | { |
| ktownsend | 4:50a31ff5f974 | 94 | /* Stay within interval limits */ |
| ktownsend | 4:50a31ff5f974 | 95 | if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) |
| ktownsend | 4:50a31ff5f974 | 96 | { |
| ktownsend | 4:50a31ff5f974 | 97 | _interval = GAP_ADV_PARAMS_INTERVAL_MIN; |
| ktownsend | 4:50a31ff5f974 | 98 | } |
| ktownsend | 4:50a31ff5f974 | 99 | if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) |
| ktownsend | 4:50a31ff5f974 | 100 | { |
| ktownsend | 4:50a31ff5f974 | 101 | _interval = GAP_ADV_PARAMS_INTERVAL_MAX; |
| ktownsend | 4:50a31ff5f974 | 102 | } |
| ktownsend | 4:50a31ff5f974 | 103 | } |
| ktownsend | 4:50a31ff5f974 | 104 | |
| ktownsend | 4:50a31ff5f974 | 105 | /* Timeout checks */ |
| ktownsend | 4:50a31ff5f974 | 106 | if (timeout) |
| ktownsend | 4:50a31ff5f974 | 107 | { |
| ktownsend | 4:50a31ff5f974 | 108 | /* Stay within timeout limits */ |
| ktownsend | 4:50a31ff5f974 | 109 | if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) |
| ktownsend | 4:50a31ff5f974 | 110 | { |
| ktownsend | 4:50a31ff5f974 | 111 | _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX; |
| ktownsend | 4:50a31ff5f974 | 112 | } |
| ktownsend | 4:50a31ff5f974 | 113 | } |
| ktownsend | 2:ffc5216bd2cc | 114 | } |
| ktownsend | 2:ffc5216bd2cc | 115 | |
| ktownsend | 2:ffc5216bd2cc | 116 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 117 | /*! |
| ktownsend | 2:ffc5216bd2cc | 118 | Destructor |
| ktownsend | 2:ffc5216bd2cc | 119 | */ |
| ktownsend | 2:ffc5216bd2cc | 120 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 121 | GapAdvertisingParams::~GapAdvertisingParams(void) |
| ktownsend | 2:ffc5216bd2cc | 122 | { |
| ktownsend | 2:ffc5216bd2cc | 123 | } |
| ktownsend | 7:5e1f0d7f7c7d | 124 | |
| ktownsend | 7:5e1f0d7f7c7d | 125 | /**************************************************************************/ |
| ktownsend | 7:5e1f0d7f7c7d | 126 | /*! |
| ktownsend | 18:86fe1e247a54 | 127 | \brief returns the current Advertising Type value |
| ktownsend | 7:5e1f0d7f7c7d | 128 | */ |
| ktownsend | 7:5e1f0d7f7c7d | 129 | /**************************************************************************/ |
| ktownsend | 7:5e1f0d7f7c7d | 130 | GapAdvertisingParams::AdvertisingType GapAdvertisingParams::getAdvertisingType(void) |
| ktownsend | 7:5e1f0d7f7c7d | 131 | { |
| ktownsend | 7:5e1f0d7f7c7d | 132 | return _advType; |
| ktownsend | 7:5e1f0d7f7c7d | 133 | } |
| ktownsend | 9:124ae067ae27 | 134 | |
| ktownsend | 9:124ae067ae27 | 135 | /**************************************************************************/ |
| ktownsend | 9:124ae067ae27 | 136 | /*! |
| ktownsend | 18:86fe1e247a54 | 137 | \brief returns the current Advertising Delay (in units of 0.625ms) |
| ktownsend | 9:124ae067ae27 | 138 | */ |
| ktownsend | 9:124ae067ae27 | 139 | /**************************************************************************/ |
| ktownsend | 9:124ae067ae27 | 140 | uint16_t GapAdvertisingParams::getInterval(void) |
| ktownsend | 9:124ae067ae27 | 141 | { |
| ktownsend | 9:124ae067ae27 | 142 | return _interval; |
| ktownsend | 9:124ae067ae27 | 143 | } |
| ktownsend | 9:124ae067ae27 | 144 | |
| ktownsend | 9:124ae067ae27 | 145 | /**************************************************************************/ |
| ktownsend | 9:124ae067ae27 | 146 | /*! |
| ktownsend | 18:86fe1e247a54 | 147 | \brief returns the current Advertising Timeout (in seconds) |
| ktownsend | 9:124ae067ae27 | 148 | */ |
| ktownsend | 9:124ae067ae27 | 149 | /**************************************************************************/ |
| ktownsend | 9:124ae067ae27 | 150 | uint16_t GapAdvertisingParams::getTimeout(void) |
| ktownsend | 9:124ae067ae27 | 151 | { |
| ktownsend | 9:124ae067ae27 | 152 | return _timeout; |
| ktownsend | 9:124ae067ae27 | 153 | } |
