![](/media/cache/profiles/1b8833c58d3a24b62eb45027f94d093e.jpg.50x50_q85.jpg)
Knight Rider PIO sample for teckBASIC, konashi.js
Dependencies: BLE_API_Native_IRC mbed
Fork of BLE_konashi_PIO_test by
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 00055 units (20ms to 10.24s). If using non-connectable mode 00056 (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is 00057 0x00A0 (100ms). 00058 00059 \par 00060 Increasing this value will allow central devices to detect 00061 your peripheral faster at the expense of more power being 00062 used by the radio due to the higher data transmit rate. 00063 00064 \par 00065 This field must be set to 0 if connectionMode is equal 00066 to ADV_CONNECTABLE_DIRECTED 00067 00068 \par 00069 See Bluetooth Core Specification, Vol 3., Part C, 00070 Appendix A for suggested advertising intervals. 00071 00072 \param[in] timeout 00073 Advertising timeout between 0x1 and 0x3FFF (1 and 16383) 00074 in seconds. Enter 0 to disable the advertising timeout. 00075 00076 \par EXAMPLE 00077 00078 \code 00079 00080 \endcode 00081 */ 00082 /**************************************************************************/ 00083 GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout) 00084 { 00085 _advType = advType; 00086 _interval = interval; 00087 _timeout = timeout; 00088 00089 /* Interval checks */ 00090 if (_advType == ADV_CONNECTABLE_DIRECTED) 00091 { 00092 /* Interval must be 0 in directed connectable mode */ 00093 _interval = 0; 00094 } 00095 else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) 00096 { 00097 /* Min interval is slightly larger than in other modes */ 00098 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) 00099 { 00100 _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON; 00101 } 00102 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) 00103 { 00104 _interval = GAP_ADV_PARAMS_INTERVAL_MAX; 00105 } 00106 } 00107 else 00108 { 00109 /* Stay within interval limits */ 00110 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) 00111 { 00112 _interval = GAP_ADV_PARAMS_INTERVAL_MIN; 00113 } 00114 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) 00115 { 00116 _interval = GAP_ADV_PARAMS_INTERVAL_MAX; 00117 } 00118 } 00119 00120 /* Timeout checks */ 00121 if (timeout) 00122 { 00123 /* Stay within timeout limits */ 00124 if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) 00125 { 00126 _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX; 00127 } 00128 } 00129 } 00130 00131 /**************************************************************************/ 00132 /*! 00133 Destructor 00134 */ 00135 /**************************************************************************/ 00136 GapAdvertisingParams::~GapAdvertisingParams (void) 00137 { 00138 } 00139 00140 /**************************************************************************/ 00141 /*! 00142 \brief returns the current Advertising Type value 00143 */ 00144 /**************************************************************************/ 00145 GapAdvertisingParams::AdvertisingType GapAdvertisingParams::getAdvertisingType(void) 00146 { 00147 return _advType; 00148 } 00149 00150 /**************************************************************************/ 00151 /*! 00152 \brief returns the current Advertising Delay (in units of 0.625ms) 00153 */ 00154 /**************************************************************************/ 00155 uint16_t GapAdvertisingParams::getInterval(void) 00156 { 00157 return _interval; 00158 } 00159 00160 /**************************************************************************/ 00161 /*! 00162 \brief returns the current Advertising Timeout (in seconds) 00163 */ 00164 /**************************************************************************/ 00165 uint16_t GapAdvertisingParams::getTimeout(void) 00166 { 00167 return _timeout; 00168 }
Generated on Tue Jul 12 2022 16:55:06 by
![doxygen](doxygen.png)