mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-25 05:04:18 +08:00
107 lines
2.5 KiB
Python
Executable File
107 lines
2.5 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 " powered [on/off]"
|
|
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] == "powered"):
|
|
if (len(sys.argv) < 3):
|
|
properties = adapter.GetProperties()
|
|
print properties["Powered"]
|
|
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("Powered", value)
|
|
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)
|