Minor temporary patch to allow DFU packet callback
Fork of BLE_API by
GapAdvertisingParams.cpp@9:124ae067ae27, 2013-12-16 (annotated)
- Committer:
- ktownsend
- Date:
- Mon Dec 16 19:43:33 2013 +0000
- Revision:
- 9:124ae067ae27
- Parent:
- 7:5e1f0d7f7c7d
- Child:
- 14:6ea5d1012a64
Preview code enabling most advertising features (requires new nRF51 firmware)
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 | 6:425638944835 | 11 | @param[in] advType |
ktownsend | 6:425638944835 | 12 | The GAP advertising mode to use for this device. Valid |
ktownsend | 6:425638944835 | 13 | values are defined in \ref AdvertisingType |
ktownsend | 2:ffc5216bd2cc | 14 | |
ktownsend | 4:50a31ff5f974 | 15 | @para |
ktownsend | 6:425638944835 | 16 | ADV_NON_CONNECTABLE_UNDIRECTED - All connections to the |
ktownsend | 6:425638944835 | 17 | peripheral device will be refused. |
ktownsend | 4:50a31ff5f974 | 18 | |
ktownsend | 4:50a31ff5f974 | 19 | @para |
ktownsend | 6:425638944835 | 20 | ADV_CONNECTABLE_DIRECTED - Only connections from a |
ktownsend | 6:425638944835 | 21 | pre-defined central device will be accepted. |
ktownsend | 4:50a31ff5f974 | 22 | |
ktownsend | 4:50a31ff5f974 | 23 | @para |
ktownsend | 6:425638944835 | 24 | ADV_CONNECTABLE_UNDIRECTED - Any central device can connect |
ktownsend | 6:425638944835 | 25 | to this peripheral. |
ktownsend | 6:425638944835 | 26 | |
ktownsend | 6:425638944835 | 27 | @para |
ktownsend | 6:425638944835 | 28 | ADV_SCANNABLE_UNDIRECTED - Any central device can connect |
ktownsend | 6:425638944835 | 29 | to this peripheral, and the secondary Scan Response |
ktownsend | 6:425638944835 | 30 | payload will be included or available to central devices. |
ktownsend | 4:50a31ff5f974 | 31 | |
ktownsend | 4:50a31ff5f974 | 32 | @note See Bluetooth Core Specification 4.0 (Vol. 3), |
ktownsend | 6:425638944835 | 33 | Part C, Section 9.3 and Core Specification 4.0 (Vol. 6), |
ktownsend | 6:425638944835 | 34 | Part B, Section 2.3.1 for further information on GAP |
ktownsend | 4:50a31ff5f974 | 35 | connection modes |
ktownsend | 4:50a31ff5f974 | 36 | |
ktownsend | 4:50a31ff5f974 | 37 | @param[in] interval |
ktownsend | 4:50a31ff5f974 | 38 | Advertising interval between 0x20 and 0x4000 (32 and 16384) |
ktownsend | 4:50a31ff5f974 | 39 | in 0.625ms intervals (20ms to 10.24s). |
ktownsend | 4:50a31ff5f974 | 40 | |
ktownsend | 4:50a31ff5f974 | 41 | @para |
ktownsend | 4:50a31ff5f974 | 42 | Increasing this value will allow central devices to detect |
ktownsend | 4:50a31ff5f974 | 43 | your peripheral faster at the expense of more power being |
ktownsend | 4:50a31ff5f974 | 44 | used by the radio due to the higher data transmit rate. |
ktownsend | 4:50a31ff5f974 | 45 | |
ktownsend | 4:50a31ff5f974 | 46 | @note This field must be set to 0 if connectionMode is equal |
ktownsend | 6:425638944835 | 47 | to \ref ADV_CONNECTABLE_DIRECTED |
ktownsend | 4:50a31ff5f974 | 48 | |
ktownsend | 4:50a31ff5f974 | 49 | @param[in] timeout |
ktownsend | 4:50a31ff5f974 | 50 | Advertising timeout between 0x1 and 0x3FFF (1 and 16383) |
ktownsend | 4:50a31ff5f974 | 51 | in seconds. Enter 0 to disable the advertising timeout. |
ktownsend | 4:50a31ff5f974 | 52 | |
ktownsend | 2:ffc5216bd2cc | 53 | @section EXAMPLE |
ktownsend | 2:ffc5216bd2cc | 54 | |
ktownsend | 2:ffc5216bd2cc | 55 | @code |
ktownsend | 2:ffc5216bd2cc | 56 | |
ktownsend | 2:ffc5216bd2cc | 57 | @endcode |
ktownsend | 2:ffc5216bd2cc | 58 | */ |
ktownsend | 2:ffc5216bd2cc | 59 | /**************************************************************************/ |
ktownsend | 6:425638944835 | 60 | GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout) |
ktownsend | 2:ffc5216bd2cc | 61 | { |
ktownsend | 6:425638944835 | 62 | _advType = advType; |
ktownsend | 2:ffc5216bd2cc | 63 | _interval = interval; |
ktownsend | 2:ffc5216bd2cc | 64 | _timeout = timeout; |
ktownsend | 4:50a31ff5f974 | 65 | |
ktownsend | 4:50a31ff5f974 | 66 | /* Interval checks */ |
ktownsend | 6:425638944835 | 67 | if (_advType == ADV_CONNECTABLE_DIRECTED) |
ktownsend | 4:50a31ff5f974 | 68 | { |
ktownsend | 4:50a31ff5f974 | 69 | /* Interval must be 0 in directed connectable mode */ |
ktownsend | 4:50a31ff5f974 | 70 | _interval = 0; |
ktownsend | 4:50a31ff5f974 | 71 | } |
ktownsend | 4:50a31ff5f974 | 72 | else |
ktownsend | 4:50a31ff5f974 | 73 | { |
ktownsend | 4:50a31ff5f974 | 74 | /* Stay within interval limits */ |
ktownsend | 4:50a31ff5f974 | 75 | if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) |
ktownsend | 4:50a31ff5f974 | 76 | { |
ktownsend | 4:50a31ff5f974 | 77 | _interval = GAP_ADV_PARAMS_INTERVAL_MIN; |
ktownsend | 4:50a31ff5f974 | 78 | } |
ktownsend | 4:50a31ff5f974 | 79 | if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) |
ktownsend | 4:50a31ff5f974 | 80 | { |
ktownsend | 4:50a31ff5f974 | 81 | _interval = GAP_ADV_PARAMS_INTERVAL_MAX; |
ktownsend | 4:50a31ff5f974 | 82 | } |
ktownsend | 4:50a31ff5f974 | 83 | } |
ktownsend | 4:50a31ff5f974 | 84 | |
ktownsend | 4:50a31ff5f974 | 85 | /* Timeout checks */ |
ktownsend | 4:50a31ff5f974 | 86 | if (timeout) |
ktownsend | 4:50a31ff5f974 | 87 | { |
ktownsend | 4:50a31ff5f974 | 88 | /* Stay within timeout limits */ |
ktownsend | 4:50a31ff5f974 | 89 | if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) |
ktownsend | 4:50a31ff5f974 | 90 | { |
ktownsend | 4:50a31ff5f974 | 91 | _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX; |
ktownsend | 4:50a31ff5f974 | 92 | } |
ktownsend | 4:50a31ff5f974 | 93 | } |
ktownsend | 2:ffc5216bd2cc | 94 | } |
ktownsend | 2:ffc5216bd2cc | 95 | |
ktownsend | 2:ffc5216bd2cc | 96 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 97 | /*! |
ktownsend | 2:ffc5216bd2cc | 98 | Destructor |
ktownsend | 2:ffc5216bd2cc | 99 | */ |
ktownsend | 2:ffc5216bd2cc | 100 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 101 | GapAdvertisingParams::~GapAdvertisingParams(void) |
ktownsend | 2:ffc5216bd2cc | 102 | { |
ktownsend | 2:ffc5216bd2cc | 103 | } |
ktownsend | 7:5e1f0d7f7c7d | 104 | |
ktownsend | 7:5e1f0d7f7c7d | 105 | /**************************************************************************/ |
ktownsend | 7:5e1f0d7f7c7d | 106 | /*! |
ktownsend | 7:5e1f0d7f7c7d | 107 | @brief returns the current Advertising Type value |
ktownsend | 7:5e1f0d7f7c7d | 108 | */ |
ktownsend | 7:5e1f0d7f7c7d | 109 | /**************************************************************************/ |
ktownsend | 7:5e1f0d7f7c7d | 110 | GapAdvertisingParams::AdvertisingType GapAdvertisingParams::getAdvertisingType(void) |
ktownsend | 7:5e1f0d7f7c7d | 111 | { |
ktownsend | 7:5e1f0d7f7c7d | 112 | return _advType; |
ktownsend | 7:5e1f0d7f7c7d | 113 | } |
ktownsend | 9:124ae067ae27 | 114 | |
ktownsend | 9:124ae067ae27 | 115 | /**************************************************************************/ |
ktownsend | 9:124ae067ae27 | 116 | /*! |
ktownsend | 9:124ae067ae27 | 117 | @brief returns the current Advertising Delay (in units of 0.625ms) |
ktownsend | 9:124ae067ae27 | 118 | */ |
ktownsend | 9:124ae067ae27 | 119 | /**************************************************************************/ |
ktownsend | 9:124ae067ae27 | 120 | uint16_t GapAdvertisingParams::getInterval(void) |
ktownsend | 9:124ae067ae27 | 121 | { |
ktownsend | 9:124ae067ae27 | 122 | return _interval; |
ktownsend | 9:124ae067ae27 | 123 | } |
ktownsend | 9:124ae067ae27 | 124 | |
ktownsend | 9:124ae067ae27 | 125 | /**************************************************************************/ |
ktownsend | 9:124ae067ae27 | 126 | /*! |
ktownsend | 9:124ae067ae27 | 127 | @brief returns the current Advertising Timeout (in seconds) |
ktownsend | 9:124ae067ae27 | 128 | */ |
ktownsend | 9:124ae067ae27 | 129 | /**************************************************************************/ |
ktownsend | 9:124ae067ae27 | 130 | uint16_t GapAdvertisingParams::getTimeout(void) |
ktownsend | 9:124ae067ae27 | 131 | { |
ktownsend | 9:124ae067ae27 | 132 | return _timeout; |
ktownsend | 9:124ae067ae27 | 133 | } |