Minor temporary patch to allow DFU packet callback

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Wed Dec 18 11:52:37 2013 +0000
Revision:
14:6ea5d1012a64
Parent:
9:124ae067ae27
Child:
18:86fe1e247a54
Fixed advertising interval checks

Who changed what in which revision?

UserRevisionLine numberNew 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 14:6ea5d1012a64 38 Advertising interval between 0x0020 and 0x4000 in 0.625ms
ktownsend 14:6ea5d1012a64 39 units (20ms to 10.24s). If using non-connectable mode
ktownsend 14:6ea5d1012a64 40 (\ref ADV_NON_CONNECTABLE_UNDIRECTED) this min value is
ktownsend 14:6ea5d1012a64 41 0x00A0 (100ms).
ktownsend 4:50a31ff5f974 42
ktownsend 4:50a31ff5f974 43 @para
ktownsend 4:50a31ff5f974 44 Increasing this value will allow central devices to detect
ktownsend 4:50a31ff5f974 45 your peripheral faster at the expense of more power being
ktownsend 4:50a31ff5f974 46 used by the radio due to the higher data transmit rate.
ktownsend 4:50a31ff5f974 47
ktownsend 4:50a31ff5f974 48 @note This field must be set to 0 if connectionMode is equal
ktownsend 6:425638944835 49 to \ref ADV_CONNECTABLE_DIRECTED
ktownsend 14:6ea5d1012a64 50
ktownsend 14:6ea5d1012a64 51 @note See Bluetooth Core Specification, Vol 3., Part C,
ktownsend 14:6ea5d1012a64 52 Appendix A for suggested advertising intervals:
ktownsend 14:6ea5d1012a64 53
ktownsend 4:50a31ff5f974 54 @param[in] timeout
ktownsend 4:50a31ff5f974 55 Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
ktownsend 4:50a31ff5f974 56 in seconds. Enter 0 to disable the advertising timeout.
ktownsend 4:50a31ff5f974 57
ktownsend 2:ffc5216bd2cc 58 @section EXAMPLE
ktownsend 2:ffc5216bd2cc 59
ktownsend 2:ffc5216bd2cc 60 @code
ktownsend 2:ffc5216bd2cc 61
ktownsend 2:ffc5216bd2cc 62 @endcode
ktownsend 2:ffc5216bd2cc 63 */
ktownsend 2:ffc5216bd2cc 64 /**************************************************************************/
ktownsend 6:425638944835 65 GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout)
ktownsend 2:ffc5216bd2cc 66 {
ktownsend 6:425638944835 67 _advType = advType;
ktownsend 2:ffc5216bd2cc 68 _interval = interval;
ktownsend 2:ffc5216bd2cc 69 _timeout = timeout;
ktownsend 4:50a31ff5f974 70
ktownsend 4:50a31ff5f974 71 /* Interval checks */
ktownsend 6:425638944835 72 if (_advType == ADV_CONNECTABLE_DIRECTED)
ktownsend 4:50a31ff5f974 73 {
ktownsend 4:50a31ff5f974 74 /* Interval must be 0 in directed connectable mode */
ktownsend 4:50a31ff5f974 75 _interval = 0;
ktownsend 4:50a31ff5f974 76 }
ktownsend 14:6ea5d1012a64 77 else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED)
ktownsend 14:6ea5d1012a64 78 {
ktownsend 14:6ea5d1012a64 79 /* Min interval is slightly larger than in other modes */
ktownsend 14:6ea5d1012a64 80 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON)
ktownsend 14:6ea5d1012a64 81 {
ktownsend 14:6ea5d1012a64 82 _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
ktownsend 14:6ea5d1012a64 83 }
ktownsend 14:6ea5d1012a64 84 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX)
ktownsend 14:6ea5d1012a64 85 {
ktownsend 14:6ea5d1012a64 86 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
ktownsend 14:6ea5d1012a64 87 }
ktownsend 14:6ea5d1012a64 88 }
ktownsend 4:50a31ff5f974 89 else
ktownsend 4:50a31ff5f974 90 {
ktownsend 4:50a31ff5f974 91 /* Stay within interval limits */
ktownsend 4:50a31ff5f974 92 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN)
ktownsend 4:50a31ff5f974 93 {
ktownsend 4:50a31ff5f974 94 _interval = GAP_ADV_PARAMS_INTERVAL_MIN;
ktownsend 4:50a31ff5f974 95 }
ktownsend 4:50a31ff5f974 96 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX)
ktownsend 4:50a31ff5f974 97 {
ktownsend 4:50a31ff5f974 98 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
ktownsend 4:50a31ff5f974 99 }
ktownsend 4:50a31ff5f974 100 }
ktownsend 4:50a31ff5f974 101
ktownsend 4:50a31ff5f974 102 /* Timeout checks */
ktownsend 4:50a31ff5f974 103 if (timeout)
ktownsend 4:50a31ff5f974 104 {
ktownsend 4:50a31ff5f974 105 /* Stay within timeout limits */
ktownsend 4:50a31ff5f974 106 if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX)
ktownsend 4:50a31ff5f974 107 {
ktownsend 4:50a31ff5f974 108 _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
ktownsend 4:50a31ff5f974 109 }
ktownsend 4:50a31ff5f974 110 }
ktownsend 2:ffc5216bd2cc 111 }
ktownsend 2:ffc5216bd2cc 112
ktownsend 2:ffc5216bd2cc 113 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 114 /*!
ktownsend 2:ffc5216bd2cc 115 Destructor
ktownsend 2:ffc5216bd2cc 116 */
ktownsend 2:ffc5216bd2cc 117 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 118 GapAdvertisingParams::~GapAdvertisingParams(void)
ktownsend 2:ffc5216bd2cc 119 {
ktownsend 2:ffc5216bd2cc 120 }
ktownsend 7:5e1f0d7f7c7d 121
ktownsend 7:5e1f0d7f7c7d 122 /**************************************************************************/
ktownsend 7:5e1f0d7f7c7d 123 /*!
ktownsend 7:5e1f0d7f7c7d 124 @brief returns the current Advertising Type value
ktownsend 7:5e1f0d7f7c7d 125 */
ktownsend 7:5e1f0d7f7c7d 126 /**************************************************************************/
ktownsend 7:5e1f0d7f7c7d 127 GapAdvertisingParams::AdvertisingType GapAdvertisingParams::getAdvertisingType(void)
ktownsend 7:5e1f0d7f7c7d 128 {
ktownsend 7:5e1f0d7f7c7d 129 return _advType;
ktownsend 7:5e1f0d7f7c7d 130 }
ktownsend 9:124ae067ae27 131
ktownsend 9:124ae067ae27 132 /**************************************************************************/
ktownsend 9:124ae067ae27 133 /*!
ktownsend 9:124ae067ae27 134 @brief returns the current Advertising Delay (in units of 0.625ms)
ktownsend 9:124ae067ae27 135 */
ktownsend 9:124ae067ae27 136 /**************************************************************************/
ktownsend 9:124ae067ae27 137 uint16_t GapAdvertisingParams::getInterval(void)
ktownsend 9:124ae067ae27 138 {
ktownsend 9:124ae067ae27 139 return _interval;
ktownsend 9:124ae067ae27 140 }
ktownsend 9:124ae067ae27 141
ktownsend 9:124ae067ae27 142 /**************************************************************************/
ktownsend 9:124ae067ae27 143 /*!
ktownsend 9:124ae067ae27 144 @brief returns the current Advertising Timeout (in seconds)
ktownsend 9:124ae067ae27 145 */
ktownsend 9:124ae067ae27 146 /**************************************************************************/
ktownsend 9:124ae067ae27 147 uint16_t GapAdvertisingParams::getTimeout(void)
ktownsend 9:124ae067ae27 148 {
ktownsend 9:124ae067ae27 149 return _timeout;
ktownsend 9:124ae067ae27 150 }