Satellite tracker and pass predictor for Android, inspired by Gpredict
Kotlin amsatcelestrakgpsham-radiohamlibhamradiokotlinnasaradiosatellitesatellite-datasatellite-positionsatellite-predictionsatellitessatnogssdrspacespacexstarlink
Simplified data output code, aligned with HamLib defaults
Arty Bishop868155c5329e
diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/BluetoothReporter.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/BluetoothReporter.ktindex b36387e2..17721c81 100644--- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/BluetoothReporter.kt+++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/BluetoothReporter.kt@@ -55,8 +55,8 @@ class BluetoothReporter(if (!rotatorConnected) return@launchval el = if (elevation > 0.0) elevation else 0.0val command = format- .replace($$"$AZ", "%03d".format(azimuth.toInt()))- .replace($$"$EL", "%03d".format(el.toInt()))+ .replace($$"$AZ", azimuth.toString())+ .replace($$"$EL", el.toString()).unescapeControlChars()write(rotatorStream, command) { rotatorConnected = false }}diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/NetworkReporter.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/NetworkReporter.ktindex f01d3dc7..b116b190 100644--- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/NetworkReporter.kt+++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/framework/NetworkReporter.kt@@ -52,6 +52,7 @@ class NetworkReporter(val command = format.replace($$"$AZ", azimuth.toString()).replace($$"$EL", el.toString())+ .unescapeControlChars()write(rotatorSocket, command) { rotatorConnected = false }}}@@ -60,7 +61,9 @@ class NetworkReporter(reporterScope.launch {ensureFrequencyConnected()if (!frequencyConnected) return@launch- val command = format.replace($$"$FREQ", frequency.toString())+ val command = format+ .replace($$"$FREQ", frequency.toString())+ .unescapeControlChars()write(frequencySocket, command) { frequencyConnected = false }}}@@ -110,4 +113,7 @@ class NetworkReporter(onError()}}++ private fun String.unescapeControlChars(): String =+ replace("\\r", "\r").replace("\\n", "\n").replace("\\t", "\t")}diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.ktindex ed33b820..494259e2 100644--- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt+++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt@@ -246,6 +246,29 @@ class SettingsRepo(//endregion//region # RC settings+ init {+ migrateRCFormats()+ }++ // TODO: Remove after a few releases (added in v4.2.0)+ private val keyRCFormatsMigrated = "rcFormatsMigrated"++ private fun migrateRCFormats() {+ if (preferences.getBoolean(keyRCFormatsMigrated, false)) return+ val formatKeys = listOf(+ keyRotatorFormat, keyFrequencyFormat, keyBluetoothRotatorFormat, keyBluetoothFrequencyFormat+ )+ preferences.edit {+ for (key in formatKeys) {+ val value = preferences.getString(key, null) ?: continue+ if (value.contains("_") && !value.startsWith("\\")) {+ putString(key, "\\$value")+ }+ }+ putBoolean(keyRCFormatsMigrated, true)+ }+ }+private val _rcSettings = MutableStateFlow(getRCSettings())override val rcSettings: StateFlow<RCSettings> = _rcSettings@@ -280,12 +303,12 @@ class SettingsRepo(frequencyPort = preferences.getString(keyFrequencyPort, null) ?: "4532",frequencyFormat = preferences.getString(keyFrequencyFormat, null) ?: $$"F $FREQ",bluetoothRotatorState = preferences.getBoolean(keyBluetoothRotatorState, false),- bluetoothRotatorFormat = preferences.getString(keyBluetoothRotatorFormat, null) ?: $$"W$AZ $EL",+ bluetoothRotatorFormat = preferences.getString(keyBluetoothRotatorFormat, null) ?: $$"P $AZ $EL",bluetoothRotatorName = preferences.getString(keyBluetoothRotatorName, null) ?: "Default",bluetoothRotatorAddress = preferences.getString(keyBluetoothRotatorAddress, null) ?: "00:0C:BF:13:80:5D",bluetoothFrequencyState = preferences.getBoolean(keyBluetoothFrequencyState, false),bluetoothFrequencyAddress = preferences.getString(keyBluetoothFrequencyAddress, null) ?: "00:0C:BF:13:80:5D",- bluetoothFrequencyFormat = preferences.getString(keyBluetoothFrequencyFormat, null) ?: $$"FA$FREQ"+ bluetoothFrequencyFormat = preferences.getString(keyBluetoothFrequencyFormat, null) ?: $$"F $FREQ")//endregiondiff --git a/feature/radar/src/main/java/com/rtbishop/look4sat/feature/radar/RadarViewModel.kt b/feature/radar/src/main/java/com/rtbishop/look4sat/feature/radar/RadarViewModel.ktindex 42d3c4cf..ebc60317 100644--- a/feature/radar/src/main/java/com/rtbishop/look4sat/feature/radar/RadarViewModel.kt+++ b/feature/radar/src/main/java/com/rtbishop/look4sat/feature/radar/RadarViewModel.kt@@ -129,7 +129,6 @@ class RadarViewModel(}processRadios(transmitters, satPass.orbitalObject, timeNow)sendPassData(pos)- sendPassDataBT(pos)delay(1000)}}@@ -149,33 +148,35 @@ class RadarViewModel(}private fun sendPassData(orbitalPos: OrbitalPos) {- viewModelScope.launch {- val rc = settingsRepo.rcSettings.value- if (rc.rotatorState) {- val azimuth = orbitalPos.azimuth.toDegrees().round(2)- val elevation = orbitalPos.elevation.toDegrees().round(2)- networkReporter.reportRotation(rc.rotatorFormat, azimuth, elevation)- }- if (rc.frequencyState) {- _uiState.value.selectedFrequency?.let { freq ->- networkReporter.reportFrequency(rc.frequencyFormat, freq)- }- }- }+ val rc = settingsRepo.rcSettings.value+ sendReporterData(+ networkReporter, orbitalPos,+ rc.rotatorState, rc.rotatorFormat,+ rc.frequencyState, rc.frequencyFormat+ )+ sendReporterData(+ bluetoothReporter, orbitalPos,+ rc.bluetoothRotatorState, rc.bluetoothRotatorFormat,+ rc.bluetoothFrequencyState, rc.bluetoothFrequencyFormat+ )}- private fun sendPassDataBT(orbitalPos: OrbitalPos) {- viewModelScope.launch {- val rc = settingsRepo.rcSettings.value- if (rc.bluetoothRotatorState) {- val azimuth = orbitalPos.azimuth.toDegrees().round(0)- val elevation = orbitalPos.elevation.toDegrees().round(0)- bluetoothReporter.reportRotation(rc.bluetoothRotatorFormat, azimuth, elevation)- }- if (rc.bluetoothFrequencyState) {- _uiState.value.selectedFrequency?.let { freq ->- bluetoothReporter.reportFrequency(rc.bluetoothFrequencyFormat, freq)- }+ private fun sendReporterData(+ reporter: IReporter,+ orbitalPos: OrbitalPos,+ rotatorEnabled: Boolean,+ rotatorFormat: String,+ frequencyEnabled: Boolean,+ frequencyFormat: String+ ) {+ if (rotatorEnabled) {+ val azimuth = orbitalPos.azimuth.toDegrees().round(2)+ val elevation = orbitalPos.elevation.toDegrees().round(2)+ reporter.reportRotation(rotatorFormat, azimuth, elevation)+ }+ if (frequencyEnabled) {+ _uiState.value.selectedFrequency?.let { freq ->+ reporter.reportFrequency(frequencyFormat, freq)}}}diff --git a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.ktindex 8e3c6d13..1b4487a8 100644--- a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt+++ b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt@@ -216,12 +216,12 @@ fun PreviewNetworkOutputDialog() {frequencyPort = "4532",frequencyFormat = $$"F $FREQ",bluetoothRotatorState = false,- bluetoothRotatorFormat = $$"W$AZ $EL",+ bluetoothRotatorFormat = $$"P $AZ $EL",bluetoothRotatorName = "Default",bluetoothRotatorAddress = "00:0C:BF:13:80:5D",bluetoothFrequencyState = false,bluetoothFrequencyAddress = "00:0C:BF:13:80:5D",- bluetoothFrequencyFormat = $$"FA$FREQ"+ bluetoothFrequencyFormat = $$"F $FREQ"),onDismiss = {},onSave = { _, _, _, _, _, _, _, _ -> }@@ -361,14 +361,14 @@ fun PreviewBluetoothOutputDialog() {frequencyState = false,frequencyAddress = "127.0.0.1",frequencyPort = "4532",- frequencyFormat = $$"set_freq $FREQ",+ frequencyFormat = $$"F $FREQ",bluetoothRotatorState = false,- bluetoothRotatorFormat = $$"W$AZ $EL",+ bluetoothRotatorFormat = $$"P $AZ $EL",bluetoothRotatorName = "Default",bluetoothRotatorAddress = "00:0C:BF:13:80:5D",bluetoothFrequencyState = false,bluetoothFrequencyAddress = "00:0C:BF:13:80:5D",- bluetoothFrequencyFormat = $$"FA$FREQ"+ bluetoothFrequencyFormat = $$"F $FREQ"),onDismiss = {},onSave = { _, _, _, _, _, _ -> }