summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-05-28 11:41:06 +0200
committerAleksander Morgado <aleksander@aleksander.es>2020-05-30 08:55:17 +0200
commit6683888d22dd22d4524ed1dc7242d5dadb5bf798 (patch)
tree30f6623203c09289843070e5c7c3dbc2d3736263
parent7c40f45495f727aa8a60e54110adf37d526e6b64 (diff)
examples: add introspection based example tester
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac2
-rw-r--r--examples/Makefile.am2
-rw-r--r--examples/simple-tester-python/Makefile.am2
-rw-r--r--examples/simple-tester-python/README24
-rwxr-xr-xexamples/simple-tester-python/simple-tester-python132
6 files changed, 163 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 0e91bc5..4446d07 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
-SUBDIRS = . data build-aux src utils docs
+SUBDIRS = . data build-aux src examples utils docs
ACLOCAL_AMFLAGS = -I m4
diff --git a/configure.ac b/configure.ac
index 7259ed1..485d521 100644
--- a/configure.ac
+++ b/configure.ac
@@ -279,6 +279,8 @@ AC_CONFIG_FILES([Makefile
src/qmi-firmware-update/Makefile
src/qmi-firmware-update/test/Makefile
utils/Makefile
+ examples/Makefile
+ examples/simple-tester-python/Makefile
docs/Makefile
docs/reference/Makefile
docs/reference/libqmi-glib/Makefile
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..dd74b93
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,2 @@
+
+SUBDIRS = simple-tester-python
diff --git a/examples/simple-tester-python/Makefile.am b/examples/simple-tester-python/Makefile.am
new file mode 100644
index 0000000..81a8b07
--- /dev/null
+++ b/examples/simple-tester-python/Makefile.am
@@ -0,0 +1,2 @@
+
+EXTRA_DIST = simple-tester-python README
diff --git a/examples/simple-tester-python/README b/examples/simple-tester-python/README
new file mode 100644
index 0000000..96c48f8
--- /dev/null
+++ b/examples/simple-tester-python/README
@@ -0,0 +1,24 @@
+
+The simple-tester-python program makes use of the 'libqmi-glib' library
+through GObject Introspection.
+
+The program will:
+ * Open a connection to the qmi-proxy, or launch the qmi-proxy itself
+ if it isn't already running.
+ * Allocate a DMS client.
+ * Query device capabilities.
+ * Release DMS client.
+
+The output will look like this:
+
+$ ./simple-tester-python /dev/cdc-wdm0
+max tx channel rate: 50000000
+max rx channel rate: 100000000
+data service: non-simultaneous-cs-ps
+sim: supported
+networks: gsm, umts, lte
+
+Note that the program requires libqmi-glib to be installed in the system
+and the introspection typelibs available in the standard paths.
+
+Have fun! \ No newline at end of file
diff --git a/examples/simple-tester-python/simple-tester-python b/examples/simple-tester-python/simple-tester-python
new file mode 100755
index 0000000..b0ee254
--- /dev/null
+++ b/examples/simple-tester-python/simple-tester-python
@@ -0,0 +1,132 @@
+#!/usr/bin/env python
+# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright (C) 2020 Aleksander Morgado <aleksander@aleksander.es>
+#
+
+import sys, signal, gi
+
+gi.require_version('Qmi', '1.0')
+from gi.repository import GLib, Gio, Qmi
+
+main_loop = None
+
+
+def signal_handler(data):
+ main_loop.quit()
+
+
+def device_close_ready(qmidev,result,user_data=None):
+ try:
+ qmidev.close_finish(result)
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't close QMI device: %s\n" % error.message)
+ main_loop.quit()
+
+
+def device_close(qmidev):
+ qmidev.close_async(10, None, device_close_ready, None)
+
+
+def release_client_ready(qmidev,result,user_data=None):
+ try:
+ qmidev.release_client_finish(result)
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't release QMI client: %s\n" % error.message)
+ device_close(qmidev)
+
+
+def release_client(qmidev,qmiclient):
+ qmidev.release_client(qmiclient, Qmi.DeviceReleaseClientFlags.RELEASE_CID, 10, None, release_client_ready, None)
+
+
+def get_capabilities_ready(qmiclient,result,qmidev):
+ try:
+ output = qmiclient.get_capabilities_finish(result)
+ output.get_result()
+ success, maxtxrate, maxrxrate, dataservicecaps, simcaps, radioifaces = output.get_info()
+
+ if success:
+ print("max tx channel rate: %u" % maxtxrate)
+ print("max rx channel rate: %u" % maxrxrate)
+ print("data service: %s" % Qmi.DmsDataServiceCapability.get_string(dataservicecaps))
+ print("sim: %s" % Qmi.DmsSimCapability.get_string(simcaps))
+ networks = ""
+ for radioiface in radioifaces:
+ if networks != "":
+ networks += ", "
+ networks += Qmi.DmsRadioInterface.get_string(radioiface)
+ print("networks: %s" % networks)
+
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't query device capabilities: %s\n" % error.message)
+
+ release_client(qmidev, qmiclient)
+
+def allocate_client_ready(qmidev,result,user_data=None):
+ try:
+ qmiclient = qmidev.allocate_client_finish(result)
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't allocate QMI client: %s\n" % error.message)
+ device_close(qmidev)
+ return
+
+ qmiclient.get_capabilities(None, 10, None, get_capabilities_ready, qmidev)
+
+
+def open_ready(qmidev,result,user_data=None):
+ try:
+ qmidev.open_finish(result)
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't open QMI device: %s\n" % error.message)
+ main_loop.quit()
+ return
+
+ qmidev.allocate_client(Qmi.Service.DMS, Qmi.CID_NONE, 10, None, allocate_client_ready, None)
+
+
+def new_ready(unused,result,user_data=None):
+ try:
+ qmidev = Qmi.Device.new_finish(result)
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't create QMI device: %s\n" % error.message)
+ main_loop.quit()
+ return
+
+ qmidev.open(Qmi.DeviceOpenFlags.PROXY, 10, None, open_ready, None)
+
+
+if __name__ == "__main__":
+
+ # Process input arguments
+ if len(sys.argv) != 2:
+ sys.stderr.write('error: wrong number of arguments\n')
+ sys.stdout.write('usage: simple-tester-python <DEVICE>\n')
+ sys.exit(1)
+
+ # Create Mbim device asynchronously
+ file = Gio.File.new_for_path(sys.argv[1])
+ Qmi.Device.new (file, None, new_ready, None)
+
+ # Main loop
+ main_loop = GLib.MainLoop()
+ GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGHUP, signal_handler, None)
+ GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, signal_handler, None)
+ try:
+ main_loop.run()
+ except KeyboardInterrupt:
+ pass