BLE 연결 파라미터가 이미 목표값인 경우 재요청 생략
- 요청 전 bt_conn_get_info()로 현재 체결값 조회 - Connection Interval, Supervision Timeout, Slave latency
This commit is contained in:
+36
-5
@@ -432,6 +432,7 @@ static int ble_request_preferred_conn_params(bool count_attempt)
|
||||
.latency = BLE_SLAVE_LATENCY,
|
||||
.timeout = BLE_CONN_SUP_TIMEOUT,
|
||||
};
|
||||
struct bt_conn_info info;
|
||||
int err;
|
||||
|
||||
if (current_conn == NULL)
|
||||
@@ -439,15 +440,41 @@ static int ble_request_preferred_conn_params(bool count_attempt)
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
// 현재 체결된 파라미터를 조회해서, 이미 목표값이면 재요청/재시도 불필요
|
||||
err = bt_conn_get_info(current_conn, &info);
|
||||
if ((err == 0) && (info.type == BT_CONN_TYPE_LE))
|
||||
{
|
||||
uint16_t cur_interval = info.le.interval;
|
||||
uint16_t cur_latency = info.le.latency;
|
||||
uint16_t cur_timeout = info.le.timeout;
|
||||
|
||||
DBG_PRINTF("[BLE] Current params: interval=%u(%u.%01ums) latency=%u timeout=%u(%ums)\r\n",
|
||||
cur_interval,
|
||||
(cur_interval * 125U) / 100U,
|
||||
((cur_interval * 125U) % 100U) / 10U,
|
||||
cur_latency,
|
||||
cur_timeout,
|
||||
cur_timeout * 10U);
|
||||
|
||||
if (ble_conn_param_is_preferred(cur_interval, cur_latency, cur_timeout))
|
||||
{
|
||||
DBG_PRINTF("[BLE] Already at preferred params, skip request\r\n");
|
||||
return -EALREADY;
|
||||
}
|
||||
}
|
||||
|
||||
if (count_attempt)
|
||||
{
|
||||
conn_param_update_attempts++;
|
||||
}
|
||||
|
||||
DBG_PRINTF("[BLE] Request params: interval=%u latency=%u timeout=%u attempt=%u\r\n",
|
||||
DBG_PRINTF("[BLE] Request params: interval=%u(%u.%01ums) latency=%u timeout=%u(%ums) attempt=%u\r\n",
|
||||
BLE_MIN_CONN_INTERVAL,
|
||||
(BLE_MIN_CONN_INTERVAL * 125U) / 100U,
|
||||
((BLE_MIN_CONN_INTERVAL * 125U) % 100U) / 10U,
|
||||
BLE_SLAVE_LATENCY,
|
||||
BLE_CONN_SUP_TIMEOUT,
|
||||
BLE_CONN_SUP_TIMEOUT * 10U,
|
||||
conn_param_update_attempts);
|
||||
|
||||
err = bt_conn_le_param_update(current_conn, &conn_param);
|
||||
@@ -585,13 +612,17 @@ static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void le_param_updated(struct bt_conn *conn, uint16_t interval,
|
||||
uint16_t latency, uint16_t timeout)
|
||||
static void le_param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, uint16_t timeout)
|
||||
{
|
||||
ARG_UNUSED(conn);
|
||||
|
||||
DBG_PRINTF("[BLE] Params: interval=%d latency=%d timeout=%d\r\n",
|
||||
interval, latency, timeout);
|
||||
DBG_PRINTF("[BLE] Params: interval=%u(%u.%01ums) latency=%u timeout=%u(%ums)\r\n",
|
||||
interval,
|
||||
(interval * 125U) / 100U,
|
||||
((interval * 125U) % 100U) / 10U,
|
||||
latency,
|
||||
timeout,
|
||||
timeout * 10U);
|
||||
|
||||
if (ble_conn_param_is_preferred(interval, latency, timeout))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user