summaryrefslogtreecommitdiffstats
path: root/src/test-adapter
blob: a4612257ebc0e7becc63d31d3574036256e0750a (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
#!/usr/bin/python

import sys
import dbus
import time

bus = dbus.SystemBus()

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

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

if (len(sys.argv) < 2):
	print "Usage: %s <command>" % (sys.argv[0])
	print ""
	print "  address"
	print "  name [name]"
	print "  mode [mode]"
	print "  requestmode <mode>"
	print "  discoverabletimeout [timeout]"
	print "  periodicdiscovery [on/off]"
	print "  addservicerecord <file>"
	sys.exit(1)

if (sys.argv[1] == "address"):
	properties = adapter.GetProperties()
	print properties["Address"]
	sys.exit(0)

if (sys.argv[1] == "name"):
	if (len(sys.argv) < 3):
		properties = adapter.GetProperties()
		print properties["Name"]
	else:
		adapter.SetProperty("Name", sys.argv[2])
	sys.exit(0)

if (sys.argv[1] == "mode"):
	if (len(sys.argv) < 3):
		properties = adapter.GetProperties()
		print properties["Mode"]
	else:
		adapter.SetProperty("Mode", sys.argv[2])
	sys.exit(0)

if (sys.argv[1] == "requestmode"):
	if (len(sys.argv) < 3):
		print "Need mode parameter"
	else:
		adapter.RequestMode(sys.argv[2])
	sys.exit(0)

if (sys.argv[1] == "discoverabletimeout"):
	if (len(sys.argv) < 3):
		properties = adapter.GetProperties()
		print properties["DiscoverableTimeout"]
	else:
		adapter.SetProperty("DiscoverableTimeout", sys.argv[2])
	sys.exit(0)

if (sys.argv[1] == "periodicdiscovery"):
	if (len(sys.argv) < 3):
		properties = adapter.GetProperties()
		print properties["PeriodicDiscovery"]
	else:
		if (sys.argv[2] == "on"):
			value = dbus.Boolean(1)
		elif (sys.argv[2] == "off"):
			value = dbus.Boolean(0)
		else:
			value = dbus.Boolean(sys.argv[2])
		adapter.SetProperty("PeriodicDiscovery", value)
		time.sleep(120)
	sys.exit(0)

if (sys.argv[1] == "addservicerecord"):
	if (len(sys.argv) < 3):
		print "Need file parameter"
	else:
		f = open(sys.argv[2])
		record = f.read()
		f.close()
		handle = adapter.AddServiceRecord(record)
		print "0x%x" % (handle)
		time.sleep(120)
	sys.exit(0)

print "Unknown command"
sys.exit(1)