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
|
// if that device later disconnects remove it as a candidate
|
||||||
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
||||||
|
|
||||||
|
if ((result.device.name?.startsWith("Mesh") ?: false)) {
|
||||||
val addr = result.device.address
|
val addr = result.device.address
|
||||||
val fullAddr = "x$addr" // full address with the bluetooh prefix
|
val fullAddr = "x$addr" // full address with the bluetooh prefix
|
||||||
// prevent logspam because weill get get lots of redundant scan results
|
// prevent logspam because weill get get lots of redundant scan results
|
||||||
|
@ -206,7 +207,10 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
|
||||||
val lastName =
|
val lastName =
|
||||||
result.device.name.substring(result.device.name.length - 4).toInt(16)
|
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) {
|
} catch (ex: Throwable) {
|
||||||
false // If we fail parsing anything, don't do this nasty hack
|
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) {
|
private fun addDevice(entry: DeviceListEntry) {
|
||||||
val oldDevs = devices.value!!
|
val oldDevs = devices.value!!
|
||||||
|
@ -313,6 +318,8 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
|
||||||
// filter and only accept devices that have our service
|
// filter and only accept devices that have our service
|
||||||
val filter =
|
val filter =
|
||||||
ScanFilter.Builder()
|
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))
|
.setServiceUuid(ParcelUuid(BluetoothInterface.BTM_SERVICE_UUID))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue