Fix frequency calculations

This commit is contained in:
Mygod
2020-07-02 08:39:42 +08:00
parent 71e0ab6ed1
commit 4c5265f0c2
4 changed files with 60 additions and 29 deletions

View File

@@ -45,7 +45,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
private const val KEY_NETWORK_NAME = "service.repeater.networkName"
private const val KEY_PASSPHRASE = "service.repeater.passphrase"
private const val KEY_OPERATING_BAND = "service.repeater.band"
private const val KEY_OPERATING_BAND = "service.repeater.band.v2"
private const val KEY_OPERATING_CHANNEL = "service.repeater.oc"
private const val KEY_DEVICE_ADDRESS = "service.repeater.mac"
/**
@@ -80,7 +80,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
var operatingChannel: Int
get() {
val result = app.pref.getString(KEY_OPERATING_CHANNEL, null)?.toIntOrNull() ?: 0
return if (result in 1..165) result else 0
return if (result > 0) result else 0
}
set(value) = app.pref.edit { putString(KEY_OPERATING_CHANNEL, value.toString()) }
var deviceAddress: MacAddressCompat?
@@ -359,8 +359,13 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
setNetworkName(PLACEHOLDER_NETWORK_NAME)
setPassphrase(passphrase)
operatingChannel.let { oc ->
if (oc == 0) setGroupOperatingBand(operatingBand)
else setGroupOperatingFrequency(SoftApConfigurationCompat.channelToFrequency(oc))
if (oc == 0) setGroupOperatingBand(when (operatingBand) {
SoftApConfigurationCompat.BAND_ANY -> WifiP2pConfig.GROUP_OWNER_BAND_AUTO
SoftApConfigurationCompat.BAND_2GHZ -> WifiP2pConfig.GROUP_OWNER_BAND_2GHZ
SoftApConfigurationCompat.BAND_5GHZ -> WifiP2pConfig.GROUP_OWNER_BAND_5GHZ
else -> throw IllegalArgumentException("Unknown band")
})
else setGroupOperatingFrequency(SoftApConfigurationCompat.channelToFrequency(operatingBand, oc))
}
setDeviceAddress(deviceAddress?.toPlatform())
}.build().run {