Skip to content

Commit eec491a

Browse files
committed
Fix Jira 671 Support update connection interval in central/peripheral
1. Add peripheral update the connection interval feature. 2. Update the library.
1 parent 017926d commit eec491a

File tree

5 files changed

+56
-5
lines changed

5 files changed

+56
-5
lines changed

libraries/CurieBLE/src/BLECentral.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void BLECentral::setScanParam(float interval, float window)
7676
bt_le_scan_param_t scan_param;
7777
scan_param.type = BT_HCI_LE_SCAN_ACTIVE;
7878
scan_param.filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_ENABLE;
79-
scan_param.interval = (uint16_t)((interval * 8) / 5);
80-
scan_param.window = (uint16_t)((window * 8) / 5);
79+
scan_param.interval = (uint16_t)MSEC_TO_UNITS(interval, UNIT_0_625_MS);;
80+
scan_param.window = (uint16_t)MSEC_TO_UNITS(window, UNIT_0_625_MS);;
8181
BLECentralRole::instance()->setScanParam(scan_param);
8282
}
8383

libraries/CurieBLE/src/BLEHelper.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ BLEHelper::clearAddress() {
9393
memset(&_address, 0x00, sizeof(_address));
9494
}
9595

96-
const bt_le_conn_param_t *BLEHelper::getConnParams()
96+
void BLEHelper::getConnParams(ble_conn_param_t &user_conn_params)
9797
{
98-
return &_conn_params;
98+
user_conn_params.interval_min = UNITS_TO_MSEC(_conn_params.interval_min, UNIT_1_25_MS);
99+
user_conn_params.interval_max = UNITS_TO_MSEC(_conn_params.interval_max, UNIT_1_25_MS);
100+
user_conn_params.timeout = UNITS_TO_MSEC(_conn_params.timeout, UNIT_10_MS);
101+
user_conn_params.latency = _conn_params.latency;
99102
}
100103

101104
void BLEHelper::setConnectionParameters(uint16_t intervalmin,
@@ -140,5 +143,18 @@ void BLEHelper::setConnectionInterval(float minInterval,
140143
updateConnectionInterval();
141144
}
142145

146+
void BLEHelper::setConnectionInterval(float minInterval,
147+
float maxInterval,
148+
uint16_t latency,
149+
uint16_t timeout)
150+
{
151+
uint16_t minVal = (uint16_t)MSEC_TO_UNITS(minInterval, UNIT_1_25_MS);
152+
uint16_t maxVal = (uint16_t)MSEC_TO_UNITS(maxInterval, UNIT_1_25_MS);
153+
uint16_t timeoutVal = MSEC_TO_UNITS(timeout, UNIT_10_MS);
154+
_conn_params.interval_min = minVal;
155+
_conn_params.interval_max = maxVal;
156+
_conn_params.timeout = timeoutVal;
157+
updateConnectionInterval();
158+
}
143159

144160

libraries/CurieBLE/src/BLEHelper.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,20 @@ class BLEHelper {
6363
bool operator==(const bt_addr_le_t& rhs) const;
6464
bool operator!=(const BLEHelper& rhs) const;
6565

66-
const bt_le_conn_param_t *getConnParams();
66+
/**
67+
* @brief Get the connection paramter
68+
*
69+
* @param[in] user_conn_params connection paramter
70+
* Minimum Connection Interval (ms)
71+
* Maximum Connection Interval (ms)
72+
* Connection Latency
73+
* Supervision Timeout (ms)
74+
*
75+
* @return none
76+
*
77+
* @note none
78+
*/
79+
void getConnParams(ble_conn_param_t &user_conn_params);
6780

6881
/**
6982
* @brief Set the connection paramter and send connection
@@ -79,6 +92,27 @@ class BLEHelper {
7992
*/
8093
void setConnectionInterval(float minInterval,
8194
float maxInterval);
95+
96+
/**
97+
* @brief Set the connection paramter and send connection
98+
* update request
99+
*
100+
* @param[in] intervalmin Minimum Connection Interval (ms)
101+
*
102+
* @param[in] intervalmax Maximum Connection Interval (ms)
103+
*
104+
* @param[in] latency Connection Latency
105+
*
106+
* @param[in] timeout Supervision Timeout (ms)
107+
*
108+
* @return none
109+
*
110+
* @note none
111+
*/
112+
void setConnectionInterval(float minInterval,
113+
float maxInterval,
114+
uint16_t latency,
115+
uint16_t timeout);
82116

83117
/**
84118
* @brief Just set the connection parameter.

libraries/CurieBLE/src/internal/ble_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum {
4040
};
4141

4242
#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
43+
#define UNITS_TO_MSEC(TIME, RESOLUTION) (((TIME) * RESOLUTION) / 1000)
4344

4445
/* Connection parameters used for Peripheral Preferred Connection Parameterss (PPCP) and update request */
4546
#define DEFAULT_MIN_CONN_INTERVAL MSEC_TO_UNITS(80, UNIT_1_25_MS)
240 KB
Binary file not shown.

0 commit comments

Comments
 (0)