Bluetooth LE library for Nucleo board

Dependents:   Nucleo_BLE_HeartRate Nucleo_BLE_UART Nucleo_BLE_Demo Nucleo_BLE_UART

Warning: Deprecated!

Supported drivers and applications can be found at this link.

Committer:
sjallouli
Date:
Fri Dec 19 19:52:49 2014 +0000
Revision:
1:79e5c08cbcc7
Parent:
0:289fd2dae405
change the USARTService->write() method access permission to public

Who changed what in which revision?

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