mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Fixed antenna rotator control issue #69
This commit is contained in:
1 parent
55a827330f
commit
db8fe3ce8d
3 files changed
+45
-58
No files matched your search
@@ -83,10 +83,6 @@ class PreferencesSource @Inject constructor(
|
||||
const val keyPositionQTH = "setPositionQTH"
|
||||
}
|
||||
|
||||
fun positionToQTH(lat: Double, lon: Double): String? {
|
||||
return QthConverter.positionToQTH(lat, lon)
|
||||
}
|
||||
|
||||
fun loadStationPosition(): GeoPos {
|
||||
val defaultSP = "0.0"
|
||||
val latitude = preferences.getString(keyLatitude, null) ?: defaultSP
|
||||
@@ -185,11 +181,9 @@ class PreferencesSource @Inject constructor(
|
||||
return preferences.getBoolean(keyRotator, false)
|
||||
}
|
||||
|
||||
fun getRotatorServer(): Pair<String, Int>? {
|
||||
return if (isRotatorEnabled()) {
|
||||
val address = preferences.getString(keyRotatorAddress, null) ?: "127.0.0.1"
|
||||
val port = preferences.getString(keyRotatorPort, null) ?: "4533"
|
||||
Pair(address, port.toInt())
|
||||
} else null
|
||||
fun getRotatorServer(): Pair<String, Int> {
|
||||
val address = preferences.getString(keyRotatorAddress, null) ?: "127.0.0.1"
|
||||
val port = preferences.getString(keyRotatorPort, null) ?: "4533"
|
||||
return Pair(address, port.toInt())
|
||||
}
|
||||
}
|
||||
@@ -78,10 +78,6 @@ class RadarViewModel @Inject constructor(
|
||||
private fun sendPassData(satPass: SatPass) {
|
||||
viewModelScope.launch {
|
||||
var satTrack: List<SatPos> = emptyList()
|
||||
val rotatorPrefs = preferences.getRotatorServer()
|
||||
if (rotatorPrefs != null) {
|
||||
dataReporter.setupRotatorSocket(rotatorPrefs.first, rotatorPrefs.second)
|
||||
}
|
||||
if (!satPass.isDeepSpace) {
|
||||
val startDate = Date(satPass.aosTime)
|
||||
val endDate = Date(satPass.losTime)
|
||||
@@ -89,9 +85,13 @@ class RadarViewModel @Inject constructor(
|
||||
}
|
||||
while (isActive) {
|
||||
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)
|
||||
if (preferences.isRotatorEnabled()) {
|
||||
val server = preferences.getRotatorServer().first
|
||||
val port = preferences.getRotatorServer().second
|
||||
val azimuth = Math.toDegrees(satPos.azimuth).round(1)
|
||||
val elevation = Math.toDegrees(satPos.elevation).round(1)
|
||||
dataReporter.reportRotation(server, port, azimuth, elevation)
|
||||
}
|
||||
_passData.postValue(RadarData(satPos, satTrack))
|
||||
delay(1000)
|
||||
}
|
||||
|
||||
@@ -17,57 +17,50 @@
|
||||
*/
|
||||
package com.rtbishop.look4sat.domain
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.BufferedWriter
|
||||
import java.net.Socket
|
||||
import kotlinx.coroutines.*
|
||||
import java.net.InetSocketAddress
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.channels.SocketChannel
|
||||
|
||||
class DataReporter(private val reporterDispatcher: CoroutineDispatcher) {
|
||||
class DataReporter(reporterDispatcher: CoroutineDispatcher) {
|
||||
|
||||
private var radioSocket: Socket? = null
|
||||
private var radioWriter: BufferedWriter? = null
|
||||
private var rotatorSocket: Socket? = null
|
||||
private var rotatorWriter: BufferedWriter? = null
|
||||
private val reporterScope = CoroutineScope(reporterDispatcher)
|
||||
private var frequencySocketChannel: SocketChannel? = null
|
||||
private var rotationSocketChannel: SocketChannel? = null
|
||||
private var frequencyReporting: Job? = null
|
||||
private var rotationReporting: Job? = null
|
||||
|
||||
suspend fun setupRadioSocket(server: String, port: Int) {
|
||||
withContext(reporterDispatcher) {
|
||||
fun reportFrequency(server: String, port: Int, frequency: Long) {
|
||||
frequencyReporting = reporterScope.launch {
|
||||
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()
|
||||
if (frequencySocketChannel == null) {
|
||||
frequencySocketChannel = SocketChannel.open(InetSocketAddress(server, port))
|
||||
} else {
|
||||
val buffer = ByteBuffer.wrap("\\set_freq $frequency\n".toByteArray())
|
||||
frequencySocketChannel?.write(buffer)
|
||||
}
|
||||
}.onFailure { println(it.localizedMessage) }
|
||||
}.onFailure { error ->
|
||||
println(error.localizedMessage)
|
||||
frequencySocketChannel = null
|
||||
frequencyReporting?.cancelAndJoin()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setupRotatorSocket(server: String, port: Int) {
|
||||
withContext(reporterDispatcher) {
|
||||
fun reportRotation(server: String, port: Int, azimuth: Double, elevation: Double) {
|
||||
rotationReporting = reporterScope.launch {
|
||||
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()
|
||||
if (rotationSocketChannel == null) {
|
||||
rotationSocketChannel = SocketChannel.open(InetSocketAddress(server, port))
|
||||
} else {
|
||||
val buffer = ByteBuffer.wrap("\\set_pos $azimuth $elevation\n".toByteArray())
|
||||
rotationSocketChannel?.write(buffer)
|
||||
}
|
||||
}.onFailure { println(it.localizedMessage) }
|
||||
}.onFailure { error ->
|
||||
println(error.localizedMessage)
|
||||
rotationSocketChannel = null
|
||||
rotationReporting?.cancelAndJoin()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user