kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
support int based lat/long
for https://github.com/meshtastic/Meshtastic-device/issues/124pull/28/head
rodzic
913a0b56fd
commit
12f7e9a8ce
|
@ -79,8 +79,26 @@ data class Position(
|
|||
val latitude: Double,
|
||||
val longitude: Double,
|
||||
val altitude: Int,
|
||||
val time: Int = (System.currentTimeMillis() / 1000).toInt() // default to current time in secs
|
||||
val time: Int = currentTime() // default to current time in secs
|
||||
) : Parcelable {
|
||||
companion object {
|
||||
/// Convert to a double representation of degrees
|
||||
fun degD(i: Int) = i * 1e-7
|
||||
fun degI(d: Double) = (d * 1e7).toInt()
|
||||
|
||||
fun currentTime() = (System.currentTimeMillis() / 1000).toInt()
|
||||
}
|
||||
|
||||
/** Create our model object from a protobuf. If time is unspecified in the protobuf, the provided default time will be used.
|
||||
*/
|
||||
constructor(p: MeshProtos.Position, defaultTime: Int = currentTime()) : this(
|
||||
// We prefer the int version of lat/lon but if not available use the depreciated legacy version
|
||||
if (p.latitudeI == 0) p.latitudeD else degD(p.latitudeI),
|
||||
if (p.longitudeI == 0) p.longitudeD else degD(p.longitudeI),
|
||||
p.altitude,
|
||||
if (p.time != 0) p.time else defaultTime
|
||||
)
|
||||
|
||||
/// @return distance in meters to some other node (or null if unknown)
|
||||
fun distance(o: Position) = latLongToMeter(latitude, longitude, o.latitude, o.longitude)
|
||||
|
||||
|
|
|
@ -746,13 +746,7 @@ class MeshService : Service(), Logging {
|
|||
/// Update our DB of users based on someone sending out a Position subpacket
|
||||
private fun handleReceivedPosition(fromNum: Int, p: MeshProtos.Position) {
|
||||
updateNodeInfo(fromNum) {
|
||||
it.position = Position(
|
||||
p.latitude,
|
||||
p.longitude,
|
||||
p.altitude,
|
||||
if (p.time != 0) p.time else it.position?.time
|
||||
?: 0 // if this position didn't include time, just keep our old one
|
||||
)
|
||||
it.position = Position(p, it.position?.time ?: 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1117,15 +1111,7 @@ class MeshService : Service(), Logging {
|
|||
if (info.hasPosition()) {
|
||||
// For the local node, it might not be able to update its times because it doesn't have a valid GPS reading yet
|
||||
// so if the info is for _our_ node we always assume time is current
|
||||
val time =
|
||||
if (it.num == mi.myNodeNum) currentSecond() else info.position.time
|
||||
|
||||
it.position = Position(
|
||||
info.position.latitude,
|
||||
info.position.longitude,
|
||||
info.position.altitude,
|
||||
time
|
||||
)
|
||||
it.position = Position(info.position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1214,8 +1200,12 @@ class MeshService : Service(), Logging {
|
|||
debug("Sending our position to=$destNum lat=$lat, lon=$lon, alt=$alt")
|
||||
|
||||
val position = MeshProtos.Position.newBuilder().also {
|
||||
it.latitude = lat
|
||||
it.longitude = lon
|
||||
it.latitudeD = lat // Only old radios will use this variant, others will just ignore it
|
||||
it.longitudeD = lon
|
||||
|
||||
it.longitudeI = Position.degI(lon)
|
||||
it.latitudeI = Position.degI(lat)
|
||||
|
||||
it.altitude = alt
|
||||
it.time = currentSecond() // Include our current timestamp
|
||||
}.build()
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit bd002e5a144f209e42c97b64fea9a05a2e513b28
|
||||
Subproject commit cabbdf51ed365b72ab995ad24b075269627f58ad
|
Ładowanie…
Reference in New Issue