[PATCH BlueZ 17/25] observer: Add python test script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 test/test-observer |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100755 test/test-observer

diff --git a/test/test-observer b/test/test-observer
new file mode 100755
index 0000000..04d3f05
--- /dev/null
+++ b/test/test-observer
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+
+'''Observer test script
+'''
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+from gi.repository import GObject
+
+import sys
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+from optparse import OptionParser, make_option
+import bluezutils
+
+def dbus_data(data):
+	return "".join(["%02x" % c for c in data])
+
+class Observer(dbus.service.Object):
+	@dbus.service.method("org.bluez.Observer1",
+					in_signature="sqay", out_signature="")
+	def ServiceReceived(self, address, uuid, value):
+		print("[ " + address + " ]")
+		print("    Service UUID = 0x%04x" % int(uuid))
+		print("    Data = %s" % dbus_data(value))
+		print()
+
+	@dbus.service.method("org.bluez.Observer1",
+					in_signature="sqay", out_signature="")
+	def ManufacturerReceived(self, address, cid, value):
+		print("[ " + address + " ]")
+		print("    Company ID = 0x%04x" % int(cid))
+		print("    Data = %s" % dbus_data(value))
+		print()
+
+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="adapter"),
+		make_option("-s", "--service", action="store",
+			type="int", dest="service_uuid",
+			help="Service UUID (e.g. \"0x0001\")"),
+		make_option("-c", "--company", action="store",
+			type="int", dest="company_id",
+			help="Company Identifier Code (e.g. \"0x0002\")"),
+		]
+
+	parser = OptionParser(option_list=option_list)
+
+	(options, args) = parser.parse_args()
+
+	if not options.service_uuid and not options.company_id:
+		parser.error("At least one option is required: -c or -s")
+
+	adapter = bluezutils.find_adapter(options.adapter)
+
+	path = "/test/observer"
+	observer = Observer(bus, path)
+
+	if options.service_uuid:
+		adapter.RegisterServiceObserver(path, dbus.UInt16(options.service_uuid))
+
+	if options.company_id:
+		adapter.RegisterManufacturerObserver(path, dbus.UInt16(options.company_id))
+
+	mainloop = GObject.MainLoop()
+	mainloop.run()
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux