Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Added frequency reporting to PassReporter.kt
Arty Bishop84240c94c699
diff --git a/app/src/main/java/com/rtbishop/look4sat/framework/NetDataReporter.kt b/app/src/main/java/com/rtbishop/look4sat/framework/NetDataReporter.ktdeleted file mode 100644index ee52b652..00000000--- a/app/src/main/java/com/rtbishop/look4sat/framework/NetDataReporter.kt+++ /dev/null@@ -1,34 +0,0 @@-package com.rtbishop.look4sat.framework--import com.rtbishop.look4sat.data.DataReporter-import kotlinx.coroutines.CoroutineDispatcher-import kotlinx.coroutines.withContext-import java.io.BufferedWriter-import java.net.Socket--class NetDataReporter(private val reporterDispatcher: CoroutineDispatcher) : DataReporter {-- private var rotatorSocket: Socket? = null- private var rotatorWriter: BufferedWriter? = null-- override suspend fun setRotatorSocket(server: String, port: Int) {- withContext(reporterDispatcher) {- runCatching {- rotatorSocket = Socket(server, port)- rotatorWriter = rotatorSocket?.getOutputStream()?.bufferedWriter()- }.onFailure { println(it.localizedMessage) }- }- }-- override suspend fun reportRotation(azim: Double, elev: Double) {- withContext(reporterDispatcher) {- runCatching {- rotatorWriter?.let { writer ->- writer.write("\\set_pos $azim $elev")- writer.newLine()- writer.flush()- }- }.onFailure { println(it.localizedMessage) }- }- }-}diff --git a/app/src/main/java/com/rtbishop/look4sat/injection/SatelliteDataModule.kt b/app/src/main/java/com/rtbishop/look4sat/injection/SatelliteDataModule.ktindex 97ce4fd3..45c3d467 100644--- a/app/src/main/java/com/rtbishop/look4sat/injection/SatelliteDataModule.kt+++ b/app/src/main/java/com/rtbishop/look4sat/injection/SatelliteDataModule.kt@@ -22,8 +22,8 @@ import android.content.SharedPreferencesimport android.location.LocationManagerimport androidx.room.Roomimport com.rtbishop.look4sat.data.*+import com.rtbishop.look4sat.domain.PassReporterimport com.rtbishop.look4sat.domain.Predictor-import com.rtbishop.look4sat.framework.NetDataReporterimport com.rtbishop.look4sat.framework.PreferencesProviderimport com.rtbishop.look4sat.framework.api.RemoteSourceimport com.rtbishop.look4sat.framework.api.SatelliteService@@ -112,7 +112,7 @@ object SatelliteDataModule {@Provides@Singleton- fun provideDataReporter(@IoDispatcher dispatcher: CoroutineDispatcher): DataReporter {- return NetDataReporter(dispatcher)+ fun provideDataReporter(@IoDispatcher dispatcher: CoroutineDispatcher): PassReporter {+ return PassReporter(dispatcher)}}diff --git a/app/src/main/java/com/rtbishop/look4sat/presentation/radarScreen/RadarViewModel.kt b/app/src/main/java/com/rtbishop/look4sat/presentation/radarScreen/RadarViewModel.ktindex 9da8e0f6..caaed8e9 100644--- a/app/src/main/java/com/rtbishop/look4sat/presentation/radarScreen/RadarViewModel.kt+++ b/app/src/main/java/com/rtbishop/look4sat/presentation/radarScreen/RadarViewModel.kt@@ -18,7 +18,7 @@package com.rtbishop.look4sat.presentation.radarScreenimport androidx.lifecycle.*-import com.rtbishop.look4sat.data.DataReporter+import com.rtbishop.look4sat.domain.PassReporterimport com.rtbishop.look4sat.data.PreferencesSourceimport com.rtbishop.look4sat.data.SatelliteRepoimport com.rtbishop.look4sat.domain.Predictor@@ -41,7 +41,7 @@ class RadarViewModel @Inject constructor(private val preferences: PreferencesSource,private val predictor: Predictor,private val satelliteRepo: SatelliteRepo,- private val dataReporter: DataReporter+ private val passReporter: PassReporter) : ViewModel(), OrientationProvider.OrientationListener {private val stationPos = preferences.loadStationPosition()@@ -80,7 +80,7 @@ class RadarViewModel @Inject constructor(var satTrack: List<SatPos> = emptyList()val rotatorPrefs = preferences.getRotatorServer()if (rotatorPrefs != null) {- dataReporter.setRotatorSocket(rotatorPrefs.first, rotatorPrefs.second)+ passReporter.setupRotatorSocket(rotatorPrefs.first, rotatorPrefs.second)}if (!satPass.isDeepSpace) {val startDate = Date(satPass.aosTime)@@ -91,7 +91,7 @@ class RadarViewModel @Inject constructor(val satPos = predictor.getSatPos(satPass.satellite, stationPos, Date())val azimuth = Math.toDegrees(satPos.azimuth).round(1)val elevation = Math.toDegrees(satPos.elevation).round(1)- dataReporter.reportRotation(azimuth, elevation)+ passReporter.reportRotation(azimuth, elevation)_passData.postValue(RadarData(satPos, satTrack))delay(1000)}diff --git a/core/src/main/java/com/rtbishop/look4sat/data/DataReporter.kt b/core/src/main/java/com/rtbishop/look4sat/data/DataReporter.ktdeleted file mode 100644index 4330a1fe..00000000--- a/core/src/main/java/com/rtbishop/look4sat/data/DataReporter.kt+++ /dev/null@@ -1,8 +0,0 @@-package com.rtbishop.look4sat.data--interface DataReporter {-- suspend fun setRotatorSocket(server: String, port: Int)-- suspend fun reportRotation(azim: Double, elev: Double)-}diff --git a/core/src/main/java/com/rtbishop/look4sat/domain/PassReporter.kt b/core/src/main/java/com/rtbishop/look4sat/domain/PassReporter.ktnew file mode 100644index 00000000..8b350692--- /dev/null+++ b/core/src/main/java/com/rtbishop/look4sat/domain/PassReporter.kt@@ -0,0 +1,56 @@+package com.rtbishop.look4sat.domain++import kotlinx.coroutines.CoroutineDispatcher+import kotlinx.coroutines.withContext+import java.io.BufferedWriter+import java.net.Socket++class PassReporter(private val reporterDispatcher: CoroutineDispatcher) {++ private var radioSocket: Socket? = null+ private var radioWriter: BufferedWriter? = null+ private var rotatorSocket: Socket? = null+ private var rotatorWriter: BufferedWriter? = null++ suspend fun setupRadioSocket(server: String, port: Int) {+ withContext(reporterDispatcher) {+ runCatching {+ radioSocket = Socket(server, port)+ radioWriter = rotatorSocket?.getOutputStream()?.bufferedWriter()+ }.onFailure { println(it.localizedMessage) }+ }+ }++ suspend fun reportFrequency(freq: Long) {+ withContext(reporterDispatcher) {+ runCatching {+ rotatorWriter?.let { writer ->+ writer.write("\\set_freq $freq")+ writer.newLine()+ writer.flush()+ }+ }.onFailure { println(it.localizedMessage) }+ }+ }++ suspend fun setupRotatorSocket(server: String, port: Int) {+ withContext(reporterDispatcher) {+ runCatching {+ rotatorSocket = Socket(server, port)+ rotatorWriter = rotatorSocket?.getOutputStream()?.bufferedWriter()+ }.onFailure { println(it.localizedMessage) }+ }+ }++ suspend fun reportRotation(azim: Double, elev: Double) {+ withContext(reporterDispatcher) {+ runCatching {+ rotatorWriter?.let { writer ->+ writer.write("\\set_pos $azim $elev")+ writer.newLine()+ writer.flush()+ }+ }.onFailure { println(it.localizedMessage) }+ }+ }+}