Wifi质量百分比

时间:2011-09-20 21:39:32

标签: network-programming wifi formula

我想知道如何根据2个值确定Wifi质量:

Signal strength measured in dBm: e.g.: -51 dBm
Signal To Noise Ratio e.g. 70/70

我从我的系统中获取这些值,但想在我的用户界面中显示一个wifi质量图标,所以我应该使用某种公式将这些值转换为百分比。

1 个答案:

答案 0 :(得分:0)

好的,所以我现在想出来了。对于那些有同样问题的人来说,这就是我的工作。

guint32
nm_ap_utils_level_to_quality (gint val)
{
  if (val < 0) {
    /* Assume dBm already; rough conversion: best = -40, worst = -100 */
    val = abs (CLAMP (val, -100, -40) + 40); /* normalize to 0 */
    val = 100 - (int) ((100.0 * (double) val) / 60.0);
  } else if (val > 110 && val < 256) {
    /* assume old-style WEXT 8-bit unsigned signal level */
    val -= 256; /* subtract 256 to convert to dBm */
    val = abs (CLAMP (val, -100, -40) + 40); /* normalize to 0 */
    val = 100 - (int) ((100.0 * (double) val) / 60.0);
  } else {
    /* Assume signal is a "quality" percentage */
    val = CLAMP (val, 0, 100);
  }
  g_assert (val >= 0);
  return (guint32) val;
}