Don't crash the app if the node sends a bogus lat > 90 deg

This commit is contained in:
geeksville 2020-06-18 14:08:21 -07:00
parent 1bff4d8178
commit 12ef3d4d7b
2 changed files with 23 additions and 1 deletions

View file

@ -89,7 +89,11 @@ data class NodeInfo(
/// return the position if it is valid, else null
val validPosition: Position?
get() {
return position?.takeIf { it.latitude != 0.0 || it.longitude != 0.0 }
return position?.takeIf {
(it.latitude <= 90.0 && it.latitude >= -90) && // If GPS gives a crap position don't crash our app
it.latitude != 0.0 &&
it.longitude != 0.0
}
}
/// @return distance in meters to some other node (or null if unknown)

View file

@ -0,0 +1,18 @@
package com.geeksville.mesh
import org.junit.Assert
import org.junit.Test
class PositionTest {
@Test
fun degGood() {
Assert.assertEquals(Position.degI(89.0), 890000000)
Assert.assertEquals(Position.degI(-89.0), -890000000)
Assert.assertEquals(Position.degD(Position.degI(89.0)), 89.0, 0.01)
Assert.assertEquals(Position.degD(Position.degI(-89.0)), -89.0, 0.01)
}
}