0611

Dependencies:   mbed

Fork of BLE_WallbotBLE_Challenge2 by Maiko Matsumoto

Committer:
mmmmmmmmma
Date:
Mon Jun 11 04:55:58 2018 +0000
Revision:
4:53eceb750885
Parent:
0:76dfa9657d9d
0611

Who changed what in which revision?

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