kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Don't rely on android filtering for BLE scan, because NRF52
rodzic
a527852f55
commit
87c272f784
|
@ -183,6 +183,7 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
|
|||
// if that device later disconnects remove it as a candidate
|
||||
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
||||
|
||||
if ((result.device.name?.startsWith("Mesh") ?: false)) {
|
||||
val addr = result.device.address
|
||||
val fullAddr = "x$addr" // full address with the bluetooh prefix
|
||||
// prevent logspam because weill get get lots of redundant scan results
|
||||
|
@ -206,7 +207,10 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
|
|||
val lastName =
|
||||
result.device.name.substring(result.device.name.length - 4).toInt(16)
|
||||
|
||||
(lastAddr - 2) != lastName
|
||||
// ESP32 macaddr are two higher than the reported device name
|
||||
// NRF52 macaddrs match the portion used in the string
|
||||
// either would be acceptable
|
||||
(lastAddr - 2) != lastName && lastAddr != lastName
|
||||
} catch (ex: Throwable) {
|
||||
false // If we fail parsing anything, don't do this nasty hack
|
||||
}
|
||||
|
@ -235,6 +239,7 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addDevice(entry: DeviceListEntry) {
|
||||
val oldDevs = devices.value!!
|
||||
|
@ -313,6 +318,8 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
|
|||
// filter and only accept devices that have our service
|
||||
val filter =
|
||||
ScanFilter.Builder()
|
||||
// Note: NRF52 doesn't put the service in the avertizement, so we can't filter by service here
|
||||
// Instead we check in the callback
|
||||
.setServiceUuid(ParcelUuid(BluetoothInterface.BTM_SERVICE_UUID))
|
||||
.build()
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue