gpt4 book ai didi

c - Wireless.h 如何打印出信号电平?

转载 作者:太空狗 更新时间:2023-10-29 16:07:54 24 4
gpt4 key购买 nike

在 c 程序中使用适用于 linux 的无线工具,我进行了网络扫描,希望找到每个检测到的网络的信号强度 (dBm)。

我在 wireless.h 中发现了以下内容:

struct  iw_quality
{
__u8 qual; /* link quality (%retries, SNR,
%missed beacons or better...) */
__u8 level; /* signal level (dBm) */
__u8 noise; /* noise level (dBm) */
__u8 updated; /* Flags to know if updated */
};

我在我的 C 程序中像这样打印出“级别”:

printf("Transmit power: %lu ", result->stats.qual.level);

也尝试了 %d,但得到了相同的输出。

我得到的结果是类似于 178、190、201、189 等的数字...

这些数字有可能以瓦为单位吗?根据瓦特->dBm 转换器,178 瓦约为 178 瓦。 52.50dBm?

我应该得到什么?因为我认为 dBm 转换为 -80dBm 或其他东西。

我需要转换这些数字吗?如何获得正确的输出?

谢谢!!

=======UPDATE=========

我注意到一些奇怪的行为。当我通过我的程序使用 wireless.h 的电平属性时,我记录的“最强”值约为 -50dBm,而使用同一路由器,当我运行“iw wlan0 scan”时,我收到的最强值约为 -14dBm信号。

有谁知道造成这种差异的原因吗?

最佳答案

看来您找到了正确答案。作为记录,这就是 source 的内容(iwlib.c) 说了编码。

 /* People are very often confused by the 8 bit arithmetic happening
* here.
* All the values here are encoded in a 8 bit integer. 8 bit integers
* are either unsigned [0 ; 255], signed [-128 ; +127] or
* negative [-255 ; 0].
* Further, on 8 bits, 0x100 == 256 == 0.
*
* Relative/percent values are always encoded unsigned, between 0 and 255.
* Absolute/dBm values are always encoded between -192 and 63.
* (Note that up to version 28 of Wireless Tools, dBm used to be
* encoded always negative, between -256 and -1).
*
* How do we separate relative from absolute values ?
* The old way is to use the range to do that. As of WE-19, we have
* an explicit IW_QUAL_DBM flag in updated...
* The range allow to specify the real min/max of the value. As the
* range struct only specify one bound of the value, we assume that
* the other bound is 0 (zero).
* For relative values, range is [0 ; range->max].
* For absolute values, range is [range->max ; 63].
*
* Let's take two example :
* 1) value is 75%. qual->value = 75 ; range->max_qual.value = 100
* 2) value is -54dBm. noise floor of the radio is -104dBm.
* qual->value = -54 = 202 ; range->max_qual.value = -104 = 152
*
* Jean II
*/

levelnoise 属于示例 2,可以通过转换为带符号的 8 位值来解码。

关于c - Wireless.h 如何打印出信号电平?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18079771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com