diff options
Diffstat (limited to 'hcid/test-adapter')
-rwxr-xr-x | hcid/test-adapter | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/hcid/test-adapter b/hcid/test-adapter new file mode 100755 index 000000000..a4612257e --- /dev/null +++ b/hcid/test-adapter @@ -0,0 +1,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) |