问题WifiManager.calculateSignalLevel(RSSI,5)问题、WifiManager、RSSI、calculateSignalLevel

2023-09-04 04:29:37 作者:Soren 索伦

我想用Wifimanager来计算的扫描过程中发现的接入点的信号电平。

I am trying to use the Wifimanager to calculate the Signal Level of the access points found during a scan.

我使用下面的方法:

WifiManager.calculateSignalLevel(INT,INT)

但它似乎总是返回相同的INT无论RSSI水平是什么。

But it appears to always return the same int no matter what the RSSI level is.

下面是我的code:

public int calculateQoS(int aRSSI){

    signalLevel = WifiManager.calculateSignalLevel(RSSI, 5);

    return signalLevel;

}

public void testCalculateQoS(){

            Log.d("signal", "signal = : "
                    + connMonitor.calculateQoS(-44)
                    + " " + connMonitor.calculateQoS(-80)
                    + " " + connMonitor.calculateQoS(-120)
                    + " " + connMonitor.calculateQoS(-20));

        }

日志记录输出1为所有的测试用例calculateQoS(INT)。

The logging outputs 1 for all the test cases for calculateQoS(int).

我在这里丢失了一些东西简单?为什么信号电始终为1?

Am I missing something simple here? Why is the SignalLevel always 1?

推荐答案

看来,calculateSignalLevel实现这种方式:

It seems that calculateSignalLevel is implemented this way:

public static int calculateSignalLevel(int rssi, int numLevels) {
  if (rssi <= MIN_RSSI) {
      return 0;
  } else if (rssi >= MAX_RSSI) {
      return numLevels - 1;
  } else {
      int partitionSize = (MAX_RSSI - MIN_RSSI) / (numLevels - 1);
      return (rssi - MIN_RSSI) / partitionSize;
  }
}

这也许code片段可以解释你的问题。另请注意:

Maybe this code snippet can explain your problem. Also note:

http://$c$c.google.com/p/android/issues/detail?id=2555