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"
|
const val keyPositionQTH = "setPositionQTH"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun positionToQTH(lat: Double, lon: Double): String? {
|
|
||||||
return QthConverter.positionToQTH(lat, lon)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun loadStationPosition(): GeoPos {
|
fun loadStationPosition(): GeoPos {
|
||||||
val defaultSP = "0.0"
|
val defaultSP = "0.0"
|
||||||
val latitude = preferences.getString(keyLatitude, null) ?: defaultSP
|
val latitude = preferences.getString(keyLatitude, null) ?: defaultSP
|
||||||
@@ -185,11 +181,9 @@ class PreferencesSource @Inject constructor(
|
|||||||
return preferences.getBoolean(keyRotator, false)
|
return preferences.getBoolean(keyRotator, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRotatorServer(): Pair<String, Int>? {
|
fun getRotatorServer(): Pair<String, Int> {
|
||||||
return if (isRotatorEnabled()) {
|
val address = preferences.getString(keyRotatorAddress, null) ?: "127.0.0.1"
|
||||||
val address = preferences.getString(keyRotatorAddress, null) ?: "127.0.0.1"
|
val port = preferences.getString(keyRotatorPort, null) ?: "4533"
|
||||||
val port = preferences.getString(keyRotatorPort, null) ?: "4533"
|
return Pair(address, port.toInt())
|
||||||
Pair(address, port.toInt())
|
|
||||||
} else null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,10 +78,6 @@ class RadarViewModel @Inject constructor(
|
|||||||
private fun sendPassData(satPass: SatPass) {
|
private fun sendPassData(satPass: SatPass) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
var satTrack: List<SatPos> = emptyList()
|
var satTrack: List<SatPos> = emptyList()
|
||||||
val rotatorPrefs = preferences.getRotatorServer()
|
|
||||||
if (rotatorPrefs != null) {
|
|
||||||
dataReporter.setupRotatorSocket(rotatorPrefs.first, rotatorPrefs.second)
|
|
||||||
}
|
|
||||||
if (!satPass.isDeepSpace) {
|
if (!satPass.isDeepSpace) {
|
||||||
val startDate = Date(satPass.aosTime)
|
val startDate = Date(satPass.aosTime)
|
||||||
val endDate = Date(satPass.losTime)
|
val endDate = Date(satPass.losTime)
|
||||||
@@ -89,9 +85,13 @@ class RadarViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
val satPos = predictor.getSatPos(satPass.satellite, stationPos, Date())
|
val satPos = predictor.getSatPos(satPass.satellite, stationPos, Date())
|
||||||
val azimuth = Math.toDegrees(satPos.azimuth).round(1)
|
if (preferences.isRotatorEnabled()) {
|
||||||
val elevation = Math.toDegrees(satPos.elevation).round(1)
|
val server = preferences.getRotatorServer().first
|
||||||
dataReporter.reportRotation(azimuth, elevation)
|
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))
|
_passData.postValue(RadarData(satPos, satTrack))
|
||||||
delay(1000)
|
delay(1000)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,57 +17,50 @@
|
|||||||
*/
|
*/
|
||||||
package com.rtbishop.look4sat.domain
|
package com.rtbishop.look4sat.domain
|
||||||
|
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.withContext
|
import java.net.InetSocketAddress
|
||||||
import java.io.BufferedWriter
|
import java.nio.ByteBuffer
|
||||||
import java.net.Socket
|
import java.nio.channels.SocketChannel
|
||||||
|
|
||||||
class DataReporter(private val reporterDispatcher: CoroutineDispatcher) {
|
class DataReporter(reporterDispatcher: CoroutineDispatcher) {
|
||||||
|
|
||||||
private var radioSocket: Socket? = null
|
private val reporterScope = CoroutineScope(reporterDispatcher)
|
||||||
private var radioWriter: BufferedWriter? = null
|
private var frequencySocketChannel: SocketChannel? = null
|
||||||
private var rotatorSocket: Socket? = null
|
private var rotationSocketChannel: SocketChannel? = null
|
||||||
private var rotatorWriter: BufferedWriter? = null
|
private var frequencyReporting: Job? = null
|
||||||
|
private var rotationReporting: Job? = null
|
||||||
|
|
||||||
suspend fun setupRadioSocket(server: String, port: Int) {
|
fun reportFrequency(server: String, port: Int, frequency: Long) {
|
||||||
withContext(reporterDispatcher) {
|
frequencyReporting = reporterScope.launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
radioSocket = Socket(server, port)
|
if (frequencySocketChannel == null) {
|
||||||
radioWriter = rotatorSocket?.getOutputStream()?.bufferedWriter()
|
frequencySocketChannel = SocketChannel.open(InetSocketAddress(server, port))
|
||||||
}.onFailure { println(it.localizedMessage) }
|
} else {
|
||||||
}
|
val buffer = ByteBuffer.wrap("\\set_freq $frequency\n".toByteArray())
|
||||||
}
|
frequencySocketChannel?.write(buffer)
|
||||||
|
|
||||||
suspend fun reportFrequency(freq: Long) {
|
|
||||||
withContext(reporterDispatcher) {
|
|
||||||
runCatching {
|
|
||||||
rotatorWriter?.let { writer ->
|
|
||||||
writer.write("\\set_freq $freq")
|
|
||||||
writer.newLine()
|
|
||||||
writer.flush()
|
|
||||||
}
|
}
|
||||||
}.onFailure { println(it.localizedMessage) }
|
}.onFailure { error ->
|
||||||
|
println(error.localizedMessage)
|
||||||
|
frequencySocketChannel = null
|
||||||
|
frequencyReporting?.cancelAndJoin()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun setupRotatorSocket(server: String, port: Int) {
|
fun reportRotation(server: String, port: Int, azimuth: Double, elevation: Double) {
|
||||||
withContext(reporterDispatcher) {
|
rotationReporting = reporterScope.launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
rotatorSocket = Socket(server, port)
|
if (rotationSocketChannel == null) {
|
||||||
rotatorWriter = rotatorSocket?.getOutputStream()?.bufferedWriter()
|
rotationSocketChannel = SocketChannel.open(InetSocketAddress(server, port))
|
||||||
}.onFailure { println(it.localizedMessage) }
|
} else {
|
||||||
}
|
val buffer = ByteBuffer.wrap("\\set_pos $azimuth $elevation\n".toByteArray())
|
||||||
}
|
rotationSocketChannel?.write(buffer)
|
||||||
|
|
||||||
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) }
|
}.onFailure { error ->
|
||||||
|
println(error.localizedMessage)
|
||||||
|
rotationSocketChannel = null
|
||||||
|
rotationReporting?.cancelAndJoin()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user