蓝牙的BlueZ API和距离校准precision [英] BlueZ Bluetooth API and distance calibration precision

查看:601
本文介绍了蓝牙的BlueZ API和距离校准precision的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的BlueZ C API到我的蓝牙鼠标程序来读取的距离。我已成立了一个蓝牙适配器。此刻,我得把鼠标移动距离至少5-10英尺的笔记本电脑(蓝牙适配器)来获得RSSI的一些阅读。低于这个距离,我得到大多数读数为0。

有没有办法使用这个API来获取RSSI更多precise值,这样我们就可以跟踪在这个范围内的距离?

 蓝牙中int8_t :: read_rssi(INT到){    INT DD = hciSocket;
    结构hci_conn_info_req * CR;
    bdaddr_t BDADDR;
    RSSI中int8_t;    str2ba(bt_addr,&安培; BDADDR);    如果(DD< 0){
            PERROR(HCI设备打开失败);
            出口(1);
    }    CR =(hci_conn_info_req *)(的malloc(sizeof的(* CR)+的sizeof(结构hci_conn_info)));
    如果(!CR){
            PERROR(无法分配内存);
            出口(1);
    }    bacpy(安培; CR-GT&; BDADDR,&安培; BDADDR);
    CR-GT&;类型= ACL_LINK;
    如果(的ioctl(DD,HCIGETCONNINFO,(无符号长)CR)小于0){
            PERROR(获取连接信息失败);
            出口(1);
    }    如果(hci_read_rssi(DD,htobs(CR-GT&;&conn_info- GT;手柄),放大器,RSSI,1000)小于0){
            PERROR(阅读RSSI失败);
            出口(1);
    }    返回RSSI;
}


解决方案

hci_read_rssi 很可能不是你想要的。它不是实际的远程RSSI。从描述HCI_Read_RSSI命令BT规范部分:


  

RSSI的参数返回测量之间的差
  接收信号强度指示(RSSI)和的极限
  黄金接收功率范围连接句柄到其他BR / EDR
  控制器。由控制器返回的任何积极的RSSI值
  指示多少分贝的RSSI高于所述上限,任何负
  值表示有多少分贝的RSSI低于下限。该
  零值表明RSSI里面黄金接收功率
  范围。


我相信你想要的值是包含在查询/扫描之一。我知道的方式来获取,但不能确定它是否是可以接受的,你或者它是否是最好的方法。

该DBUS bluez的设备API具有RSSI的属性之一。该API文档可以在这里找到

更新:我还没有尝试过自己,但看起来像pybluez支持获取查询RSSI。请参见这个pybluez例子

下面是bluez4一个简单的例子:

https://bitbucket.org/kaylum/bluez-rssi-example/src

I am using BlueZ C API to program my bluetooth mouse to read the distance. I have set up a bluetooth dongle. At the moment, I have to move the mouse at least 5-10 feet from the laptop (bluetooth dongle) to get some reading of RSSI. Below this distance, I get most of the readings as 0.

Is there any way to use this API to get more precise value of RSSI so that we can track the distance in this range?

int8_t Bluetooth::read_rssi(int to) {

    int dd = hciSocket;
    struct hci_conn_info_req *cr;
    bdaddr_t bdaddr;
    int8_t rssi;

    str2ba(bt_addr, &bdaddr);

    if (dd < 0) {
            perror("HCI device open failed");
            exit(1);
    }   

    cr = (hci_conn_info_req *)(malloc(sizeof(*cr) + sizeof(struct hci_conn_info)));
    if (!cr) {
            perror("Can't allocate memory");
            exit(1);
    }   

    bacpy(&cr->bdaddr, &bdaddr);
    cr->type = ACL_LINK;
    if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0) {
            perror("Get connection info failed");
            exit(1);
    }   

    if (hci_read_rssi(dd, htobs(cr->conn_info->handle), &rssi, 1000) < 0) {
            perror("Read RSSI failed");
            exit(1);
    }   

    return rssi;
}

解决方案

hci_read_rssi is probably not what you want. It's not the actual remote RSSI. From the BT spec section describing the HCI_Read_RSSI command:

The RSSI parameter returns the difference between the measured Received Signal Strength Indication (RSSI) and the limits of the Golden Receive Power Range for a Connection Handle to another BR/EDR Controller. Any positive RSSI value returned by the Controller indicates how many dB the RSSI is above the upper limit, any negative value indicates how many dB the RSSI is below the lower limit. The value zero indicates that the RSSI is inside the Golden Receive Power Range.

I believe the value you want is the one contained in the inquiry/scan. I know of a way to get that but not sure whether it's acceptable to you or whether it is the best way.

The bluez dbus device API has RSSI as one of the properties. The api doc can be found here.

UPDATE: I haven't tried it myself but looks like pybluez supports getting the inquiry RSSI. See this pybluez example.

Here's a simple example for bluez4:

https://bitbucket.org/kaylum/bluez-rssi-example/src

这篇关于蓝牙的BlueZ API和距离校准precision的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆