ble

Dependencies:   HC_SR04_Ultrasonic_Library Servo mbed

Fork of FIP_REV1 by Robotique FIP

Committer:
julientiron
Date:
Thu Jul 09 13:33:36 2015 +0000
Revision:
4:69a35a56ac48
Parent:
0:3d641e170a74
BLE

Who changed what in which revision?

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