From bd74d64be0a8c4272a226c18a799e3de0ab47827 Mon Sep 17 00:00:00 2001 From: Vadim Furman Date: Tue, 13 Apr 2021 17:42:24 -0700 Subject: [PATCH 1/2] Added utf8 to Datapacket to make the remote IMeshService work --- app/src/main/java/com/geeksville/mesh/DataPacket.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/geeksville/mesh/DataPacket.kt b/app/src/main/java/com/geeksville/mesh/DataPacket.kt index 352cdfa6..ee5df494 100644 --- a/app/src/main/java/com/geeksville/mesh/DataPacket.kt +++ b/app/src/main/java/com/geeksville/mesh/DataPacket.kt @@ -4,6 +4,8 @@ import android.os.Parcel import android.os.Parcelable import kotlinx.parcelize.Parcelize import kotlinx.serialization.Serializable +import java.nio.charset.Charset + @Parcelize enum class MessageStatus : Parcelable { @@ -144,6 +146,8 @@ data class DataPacket( override fun newArray(size: Int): Array { return arrayOfNulls(size) } + val utf8 = Charset.forName("UTF-8") } + } \ No newline at end of file From b87ac0a1af4896eaeb878159b6185e342eee2c5c Mon Sep 17 00:00:00 2001 From: Vadim Furman Date: Tue, 13 Apr 2021 17:50:34 -0700 Subject: [PATCH 2/2] Removed checking for device name to contain MAC address. We still verify it starts with Mesh --- .../geeksville/mesh/ui/SettingsFragment.kt | 66 +++++-------------- 1 file changed, 18 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index fde6466b..d6fd03cf 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -194,57 +194,27 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { val oldDevs = devices.value!! val oldEntry = oldDevs[fullAddr] 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 + val entry = DeviceListEntry( + result.device.name + ?: "unnamed-$addr", // autobug: some devices might not have a name, if someone is running really old device code? + fullAddr, + isBonded + ) + // If nothing was selected, by default select the first valid thing we see + val activity: MainActivity? = try { + GeeksvilleApplication.currentActivity as MainActivity? // Can be null if app is shutting down + } catch (_: ClassCastException) { + // Buggy "Z812" phones apparently have the wrong class type for this + errormsg("Unexpected class for main activity") + null } - if (skipBogus) - errormsg("Skipping bogus BLE entry $result") - else { - val entry = DeviceListEntry( - result.device.name - ?: "unnamed-$addr", // autobug: some devices might not have a name, if someone is running really old device code? - fullAddr, - isBonded + if (selectedAddress == null && entry.bonded && activity != null) + changeScanSelection( + activity, + fullAddr ) - debug("onScanResult ${entry}") - - // If nothing was selected, by default select the first valid thing we see - val activity: MainActivity? = try { - GeeksvilleApplication.currentActivity as MainActivity? // Can be null if app is shutting down - } catch (_: ClassCastException) { - // Buggy "Z812" phones apparently have the wrong class type for this - errormsg("Unexpected class for main activity") - null - } - - if (selectedAddress == null && entry.bonded && activity != null) - changeScanSelection( - activity, - fullAddr - ) - addDevice(entry) // Add/replace entry - } + addDevice(entry) // Add/replace entry } } }