Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ConnectionParameters.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 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 "gap/ConnectionParameters.h" 00018 00019 namespace ble { 00020 00021 ConnectionParameters::ConnectionParameters( 00022 phy_t phy, 00023 scan_interval_t scanInterval, 00024 scan_window_t scanWindow, 00025 conn_interval_t minConnectionInterval, 00026 conn_interval_t maxConnectionInterval, 00027 slave_latency_t slaveLatency, 00028 supervision_timeout_t connectionSupervisionTimeout, 00029 conn_event_length_t minEventLength, 00030 conn_event_length_t maxEventLength 00031 ) : 00032 _filterPolicy(initiator_filter_policy_t::NO_FILTER), 00033 _ownAddressType(own_address_type_t::RANDOM) 00034 { 00035 for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) { 00036 _enabledPhy[i] = false; 00037 } 00038 if (phy != phy_t::NONE) { 00039 uint8_t phy_index = phyToIndex(phy); 00040 00041 if (phy_index < MAX_PARAM_PHYS) { 00042 _scanInterval[phy_index] = scanInterval.value(); 00043 _scanWindow[phy_index] = scanWindow.value(); 00044 _minConnectionInterval[phy_index] = minConnectionInterval.value(); 00045 _maxConnectionInterval[phy_index] = maxConnectionInterval.value(); 00046 _slaveLatency[phy_index] = slaveLatency.value(); 00047 _connectionSupervisionTimeout[phy_index] = connectionSupervisionTimeout.value(); 00048 _enabledPhy[phy_index] = true; 00049 _minEventLength[phy_index] = minEventLength.value(); 00050 _maxEventLength[phy_index] = maxEventLength.value(); 00051 } 00052 } 00053 } 00054 00055 /* setters */ 00056 00057 ConnectionParameters &ConnectionParameters::setScanParameters( 00058 phy_t phy, 00059 scan_interval_t scanInterval, 00060 scan_window_t scanWindow 00061 ) 00062 { 00063 uint8_t phy_index = handlePhyToggle(phy, true); 00064 00065 if (phy_index < MAX_PARAM_PHYS) { 00066 _scanInterval[phy_index] = scanInterval.value(); 00067 _scanWindow[phy_index] = scanWindow.value(); 00068 } 00069 00070 return *this; 00071 } 00072 00073 ConnectionParameters &ConnectionParameters::setConnectionParameters( 00074 phy_t phy, 00075 conn_interval_t minConnectionInterval, 00076 conn_interval_t maxConnectionInterval, 00077 slave_latency_t slaveLatency, 00078 supervision_timeout_t connectionSupervisionTimeout, 00079 conn_event_length_t minEventLength, 00080 conn_event_length_t maxEventLength 00081 ) 00082 { 00083 uint8_t phy_index = handlePhyToggle(phy, true); 00084 00085 if (phy_index < MAX_PARAM_PHYS) { 00086 _minConnectionInterval[phy_index] = minConnectionInterval.value(); 00087 _maxConnectionInterval[phy_index] = maxConnectionInterval.value(); 00088 _slaveLatency[phy_index] = slaveLatency.value(); 00089 _connectionSupervisionTimeout[phy_index] = connectionSupervisionTimeout.value(); 00090 00091 /* avoid overflows and truncation */ 00092 if (minEventLength.value() > maxEventLength.value()) { 00093 minEventLength = maxEventLength; 00094 } 00095 00096 _minEventLength[phy_index] = minEventLength.value(); 00097 _maxEventLength[phy_index] = maxEventLength.value(); 00098 } 00099 00100 return *this; 00101 } 00102 00103 #if BLE_FEATURE_PHY_MANAGEMENT 00104 /** Handle the swapping of 2M and CODED so that the array is ready for the pal call. */ 00105 void ConnectionParameters::swapCodedAnd2M() 00106 { 00107 uint16_t scanInterval = _scanInterval[LE_2M_INDEX]; 00108 uint16_t scanWindow = _scanWindow[LE_2M_INDEX]; 00109 uint16_t minConnectionInterval = _minConnectionInterval[LE_2M_INDEX]; 00110 uint16_t maxConnectionInterval = _maxConnectionInterval[LE_2M_INDEX]; 00111 uint16_t slaveLatency = _slaveLatency[LE_2M_INDEX]; 00112 uint16_t connectionSupervisionTimeout = _connectionSupervisionTimeout[LE_2M_INDEX]; 00113 uint16_t minEventLength = _minEventLength[LE_2M_INDEX]; 00114 uint16_t maxEventLength = _maxEventLength[LE_2M_INDEX]; 00115 00116 _scanInterval[LE_2M_INDEX] = _scanInterval[LE_CODED_INDEX]; 00117 _scanWindow[LE_2M_INDEX] = _scanWindow[LE_CODED_INDEX]; 00118 _minConnectionInterval[LE_2M_INDEX] = _minConnectionInterval[LE_CODED_INDEX]; 00119 _maxConnectionInterval[LE_2M_INDEX] = _maxConnectionInterval[LE_CODED_INDEX]; 00120 _slaveLatency[LE_2M_INDEX] = _slaveLatency[LE_CODED_INDEX]; 00121 _connectionSupervisionTimeout[LE_2M_INDEX] = _connectionSupervisionTimeout[LE_CODED_INDEX]; 00122 _minEventLength[LE_2M_INDEX] = _minEventLength[LE_CODED_INDEX]; 00123 _maxEventLength[LE_2M_INDEX] = _maxEventLength[LE_CODED_INDEX]; 00124 00125 _scanInterval[LE_CODED_INDEX] = scanInterval; 00126 _scanWindow[LE_CODED_INDEX] = scanWindow; 00127 _minConnectionInterval[LE_CODED_INDEX] = minConnectionInterval; 00128 _maxConnectionInterval[LE_CODED_INDEX] = maxConnectionInterval; 00129 _slaveLatency[LE_CODED_INDEX] = slaveLatency; 00130 _connectionSupervisionTimeout[LE_CODED_INDEX] = connectionSupervisionTimeout; 00131 _minEventLength[LE_CODED_INDEX] = minEventLength; 00132 _maxEventLength[LE_CODED_INDEX] = maxEventLength; 00133 } 00134 #endif // BLE_FEATURE_PHY_MANAGEMENT 00135 00136 } // namespace ble
Generated on Tue Jul 12 2022 13:54:13 by
