Merge pull request #276 from vfurman-gh/master

Two fixes
pull/272/head^2
Kevin Hester 2021-04-15 12:06:31 +08:00 zatwierdzone przez GitHub
commit 6df1d4fabd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 22 dodań i 48 usunięć

Wyświetl plik

@ -4,6 +4,8 @@ import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import java.nio.charset.Charset
@Parcelize @Parcelize
enum class MessageStatus : Parcelable { enum class MessageStatus : Parcelable {
@ -143,6 +145,8 @@ data class DataPacket(
override fun newArray(size: Int): Array<DataPacket?> { override fun newArray(size: Int): Array<DataPacket?> {
return arrayOfNulls(size) return arrayOfNulls(size)
} }
val utf8 = Charset.forName("UTF-8")
} }
} }

Wyświetl plik

@ -191,41 +191,12 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
val oldDevs = devices.value!! val oldDevs = devices.value!!
val oldEntry = oldDevs[fullAddr] val oldEntry = oldDevs[fullAddr]
if (oldEntry == null || oldEntry.bonded != isBonded) { // Don't spam the GUI with endless updates for non changing nodes if (oldEntry == null || oldEntry.bonded != isBonded) { // Don't spam the GUI with endless updates for non changing nodes
val skipBogus = try {
// Note Soyes XS has a buggy BLE scan implementation and returns devices we didn't ask for. So we check to see if the
// last two chars of the name matches the last two of the address - if not we skip it
// Note: the address is always two more than the hex string we show in the name
// nasty parsing of a string that ends with ab:45 as four hex digits
val lastAddr = (addr.substring(
addr.length - 5,
addr.length - 3
) + addr.substring(addr.length - 2)).toInt(16)
val lastName =
result.device.name.substring(result.device.name.length - 4).toInt(16)
// 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
}
if (skipBogus)
errormsg("Skipping bogus BLE entry $result")
else {
val entry = DeviceListEntry( val entry = DeviceListEntry(
result.device.name result.device.name
?: "unnamed-$addr", // autobug: some devices might not have a name, if someone is running really old device code? ?: "unnamed-$addr", // autobug: some devices might not have a name, if someone is running really old device code?
fullAddr, fullAddr,
isBonded isBonded
) )
debug("onScanResult ${entry}")
// If nothing was selected, by default select the first valid thing we see // If nothing was selected, by default select the first valid thing we see
val activity: MainActivity? = try { val activity: MainActivity? = try {
GeeksvilleApplication.currentActivity as MainActivity? // Can be null if app is shutting down GeeksvilleApplication.currentActivity as MainActivity? // Can be null if app is shutting down
@ -245,7 +216,6 @@ 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!!