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@4:50a31ff5f974, 2013-12-12 (annotated)
- Committer:
- ktownsend
- Date:
- Thu Dec 12 02:20:54 2013 +0000
- Revision:
- 4:50a31ff5f974
- Parent:
- 2:ffc5216bd2cc
- Child:
- 6:425638944835
More GAP refactoring
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 | 4:50a31ff5f974 | 9 | @brief Instantiates a new GapAdvertisingParams instance |
| ktownsend | 4:50a31ff5f974 | 10 | |
| ktownsend | 4:50a31ff5f974 | 11 | @param[in] connectionMode |
| ktownsend | 4:50a31ff5f974 | 12 | The GAP connection mode to use for this device. Valid |
| ktownsend | 4:50a31ff5f974 | 13 | values are defined in \ref ConnectionMode |
| ktownsend | 2:ffc5216bd2cc | 14 | |
| ktownsend | 4:50a31ff5f974 | 15 | @para |
| ktownsend | 4:50a31ff5f974 | 16 | NON_CONNECTABLE - All connections to the peripheral device |
| ktownsend | 4:50a31ff5f974 | 17 | will be refused. |
| ktownsend | 4:50a31ff5f974 | 18 | |
| ktownsend | 4:50a31ff5f974 | 19 | @para |
| ktownsend | 4:50a31ff5f974 | 20 | DIRECTED_CONNECTABLE - Only connections from a pre-defined |
| ktownsend | 4:50a31ff5f974 | 21 | central device will be accepted. |
| ktownsend | 4:50a31ff5f974 | 22 | |
| ktownsend | 4:50a31ff5f974 | 23 | @para |
| ktownsend | 4:50a31ff5f974 | 24 | UNDIRECTED_CONNECTABLE - Any central device can connect to |
| ktownsend | 4:50a31ff5f974 | 25 | this peripheral. |
| ktownsend | 4:50a31ff5f974 | 26 | |
| ktownsend | 4:50a31ff5f974 | 27 | @note See Bluetooth Core Specification 4.0 (Vol. 3), |
| ktownsend | 4:50a31ff5f974 | 28 | Part C, Section 9.3 for further information on GAP |
| ktownsend | 4:50a31ff5f974 | 29 | connection modes |
| ktownsend | 4:50a31ff5f974 | 30 | |
| ktownsend | 4:50a31ff5f974 | 31 | @param[in] interval |
| ktownsend | 4:50a31ff5f974 | 32 | Advertising interval between 0x20 and 0x4000 (32 and 16384) |
| ktownsend | 4:50a31ff5f974 | 33 | in 0.625ms intervals (20ms to 10.24s). |
| ktownsend | 4:50a31ff5f974 | 34 | |
| ktownsend | 4:50a31ff5f974 | 35 | @para |
| ktownsend | 4:50a31ff5f974 | 36 | Increasing this value will allow central devices to detect |
| ktownsend | 4:50a31ff5f974 | 37 | your peripheral faster at the expense of more power being |
| ktownsend | 4:50a31ff5f974 | 38 | used by the radio due to the higher data transmit rate. |
| ktownsend | 4:50a31ff5f974 | 39 | |
| ktownsend | 4:50a31ff5f974 | 40 | @note This field must be set to 0 if connectionMode is equal |
| ktownsend | 4:50a31ff5f974 | 41 | to \ref DIRECTED_CONNECTABLE |
| ktownsend | 4:50a31ff5f974 | 42 | |
| ktownsend | 4:50a31ff5f974 | 43 | @param[in] timeout |
| ktownsend | 4:50a31ff5f974 | 44 | Advertising timeout between 0x1 and 0x3FFF (1 and 16383) |
| ktownsend | 4:50a31ff5f974 | 45 | in seconds. Enter 0 to disable the advertising timeout. |
| ktownsend | 4:50a31ff5f974 | 46 | |
| ktownsend | 2:ffc5216bd2cc | 47 | @section EXAMPLE |
| ktownsend | 2:ffc5216bd2cc | 48 | |
| ktownsend | 2:ffc5216bd2cc | 49 | @code |
| ktownsend | 2:ffc5216bd2cc | 50 | |
| ktownsend | 2:ffc5216bd2cc | 51 | @endcode |
| ktownsend | 2:ffc5216bd2cc | 52 | */ |
| ktownsend | 2:ffc5216bd2cc | 53 | /**************************************************************************/ |
| ktownsend | 4:50a31ff5f974 | 54 | GapAdvertisingParams::GapAdvertisingParams(ConnectionMode connectionMode, uint16_t interval, uint16_t timeout) |
| ktownsend | 2:ffc5216bd2cc | 55 | { |
| ktownsend | 4:50a31ff5f974 | 56 | _connectionMode = connectionMode; |
| ktownsend | 2:ffc5216bd2cc | 57 | _interval = interval; |
| ktownsend | 2:ffc5216bd2cc | 58 | _timeout = timeout; |
| ktownsend | 4:50a31ff5f974 | 59 | |
| ktownsend | 4:50a31ff5f974 | 60 | /* Interval checks */ |
| ktownsend | 4:50a31ff5f974 | 61 | if (_connectionMode == DIRECTED_CONNECTABLE) |
| ktownsend | 4:50a31ff5f974 | 62 | { |
| ktownsend | 4:50a31ff5f974 | 63 | /* Interval must be 0 in directed connectable mode */ |
| ktownsend | 4:50a31ff5f974 | 64 | _interval = 0; |
| ktownsend | 4:50a31ff5f974 | 65 | } |
| ktownsend | 4:50a31ff5f974 | 66 | else |
| ktownsend | 4:50a31ff5f974 | 67 | { |
| ktownsend | 4:50a31ff5f974 | 68 | /* Stay within interval limits */ |
| ktownsend | 4:50a31ff5f974 | 69 | if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) |
| ktownsend | 4:50a31ff5f974 | 70 | { |
| ktownsend | 4:50a31ff5f974 | 71 | _interval = GAP_ADV_PARAMS_INTERVAL_MIN; |
| ktownsend | 4:50a31ff5f974 | 72 | } |
| ktownsend | 4:50a31ff5f974 | 73 | if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) |
| ktownsend | 4:50a31ff5f974 | 74 | { |
| ktownsend | 4:50a31ff5f974 | 75 | _interval = GAP_ADV_PARAMS_INTERVAL_MAX; |
| ktownsend | 4:50a31ff5f974 | 76 | } |
| ktownsend | 4:50a31ff5f974 | 77 | } |
| ktownsend | 4:50a31ff5f974 | 78 | |
| ktownsend | 4:50a31ff5f974 | 79 | /* Timeout checks */ |
| ktownsend | 4:50a31ff5f974 | 80 | if (timeout) |
| ktownsend | 4:50a31ff5f974 | 81 | { |
| ktownsend | 4:50a31ff5f974 | 82 | /* Stay within timeout limits */ |
| ktownsend | 4:50a31ff5f974 | 83 | if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) |
| ktownsend | 4:50a31ff5f974 | 84 | { |
| ktownsend | 4:50a31ff5f974 | 85 | _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX; |
| ktownsend | 4:50a31ff5f974 | 86 | } |
| ktownsend | 4:50a31ff5f974 | 87 | } |
| ktownsend | 2:ffc5216bd2cc | 88 | } |
| ktownsend | 2:ffc5216bd2cc | 89 | |
| ktownsend | 2:ffc5216bd2cc | 90 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 91 | /*! |
| ktownsend | 2:ffc5216bd2cc | 92 | Destructor |
| ktownsend | 2:ffc5216bd2cc | 93 | */ |
| ktownsend | 2:ffc5216bd2cc | 94 | /**************************************************************************/ |
| ktownsend | 2:ffc5216bd2cc | 95 | GapAdvertisingParams::~GapAdvertisingParams(void) |
| ktownsend | 2:ffc5216bd2cc | 96 | { |
| ktownsend | 2:ffc5216bd2cc | 97 | } |
