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,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