summaryrefslogtreecommitdiffstats
path: root/test/test-adapter
blob: 3486b2f869ff78dbd3903247803adfdb696a84d5 (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

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 "  pairable [on/off]"
	print "  pairabletimeout [timeout]"
	print "  discoverable [on/off]"
	print "  discoverabletimeout [timeout]"
	print "  discovering"
	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] == "pairable"):
	if (len(sys.argv) < 3):
		properties = adapter.GetProperties()
		print properties["Pairable"]
	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("Pairable", value)
	sys.exit(0)

if (sys.argv[1] == "pairabletimeout"):
	if (len(sys.argv) < 3):
		properties = adapter.GetProperties()
		print properties["PairableTimeout"]
	else:
		timeout = dbus.UInt32(sys.argv[2])
		adapter.SetProperty("PairableTimeout", timeout)
	sys.exit(0)

if (sys.argv[1] == "discoverable"):
	if (len(sys.argv) < 3):
		properties = adapter.GetProperties()
		print properties["Discoverable"]
	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("Discoverable", value)
	sys.exit(0)

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

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

print "Unknown command"
sys.exit(1)