From a097cc2f25d4f3d1bca3357a4dd65d8a875c728f Mon Sep 17 00:00:00 2001 From: andrekir Date: Wed, 26 Jan 2022 02:35:37 -0300 Subject: [PATCH] send position to local node (without broadcast) --- .../com/geeksville/mesh/service/MeshService.kt | 16 +++------------- .../mesh/service/MeshServiceLocationCallback.kt | 4 ++-- .../mesh/ui/AdvancedSettingsFragment.kt | 5 +++-- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index b2db3268d..93e756fa6 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -135,7 +135,7 @@ class MeshService : Service(), Logging { } private val locationCallback = MeshServiceLocationCallback( - ::perhapsSendPosition, + ::sendPositionScoped, onSendPositionFailed = { onConnectionChanged(ConnectionState.DEVICE_SLEEP) }, getNodeNum = { myNodeNum } ) @@ -170,7 +170,7 @@ class MeshService : Service(), Logging { * We first check to see if our local device has already sent a position and if so, we punt until the next check. * This allows us to only 'fill in' with GPS positions when the local device happens to have no good GPS sats. */ - private fun perhapsSendPosition( + private fun sendPositionScoped( lat: Double = 0.0, lon: Double = 0.0, alt: Int = 0, @@ -181,17 +181,7 @@ class MeshService : Service(), Logging { // do most of the work in my service thread serviceScope.handledLaunch { // if android called us too soon, just ignore - - val myInfo = localNodeInfo - val lastLat = (myInfo?.position?.latitude ?: 0.0) - val lastLon = (myInfo?.position?.longitude ?: 0.0) - val lastSendMsec = (myInfo?.position?.time ?: 0) * 1000L - val now = System.currentTimeMillis() - if ((lastLat == 0.0 && lastLon == 0.0) || (now - lastSendMsec > locationIntervalMsec)) // && minBroadcastPeriod ? - sendPosition(lat, lon, alt, destNum, wantResponse) - else { - debug("Not sending position - local node sent ${(now - lastSendMsec) / 1000L}s ago ${myInfo?.position?.toPIIString()}") - } + sendPosition(lat, lon, alt, destNum, wantResponse) } } 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 bb7e4bc24..2225756ec 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshServiceLocationCallback.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshServiceLocationCallback.kt @@ -38,9 +38,9 @@ class MeshServiceLocationCallback( if (location.isAccurateForMesh) { // if within 200 meters, or accuracy is unknown try { - // Do we want to broadcast this position globally, or are we just telling the local node what its current position is ( + // Do we want to broadcast this position globally, or are we just telling the local node what its current position is val shouldBroadcast = - true // no need to rate limit, because we are just sending at the interval requested by the preferences + false // no need to rate limit, because we are just sending to the local node val destinationNumber = if (shouldBroadcast) DataPacket.NODENUM_BROADCAST else getNodeNum() diff --git a/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt index 16881c2e4..ddd62eadd 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/AdvancedSettingsFragment.kt @@ -28,7 +28,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { _binding = AdvancedSettingsBinding.inflate(inflater, container, false) return binding.root } @@ -39,6 +39,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging { model.radioConfig.observe(viewLifecycleOwner, { binding.positionBroadcastPeriodEditText.setText(model.positionBroadcastSecs.toString()) binding.lsSleepEditText.setText(model.lsSleepSecs.toString()) + binding.positionBroadcastPeriodView.isEnabled = model.locationShare ?: true binding.positionBroadcastSwitch.isChecked = model.locationShare ?: true binding.lsSleepView.isEnabled = model.isPowerSaving ?: false binding.lsSleepSwitch.isChecked = model.isPowerSaving ?: false @@ -47,7 +48,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging { model.isConnected.observe(viewLifecycleOwner, { connectionState -> val connected = connectionState == MeshService.ConnectionState.CONNECTED - binding.positionBroadcastPeriodView.isEnabled = connected + binding.positionBroadcastPeriodView.isEnabled = connected && model.locationShare ?: true binding.lsSleepView.isEnabled = connected && model.isPowerSaving ?: false binding.positionBroadcastSwitch.isEnabled = connected binding.lsSleepSwitch.isEnabled = connected