Refuse rotator port 65535 and reload antenna proposals on a source change

setStn_pstRotatorPort stores 1..65534 and replaces anything else by 12000, so the wizard must not accept 65535. And antenna values typed for a new station stayed in the summary after the operator chose to keep the station, where they are not written.

Written-by: Claude Fable 5.2
This commit is contained in:
Rsclub2_2 committed 2026-11-18 21:32:14 +01:00
1 parent bde77f3ec1
commit a24534bbb1
6 files changed
+105 -6

No files matched your search

@@ -183,6 +183,8 @@ class SetupWizardState(prefs: ChatPreferences) {
gearShown = !keep gearShown = !keep
// A new station gets only what the operator says yes to. // A new station gets only what the operator says yes to.
if (keep) integrations.loadStored() else integrations.loadFresh() 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 appliedStationSource = stationSource
} }
} }
@@ -21,13 +21,32 @@ import kst4contest.view.compose.tabs.StationTabState
*/ */
class WizardAntenna(prefs: ChatPreferences) { class WizardAntenna(prefs: ChatPreferences) {
var beamWidthDeg: Double by mutableStateOf(prefs.getStn_antennaBeamWidthDeg()) private val storedBeamWidthDeg = prefs.getStn_antennaBeamWidthDeg()
var gainDbi: Double by mutableStateOf(prefs.getStn_pathAnalysisOwnAntennaGainDbi()) private val storedGainDbi = prefs.getStn_pathAnalysisOwnAntennaGainDbi()
var heightMeters: Double by mutableStateOf(prefs.getStn_pathAnalysisOwnAntennaHeightMeters()) private val storedHeightMeters = prefs.getStn_pathAnalysisOwnAntennaHeightMeters()
var txPowerWatts: Double by mutableStateOf(prefs.getStn_pathAnalysisOwnTxPowerWatts()) 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. */ /** 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. */ /** A site elevation that is neither empty nor a number in the accepted range. */
val heightAslRefused: Boolean val heightAslRefused: Boolean
@@ -151,7 +151,7 @@ class WizardIntegrations(prefs: ChatPreferences) {
val gearComplete: Boolean val gearComplete: Boolean
get() { get() {
val rotatorComplete = !rotator || val rotatorComplete = !rotator ||
(rotatorHost.isNotBlank() && AirscoutTabState.isValidPort(rotatorPort) && !rotatorPortClashes) (rotatorHost.isNotBlank() && rotatorPort in ROTATOR_PORTS && !rotatorPortClashes)
val airScoutComplete = !airScout || val airScoutComplete = !airScout ||
(AirscoutTabState.isValidPort(airScoutPort) && (AirscoutTabState.isValidPort(airScoutPort) &&
AirscoutTabState.isValidIdentifier(airScoutServerName) && AirscoutTabState.isValidIdentifier(airScoutServerName) &&
@@ -218,4 +218,13 @@ class WizardIntegrations(prefs: ChatPreferences) {
if (storedRotator && !rotator) add(WizardSwitch.ROTATOR) if (storedRotator && !rotator) add(WizardSwitch.ROTATOR)
if (storedAirScout && !airScout) add(WizardSwitch.AIRSCOUT) 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
}
} }
@@ -565,4 +565,34 @@ class SetupWizardStateTest {
assertTrue(state.canGoNext) assertTrue(state.canGoNext)
assertTrue(state.mandatoryComplete) 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",
)
}
} }
@@ -105,4 +105,23 @@ class WizardAntennaTest {
assertTrue(target.getStn_pathAnalysisOwnHeightAslMeters().isNaN(), "empty hands the elevation back to the model") 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)
}
} }
@@ -277,4 +277,24 @@ class WizardIntegrationsTest {
assertEquals(emptyList<WizardSwitch>(), answers.switchedOffByLog()) assertEquals(emptyList<WizardSwitch>(), answers.switchedOffByLog())
assertEquals(emptyList<WizardSwitch>(), answers.switchedOffByGear()) assertEquals(emptyList<WizardSwitch>(), 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)
}
} }