Skip to content

Commit a3bdcfa

Browse files
committed
Restrict calculated ASU values to 0-31, 99
The values 0-31, 99 are well known and expected. After that, things depend. Sometimes an extended range from 100-199 is used. The existing calculation can return values between 31 and 99 (most often 32), and that was unexpected.
1 parent 9afda18 commit a3bdcfa

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/vintage_net_qmi/asu_calculator.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ defmodule VintageNetQMI.ASUCalculator do
6767
end
6868

6969
defp dbm_to_gsm_asu(dbm) when dbm <= -113, do: 99
70+
defp dbm_to_gsm_asu(dbm) when dbm >= -50, do: 31
7071

7172
defp dbm_to_gsm_asu(dbm) do
7273
div(dbm + 113, 2)

test/vintage_net_qmi/asu_calculator_test.exs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ defmodule VintageNetQMI.ASUCalculatorTest do
2525
end
2626

2727
test "computes lte asu" do
28-
# Really, the only important thing here is that -113 goes to 99
29-
# since 99 is a special number.
28+
# The calculator only supports values 0-31 and 99, so
29+
# check that it doesn't return anything out of range.
30+
assert ASUCalculator.from_lte_rssi(-200).asu == 99
3031
assert ASUCalculator.from_lte_rssi(-113).asu == 99
3132
assert ASUCalculator.from_lte_rssi(-112).asu == 0
32-
assert ASUCalculator.from_lte_rssi(0).asu == 56
33+
assert ASUCalculator.from_lte_rssi(-52).asu == 30
34+
assert ASUCalculator.from_lte_rssi(-49).asu == 31
35+
assert ASUCalculator.from_lte_rssi(0).asu == 31
3336
end
3437

3538
test "computes lte bars" do

0 commit comments

Comments
 (0)