3
from __future__ import absolute_import, print_function, unicode_literals
4
# Script for testing the Attribute D-Bus API
7
from optparse import OptionParser, OptionValueError
8
from binascii import hexlify, unhexlify
14
import dbus.mainloop.glib
15
from optparse import OptionParser, make_option
17
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
18
bus = dbus.SystemBus()
19
mainloop = gobject.MainLoop()
21
manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
24
make_option("-i", "--device", action="store",
25
type="string", dest="dev_id"),
27
parser = OptionParser(option_list=option_list)
29
(options, args) = parser.parse_args()
32
adapter_path = manager.FindAdapter(options.dev_id)
34
adapter_path = manager.DefaultAdapter()
36
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
40
print("Usage: %s <command>" % (sys.argv[0]))
43
print(" services <address>")
44
print(" discover <service path>")
45
print(" chars <service path>")
48
if (args[0] == "list"):
49
for path in adapter.ListDevices():
50
device = dbus.Interface(bus.get_object("org.bluez", path),
52
devprop = device.GetProperties()
53
print("[ %s ]" % devprop["Address"])
54
for path in devprop["Services"]:
56
service = dbus.Interface(bus.get_object("org.bluez", path),
57
"org.bluez.Characteristic")
58
srvprop = service.GetProperties()
59
print(" * %s" % (path))
60
print(" UUID: %s" % srvprop["UUID"])
62
for char in srvprop["Characteristics"]:
69
if (args[0] == "services"):
71
print("Need address parameter")
73
path = adapter.FindDevice(args[1])
74
device = dbus.Interface(bus.get_object("org.bluez", path),
76
properties = device.GetProperties()
77
for path in properties["Services"]:
81
if (args[0] == "discover"):
83
print("Need service path parameter")
85
service = dbus.Interface(bus.get_object("org.bluez", args[1]),
86
"org.bluez.Characteristic")
87
for path in service.DiscoverCharacteristics():
91
if (args[0] == "chars"):
93
print("Need service path parameter")
95
service = dbus.Interface(bus.get_object("org.bluez", args[1]),
96
"org.bluez.Characteristic")
97
srvprop = service.GetProperties()
98
for path in srvprop["Characteristics"]:
99
print("[ %s ]" % (path))
100
char = dbus.Interface(bus.get_object("org.bluez", path),
101
"org.bluez.Characteristic")
102
charprop = char.GetProperties()
103
print(" Name: %s" % charprop["Name"])
104
print(" UUID: %s" % charprop["UUID"])
109
print("Unknown command")