Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 44e0e7b

Browse files
committedSep 13, 2022
slicemk: improve central connection handling
1 parent 4419307 commit 44e0e7b

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed
 

‎app/src/split/bluetooth/central.c

+16-27
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,6 @@ static void split_central_process_connection(struct bt_conn *conn) {
355355
static bool split_central_eir_found(const bt_addr_le_t *addr) {
356356
LOG_DBG("Found the split service");
357357

358-
int slot_idx = reserve_peripheral_slot(addr);
359-
if (slot_idx < 0) {
360-
LOG_ERR("Failed to reserve peripheral slot (err %d)", slot_idx);
361-
return false;
362-
}
363-
364358
// Stop scanning so we can connect to the peripheral device.
365359
LOG_DBG("Stopping peripheral scanning");
366360
is_scanning = false;
@@ -370,29 +364,24 @@ static bool split_central_eir_found(const bt_addr_le_t *addr) {
370364
return false;
371365
}
372366

373-
struct peripheral_slot *slot = &peripherals[slot_idx];
374-
375-
slot->conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr);
376-
if (slot->conn) {
377-
LOG_DBG("Found existing connection");
378-
split_central_process_connection(slot->conn);
379-
err = bt_conn_le_phy_update(slot->conn, BT_CONN_LE_PHY_PARAM_2M);
380-
if (err) {
381-
LOG_ERR("Update phy conn failed (err %d)", err);
382-
}
383-
} else {
384-
struct bt_le_conn_param *param = BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400);
385-
386-
LOG_DBG("Initiating new connnection");
387-
388-
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &slot->conn);
389-
if (err) {
390-
LOG_ERR("Create conn failed (err %d) (create conn? 0x%04x)", err,
391-
BT_HCI_OP_LE_CREATE_CONN);
392-
start_scan();
393-
}
367+
int slot_idx = reserve_peripheral_slot(addr);
368+
if (slot_idx < 0) {
369+
LOG_ERR("Failed to reserve peripheral slot (err %d)", slot_idx);
370+
start_scan();
371+
return false;
394372
}
395373

374+
LOG_DBG("Initiating new connnection");
375+
struct bt_le_conn_param *param = BT_LE_CONN_PARAM(6, 6, 399, 900);
376+
struct peripheral_slot *slot = &peripherals[slot_idx];
377+
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &slot->conn);
378+
if (err) {
379+
LOG_ERR("Create conn failed (err %d) (create conn? 0x%04x)", err,
380+
BT_HCI_OP_LE_CREATE_CONN);
381+
release_peripheral_slot(slot_idx);
382+
start_scan();
383+
}
384+
396385
return false;
397386
}
398387

0 commit comments

Comments
 (0)
Please sign in to comment.