2011-08-03 20:45:46 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2012-05-25 13:44:25 +08:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
2011-08-03 20:45:46 +08:00
|
|
|
'''
|
|
|
|
Proximity Monitor test script
|
|
|
|
'''
|
|
|
|
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import dbus
|
|
|
|
import dbus.mainloop.glib
|
|
|
|
from optparse import OptionParser, make_option
|
|
|
|
|
|
|
|
def property_changed(name, value):
|
|
|
|
|
2012-05-25 13:44:25 +08:00
|
|
|
print("PropertyChanged('%s', '%s')" % (name, value))
|
2011-08-03 20:45:46 +08:00
|
|
|
mainloop.quit()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
|
|
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
|
|
|
|
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
|
|
|
|
"org.bluez.Manager")
|
|
|
|
|
|
|
|
option_list = [
|
|
|
|
make_option("-i", "--adapter", action="store",
|
|
|
|
type="string", dest="dev_id"),
|
|
|
|
make_option("-b", "--device", action="store",
|
|
|
|
type="string", dest="address"),
|
|
|
|
|
|
|
|
]
|
|
|
|
parser = OptionParser(option_list=option_list)
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if options.dev_id:
|
|
|
|
adapter_path = manager.FindAdapter(options.dev_id)
|
|
|
|
else:
|
|
|
|
adapter_path = manager.DefaultAdapter()
|
|
|
|
|
|
|
|
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
|
|
|
|
"org.bluez.Adapter")
|
|
|
|
|
|
|
|
if (len(args) < 1):
|
2012-05-25 13:44:25 +08:00
|
|
|
print("Usage: %s <command>" % (sys.argv[0]))
|
|
|
|
print("")
|
|
|
|
print(" -b MAC LinkLossAlertLevel <none|mild|high>")
|
|
|
|
print(" -b MAC ImmediateAlertLevel <none|mild|high>")
|
2011-08-03 20:45:46 +08:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
device_path = adapter.FindDevice(options.address)
|
|
|
|
|
|
|
|
bus.add_signal_receiver(property_changed, bus_name="org.bluez",
|
2012-02-03 21:42:56 +08:00
|
|
|
dbus_interface="org.bluez.ProximityMonitor",
|
2011-08-03 20:45:46 +08:00
|
|
|
signal_name="PropertyChanged")
|
|
|
|
|
|
|
|
proximity = dbus.Interface(bus.get_object("org.bluez",
|
2012-02-03 21:42:56 +08:00
|
|
|
device_path), "org.bluez.ProximityMonitor")
|
2011-08-03 20:45:46 +08:00
|
|
|
|
2012-05-25 13:44:25 +08:00
|
|
|
print("Proximity SetProperty('%s', '%s')" % (args[0], args[1]))
|
2011-08-03 20:45:46 +08:00
|
|
|
proximity.SetProperty(args[0], args[1])
|
|
|
|
|
|
|
|
mainloop = gobject.MainLoop()
|
|
|
|
mainloop.run()
|