diff --git a/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/SetupWizardState.kt b/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/SetupWizardState.kt index d977da42..2c4fe4ae 100644 --- a/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/SetupWizardState.kt +++ b/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/SetupWizardState.kt @@ -183,6 +183,8 @@ class SetupWizardState(prefs: ChatPreferences) { gearShown = !keep // A new station gets only what the operator says yes to. if (keep) integrations.loadStored() else integrations.loadFresh() + // Proposals from the profile either way; what was typed under the other choice goes. + antenna.loadStored() appliedStationSource = stationSource } } diff --git a/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/WizardAntenna.kt b/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/WizardAntenna.kt index 1815e3ab..9b14357e 100644 --- a/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/WizardAntenna.kt +++ b/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/WizardAntenna.kt @@ -21,13 +21,32 @@ import kst4contest.view.compose.tabs.StationTabState */ class WizardAntenna(prefs: ChatPreferences) { - var beamWidthDeg: Double by mutableStateOf(prefs.getStn_antennaBeamWidthDeg()) - var gainDbi: Double by mutableStateOf(prefs.getStn_pathAnalysisOwnAntennaGainDbi()) - var heightMeters: Double by mutableStateOf(prefs.getStn_pathAnalysisOwnAntennaHeightMeters()) - var txPowerWatts: Double by mutableStateOf(prefs.getStn_pathAnalysisOwnTxPowerWatts()) + private val storedBeamWidthDeg = prefs.getStn_antennaBeamWidthDeg() + private val storedGainDbi = prefs.getStn_pathAnalysisOwnAntennaGainDbi() + private val storedHeightMeters = prefs.getStn_pathAnalysisOwnAntennaHeightMeters() + private val storedTxPowerWatts = prefs.getStn_pathAnalysisOwnTxPowerWatts() + private val storedHeightAslText = elevationText(prefs.getStn_pathAnalysisOwnHeightAslMeters()) + + var beamWidthDeg: Double by mutableStateOf(storedBeamWidthDeg) + var gainDbi: Double by mutableStateOf(storedGainDbi) + var heightMeters: Double by mutableStateOf(storedHeightMeters) + var txPowerWatts: Double by mutableStateOf(storedTxPowerWatts) /** The site elevation above sea level as the operator types it; empty for the model. */ - var heightAslText: String by mutableStateOf(elevationText(prefs.getStn_pathAnalysisOwnHeightAslMeters())) + var heightAslText: String by mutableStateOf(storedHeightAslText) + + /** + * Puts every answer back to what the profile holds. For the moment the operator changes + * his mind about where the station comes from: what he typed for one choice must not + * show in the summary of the other, where it would not be written. + */ + fun loadStored() { + beamWidthDeg = storedBeamWidthDeg + gainDbi = storedGainDbi + heightMeters = storedHeightMeters + txPowerWatts = storedTxPowerWatts + heightAslText = storedHeightAslText + } /** A site elevation that is neither empty nor a number in the accepted range. */ val heightAslRefused: Boolean diff --git a/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/WizardIntegrations.kt b/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/WizardIntegrations.kt index f7b0416f..f02886a9 100644 --- a/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/WizardIntegrations.kt +++ b/app-desktop/src/main/kotlin/kst4contest/view/compose/wizard/WizardIntegrations.kt @@ -151,7 +151,7 @@ class WizardIntegrations(prefs: ChatPreferences) { val gearComplete: Boolean get() { val rotatorComplete = !rotator || - (rotatorHost.isNotBlank() && AirscoutTabState.isValidPort(rotatorPort) && !rotatorPortClashes) + (rotatorHost.isNotBlank() && rotatorPort in ROTATOR_PORTS && !rotatorPortClashes) val airScoutComplete = !airScout || (AirscoutTabState.isValidPort(airScoutPort) && AirscoutTabState.isValidIdentifier(airScoutServerName) && @@ -218,4 +218,13 @@ class WizardIntegrations(prefs: ChatPreferences) { if (storedRotator && !rotator) add(WizardSwitch.ROTATOR) if (storedAirScout && !airScout) add(WizardSwitch.AIRSCOUT) } + + private companion object { + /** + * The ports setStn_pstRotatorPort stores. One short of the full range, because + * PSTRotator answers on port + 1; the setter replaces anything else by its factory + * default, which would be the wizard inventing a number. + */ + val ROTATOR_PORTS = 1..65534 + } } diff --git a/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/SetupWizardStateTest.kt b/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/SetupWizardStateTest.kt index ea7f3105..819dba97 100644 --- a/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/SetupWizardStateTest.kt +++ b/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/SetupWizardStateTest.kt @@ -565,4 +565,34 @@ class SetupWizardStateTest { assertTrue(state.canGoNext) assertTrue(state.mandatoryComplete) } + + @Test + fun antennaValuesTypedForANewStationAreGoneWhenTheStationIsKeptAfterAll() { + val profile = duplicatedWinTestStation().apply { setStn_antennaBeamWidthDeg(28.0) } + val state = SetupWizardState(profile) + state.chooseStationSource(WizardSource.NEW) + state.next() + state.name = "Philipp" + state.next() + state.callsign = "DL0TEST" + state.password = "secret" + state.next() + state.locator = "JO50AA" + state.setBand(WizardBand.B144, true) + state.next() + assertEquals(WizardPage.ANTENNA, state.page) + state.antenna.beamWidthDeg = 99.0 + + repeat(4) { state.back() } + assertEquals(WizardPage.ENTRY, state.page) + state.chooseStationSource(WizardSource.KEEP) + state.next() + + assertFalse(state.pages.contains(WizardPage.ANTENNA), "a kept station does not write the antenna page") + assertEquals( + 28.0, + state.antenna.beamWidthDeg, + "the summary must not show a value that Save will not write", + ) + } } diff --git a/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/WizardAntennaTest.kt b/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/WizardAntennaTest.kt index 8cd22471..237e3e69 100644 --- a/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/WizardAntennaTest.kt +++ b/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/WizardAntennaTest.kt @@ -105,4 +105,23 @@ class WizardAntennaTest { assertTrue(target.getStn_pathAnalysisOwnHeightAslMeters().isNaN(), "empty hands the elevation back to the model") } + + @Test + fun loadingTheStoredValuesAgainDropsWhatWasTyped() { + val antenna = WizardAntenna(stored()) + antenna.beamWidthDeg = 99.0 + antenna.gainDbi = 1.0 + antenna.heightMeters = 2.0 + antenna.txPowerWatts = 3.0 + antenna.heightAslText = "abc" + + antenna.loadStored() + + assertEquals(28.0, antenna.beamWidthDeg) + assertEquals(16.5, antenna.gainDbi) + assertEquals(18.0, antenna.heightMeters) + assertEquals(400.0, antenna.txPowerWatts) + assertEquals("612", antenna.heightAslText) + assertTrue(antenna.complete) + } } diff --git a/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/WizardIntegrationsTest.kt b/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/WizardIntegrationsTest.kt index 47abe489..7020f612 100644 --- a/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/WizardIntegrationsTest.kt +++ b/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/WizardIntegrationsTest.kt @@ -277,4 +277,24 @@ class WizardIntegrationsTest { assertEquals(emptyList(), answers.switchedOffByLog()) assertEquals(emptyList(), answers.switchedOffByGear()) } + + @Test + fun theHighestPortIsNoRotatorPort() { + // PSTRotator answers on port + 1, so the setter stores 1..65534 only and would + // replace 65535 by its factory default without a word. + val target = allOff() + val answers = WizardIntegrations(target) + answers.rotator = true + + answers.rotatorPort = 65535 + assertFalse(answers.gearComplete, "65535 would be stored as 12000") + + answers.rotatorPort = 65534 + assertTrue(answers.gearComplete) + answers.writeGearTo(target) + assertEquals(65534, target.getStn_pstRotatorPort(), "an accepted port is stored as entered") + + answers.rotatorPort = 0 + assertFalse(answers.gearComplete) + } }