summaryrefslogtreecommitdiff
path: root/test/test-attrib
blob: b9e83c595b14ce67732b899772e9272e55cdcdd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/python
# Script for testing the Attribute D-Bus API

import sys
from optparse import OptionParser, OptionValueError
from binascii import hexlify, unhexlify

import gobject

import sys
import dbus
import dbus.mainloop.glib
from optparse import OptionParser, make_option

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
mainloop = gobject.MainLoop()

manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")

option_list = [
		make_option("-i", "--device", action="store",
				type="string", dest="dev_id"),
		]
parser = OptionParser(option_list=option_list)

(options, args) = parser.parse_args()

if options.dev_id:
	adapter_path = manager.FindAdapter(options.dev_id)
else:
	adapter_path = manager.DefaultAdapter()

adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
							"org.bluez.Adapter")

if (len(args) < 1):
	print "Usage: %s <command>" % (sys.argv[0])
	print ""
	print "	 list"
	print "	 services <address>"
	print "	 discover <service path>"
	print "	 chars <service path>"
	sys.exit(1)

if (args[0] == "list"):
	for path in adapter.ListDevices():
		device = dbus.Interface(bus.get_object("org.bluez", path),
							"org.bluez.Device")
		devprop = device.GetProperties()
		print "[ %s ]" % devprop["Address"]
		for path in devprop["Services"]:

			service = dbus.Interface(bus.get_object("org.bluez", path),
									 "org.bluez.Characteristic")
			srvprop = service.GetProperties()
			print " * %s" % (path)
			print "	UUID: %s" % srvprop["UUID"]
			print "	Chars: ",
			for char in srvprop["Characteristics"]:
				print "%s " % char,
			print
			print
		print
	sys.exit(0)

if (args[0] == "services"):
	if (len(args) < 2):
		print "Need address parameter"
	else:
		path = adapter.FindDevice(args[1])
		device = dbus.Interface(bus.get_object("org.bluez", path),
							"org.bluez.Device")
		properties = device.GetProperties()
		for path in properties["Services"]:
			print path
	sys.exit(0)

if (args[0] == "discover"):
	if (len(args) < 2):
		print "Need service path parameter"
	else:
		service = dbus.Interface(bus.get_object("org.bluez", args[1]),
							"org.bluez.Characteristic")
		for path in service.DiscoverCharacteristics():
			print path
	sys.exit(0)

if (args[0] == "chars"):
	if (len(args) < 2):
		print "Need service path parameter"
	else:
		service = dbus.Interface(bus.get_object("org.bluez", args[1]),
								 "org.bluez.Characteristic")
		srvprop = service.GetProperties()
		for path in srvprop["Characteristics"]:
			print "[ %s ]" % (path)
			char = dbus.Interface(bus.get_object("org.bluez", path),
								 "org.bluez.Characteristic")
			charprop = char.GetProperties()
			print "	Name: %s" % charprop["Name"]
			print "	UUID: %s" % charprop["UUID"]
			print
		print
	sys.exit(0)

print "Unknown command"
sys.exit(1)