bluez/test/test-adapter
2008-09-01 22:34:04 +02:00

92 lines
2.1 KiB
Python
Executable File

#!/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:
timeout = dbus.UInt32(sys.argv[2])
adapter.SetProperty("DiscoverableTimeout", timeout)
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)