Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Added several extension functions

Arty Bishop332b6f666c48
diff --git a/app/src/main/java/com/rtbishop/look4sat/utility/Extensions.kt b/app/src/main/java/com/rtbishop/look4sat/utility/Extensions.kt
index 4bbdbaf6..cdd2c025 100644
--- a/app/src/main/java/com/rtbishop/look4sat/utility/Extensions.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/utility/Extensions.kt
@@ -38,6 +38,10 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import java.util.concurrent.TimeUnit
+import kotlin.math.max
+import kotlin.math.min
+import kotlin.math.pow
+import kotlin.math.sqrt
fun Long.formatForTimer(): String {
val format = "%02d:%02d:%02d"
@@ -47,12 +51,37 @@ fun Long.formatForTimer(): String {
return String.format(format, hours, minutes, seconds)
}
+fun Long.getDopplerFreq(rangeRate: Double, isDownlink: Boolean): Long {
+ val speedOfLight = 2.99792458E8
+ return if (isDownlink) {
+ (this.toDouble() * (speedOfLight - rangeRate * 1000.0) / speedOfLight).toLong()
+ } else {
+ (this.toDouble() * (speedOfLight + rangeRate * 1000.0) / speedOfLight).toLong()
+ }
+}
+
fun Double.round(decimals: Int): Double {
var multiplier = 1.0
repeat(decimals) { multiplier *= 10 }
return kotlin.math.round(this * multiplier) / multiplier
}
+fun Double.toOsmLat(): Double {
+ return min(max(this, -85.0), 85.0)
+}
+
+fun Double.toOsmLon(): Double {
+ val newLon = if (this < -180.0) this + 360.0 else if (this > 180.0) this - 360.0 else this
+ return min(max(newLon, -180.0), 180.0)
+}
+
+fun Double.getOrbitalVelocity(): Double {
+ val earthG = 6.674 * 10.0.pow(-11)
+ val earthM = 5.98 * 10.0.pow(24)
+ val radius = 6.37 * 10.0.pow(6) + this * 10.0.pow(3)
+ return sqrt(earthG * earthM / radius) / 1000
+}
+
fun Satellite.getPredictor(stationPosition: GroundStationPosition): PassPredictor {
return PassPredictor(this, stationPosition)
}