BlueZ5:入站配对完成时发生的事件

时间:2019-05-17 12:35:53

标签: c++ linux bluetooth dbus bluez

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

作为实现入站配对的第一步,我做了以下事情:

  • 通过AgentManager1接口注册“ NoInputNoOutput”代理
  • 设置可配对和可配对超时,以及通过Adapter1接口可发现和可发现超时

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

有这样的事件吗?似乎是 bluetoothctl 发出类似

的消息
  

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

设备配对后...

有人可以告诉我我必须听哪个事件吗?

还是我必须进行投票?我不认为 bluetoothctl 会进行快速反应。

1 个答案:

答案 0 :(得分:1)

来自here

  

布尔值已连接[只读]

     

指示当前是否连接了远程设备。   PropertiesChanged信号指示对此状态的更改。

添加新设备后,InterfaceAdded信号将在interface = org.freedesktop.DBus.ObjectManager上广播。请参阅以下使用dbus-monitor捕获的信号。检查属性“已连接”。

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 [
   ]
相关问题