以百分比显示 Android 的 getGsmSignalStrength() 值

发布于 2024-12-10 16:45:43 字数 796 浏览 0 评论 0原文

根据 getGsmSignalStrength() 对应的 dBm 值,比例看起来是线性的。 (请参阅此处的 dBm 值)。 但我观察到,在几乎所有应用中,该比例尺都不用作线性比例尺。

例如,考虑Android的src StatusBarPolicy::updateSignalStrength

signal strength = 0 or 99 -> no signal
signal strength >= 12 -> very good signal
signal strength >= 8 -> good signal
signal strength >= 5 -> poor signal
signal strength <5 -> very poor signal

任何人都可以帮助我找出可以用百分比显示信号强度的比例。

According to the corresponding dBm values of getGsmSignalStrength(), the scale appears to be linear. (See dBm values here).
But I've observed that in almost all applications, this scale is not used as linear scale.

For example consider Android's src StatusBarPolicy::updateSignalStrength

signal strength = 0 or 99 -> no signal
signal strength >= 12 -> very good signal
signal strength >= 8 -> good signal
signal strength >= 5 -> poor signal
signal strength <5 -> very poor signal

can anyone help me find out the scale using which i can display the signal strength in percentage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵情客 2024-12-17 16:45:43

从您提供的链接:

0 -113 dBm 或更低
1 -111 dBm
2...30 -109... -53 dBm
31 -51 dBm 或更高

99 未知或不可检测

这意味着您的范围为 -113 至 -51,或 -62dBm。要将其转换为百分比,您可以获取收到的值 (0-31,99),计算出相应的 dBm 是多少,然后找到与 -113 的差值并除以 62。

例如,
0=-113dBm。与 -113 的差值 = 0。0/62 = 0%。
1=-111dBm。与-113之差=2. 2/62 ~ 3%。
30=-53dBm。与-113 的差异= 60。60/62 ~97%。

您需要的唯一特殊情况是 99,它应该像 0 一样处理。

From the link you provided:

0 -113 dBm or less
1 -111 dBm
2...30 -109... -53 dBm
31 -51 dBm or greater

99 not known or not detectable

This would mean you have a range or -113 to -51, or -62dBm. To convert that to a percentage, you can take the value you receive (0-31,99), figure out what the corresponding dBm is, and then find the difference with -113 and divide by 62.

For example,
0=-113dBm. Difference with -113 = 0. 0/62 = 0%.
1=-111dBm. Difference with -113 = 2. 2/62 ~ 3%.
30=-53dBm. Difference with -113 = 60. 60/62 ~97%.

The only special case you need is for 99, which should be handled like 0.

困倦 2024-12-17 16:45:43

信号强度值以 dBm 表示。这意味着它是对数尺度的。
它是对数的,允许表示非常大和非常小的值。
对数标度意味着:
功率增加 100W 即可获得 20dBm;
但增加 1000W 功率不会给你带来 200dBm 而是 30dBm。
如果将对数刻度转换为线性刻度,您将失去表示大范围值的能力。但如果你想这样做,这里有一个算法:

    final double pMax = Math.pow(10d, 31/10d);
    if (gsmSignalStrength == 99) {
        return -1;
    }
    double r = Math.pow(10d, gsmSignalStrength/10d) / pMax; // value <0,1>
    return (float) r;

参考文档: https://www.etsi.org/deliver/etsi_ts/127000_127099/127007/08.05.00_60/ts_127007v080500p.pdf第82页

A value of signal strength is represented in dBm. That means it's in logarithmic scale.
It is logarithmic to allow representation of very big and also very small values.
A logarithmic scale means that:
Increase power by 100W will give you 20dBm;
but increase power by 1000W will not give you 200dBm but 30dBm.
If you convert logarithmic scale to linear scale you will loose ability to represent wide range of values. But if you want to do it here is an algorithm:

    final double pMax = Math.pow(10d, 31/10d);
    if (gsmSignalStrength == 99) {
        return -1;
    }
    double r = Math.pow(10d, gsmSignalStrength/10d) / pMax; // value <0,1>
    return (float) r;

Reference doc: https://www.etsi.org/deliver/etsi_ts/127000_127099/127007/08.05.00_60/ts_127007v080500p.pdf page 82

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文