Added Maidenhead locator conversion functions and tests #2

This commit is contained in:
Arty Bishop committed 2020-10-27 08:12:49 +00:00
1 parent e06b1bcb11
commit ca92f8581e
2 files changed
+72

No files matched your search

@@ -2,6 +2,7 @@ package com.rtbishop.look4sat.utility
import android.content.SharedPreferences
import android.view.View
import com.github.amsacode.predict4java.GroundStationPosition
import com.google.android.material.snackbar.Snackbar
import java.util.concurrent.TimeUnit
import kotlin.math.round
@@ -33,4 +34,36 @@ object Utilities {
fun SharedPreferences.getDouble(key: String, default: Double): Double {
return Double.fromBits(getLong(key, default.toRawBits()))
}
fun qthToGSP(qthString: String): GroundStationPosition {
val latFirst = (qthString[1].toInt() - 65) * 10
val latSecond = qthString[3].toString().toInt()
val latThird = (((qthString[5].toInt() - 97) / 24.0) + (1.0 / 48.0)) - 90
val latitude = latFirst + latSecond + latThird
val lonFirst = (qthString[0].toInt() - 65) * 20
val lonSecond = qthString[2].toString().toInt() * 2
val lonThird = (((qthString[4].toInt() - 97) / 12.0) + (1.0 / 24.0)) - 180
val longitude = lonFirst + lonSecond + lonThird
return GroundStationPosition(latitude, longitude, 0.0)
}
fun locToQTH(lat: Double, lon: Double): String {
val tempLon = if (lon > 180.0) lon - 360 else lon
val upper = "ABCDEFGHIJKLMNOPQRSTUVWX"
val lower = "abcdefghijklmnopqrstuvwx"
val latitude = lat + 90
val latFirst = upper[(latitude / 10).toInt()]
val latSecond = (latitude % 10).toInt().toString()
val latThird = lower[((latitude % 1) * 24).toInt()]
val longitude = tempLon + 180
val lonFirst = upper[(longitude / 20).toInt()]
val lonSecond = ((longitude / 2) % 10).toInt().toString()
val lonThird = lower[((longitude % 2) * 12).toInt()]
return "$lonFirst$latFirst$lonSecond$latSecond$lonThird$latThird"
}
}