近期研究了android bluetooth,发现bluez消息都是通过dbus进行传输,但是在java层和bluez通信的过程中,有些会被block住,这样就需要dbus进行调试,下面讲述dbus进行调试的方法。
dbus提供2个tool,一个是dbus-send, 一个是dbus-monitor。dbus-send可以像调用API那样进行消息传递,而dbus-monitor可以监听dbus消息传递过程。在这里讲述如何通过dbus-send和dbus-monitor结合进行调试。
dbus-monitor监听的时候需要指定sender和dest,如果想hci那样,每次的path都是不同的,怎样指定dest呢?我们需要下面的命令:
root@smi:/ # dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez org.freedesktop.DBus.Introspectable.Introspect
g/bluez org.freedesktop.DBus.Introspectable.Introspect <
method return sender=:1.1 -> dest=:1.3 reply_serial=2
string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection
1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg type="s" direction="out"/>
</method>
</interface>
<interface name="org.bluez.HealthManager">
<method name="CreateApplication">
<arg type="a{sv}" direction="in"/>
<arg type="o" direction="out"/>
</method>
<method name="DestroyApplication">
<arg type="o" direction="in"/>
</method>
</interface>
<node name="356"/> <-------------看到node name没这就是下一个path
</node>
"
root@smi:/ #
继续看是否有下一级path
root@smi:/ # dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/356 org.freedesktop.DBus.Introspectable.Introspect
org/bluez/356 org.freedesktop.DBus.Introspectable.Introspect <
method return sender=:1.1 -> dest=:1.12 reply_serial=2
string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection
1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<node name="any"/>
<node name="hci0"/> <------------------------这个就是下一级path啦
</node>
"
再继续看,发现没有node节点了……
root@smi:/ # dbus-send --system --type=method_call --print-reply --dest=org.bluz /org/bluez/356/hci0 org.freedesktop.DBus.Introspectable.Introspect
g/bluez/355/hci0 org.freedesktop.DBus.Introspectable.Introspect <
method return sender=:1.1 -> dest=:1.13 reply_serial=2
string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspectio
1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg type="s" direction="out"/>
</method>
</interface>
<interface name="org.bluez.Adapter">
<method name="GetProperties">
<arg type="a{sv}" direction="out"/>
</method>
<method name="SetProperty">
<arg type="s" direction="in"/>
<arg type="v" direction="in"/>
</method>
<method name="RequestSession"/>
<method name="ReleaseSession"/>
<method name="StartDiscovery"/>
<method name="ListConnection">
<arg type="i" direction="out"/>
</method>
<method name="StopDiscovery"/>
<method name="ListDevices">
<arg type="ao" direction="out"/>
</method>
<method name="CreateDevice">
<arg type="s" direction="in"/>
<arg type="o" direction="out"/>
</method>
<method name="CreatePairedDevice">
<arg type="s" direction="in"/>
<arg type="o" direction="in"/>
<arg type="s" direction="in"/>
<arg type="o" direction="out"/>
</method>
<method name="CreatePairedDeviceOutOfBand">
<arg type="s" direction="in"/>
<arg type="o" direction="in"/>
<arg type="s" direction="in"/>
<arg type="o" direction="out"/>
</method>
<method name="CancelDeviceCreation">
<arg type="s" direction="in"/>
</method>
<method name="RemoveDevice">
<arg type="o" direction="in"/>
</method>
<method name="FindDevice">
<arg type="s" direction="in"/>
<arg type="o" direction="out"/>
</method>
<method name="ReadLocalOutOfBandData">
<arg type="ay" direction="out"/>
<arg type="ay" direction="out"/>
</method>
<method name="RegisterAgent">
<arg type="o" direction="in"/>
<arg type="s" direction="in"/>
</method>
<method name="RegisterAgent">
<arg type="o" direction="in"/>
<arg type="s" direction="in"/>
<arg type="b" direction="in"/>
</method>
<method name="UnregisterAgent">
<arg type="o" direction="in"/>
</method>
<method name="AddRfcommServiceRecord">
<arg type="s" direction="in"/>
<arg type="t" direction="in"/>
<arg type="t" direction="in"/>
<arg type="q" direction="in"/>
<arg type="u" direction="out"/>
</method>
<method name="RemoveServiceRecord">
<arg type="u" direction="in"/>
</method>
<method name="SetLinkTimeout">
<arg type="o" direction="in"/>
<arg type="u" direction="in"/>
</method>
<method name="AddReservedServiceRecords">
<arg type="au" direction="in"/>
<arg type="au" direction="out"/>
</method>
<method name="RemoveReservedServiceRecords">
<arg type="au" direction="in"/>
</method>
<method name="DisconnectAllConnections"/>
<signal name="PropertyChanged">
<arg type="s"/>
<arg type="v"/>
</signal>
<signal name="DeviceCreated">
<arg type="o"/>
</signal>
<signal name="DeviceRemoved">
<arg type="o"/>
</signal>
<signal name="DeviceFound">
<arg type="s"/>
<arg type="a{sv}"/>
</signal>
<signal name="DeviceDisappeared">
<arg type="s"/>
</signal>
</interface>
<interface name="org.bluez.Service">
<method name="AddRecord">
<arg type="s" direction="in"/>
<arg type="u" direction="out"/>
</method>
<method name="UpdateRecord">
<arg type="u" direction="in"/>
<arg type="s" direction="in"/>
</method>
<method name="RemoveRecord">
<arg type="u" direction="in"/>
</method>
<method name="RequestAuthorization">
<arg type="s" direction="in"/>
<arg type="u" direction="in"/>
</method>
<method name="CancelAuthorization"/>
</interface>
<interface name="org.bluez.NetworkServer">
<method name="Register">
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
</method>
<method name="Unregister">
<arg type="s" direction="in"/>
</method>
<method name="DisconnectDevice">
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
</method>
<signal name="DeviceConnected">
<arg type="s"/>
<arg type="s"/>
<arg type="q"/>
</signal>
<signal name="DeviceDisconnected">
<arg type="s"/>
</signal>
</interface>
</node>
"
尝试着用dbus-send调用method,
1|root@smi:/ # dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/356/hci0 org.bluez.Adapter.ListConnection
org/bluez/355/hci0 org.bluez.Adapter.ListConnection <
method return sender=:1.1 -> dest=:1.15 reply_serial=2
int32 0 <--------------------返回值是0
root@smi:/ #
下面我们知道ListConnection这个method那我们要监听他了!注意上面的返回值发现有sender=:1.1 -> dest=:1.15 这就是我们要监听的源和目的了。1.1是Java层,1.15就是bluez啦。
下面dbus-monitor的命令由于种种原因我没有试通,总是有“process 6436: D-Bus not compiled with backtrace support so unable to print a backtrace
Segmentation fault (core dumped)” 这样的返回,问了很多人不知道怎样打开,但是通过这样的返回,可以看出命令本身没有问题,只是dbus-monitor没有打开这样的功能。如果您有返回值,或者发现什么错误,欢迎您回复我,我好能够完善,谢谢先!
监听整个路径
root@smi:/ # dbus-monitor signal sender=1.1->dest=1.15 path=/org/bluez/356/hci0 interface=org.bluez.Adapter member=ListConnection
监听从dbus-daemon到Java
root@smi:/ # dbus-monitor signal sender=org.freedesktop.DBus->dest=1.1 path=/org/bluez/356/hci0 interface=org.bluez.Adapter member=ListConnection
监听dbus-daemon到bluez
root@smi:/ # dbus-monitor signal sender=1.15->dest=org.freedesktop.DBus- path=/org/bluez/356/hci0 interface=org.bluez.Adapter member=ListConnectionroot@smi:/ # dbus-monitor signal sender=1.1->dest=1.15 path=/org/bluez/355/hci0 interface=org.bluez.Adapter member=ListConnection
member=ListConnection
来源:CSDN
作者:Simons(1075271250@qq
链接:https://blog.csdn.net/Luohsh1/article/details/10812667