Skip to content

Commit 294e056

Browse files
committed
adding central BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST
1 parent 37203b9 commit 294e056

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

libraries/Bluefruit52Lib/src/BLECentral.cpp

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,63 @@ void BLECentral::clearBonds(void)
147147
void BLECentral::_event_handler(ble_evt_t* evt)
148148
{
149149
// conn handle has fixed offset regardless of event type
150-
const uint16_t evt_conn_hdl = evt->evt.common_evt.conn_handle;
150+
const uint16_t conn_hdl = evt->evt.common_evt.conn_handle;
151151

152152
/* PrPh handle connection is already filtered. Only handle Central events or
153-
* connection handle is BLE_CONN_HANDLE_INVALID (e.g BLE_GAP_EVT_ADV_REPORT)
154-
*/
153+
* connection handle is BLE_CONN_HANDLE_INVALID (e.g BLE_GAP_EVT_ADV_REPORT) */
155154
switch ( evt->header.evt_id )
156155
{
157156
case BLE_GAP_EVT_CONNECTED:
158-
if ( Bluefruit.Gap.getRole(evt_conn_hdl) == BLE_GAP_ROLE_CENTRAL)
157+
if ( Bluefruit.Gap.getRole(conn_hdl) == BLE_GAP_ROLE_CENTRAL)
159158
{
160159
// Invoke callback
161-
if ( _connect_cb) ada_callback(NULL, _connect_cb, evt_conn_hdl);
160+
if ( _connect_cb) ada_callback(NULL, _connect_cb, conn_hdl);
162161
}
163162
break;
164163

165164
case BLE_GAP_EVT_DISCONNECTED:
166-
if ( Bluefruit.Gap.getRole(evt_conn_hdl) == BLE_GAP_ROLE_CENTRAL)
165+
if ( Bluefruit.Gap.getRole(conn_hdl) == BLE_GAP_ROLE_CENTRAL)
167166
{
168167
// Invoke callback reason is BLE_HCI_STATUS code
169-
if ( _disconnect_cb) ada_callback(NULL, _disconnect_cb, evt_conn_hdl, evt->evt.gap_evt.params.disconnected.reason);
168+
if ( _disconnect_cb) ada_callback(NULL, _disconnect_cb, conn_hdl, evt->evt.gap_evt.params.disconnected.reason);
170169
}
171170
break;
172171

172+
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
173+
{
174+
ble_gap_conn_params_t* request_param = &evt->evt.gap_evt.params.conn_param_update_request.conn_params;
175+
176+
PRINT_INT(request_param->min_conn_interval);
177+
PRINT_INT(request_param->max_conn_interval);
178+
PRINT_INT(request_param->slave_latency);
179+
PRINT_INT(request_param->conn_sup_timeout);
180+
181+
// Accept request parameter if it is within our supported range, otherwise reject
182+
if ( ( request_param->max_conn_interval < _ppcp_min_conn ) || ( request_param->min_conn_interval > _ppcp_max_conn ) )
183+
{
184+
LOG_LV1("GAP", "Reject Conn Param Update Request: our = ( %.2f, %.2f ), request = ( %.2f, %.2f )",
185+
ppcp_min_conn*1.25f, _ppcp_max_conn*1.25f, request_param->min_conn_interval*1.25f, request_param->max_conn_interval*1.25f);
186+
187+
sd_ble_gap_conn_param_update(conn_hdl, NULL); // reject request
188+
}else
189+
{
190+
uint16_t const conn_interval = max16(_ppcp_min_conn, request_param->min_conn_interval);
191+
192+
ble_gap_conn_params_t resp_param =
193+
{
194+
.min_conn_interval = conn_interval,
195+
.max_conn_interval = conn_interval, // central set min = max
196+
.slave_latency = request_param->slave_latency, // TODO check save latency
197+
.conn_sup_timeout = request_param->conn_sup_timeout, // TODO check supervisor timeout
198+
};
199+
200+
LOG_LV2("GAP", "Conn Interval is updated to %.2f ms", conn_interval*1.25f);
201+
202+
sd_ble_gap_conn_param_update(conn_hdl, &resp_param);
203+
}
204+
}
205+
break;
206+
173207
default: break;
174208
}
175209
}

libraries/Bluefruit52Lib/src/BLECentral.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ class BLECentral
6161
/*------------------------------------------------------------------*/
6262
/* GAP
6363
*------------------------------------------------------------------*/
64-
bool setConnInterval(uint16_t min, uint16_t max);
65-
bool setConnIntervalMS (uint16_t min_ms, uint16_t max_ms);
64+
bool setConnInterval(uint16_t min, uint16_t max);
65+
bool setConnIntervalMS (uint16_t min_ms, uint16_t max_ms);
6666

67-
bool connect(const ble_gap_evt_adv_report_t* adv_report);
68-
bool connect(const ble_gap_addr_t *peer_addr);
69-
bool disconnect(uint16_t conn_handle);
67+
bool connect(const ble_gap_evt_adv_report_t* adv_report);
68+
bool connect(const ble_gap_addr_t *peer_addr);
69+
bool disconnect(uint16_t conn_handle);
7070

71-
bool connected (uint16_t conn_handle); // If connected to a specific peripheral
72-
bool connected (void); // If connected to any peripherals
71+
bool connected (uint16_t conn_handle); // If connected to a specific peripheral
72+
bool connected (void); // If connected to any peripherals
7373

74-
void clearBonds (void);
74+
void clearBonds (void);
7575

7676
/*------------- Callbacks -------------*/
7777
void setConnectCallback ( BLEGap::connect_callback_t fp);

0 commit comments

Comments
 (0)