Skip to content

Commit aaa81f2

Browse files
Use API data to calculate Wi-Fi width center frequency
1 parent 17f0a42 commit aaa81f2

File tree

3 files changed

+26
-161
lines changed

3 files changed

+26
-161
lines changed

app/build.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Build Properties
2-
#Fri Mar 28 18:21:30 EDT 2025
3-
version_build=14
2+
#Sat Mar 29 12:14:52 EDT 2025
3+
version_build=15
44
version_major=3
55
version_minor=1
66
version_patch=4

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/WiFiWidth.kt

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,6 @@ import kotlin.math.abs
2323

2424
private val CHANNEL_WIDTH_320MHZ = if (buildMinVersionT()) ScanResult.CHANNEL_WIDTH_320MHZ else 5
2525

26-
// 5GHz: 50, 82, 114, 163 | 6GHz: 15, 47, 79, 111, 143, 175, 207
27-
private val frequency160Range = listOf(
28-
5250 to (5170 to 5329),
29-
5410 to (5330 to 5489),
30-
5650 to (5490 to 5730),
31-
5815 to (5735 to 5895),
32-
6025 to (5945 to 6104),
33-
6185 to (6105 to 6264),
34-
6345 to (6265 to 6424),
35-
6505 to (6425 to 6584),
36-
6665 to (6585 to 6744),
37-
6825 to (6745 to 6904),
38-
6985 to (6905 to 7065)
39-
)
40-
private val frequency160center = frequency160Range.map { it.first }
41-
42-
// 6GHz: 31, 95, 159, 191
43-
private val frequency320Range = listOf(
44-
6100 to (5945 to 6264),
45-
6430 to (6265 to 6584),
46-
6750 to (6585 to 6904),
47-
6910 to (6905 to 7065)
48-
)
49-
50-
// 6GHz: 31, 63, 95, 127, 159, 191
51-
private val frequency320Center = listOf(6100, 6270, 6430, 6590, 6750, 6910)
52-
5326
typealias ChannelWidth = Int
5427
typealias CalculateCenter = (primary: Int, center0: Int, center1: Int) -> Int
5528

@@ -58,22 +31,8 @@ internal val calculateCenter40: CalculateCenter = { primary, center0, _ ->
5831
if (abs(primary - center0) >= WiFiWidth.MHZ_40.frequencyWidthHalf) (primary + center0) / 2 else center0
5932
}
6033
internal val calculateCenter80: CalculateCenter = { _, center0, _ -> center0 }
61-
internal val calculateCenter160: CalculateCenter = { primary, center0, center1 ->
62-
when {
63-
center1 in frequency160center -> center1
64-
center0 in frequency160center -> center0
65-
primary in frequency160center -> primary
66-
else -> frequency160Range.firstOrNull { primary in it.second.first..it.second.second }?.first ?: center1
67-
}
68-
}
69-
internal val calculateCenter320: CalculateCenter = { primary, center0, center1 ->
70-
when {
71-
center1 in frequency320Center -> center1
72-
center0 in frequency320Center -> center0
73-
primary in frequency320Center -> primary
74-
else -> frequency320Range.firstOrNull { primary in it.second.first..it.second.second }?.first ?: center1
75-
}
76-
}
34+
internal val calculateCenter160: CalculateCenter = { _, _, center1 -> center1 }
35+
internal val calculateCenter320: CalculateCenter = { _, _, center1 -> center1 }
7736

7837
enum class WiFiWidth(val channelWidth: ChannelWidth, val frequencyWidth: Int, val guardBand: Int, val calculateCenter: CalculateCenter) {
7938
MHZ_20(ScanResult.CHANNEL_WIDTH_20MHZ, 20, 2, calculateCenter20),

app/src/test/kotlin/com/vrem/wifianalyzer/wifi/model/WiFiWidthTest.kt

Lines changed: 22 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -117,135 +117,41 @@ class WiFiWidthTest {
117117
// setup
118118
val expected = 35
119119
// execute & validate
120-
assertThat(calculateCenter80(Int.MIN_VALUE, expected, Int.MIN_VALUE)).isEqualTo(expected)
120+
assertThat(calculateCenter80(0, expected, 0)).isEqualTo(expected)
121121
assertThat(calculateCenter80(0, expected, Int.MIN_VALUE)).isEqualTo(expected)
122-
assertThat(calculateCenter80(Int.MAX_VALUE, expected, Int.MIN_VALUE)).isEqualTo(expected)
122+
assertThat(calculateCenter80(0, expected, Int.MAX_VALUE)).isEqualTo(expected)
123+
assertThat(calculateCenter80(Int.MIN_VALUE, expected, 0)).isEqualTo(expected)
124+
assertThat(calculateCenter80(Int.MAX_VALUE, expected, 0)).isEqualTo(expected)
125+
assertThat(calculateCenter80(Int.MIN_VALUE, expected, Int.MIN_VALUE)).isEqualTo(expected)
126+
assertThat(calculateCenter80(Int.MAX_VALUE, expected, Int.MAX_VALUE)).isEqualTo(expected)
123127
}
124128

125129
@Test
126130
fun calculateCenter160() {
127131
// setup
128-
val frequencyRange = listOf(
129-
50 to (5250 to (5170 to 5329)),
130-
82 to (5410 to (5330 to 5489)),
131-
114 to (5650 to (5490 to 5730)),
132-
163 to (5815 to (5735 to 5895)),
133-
15 to (6025 to (5945 to 6104)),
134-
47 to (6185 to (6105 to 6264)),
135-
79 to (6345 to (6265 to 6424)),
136-
111 to (6505 to (6425 to 6584)),
137-
143 to (6665 to (6585 to 6744)),
138-
175 to (6825 to (6745 to 6904)),
139-
207 to (6985 to (6905 to 7065))
140-
)
141-
val frequencyCenter = frequencyRange.map { it.first to it.second.first }
142-
val frequencyOutOfRange = listOf(5169, 5731, 5732, 5733, 5734, 5896, 5944, 7066)
132+
val expected = 35
143133
// execute & validate
144-
calculateCenterUsingCenter1(frequencyCenter, calculateCenter160)
145-
calculateCenterUsingCenter0(frequencyCenter, calculateCenter160)
146-
calculateCenterUsingPrimary(frequencyCenter, calculateCenter160)
147-
calculateCenterUsingRange(frequencyRange, calculateCenter160, frequencyCenter.map { it.second })
148-
calculateCenterUsingOutOfRange(frequencyOutOfRange, calculateCenter160)
134+
assertThat(calculateCenter160(0, 0, expected)).isEqualTo(expected)
135+
assertThat(calculateCenter160(0, Int.MIN_VALUE, expected)).isEqualTo(expected)
136+
assertThat(calculateCenter160(0, Int.MAX_VALUE, expected)).isEqualTo(expected)
137+
assertThat(calculateCenter160(Int.MIN_VALUE, 0, expected)).isEqualTo(expected)
138+
assertThat(calculateCenter160(Int.MAX_VALUE, 0, expected)).isEqualTo(expected)
139+
assertThat(calculateCenter160(Int.MIN_VALUE, Int.MIN_VALUE, expected)).isEqualTo(expected)
140+
assertThat(calculateCenter160(Int.MAX_VALUE, Int.MAX_VALUE, expected)).isEqualTo(expected)
149141
}
150142

151143
@Test
152144
fun calculateCenter320() {
153145
// setup
154-
val frequencyRange = listOf(
155-
31 to (6100 to (5945 to 6264)),
156-
95 to (6430 to (6265 to 6584)),
157-
159 to (6750 to (6585 to 6904)),
158-
191 to (6910 to (6905 to 7065))
159-
)
160-
val frequencyCenter = listOf(31 to 6100, 63 to 6270, 95 to 6430, 127 to 6590, 159 to 6750, 191 to 6910)
161-
val frequencyOutOfRange = listOf(5944, 7066)
146+
val expected = 35
162147
// execute & validate
163-
calculateCenterUsingCenter1(frequencyCenter, calculateCenter320)
164-
calculateCenterUsingCenter0(frequencyCenter, calculateCenter320)
165-
calculateCenterUsingPrimary(frequencyCenter, calculateCenter320)
166-
calculateCenterUsingRange(frequencyRange, calculateCenter320, frequencyCenter.map { it.second })
167-
calculateCenterUsingOutOfRange(frequencyOutOfRange, calculateCenter320)
148+
assertThat(calculateCenter320(0, 0, expected)).isEqualTo(expected)
149+
assertThat(calculateCenter320(0, Int.MIN_VALUE, expected)).isEqualTo(expected)
150+
assertThat(calculateCenter320(0, Int.MAX_VALUE, expected)).isEqualTo(expected)
151+
assertThat(calculateCenter320(Int.MIN_VALUE, 0, expected)).isEqualTo(expected)
152+
assertThat(calculateCenter320(Int.MAX_VALUE, 0, expected)).isEqualTo(expected)
153+
assertThat(calculateCenter320(Int.MIN_VALUE, Int.MIN_VALUE, expected)).isEqualTo(expected)
154+
assertThat(calculateCenter320(Int.MAX_VALUE, Int.MAX_VALUE, expected)).isEqualTo(expected)
168155
}
169156

170-
/**
171-
* parameters:
172-
* frequencyCenter: list of channel and frequency center
173-
* calculateCenter: function to calculate center
174-
*/
175-
private fun calculateCenterUsingCenter1(frequencyCenter: List<Pair<Int, Int>>, calculateCenter: CalculateCenter) {
176-
frequencyCenter.forEach { (channel, expected) ->
177-
// execute
178-
val actualCenter1 = calculateCenter(0, 0, expected)
179-
// validate
180-
assertThat(actualCenter1).describedAs("channel: $channel | frequency: $expected").isEqualTo(expected)
181-
}
182-
}
183-
184-
/**
185-
* parameters:
186-
* frequencyCenter: list of channel and frequency center
187-
* calculateCenter: function to calculate center
188-
*/
189-
private fun calculateCenterUsingCenter0(frequencyCenter: List<Pair<Int, Int>>, calculateCenter: CalculateCenter) {
190-
frequencyCenter.forEach { (channel, expected) ->
191-
// execute
192-
val actualCenter0 = calculateCenter(0, expected, 0)
193-
// validate
194-
assertThat(actualCenter0).describedAs("channel: $channel | frequency: $expected").isEqualTo(expected)
195-
}
196-
}
197-
198-
/**
199-
* parameters:
200-
* frequencyCenter: list of channel and frequency center
201-
* calculateCenter: function to calculate center
202-
*/
203-
private fun calculateCenterUsingPrimary(frequencyCenter: List<Pair<Int, Int>>, calculateCenter: CalculateCenter) {
204-
frequencyCenter.forEach { (channel, expected) ->
205-
// execute
206-
val actualPrimary = calculateCenter(expected, 0, 0)
207-
// validate
208-
assertThat(actualPrimary).describedAs("channel: $channel | frequency: $expected").isEqualTo(expected)
209-
}
210-
}
211-
212-
/**
213-
* parameters:
214-
* frequencyRange: list of channel, frequency center, frequency range
215-
* calculateCenter: function to calculate center
216-
* frequencyCenter: list of frequency center
217-
*/
218-
private fun calculateCenterUsingRange(
219-
frequencyRange: List<Pair<Int, Pair<Int, Pair<Int, Int>>>>,
220-
calculateCenter: CalculateCenter,
221-
frequencyCenter: List<Int>
222-
) {
223-
frequencyRange.forEach { (channel, frequencyAndRange) ->
224-
val (expected, range) = frequencyAndRange
225-
(range.first..range.second)
226-
.filter { it !in frequencyCenter }
227-
.forEach {
228-
// execute
229-
val actualPrimary = calculateCenter(it, 0, 0)
230-
// validate
231-
assertThat(actualPrimary).describedAs("channel: $channel | frequency: $it").isEqualTo(expected)
232-
}
233-
}
234-
}
235-
236-
/**
237-
* parameters:
238-
* outOfRangeFrequencies: list of out of range frequencies
239-
* calculateCenter: function to calculate center
240-
*/
241-
private fun calculateCenterUsingOutOfRange(outOfRangeFrequencies: List<Int>, calculateCenter: CalculateCenter) {
242-
outOfRangeFrequencies.forEach { frequency ->
243-
// setup
244-
val expected = 111
245-
// execute
246-
val actualPrimary = calculateCenter(frequency, 0, expected)
247-
// validate
248-
assertThat(actualPrimary).describedAs("frequency: $frequency").isEqualTo(expected)
249-
}
250-
}
251157
}

0 commit comments

Comments
 (0)