WallbotBLE default code

Dependencies:   mbed

Fork of BLE_WallbotBLE_Challenge by Wallbot BLE Developer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GapAdvertisingParams.cpp Source File

GapAdvertisingParams.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include <stdio.h>
00018 #include <string.h>
00019 
00020 #include "blecommon.h"
00021 #include "GapAdvertisingParams.h"
00022 
00023 /**************************************************************************/
00024 /*!
00025     \brief
00026     Instantiates a new GapAdvertisingParams instance
00027 
00028     \param[in]  advType
00029                 The GAP advertising mode to use for this device. Valid
00030                 values are defined in AdvertisingType:
00031 
00032                 \par ADV_NON_CONNECTABLE_UNDIRECTED
00033                 All connections to the peripheral device will be refused.
00034 
00035                 \par ADV_CONNECTABLE_DIRECTED
00036                 Only connections from a pre-defined central device will be
00037                 accepted.
00038 
00039                 \par ADV_CONNECTABLE_UNDIRECTED
00040                 Any central device can connect to this peripheral.
00041 
00042                 \par ADV_SCANNABLE_UNDIRECTED
00043                 Any central device can connect to this peripheral, and
00044                 the secondary Scan Response payload will be included or
00045                 available to central devices.
00046 
00047                 \par
00048                 See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
00049                 Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
00050                 Section 2.3.1 for further information on GAP connection
00051                 modes
00052 
00053     \param[in]  interval
00054                 Advertising interval between 0x0020 and 0x4000 in 0.625ms units
00055                 (20ms to 10.24s).  If using non-connectable mode
00056                 (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is 0x00A0
00057                 (100ms). To reduce the likelihood of collisions, the link layer
00058                 perturbs this interval by a pseudo-random delay with a range of
00059                 0 ms to 10 ms for each advertising event.
00060 
00061                 \par
00062                 Decreasing this value will allow central devices to detect
00063                 your peripheral faster at the expense of more power being
00064                 used by the radio due to the higher data transmit rate.
00065 
00066                 \par
00067                 This field must be set to 0 if connectionMode is equal
00068                 to ADV_CONNECTABLE_DIRECTED
00069 
00070                 \par
00071                 See Bluetooth Core Specification, Vol 3., Part C,
00072                 Appendix A for suggested advertising intervals.
00073 
00074     \param[in]  timeout
00075                 Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
00076                 in seconds.  Enter 0 to disable the advertising timeout.
00077 
00078     \par EXAMPLE
00079 
00080     \code
00081 
00082     \endcode
00083 */
00084 /**************************************************************************/
00085 GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout)
00086 {
00087     _advType  = advType;
00088     _interval = interval;
00089     _timeout  = timeout;
00090 
00091     /* Interval checks */
00092     if (_advType == ADV_CONNECTABLE_DIRECTED) {
00093         /* Interval must be 0 in directed connectable mode */
00094         _interval = 0;
00095     } else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
00096         /* Min interval is slightly larger than in other modes */
00097         if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
00098             _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
00099         }
00100         if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
00101             _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
00102         }
00103     } else {
00104         /* Stay within interval limits */
00105         if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) {
00106             _interval = GAP_ADV_PARAMS_INTERVAL_MIN;
00107         }
00108         if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
00109             _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
00110         }
00111     }
00112 
00113     /* Timeout checks */
00114     if (timeout) {
00115         /* Stay within timeout limits */
00116         if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) {
00117             _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
00118         }
00119     }
00120 }
00121 
00122 /**************************************************************************/
00123 /*!
00124     Destructor
00125 */
00126 /**************************************************************************/
00127 GapAdvertisingParams::~GapAdvertisingParams (void)
00128 {
00129 }