mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-12-23 02:43:29 +08:00
67dab2d2ae
The method is now deprecated and thus the replacement utility library should be used in the test scripts.
64 lines
1.7 KiB
Python
Executable File
64 lines
1.7 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
'''
|
|
Proximity Monitor test script
|
|
'''
|
|
|
|
import gobject
|
|
|
|
import sys
|
|
import dbus
|
|
import dbus.mainloop.glib
|
|
from optparse import OptionParser, make_option
|
|
import bluezutils
|
|
|
|
def properties_changed(interface, changed, invalidated):
|
|
if interface != "org.bluez.ProximityMonitor":
|
|
return
|
|
|
|
for name, value in changed.iteritems():
|
|
print("Property %s changed: %s" % (name, str(value)))
|
|
|
|
if __name__ == "__main__":
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
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)
|
|
|
|
if (len(args) < 1):
|
|
print("Usage: %s <command>" % (sys.argv[0]))
|
|
print("")
|
|
print(" -b MAC LinkLossAlertLevel <none|mild|high>")
|
|
print(" -b MAC ImmediateAlertLevel <none|mild|high>")
|
|
sys.exit(1)
|
|
|
|
device = bluezutils.find_device(options.address, options.dev_id)
|
|
device_path = device.object_path
|
|
|
|
bus.add_signal_receiver(properties_changed, bus_name="org.bluez",
|
|
path=device_path,
|
|
dbus_interface="org.freedesktop.DBus.Properties",
|
|
signal_name="PropertiesChanged")
|
|
|
|
proximity = dbus.Interface(bus.get_object("org.bluez",
|
|
device_path), "org.bluez.ProximityMonitor")
|
|
|
|
device_prop = dbus.Interface(bus.get_object("org.bluez", device_path),
|
|
"org.freedesktop.DBus.Properties")
|
|
|
|
print("Proximity SetProperty('%s', '%s')" % (args[0], args[1]))
|
|
device_prop.Set("org.bluez.ProximityMonitor", args[0], args[1])
|
|
|
|
mainloop = gobject.MainLoop()
|
|
mainloop.run()
|