Skip to content

Commit

Permalink
Restrict calculated ASU values to 0-31, 99
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fhunleth committed Apr 25, 2023
1 parent 9afda18 commit a3bdcfa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/vintage_net_qmi/asu_calculator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ defmodule VintageNetQMI.ASUCalculator do
end

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

defp dbm_to_gsm_asu(dbm) do
div(dbm + 113, 2)
Expand Down
9 changes: 6 additions & 3 deletions test/vintage_net_qmi/asu_calculator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ defmodule VintageNetQMI.ASUCalculatorTest do
end

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

test "computes lte bars" do
Expand Down

0 comments on commit a3bdcfa

Please sign in to comment.