mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
send position to local node (without broadcast)
This commit is contained in:
parent
fb48f379c7
commit
a097cc2f25
3 changed files with 8 additions and 17 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue