---
Makefile.tools | 1 +
test/test-thermometer | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 0 deletions(-)
create mode 100755 test/test-thermometer
diff --git a/Makefile.tools b/Makefile.tools
index ff93bc9..c0a54d0 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -214,6 +214,7 @@ EXTRA_DIST += test/apitest test/sap-client test/hsplay test/hsmicro \
test/simple-service test/simple-endpoint test/test-audio \
test/test-input test/test-attrib test/test-proximity \
test/test-sap-server test/test-oob test/test-serial-proxy \
+ test/test-thermometer \
test/service-record.dtd test/service-did.xml \
test/service-spp.xml test/service-opp.xml test/service-ftp.xml
diff --git a/test/test-thermometer b/test/test-thermometer
new file mode 100755
index 0000000..a00efbb
--- /dev/null
+++ b/test/test-thermometer
@@ -0,0 +1,89 @@
+#!/usr/bin/python
+
+'''
+Thermometer test script
+'''
+
+import gobject
+
+import sys
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+from optparse import OptionParser, make_option
+
+class Watcher(dbus.service.Object):
+
+ @dbus.service.method("org.bluez.ThermometerWatcher",
+ in_signature="a{sv}", out_signature="")
+ def MeasurementReceived(self, measure):
+ print measure["Measurement"], " measurement received"
+ print "Exponent: ", measure["Exponent"]
+ print "Mantissa: ", measure["Mantissa"]
+ print "Unit: ", measure["Unit"]
+
+ if measure.has_key("Time"):
+ print "Time: ", measure["Time"]
+
+ print "Type: ", measure["Type"]
+
+def property_changed(name, value):
+
+ print "PropertyChanged('%s', '%s')" % (name, value)
+
+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("-b", "--device", action="store",
+ type="string", dest="address"),
+ ]
+
+ parser = OptionParser(option_list=option_list)
+
+ (options, args) = parser.parse_args()
+
+ if not options.address:
+ print "Usage: %s -b MAC [command]" % (sys.argv[0])
+ print ""
+ print "EnableIntermediateMeasurement"
+ sys.exit(1)
+
+ if options.adapter:
+ adapter_path = manager.FindAdapter(options.adapter)
+ else:
+ adapter_path = manager.DefaultAdapter()
+
+ adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
+ "org.bluez.Adapter")
+
+ device_path = adapter.FindDevice(options.address)
+
+ bus.add_signal_receiver(property_changed, bus_name="org.bluez",
+ dbus_interface="org.bluez.Thermometer",
+ signal_name="PropertyChanged")
+
+ thermometer = dbus.Interface(bus.get_object("org.bluez",
+ device_path), "org.bluez.Thermometer")
+
+ path = "/test/watcher"
+ watcher = Watcher(bus, path)
+
+ thermometer.RegisterWatcher(path)
+
+ if len(args) > 0:
+ if args[0] == "EnableIntermediateMeasurement":
+ thermometer.EnableIntermediateMeasurement(path)
+ else:
+ print "unknown command"
+ sys.exit(1)
+
+ mainloop = gobject.MainLoop()
+ mainloop.run()
--
1.7.7.4
Hi Santiago,
On Tue, Nov 22, 2011, Santiago Carot-Nemesio wrote:
> ---
> Makefile.tools | 1 +
> test/test-thermometer | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 90 insertions(+), 0 deletions(-)
> create mode 100755 test/test-thermometer
After a couple more cosmetic fixes I went ahead and applied the patch.
Thanks.
Johan
Hi Santiago,
On Tue, Nov 22, 2011, Santiago Carot-Nemesio wrote:
> --- a/Makefile.tools
> +++ b/Makefile.tools
> @@ -215,8 +215,8 @@ EXTRA_DIST += test/apitest test/sap-client test/hsplay test/hsmicro \
> test/test-input test/test-attrib test/test-proximity \
> test/test-sap-server test/test-oob test/test-serial-proxy \
> test/service-record.dtd test/service-did.xml \
> - test/service-spp.xml test/service-opp.xml test/service-ftp.xml
> -
> + test/service-spp.xml test/service-opp.xml test/service-ftp.xml \
> + test/test-thermometer
The idea is to have these ordered so that the tests come before the xml
files, i.e. add your test after test-serial-proxy.
> + exit_on_release = True
> +
> + def set_exit_on_release(self, exit_on_release):
> + self.exit_on_release = exit_on_release
What's this for? Doesn't seem to be used anywhere.
> + option_list = [
> + make_option("-i", "--adapter", action="store",
> + type="string", dest="adapter"),
> + make_option("-b", "--device", action="store",
> + type="string", dest="address"),
> + ]
> +
> + parser = OptionParser(option_list=option_list)
> +
> + (options, args) = parser.parse_args()
> +
> + if options.adapter:
> + adapter_path = manager.FindAdapter(options.adapter)
> + else:
> + adapter_path = manager.DefaultAdapter()
> +
> + adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
> + "org.bluez.Adapter")
> +
> + device_path = adapter.FindDevice(options.address)
I know you've probably just copied the options.address stuff from
test-proximity, but since the remote address is mandatory why not make
it a plain (non-switch) command line parameter. You're in any case
missing the check for whether it was provided or not which would
probably trigger an exception instead of a clean error message.
Johan
Hi Santiago,
On Mon, Nov 21, 2011, Santiago Carot-Nemesio wrote:
> ---
> test/test-thermometer.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 81 insertions(+), 0 deletions(-)
> create mode 100644 test/test-thermometer.py
Drop the .py suffix since no other test script uses that either, and add
the script to EXTRA_DIST in Makefile.tools so that it gets included in
"make dist".
Johan