Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Removed redundant StationPos.kt class

Arty Bishop673474a51f54
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/PreferencesProvider.kt b/app/src/main/java/com/rtbishop/look4sat/framework/PreferencesProvider.kt
index e9efded1..92c84f75 100644
--- a/app/src/main/java/com/rtbishop/look4sat/framework/PreferencesProvider.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/framework/PreferencesProvider.kt
@@ -22,8 +22,8 @@ import android.hardware.GeomagneticField
import android.location.LocationManager
import androidx.core.content.edit
import com.rtbishop.look4sat.data.PreferencesSource
+import com.rtbishop.look4sat.domain.GeoPos
import com.rtbishop.look4sat.domain.QthConverter
-import com.rtbishop.look4sat.domain.StationPos
import com.rtbishop.look4sat.utility.round
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
@@ -88,15 +88,15 @@ class PreferencesProvider @Inject constructor(
return QthConverter.positionToQTH(lat, lon)
}
- override fun loadStationPosition(): StationPos {
+ override fun loadStationPosition(): GeoPos {
val defaultSP = "0.0"
val latitude = preferences.getString(keyLatitude, null) ?: defaultSP
val longitude = preferences.getString(keyLongitude, null) ?: defaultSP
val altitude = preferences.getString(keyAltitude, null) ?: defaultSP
- return StationPos(latitude.toDouble(), longitude.toDouble(), altitude.toDouble())
+ return GeoPos(latitude.toDouble(), longitude.toDouble(), altitude.toDouble())
}
- override fun saveStationPosition(pos: StationPos) {
+ override fun saveStationPosition(pos: GeoPos) {
preferences.edit {
putString(keyLatitude, pos.latitude.toString())
putString(keyLongitude, pos.longitude.toString())
@@ -112,7 +112,7 @@ class PreferencesProvider @Inject constructor(
val latitude = location.latitude.round(4)
val longitude = location.longitude.round(4)
val altitude = location.altitude.round(1)
- val stationPosition = StationPos(latitude, longitude, altitude)
+ val stationPosition = GeoPos(latitude, longitude, altitude)
saveStationPosition(stationPosition)
return true
}
@@ -123,7 +123,7 @@ class PreferencesProvider @Inject constructor(
override fun updatePositionFromQTH(qthString: String): Boolean {
val position = QthConverter.qthToPosition(qthString) ?: return false
- val stationPosition = StationPos(position.latitude, position.longitude, 0.0)
+ val stationPosition = GeoPos(position.latitude, position.longitude, 0.0)
saveStationPosition(stationPosition)
return true
}
diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/satMapScreen/SatMapViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/satMapScreen/SatMapViewModel.kt
index 67883477..08189085 100644
--- a/app/src/main/java/com/rtbishop/look4sat/presentation/satMapScreen/SatMapViewModel.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/satMapScreen/SatMapViewModel.kt
@@ -105,7 +105,7 @@ class SatMapViewModel @Inject constructor(
}
}
- private suspend fun getSatTrack(satellite: Satellite, pos: StationPos, date: Date) {
+ private suspend fun getSatTrack(satellite: Satellite, pos: GeoPos, date: Date) {
val satTracks = mutableListOf<List<GeoPos>>()
val currentTrack = mutableListOf<GeoPos>()
val endDate = Date(date.time + (satellite.orbitalPeriod * 2.4 * 60000L).toLong())
@@ -134,7 +134,7 @@ class SatMapViewModel @Inject constructor(
_satTrack.postValue(satTracks)
}
- private suspend fun getPositions(satellites: List<Satellite>, pos: StationPos, date: Date) {
+ private suspend fun getPositions(satellites: List<Satellite>, pos: GeoPos, date: Date) {
val positions = mutableMapOf<Satellite, GeoPos>()
satellites.forEach { satellite ->
val satPos = predictor.getSatPos(satellite, pos, date)
@@ -145,7 +145,7 @@ class SatMapViewModel @Inject constructor(
_satPositions.postValue(positions)
}
- private suspend fun getSatFootprint(satellite: Satellite, pos: StationPos, date: Date) {
+ private suspend fun getSatFootprint(satellite: Satellite, pos: GeoPos, date: Date) {
val satPos = predictor.getSatPos(satellite, pos, date)
val satFootprint = satPos.getRangeCircle().map { rangePos ->
val osmLat = clipLat(rangePos.latitude)
@@ -155,7 +155,7 @@ class SatMapViewModel @Inject constructor(
_satFootprint.postValue(satFootprint)
}
- private suspend fun getSatData(satellite: Satellite, pos: StationPos, date: Date) {
+ private suspend fun getSatData(satellite: Satellite, pos: GeoPos, date: Date) {
val satPos = predictor.getSatPos(satellite, pos, date)
val osmLat = clipLat(Math.toDegrees(satPos.latitude))
val osmLon = clipLon(Math.toDegrees(satPos.longitude))
diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/satPassInfoScreen/PassInfoView.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/satPassInfoScreen/PassInfoView.kt
index eaab3bb3..cc83c47c 100644
--- a/app/src/main/java/com/rtbishop/look4sat/presentation/satPassInfoScreen/PassInfoView.kt
+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/satPassInfoScreen/PassInfoView.kt
@@ -22,8 +22,8 @@ import android.graphics.*
import android.view.View
import androidx.core.content.ContextCompat
import com.rtbishop.look4sat.R
+import com.rtbishop.look4sat.domain.GeoPos
import com.rtbishop.look4sat.domain.SatPass
-import com.rtbishop.look4sat.domain.StationPos
import java.util.*
import kotlin.math.cos
import kotlin.math.min
@@ -38,7 +38,7 @@ class PassInfoView(context: Context) : View(context) {
private val radarRadius = radarWidth * 0.48f
private val piDiv2 = Math.PI / 2.0
private val strokeSize = scale * 2f
- private var stationPos: StationPos = StationPos(0.0, 0.0, 0.0)
+ private var stationPos: GeoPos = GeoPos(0.0, 0.0, 0.0)
private var radarColor = ContextCompat.getColor(context, R.color.greyLight)
private var radarCircleNum = 3
@@ -103,7 +103,7 @@ class PassInfoView(context: Context) : View(context) {
this.satPass = satPass
}
- fun setStationPos(stationPos: StationPos) {
+ fun setStationPos(stationPos: GeoPos) {
this.stationPos = stationPos
}
diff --git a/core/src/main/java/com/rtbishop/look4sat/data/PreferencesSource.kt b/core/src/main/java/com/rtbishop/look4sat/data/PreferencesSource.kt
index d4360a6e..af6fa294 100644
--- a/core/src/main/java/com/rtbishop/look4sat/data/PreferencesSource.kt
+++ b/core/src/main/java/com/rtbishop/look4sat/data/PreferencesSource.kt
@@ -17,15 +17,15 @@
*/
package com.rtbishop.look4sat.data
-import com.rtbishop.look4sat.domain.StationPos
+import com.rtbishop.look4sat.domain.GeoPos
interface PreferencesSource {
fun positionToQTH(lat: Double, lon: Double): String?
- fun loadStationPosition(): StationPos
+ fun loadStationPosition(): GeoPos
- fun saveStationPosition(pos: StationPos)
+ fun saveStationPosition(pos: GeoPos)
fun updatePositionFromGPS(): Boolean
diff --git a/core/src/main/java/com/rtbishop/look4sat/domain/GeoPos.kt b/core/src/main/java/com/rtbishop/look4sat/domain/GeoPos.kt
index 63d95bdb..b1c779c8 100644
--- a/core/src/main/java/com/rtbishop/look4sat/domain/GeoPos.kt
+++ b/core/src/main/java/com/rtbishop/look4sat/domain/GeoPos.kt
@@ -17,4 +17,4 @@
*/
package com.rtbishop.look4sat.domain
-data class GeoPos(val latitude: Double, val longitude: Double)
+data class GeoPos(val latitude: Double, val longitude: Double, val altitude: Double = 0.0)
diff --git a/core/src/main/java/com/rtbishop/look4sat/domain/Predictor.kt b/core/src/main/java/com/rtbishop/look4sat/domain/Predictor.kt
index fe097675..b0b454d3 100644
--- a/core/src/main/java/com/rtbishop/look4sat/domain/Predictor.kt
+++ b/core/src/main/java/com/rtbishop/look4sat/domain/Predictor.kt
@@ -30,12 +30,12 @@ class Predictor(private val predictorDispatcher: CoroutineDispatcher) {
private var selectedSatIds = emptyList<Int>()
val passes: SharedFlow<List<SatPass>> = _passes
- suspend fun getSatPos(sat: Satellite, pos: StationPos, date: Date): SatPos =
+ suspend fun getSatPos(sat: Satellite, pos: GeoPos, date: Date): SatPos =
withContext(predictorDispatcher) {
return@withContext sat.getPosition(pos, date.time)
}
- suspend fun getSatTrack(sat: Satellite, pos: StationPos, start: Date, end: Date): List<SatPos> =
+ suspend fun getSatTrack(sat: Satellite, pos: GeoPos, start: Date, end: Date): List<SatPos> =
withContext(predictorDispatcher) {
val positions = mutableListOf<SatPos>()
var currentTime = start.time
@@ -48,7 +48,7 @@ class Predictor(private val predictorDispatcher: CoroutineDispatcher) {
suspend fun triggerCalculation(
satellites: List<Satellite>,
- pos: StationPos,
+ pos: GeoPos,
date: Date = Date(),
hoursAhead: Int = 8,
minElevation: Double = 16.0
@@ -65,7 +65,7 @@ class Predictor(private val predictorDispatcher: CoroutineDispatcher) {
suspend fun forceCalculation(
satellites: List<Satellite>,
- pos: StationPos,
+ pos: GeoPos,
date: Date = Date(),
hoursAhead: Int = 8,
minElevation: Double = 16.0
@@ -84,7 +84,7 @@ class Predictor(private val predictorDispatcher: CoroutineDispatcher) {
}
}
- private fun Satellite.getPasses(pos: StationPos, date: Date, hours: Int): List<SatPass> {
+ private fun Satellite.getPasses(pos: GeoPos, date: Date, hours: Int): List<SatPass> {
val passes = mutableListOf<SatPass>()
val endDate = Date(date.time + hours * 60L * 60L * 1000L)
val quarterOrbitMin = (this.orbitalPeriod / 4.0).toInt()
@@ -117,7 +117,7 @@ class Predictor(private val predictorDispatcher: CoroutineDispatcher) {
.sortedBy { it.aosTime }
}
- private fun getGeoPass(sat: Satellite, pos: StationPos, date: Date): SatPass {
+ private fun getGeoPass(sat: Satellite, pos: GeoPos, date: Date): SatPass {
val satPos = sat.getPosition(pos, date.time)
val aos = Date(date.time - 24 * 60L * 60L * 1000L).time
val los = Date(date.time + 24 * 60L * 60L * 1000L).time
@@ -128,7 +128,7 @@ class Predictor(private val predictorDispatcher: CoroutineDispatcher) {
return SatPass(aos, az, los, az, tca, az, alt, elev, sat)
}
- private fun getLeoPass(sat: Satellite, pos: StationPos, date: Date, rewind: Boolean): SatPass {
+ private fun getLeoPass(sat: Satellite, pos: GeoPos, date: Date, rewind: Boolean): SatPass {
val quarterOrbitMin = (sat.orbitalPeriod / 4.0).toInt()
val calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")).apply {
clear()
diff --git a/core/src/main/java/com/rtbishop/look4sat/domain/Satellite.kt b/core/src/main/java/com/rtbishop/look4sat/domain/Satellite.kt
index 0279716e..df4b022f 100644
--- a/core/src/main/java/com/rtbishop/look4sat/domain/Satellite.kt
+++ b/core/src/main/java/com/rtbishop/look4sat/domain/Satellite.kt
@@ -42,7 +42,7 @@ abstract class Satellite(val params: TLE) {
var qoms24 = 0.0
var s4 = 0.0
- fun willBeSeen(pos: StationPos): Boolean {
+ fun willBeSeen(pos: GeoPos): Boolean {
return if (params.meanmo < 1e-8) false
else {
val sma = 331.25 * exp(ln(1440.0 / params.meanmo) * (2.0 / 3.0))
@@ -53,7 +53,7 @@ abstract class Satellite(val params: TLE) {
}
}
- fun getPosition(pos: StationPos, time: Long): SatPos {
+ fun getPosition(pos: GeoPos, time: Long): SatPos {
val satPos = SatPos()
// Date/time at which the position and velocity were calculated
val julUTC = calcCurrentDaynum(time) + 2444238.5
@@ -116,7 +116,7 @@ abstract class Satellite(val params: TLE) {
julianUTC: Double,
positionVector: Vector4,
velocityVector: Vector4,
- gsPos: StationPos,
+ gsPos: GeoPos,
squintVector: Vector4,
satPos: SatPos
) {
@@ -158,7 +158,7 @@ abstract class Satellite(val params: TLE) {
// Returns the ECI position and velocity of the observer
private fun calculateUserPosVel(
time: Double,
- gsPos: StationPos,
+ gsPos: GeoPos,
gsPosTheta: AtomicReference<Double>,
obsPos: Vector4,
obsVel: Vector4
diff --git a/core/src/main/java/com/rtbishop/look4sat/domain/StationPos.kt b/core/src/main/java/com/rtbishop/look4sat/domain/StationPos.kt
deleted file mode 100644
index 9c0e4e92..00000000
--- a/core/src/main/java/com/rtbishop/look4sat/domain/StationPos.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Look4Sat. Amateur radio satellite tracker and pass predictor.
- * Copyright (C) 2019-2021 Arty Bishop ([email protected])
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-package com.rtbishop.look4sat.domain
-
-data class StationPos(
- val latitude: Double,
- val longitude: Double,
- val altitude: Double,
- val name: String = "default"
-)