Fix BLE connection collision and filter unnamed devices
This commit is contained in:
@@ -57,6 +57,7 @@ int ble_gap_disc_event_handler(struct ble_gap_event* event, void* arg) {
|
||||
}
|
||||
}
|
||||
|
||||
bool should_publish = false;
|
||||
{
|
||||
xSemaphoreTake(ctx->scan_mutex, portMAX_DELAY);
|
||||
bool found = false;
|
||||
@@ -68,29 +69,41 @@ int ble_gap_disc_event_handler(struct ble_gap_event* event, void* arg) {
|
||||
}
|
||||
ctx->scan_results[i].rssi = record.rssi;
|
||||
found = true;
|
||||
should_publish = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found && ctx->scan_count < 64) {
|
||||
if (!found && record.name[0] != '\0' && ctx->scan_count < 64) {
|
||||
ctx->scan_results[ctx->scan_count] = record;
|
||||
ctx->scan_addrs[ctx->scan_count] = disc.addr; // full addr (type+val)
|
||||
ctx->scan_count++;
|
||||
should_publish = true;
|
||||
}
|
||||
xSemaphoreGive(ctx->scan_mutex);
|
||||
}
|
||||
|
||||
struct BtEvent e = {};
|
||||
e.type = BT_EVENT_PEER_FOUND;
|
||||
e.peer = record;
|
||||
ble_publish_event(device, e);
|
||||
if (should_publish) {
|
||||
LOG_I(TAG, "Peer found: name='%s' addr=%02x:%02x:%02x:%02x:%02x:%02x rssi=%d",
|
||||
record.name,
|
||||
record.addr[0], record.addr[1], record.addr[2],
|
||||
record.addr[3], record.addr[4], record.addr[5],
|
||||
record.rssi);
|
||||
struct BtEvent e = {};
|
||||
e.type = BT_EVENT_PEER_FOUND;
|
||||
e.peer = record;
|
||||
ble_publish_event(device, e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case BLE_GAP_EVENT_DISC_COMPLETE:
|
||||
LOG_I(TAG, "Scan complete (reason=%d)", event->disc_complete.reason);
|
||||
// Keep scan_active=true; resolveNextUnnamedPeer clears it and fires ScanFinished
|
||||
// once name resolution finishes, so the UI spinner stays active throughout.
|
||||
ble_resolve_next_unnamed_peer(device, 0);
|
||||
ble_set_scan_active(device, false);
|
||||
{
|
||||
struct BtEvent e = {};
|
||||
e.type = BT_EVENT_SCAN_FINISHED;
|
||||
ble_publish_event(device, e);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user