3
# Script for testing the Attribute D-Bus API
6
from optparse import OptionParser, OptionValueError
7
from binascii import hexlify, unhexlify
13
import dbus.mainloop.glib
14
from optparse import OptionParser, make_option
16
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
17
bus = dbus.SystemBus()
18
mainloop = gobject.MainLoop()
20
manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
23
make_option("-i", "--device", action="store",
24
type="string", dest="dev_id"),
26
parser = OptionParser(option_list=option_list)
28
(options, args) = parser.parse_args()
31
adapter_path = manager.FindAdapter(options.dev_id)
33
adapter_path = manager.DefaultAdapter()
35
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
39
print("Usage: %s <command>" % (sys.argv[0]))
42
print(" services <address>")
43
print(" discover <service path>")
44
print(" chars <service path>")
47
if (args[0] == "list"):
48
for path in adapter.ListDevices():
49
device = dbus.Interface(bus.get_object("org.bluez", path),
51
devprop = device.GetProperties()
52
print("[ %s ]" % devprop["Address"])
53
for path in devprop["Services"]:
55
service = dbus.Interface(bus.get_object("org.bluez", path),
56
"org.bluez.Characteristic")
57
srvprop = service.GetProperties()
58
print(" * %s" % (path))
59
print(" UUID: %s" % srvprop["UUID"])
61
for char in srvprop["Characteristics"]:
68
if (args[0] == "services"):
70
print("Need address parameter")
72
path = adapter.FindDevice(args[1])
73
device = dbus.Interface(bus.get_object("org.bluez", path),
75
properties = device.GetProperties()
76
for path in properties["Services"]:
80
if (args[0] == "discover"):
82
print("Need service path parameter")
84
service = dbus.Interface(bus.get_object("org.bluez", args[1]),
85
"org.bluez.Characteristic")
86
for path in service.DiscoverCharacteristics():
90
if (args[0] == "chars"):
92
print("Need service path parameter")
94
service = dbus.Interface(bus.get_object("org.bluez", args[1]),
95
"org.bluez.Characteristic")
96
srvprop = service.GetProperties()
97
for path in srvprop["Characteristics"]:
98
print("[ %s ]" % (path))
99
char = dbus.Interface(bus.get_object("org.bluez", path),
100
"org.bluez.Characteristic")
101
charprop = char.GetProperties()
102
print(" Name: %s" % charprop["Name"])
103
print(" UUID: %s" % charprop["UUID"])
108
print("Unknown command")