【发布时间】:2015-07-13 13:03:37
【问题描述】:
我正在使用 BlueZ C API 对我的蓝牙鼠标进行编程以读取距离。我已经设置了一个蓝牙加密狗。目前,我必须将鼠标从笔记本电脑(蓝牙加密狗)移开至少 5-10 英尺才能读取 RSSI。在这个距离以下,我得到的大部分读数都是 0。
有没有什么方法可以使用这个 API 来获得更精确的 RSSI 值,以便我们可以跟踪这个范围内的距离?
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;
}
【问题讨论】:
标签: c bluetooth bluetooth-lowenergy bluez