简体   繁体   English

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

[英]BlueZ5: Event when inbound pairing is complete

I'm writing a C++-application which manages Bluetooth connections for an embedded device. 我正在编写一个C ++应用程序,该应用程序管理嵌入式设备的蓝牙连接。 I talk to BlueZ5 via D-Bus under Linux. 我在Linux下通过D-Bus与BlueZ5通讯。

As first steps in implementing inbound pairing I did the following: 作为实现入站配对的第一步,我做了以下工作:

  • Register "NoInputNoOutput" agent via the AgentManager1 interface 通过AgentManager1接口注册“ NoInputNoOutput”代理
  • set pairable on and pairable timeout as well as discoverable on and discoverable timeout via the Adapter1 interface 通过Adapter1接口设置可配对的开启和可配对的超时以及可发现的开启和可发现的超时

Now I need an event that tells me that a new device was paired, so I can trust it and accept SPP connections. 现在,我需要一个事件来告诉我新设备已配对,因此我可以信任它并接受SPP连接。 But I couldn't find such an event in the spec yet ( https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc ). 但是我还没有在规范中找到这样的事件( https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc )。

Is there such an event? 有这样的事件吗? It seems it as bluetoothctl emits a message like 似乎随着bluetoothctl发出一条消息

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

as soon as device is paired... 设备配对后...

Can somebody tell me which event I have to listen for? 有人可以告诉我我必须听哪个事件吗?

Or do I have to poll? 还是我必须投票? I don't think bluetoothctl polls as it reacts really quickly. 我不认为bluetoothctl轮询会很快做出反应。

From here 这里

boolean Connected [readonly] 布尔值已连接[只读]

Indicates if the remote device is currently connected. 指示当前是否连接了远程设备。 A PropertiesChanged signal indicate changes to this status. PropertiesChanged信号指示对此状态的更改。

When the new device is added, InterfaceAdded signal is broadcasted on interface=org.freedesktop.DBus.ObjectManager. 添加新设备后,InterfaceAdded信号将在interface = org.freedesktop.DBus.ObjectManager上广播。 See the below signal captured using dbus-monitor. 请参阅以下使用dbus-monitor捕获的信号。 Check for the property 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 [
         ]
      )
   ]

If device is already added then you get PropertiesChanged signal on interface=org.freedesktop.DBus.Properties. 如果已添加设备,则在interface = org.freedesktop.DBus.Properties上会收到PropertiesChanged信号。 See below capture, its a log on disconnect, but the one above could help you to receive signal when device is connected. 见下面的截图,它是一个断开连接的日志,但是上面的一个可以帮助您在连接设备时接收信号。

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 [
   ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM