gpt4 book ai didi

c++ - BlueZ5 : Event when inbound pairing is complete

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:05 25 4
gpt4 key购买 nike

我正在编写一个 C++ 应用程序来管理嵌入式设备的蓝牙连接。我在 Linux 下通过 D-Bus 与 BlueZ5 对话。

作为实现入站配对的第一步,我执行了以下操作:

  • 通过AgentManager1接口(interface)注册“NoInputNoOutput”代理
  • 通过 Adapter1 接口(interface)设置 pairable on 和 pairable timeout 以及 discoverable on 和 discoverable timeout

现在我需要一个事件来告诉我新设备已配对,这样我就可以信任它并接受 SPP 连接。但是我在规范中找不到这样的事件 ( https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc )。

有这样的事件吗?似乎 bluetoothctl 发出一条消息,如

[NEW] Device 44:55:66:11:22:33 Foo Bar

一旦设备配对...

有人能告诉我必须监听哪个事件吗?

还是我必须投票?我认为 bluetoothctl 不会进行轮询,因为它的 react 非常快。

最佳答案

来自 here

boolean Connected [readonly]

Indicates if the remote device is currently connected. A PropertiesChanged signal indicate changes to this status.

当添加新设备时,InterfaceAdded 信号在 interface=org.freedesktop.DBus.ObjectManager 上广播。请参阅以下使用 dbus-monitor 捕获的信号。检查属性 Connected。

signal time=1558128293.155096 sender=:1.2 -> destination=(null destination) serial=65 path=/; interface=org.freedesktop.DBus.ObjectManager; member=InterfacesAdded
object path "/org/bluez/hci0/dev_F0_D7_AA_AA_0C_41"
array [
dict entry(
string "org.freedesktop.DBus.Introspectable"
array [
]
)
dict entry(
string "org.bluez.Device1"
array [
dict entry(
string "Address"
variant string "F0:D7:AA:AA:0C:41"
)
dict entry(
string "Name"
variant string "Moto"
)
dict entry(
string "Alias"
variant string "Moto"
)
dict entry(
string "Class"
variant uint32 5898764
)
dict entry(
string "Icon"
variant string "phone"
)
dict entry(
string "Paired"
variant boolean false
)
dict entry(
string "Trusted"
variant boolean false
)
dict entry(
string "Blocked"
variant boolean false
)
dict entry(
string "LegacyPairing"
variant boolean false
)
dict entry(
string "Connected"
variant boolean true
)
dict entry(
string "UUIDs"
variant array [
]
)
dict entry(
string "Adapter"
variant object path "/org/bluez/hci0"
)
]
)
dict entry(
string "org.freedesktop.DBus.Properties"
array [
]
)
]

如果设备已经添加,那么您会在 interface=org.freedesktop.DBus.Properties 上收到 PropertiesChanged 信号。请参阅下面的捕获,它是断开连接时的登录,但上面的捕获可以帮助您在设备连接时接收信号。

signal time=1558128303.204016 sender=:1.2 -> destination=(null destination) serial=71 path=/org/bluez/hci0/dev_F0_D7_AA_AA_0C_41; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string "org.bluez.Device1"
array [
dict entry(
string "Connected"
variant boolean false
)
]
array [
]

关于c++ - BlueZ5 : Event when inbound pairing is complete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56186562/

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