send position to local node (without broadcast)

This commit is contained in:
andrekir
2022-01-26 02:35:37 -03:00
parent fb48f379c7
commit a097cc2f25
3 changed files with 8 additions and 17 deletions

View File

@@ -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)
}
}

View File

@@ -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()

View File

@@ -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