テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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