From 6ed7af37638e1e586a45d2fde374898d26047e1f Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 17 Mar 2021 16:04:29 +0800 Subject: [PATCH] fix autobug with getnodenum failing during startup --- .../service/MeshServiceLocationCallback.kt | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshServiceLocationCallback.kt b/app/src/main/java/com/geeksville/mesh/service/MeshServiceLocationCallback.kt index b0bc2e857..ac04a0f24 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshServiceLocationCallback.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshServiceLocationCallback.kt @@ -38,12 +38,22 @@ class MeshServiceLocationCallback( MeshService.info("got phone location") if (location.isAccurateForMesh) { // if within 200 meters, or accuracy is unknown - // Do we want to broadcast this position globally, or are we just telling the local node what its current position is ( - val shouldBroadcast = isAllowedToSend() - val destinationNumber = if (shouldBroadcast) DataPacket.NODENUM_BROADCAST else getNodeNum() + try { + // Do we want to broadcast this position globally, or are we just telling the local node what its current position is ( + val shouldBroadcast = isAllowedToSend() + val destinationNumber = + if (shouldBroadcast) DataPacket.NODENUM_BROADCAST else getNodeNum() - // Note: we never want this message sent as a reliable message, because it is low value and we'll be sending one again later anyways - sendPosition(location, destinationNumber, wantResponse = false) + // Note: we never want this message sent as a reliable message, because it is low value and we'll be sending one again later anyways + sendPosition(location, destinationNumber, wantResponse = false) + + } catch (ex: RemoteException) { // Really a RadioNotConnected exception, but it has changed into this type via remoting + MeshService.warn("Lost connection to radio, stopping location requests") + onSendPositionFailed() + } catch (ex: BLEException) { // Really a RadioNotConnected exception, but it has changed into this type via remoting + MeshService.warn("BLE exception, stopping location requests $ex") + onSendPositionFailed() + } } else { MeshService.warn("accuracy ${location.accuracy} is too poor to use") } @@ -51,21 +61,13 @@ class MeshServiceLocationCallback( } private fun sendPosition(location: Location, destinationNumber: Int, wantResponse: Boolean) { - try { - onSendPosition( - location.latitude, - location.longitude, - location.altitude.toInt(), - destinationNumber, - wantResponse // wantResponse? - ) - } catch (ex: RemoteException) { // Really a RadioNotConnected exception, but it has changed into this type via remoting - MeshService.warn("Lost connection to radio, stopping location requests") - onSendPositionFailed() - } catch (ex: BLEException) { // Really a RadioNotConnected exception, but it has changed into this type via remoting - MeshService.warn("BLE exception, stopping location requests $ex") - onSendPositionFailed() - } + onSendPosition( + location.latitude, + location.longitude, + location.altitude.toInt(), + destinationNumber, + wantResponse // wantResponse? + ) } /**