mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added frequency reporting to PassReporter.kt
This commit is contained in:
1 parent
09f35579dc
commit
84240c94c6
5 files changed
+63
-49
No files matched your search
@@ -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) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,8 +22,8 @@ import android.content.SharedPreferences
|
|||||||
import android.location.LocationManager
|
import android.location.LocationManager
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import com.rtbishop.look4sat.data.*
|
import com.rtbishop.look4sat.data.*
|
||||||
|
import com.rtbishop.look4sat.domain.PassReporter
|
||||||
import com.rtbishop.look4sat.domain.Predictor
|
import com.rtbishop.look4sat.domain.Predictor
|
||||||
import com.rtbishop.look4sat.framework.NetDataReporter
|
|
||||||
import com.rtbishop.look4sat.framework.PreferencesProvider
|
import com.rtbishop.look4sat.framework.PreferencesProvider
|
||||||
import com.rtbishop.look4sat.framework.api.RemoteSource
|
import com.rtbishop.look4sat.framework.api.RemoteSource
|
||||||
import com.rtbishop.look4sat.framework.api.SatelliteService
|
import com.rtbishop.look4sat.framework.api.SatelliteService
|
||||||
@@ -112,7 +112,7 @@ object SatelliteDataModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideDataReporter(@IoDispatcher dispatcher: CoroutineDispatcher): DataReporter {
|
fun provideDataReporter(@IoDispatcher dispatcher: CoroutineDispatcher): PassReporter {
|
||||||
return NetDataReporter(dispatcher)
|
return PassReporter(dispatcher)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
package com.rtbishop.look4sat.presentation.radarScreen
|
package com.rtbishop.look4sat.presentation.radarScreen
|
||||||
|
|
||||||
import androidx.lifecycle.*
|
import androidx.lifecycle.*
|
||||||
import com.rtbishop.look4sat.data.DataReporter
|
import com.rtbishop.look4sat.domain.PassReporter
|
||||||
import com.rtbishop.look4sat.data.PreferencesSource
|
import com.rtbishop.look4sat.data.PreferencesSource
|
||||||
import com.rtbishop.look4sat.data.SatelliteRepo
|
import com.rtbishop.look4sat.data.SatelliteRepo
|
||||||
import com.rtbishop.look4sat.domain.Predictor
|
import com.rtbishop.look4sat.domain.Predictor
|
||||||
@@ -41,7 +41,7 @@ class RadarViewModel @Inject constructor(
|
|||||||
private val preferences: PreferencesSource,
|
private val preferences: PreferencesSource,
|
||||||
private val predictor: Predictor,
|
private val predictor: Predictor,
|
||||||
private val satelliteRepo: SatelliteRepo,
|
private val satelliteRepo: SatelliteRepo,
|
||||||
private val dataReporter: DataReporter
|
private val passReporter: PassReporter
|
||||||
) : ViewModel(), OrientationProvider.OrientationListener {
|
) : ViewModel(), OrientationProvider.OrientationListener {
|
||||||
|
|
||||||
private val stationPos = preferences.loadStationPosition()
|
private val stationPos = preferences.loadStationPosition()
|
||||||
@@ -80,7 +80,7 @@ class RadarViewModel @Inject constructor(
|
|||||||
var satTrack: List<SatPos> = emptyList()
|
var satTrack: List<SatPos> = emptyList()
|
||||||
val rotatorPrefs = preferences.getRotatorServer()
|
val rotatorPrefs = preferences.getRotatorServer()
|
||||||
if (rotatorPrefs != null) {
|
if (rotatorPrefs != null) {
|
||||||
dataReporter.setRotatorSocket(rotatorPrefs.first, rotatorPrefs.second)
|
passReporter.setupRotatorSocket(rotatorPrefs.first, rotatorPrefs.second)
|
||||||
}
|
}
|
||||||
if (!satPass.isDeepSpace) {
|
if (!satPass.isDeepSpace) {
|
||||||
val startDate = Date(satPass.aosTime)
|
val startDate = Date(satPass.aosTime)
|
||||||
@@ -91,7 +91,7 @@ class RadarViewModel @Inject constructor(
|
|||||||
val satPos = predictor.getSatPos(satPass.satellite, stationPos, Date())
|
val satPos = predictor.getSatPos(satPass.satellite, stationPos, Date())
|
||||||
val azimuth = Math.toDegrees(satPos.azimuth).round(1)
|
val azimuth = Math.toDegrees(satPos.azimuth).round(1)
|
||||||
val elevation = Math.toDegrees(satPos.elevation).round(1)
|
val elevation = Math.toDegrees(satPos.elevation).round(1)
|
||||||
dataReporter.reportRotation(azimuth, elevation)
|
passReporter.reportRotation(azimuth, elevation)
|
||||||
_passData.postValue(RadarData(satPos, satTrack))
|
_passData.postValue(RadarData(satPos, satTrack))
|
||||||
delay(1000)
|
delay(1000)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -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) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user