From d2f669e300da814a52793458b4702fcdbde09063 Mon Sep 17 00:00:00 2001 From: ogatatsu Date: Mon, 5 Oct 2020 13:53:55 +0900 Subject: [PATCH 1/3] Add some functions BLEPeriph::setSlaveLatency() BLEConnection::getSlaveLatency() BLEConnection::getConnSupervisionTimeout() --- libraries/Bluefruit52Lib/src/BLEConnection.cpp | 18 ++++++++++++++++-- libraries/Bluefruit52Lib/src/BLEConnection.h | 4 ++++ libraries/Bluefruit52Lib/src/BLEPeriph.cpp | 9 +++++++++ libraries/Bluefruit52Lib/src/BLEPeriph.h | 1 + 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/BLEConnection.cpp b/libraries/Bluefruit52Lib/src/BLEConnection.cpp index 67a36ac8d..775c9204f 100644 --- a/libraries/Bluefruit52Lib/src/BLEConnection.cpp +++ b/libraries/Bluefruit52Lib/src/BLEConnection.cpp @@ -48,7 +48,9 @@ BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* e _mtu = BLE_GATT_ATT_MTU_DEFAULT; _data_length = BLE_GATT_ATT_MTU_DEFAULT + 4; // 27 _phy = BLE_GAP_PHY_1MBPS; - _conn_interval = 0; + _conn_interval = evt_connected->conn_params.max_conn_interval; + _slave_latency = evt_connected->conn_params.slave_latency; + _sup_timeout = evt_connected->conn_params.conn_sup_timeout; _peer_addr = evt_connected->peer_addr; _role = evt_connected->role; @@ -108,6 +110,16 @@ uint16_t BLEConnection::getConnectionInterval(void) return _conn_interval; } +uint16_t BLEConnection::getSlaveLatency(void) +{ + return _slave_latency; +} + +uint16_t BLEConnection::getConnSupervisionTimeout(void) +{ + return _sup_timeout; +} + uint16_t BLEConnection::getDataLength(void) { return _data_length; @@ -318,8 +330,10 @@ void BLEConnection::_eventHandler(ble_evt_t* evt) { ble_gap_conn_params_t* param = &evt->evt.gap_evt.params.conn_param_update.conn_params; _conn_interval = param->max_conn_interval; + _slave_latency = param->slave_latency; + _sup_timeout = param->conn_sup_timeout; - LOG_LV1("GAP", "Conn Interval= %.2f ms, Latency = %d, Supervisor Timeout = %d ms", _conn_interval*1.25f, param->slave_latency, 10*param->conn_sup_timeout); + LOG_LV1("GAP", "Conn Interval= %.2f ms, Latency = %d, Supervisor Timeout = %d ms", _conn_interval*1.25f, _slave_latency, 10*_sup_timeout); } break; diff --git a/libraries/Bluefruit52Lib/src/BLEConnection.h b/libraries/Bluefruit52Lib/src/BLEConnection.h index d940878c3..238a256ed 100644 --- a/libraries/Bluefruit52Lib/src/BLEConnection.h +++ b/libraries/Bluefruit52Lib/src/BLEConnection.h @@ -47,6 +47,8 @@ class BLEConnection uint16_t _conn_hdl; uint16_t _mtu; uint16_t _conn_interval; + uint16_t _slave_latency; + uint16_t _sup_timeout; uint16_t _data_length; uint8_t _phy; @@ -80,6 +82,8 @@ class BLEConnection uint8_t getRole(void); uint16_t getMtu (void); uint16_t getConnectionInterval(void); + uint16_t getSlaveLatency(void); + uint16_t getConnSupervisionTimeout(void); uint16_t getDataLength(void); uint8_t getPHY(void); diff --git a/libraries/Bluefruit52Lib/src/BLEPeriph.cpp b/libraries/Bluefruit52Lib/src/BLEPeriph.cpp index 78a763917..5a6328422 100644 --- a/libraries/Bluefruit52Lib/src/BLEPeriph.cpp +++ b/libraries/Bluefruit52Lib/src/BLEPeriph.cpp @@ -98,6 +98,15 @@ bool BLEPeriph::setConnIntervalMS (uint16_t min_ms, uint16_t max_ms) return setConnInterval( MS100TO125(min_ms), MS100TO125(max_ms) ); } +bool BLEPeriph::setSlaveLatency (uint16_t latency) +{ + _ppcp.slave_latency = latency; + + VERIFY_STATUS( sd_ble_gap_ppcp_set(&_ppcp), false); + + return true; +} + bool BLEPeriph::setConnSupervisionTimeout(uint16_t timeout) { _ppcp.conn_sup_timeout = timeout; diff --git a/libraries/Bluefruit52Lib/src/BLEPeriph.h b/libraries/Bluefruit52Lib/src/BLEPeriph.h index 2649e928b..f3043ea1d 100644 --- a/libraries/Bluefruit52Lib/src/BLEPeriph.h +++ b/libraries/Bluefruit52Lib/src/BLEPeriph.h @@ -54,6 +54,7 @@ class BLEPeriph bool setConnInterval (uint16_t min, uint16_t max); bool setConnIntervalMS (uint16_t min_ms, uint16_t max_ms); + bool setSlaveLatency (uint16_t latency); bool setConnSupervisionTimeout(uint16_t timeout); bool setConnSupervisionTimeoutMS(uint16_t timeout_ms); From 1a506b5f54edef6f4c3ca3fa10352be635f04411 Mon Sep 17 00:00:00 2001 From: ogatatsu Date: Sun, 11 Oct 2020 13:48:56 +0900 Subject: [PATCH 2/3] Remove the process that automatically negotiates when connecting Better to use the BLEConnection::requestConnectionParameter() function --- libraries/Bluefruit52Lib/src/BLEPeriph.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/BLEPeriph.cpp b/libraries/Bluefruit52Lib/src/BLEPeriph.cpp index 5a6328422..c096253d2 100644 --- a/libraries/Bluefruit52Lib/src/BLEPeriph.cpp +++ b/libraries/Bluefruit52Lib/src/BLEPeriph.cpp @@ -134,22 +134,13 @@ void BLEPeriph::setDisconnectCallback( ble_disconnect_callback_t fp ) void BLEPeriph::_eventHandler(ble_evt_t* evt) { - uint16_t const conn_hdl = evt->evt.common_evt.conn_handle; + // uint16_t const conn_hdl = evt->evt.common_evt.conn_handle; // BLEConnection* conn = Bluefruit.Connection(conn_hdl); switch ( evt->header.evt_id ) { case BLE_GAP_EVT_CONNECTED: - { - ble_gap_evt_connected_t* para = &evt->evt.gap_evt.params.connected; - - // Connection interval set by Central is out of preferred range - // Try to negotiate with Central using our preferred values - if ( !is_within(_ppcp.min_conn_interval, para->conn_params.min_conn_interval, _ppcp.max_conn_interval) ) - { - VERIFY_STATUS( sd_ble_gap_conn_param_update(conn_hdl, &_ppcp), ); - } - } + break; case BLE_GAP_EVT_DISCONNECTED: From 2794dfebfa6fda26eda61a3da7400cb313711792 Mon Sep 17 00:00:00 2001 From: ogatatsu Date: Tue, 13 Oct 2020 21:07:08 +0900 Subject: [PATCH 3/3] Rename functions for consistency --- libraries/Bluefruit52Lib/src/BLEConnection.cpp | 2 +- libraries/Bluefruit52Lib/src/BLEConnection.h | 2 +- libraries/Bluefruit52Lib/src/BLEPeriph.cpp | 3 +-- libraries/Bluefruit52Lib/src/BLEPeriph.h | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/BLEConnection.cpp b/libraries/Bluefruit52Lib/src/BLEConnection.cpp index 775c9204f..7764aa1d1 100644 --- a/libraries/Bluefruit52Lib/src/BLEConnection.cpp +++ b/libraries/Bluefruit52Lib/src/BLEConnection.cpp @@ -115,7 +115,7 @@ uint16_t BLEConnection::getSlaveLatency(void) return _slave_latency; } -uint16_t BLEConnection::getConnSupervisionTimeout(void) +uint16_t BLEConnection::getSupervisionTimeout(void) { return _sup_timeout; } diff --git a/libraries/Bluefruit52Lib/src/BLEConnection.h b/libraries/Bluefruit52Lib/src/BLEConnection.h index 238a256ed..d69d52f5e 100644 --- a/libraries/Bluefruit52Lib/src/BLEConnection.h +++ b/libraries/Bluefruit52Lib/src/BLEConnection.h @@ -83,7 +83,7 @@ class BLEConnection uint16_t getMtu (void); uint16_t getConnectionInterval(void); uint16_t getSlaveLatency(void); - uint16_t getConnSupervisionTimeout(void); + uint16_t getSupervisionTimeout(void); uint16_t getDataLength(void); uint8_t getPHY(void); diff --git a/libraries/Bluefruit52Lib/src/BLEPeriph.cpp b/libraries/Bluefruit52Lib/src/BLEPeriph.cpp index c096253d2..849ddd1d9 100644 --- a/libraries/Bluefruit52Lib/src/BLEPeriph.cpp +++ b/libraries/Bluefruit52Lib/src/BLEPeriph.cpp @@ -98,7 +98,7 @@ bool BLEPeriph::setConnIntervalMS (uint16_t min_ms, uint16_t max_ms) return setConnInterval( MS100TO125(min_ms), MS100TO125(max_ms) ); } -bool BLEPeriph::setSlaveLatency (uint16_t latency) +bool BLEPeriph::setConnSlaveLatency(uint16_t latency) { _ppcp.slave_latency = latency; @@ -166,4 +166,3 @@ void BLEPeriph::printInfo(void) logger.printf("%d ms", _ppcp.conn_sup_timeout*10); logger.println(); } - diff --git a/libraries/Bluefruit52Lib/src/BLEPeriph.h b/libraries/Bluefruit52Lib/src/BLEPeriph.h index f3043ea1d..23cea49b0 100644 --- a/libraries/Bluefruit52Lib/src/BLEPeriph.h +++ b/libraries/Bluefruit52Lib/src/BLEPeriph.h @@ -54,7 +54,7 @@ class BLEPeriph bool setConnInterval (uint16_t min, uint16_t max); bool setConnIntervalMS (uint16_t min_ms, uint16_t max_ms); - bool setSlaveLatency (uint16_t latency); + bool setConnSlaveLatency(uint16_t latency); bool setConnSupervisionTimeout(uint16_t timeout); bool setConnSupervisionTimeoutMS(uint16_t timeout_ms);