[PATCH v1] ublox: use ID_MM_UBLOX_PORT_READY_DELAY udev flag as init delay

Matthew Starr mstarr at hedonline.com
Fri May 4 21:29:45 UTC 2018


Added reading the ID_MM_UBLOX_PORT_READY_DELAY udev flag value and
using it as an init delay when a value is set.

The 20 second delay for the TOBY-L4 +READ URC has been reimplemented
using the new ID_MM_UBLOX_PORT_READY_DELAY udev value.

A 2 second delay for the TOBY-R2 was added since sometimes when the
ttyACM interfaces appear, the modem is not ready and ModemManager fails
to properly detect the modem.
---
 plugins/ublox/77-mm-ublox-port-types.rules |  5 +++++
 plugins/ublox/mm-plugin-ublox.c            | 22 ++++++++++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/plugins/ublox/77-mm-ublox-port-types.rules b/plugins/ublox/77-mm-ublox-port-types.rules
index 31128dac..b7bf3e5a 100644
--- a/plugins/ublox/77-mm-ublox-port-types.rules
+++ b/plugins/ublox/77-mm-ublox-port-types.rules
@@ -11,9 +11,11 @@ SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInte
 #  ttyACM0 (if #2): secondary (ignore)
 #  ttyACM1 (if #4): debug port (ignore)
 #  ttyACM2 (if #6): primary
+#      Wait up to 20s for the +READY URC
 #  ttyACM3 (if #8): AT port for FOTA (ignore)
 ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1010", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_PORT_IGNORE}="1"
 ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1010", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_PORT_IGNORE}="1"
+ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1010", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_UBLOX_PORT_READY_DELAY}="20"
 ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1010", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1"
 
 # TOBY-R2 port types
@@ -23,6 +25,9 @@ ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1010", ENV{.MM_USBIFNUM}=="08", ENV{
 #  ttyACM3 (if #6): GNSS Tunneling (ignore)
 #  ttyACM4 (if #8): SIM Access Profile (ignore)
 #  ttyACM5 (if #10): Primary Log for diagnostics (ignore)
+ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1107", ENV{.MM_USBIFNUM}=="00", ENV{ID_MM_UBLOX_PORT_READY_DELAY}="2"
+ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1107", ENV{.MM_USBIFNUM}=="02", ENV{ID_MM_UBLOX_PORT_READY_DELAY}="2"
+ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1107", ENV{.MM_USBIFNUM}=="04", ENV{ID_MM_UBLOX_PORT_READY_DELAY}="2"
 ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1107", ENV{.MM_USBIFNUM}=="06", ENV{ID_MM_PORT_IGNORE}="1"
 ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1107", ENV{.MM_USBIFNUM}=="08", ENV{ID_MM_PORT_IGNORE}="1"
 ATTRS{idVendor}=="1546", ATTRS{idProduct}=="1107", ENV{.MM_USBIFNUM}=="0a", ENV{ID_MM_PORT_IGNORE}="1"
diff --git a/plugins/ublox/mm-plugin-ublox.c b/plugins/ublox/mm-plugin-ublox.c
index f4553a60..bde46476 100644
--- a/plugins/ublox/mm-plugin-ublox.c
+++ b/plugins/ublox/mm-plugin-ublox.c
@@ -50,13 +50,11 @@ create_modem (MMPlugin     *self,
 /*****************************************************************************/
 /* Custom init context */
 
-/* Wait up to 20s for the +READY URC */
-#define READY_WAIT_TIME_SECS 20
-
 typedef struct {
     MMPortSerialAt *port;
     GRegex         *ready_regex;
     guint           timeout_id;
+    gint            wait_timeout_secs;
 } CustomInitContext;
 
 static void
@@ -147,8 +145,13 @@ wait_for_ready (GTask *task)
                                                    task,
                                                    NULL);
 
+    mm_dbg ("(%s/%s) waiting %d seconds for init timeout",
+            mm_port_probe_get_port_subsys (probe),
+            mm_port_probe_get_port_name   (probe),
+            ctx->wait_timeout_secs);
+
     /* Otherwise, let the custom init timeout in some seconds. */
-    ctx->timeout_id = g_timeout_add_seconds (READY_WAIT_TIME_SECS, (GSourceFunc) ready_timeout, task);
+    ctx->timeout_id = g_timeout_add_seconds (ctx->wait_timeout_secs, (GSourceFunc) ready_timeout, task);
 }
 
 static void
@@ -208,6 +211,11 @@ ublox_custom_init (MMPortProbe         *probe,
                                     G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
     g_task_set_task_data (task, ctx, (GDestroyNotify) custom_init_context_free);
 
+    ctx->wait_timeout_secs = mm_kernel_device_get_property_as_int (mm_port_probe_peek_port(probe), "ID_MM_UBLOX_PORT_READY_DELAY");
+    if (ctx->wait_timeout_secs < 0) {
+	    ctx->wait_timeout_secs = 0;
+    }
+
     /* If the device hasn't been plugged in right away, we assume it was already
      * running for some time. We validate the assumption with a quick AT probe,
      * and if it times out, we run the explicit READY wait from scratch (e.g.
@@ -225,8 +233,10 @@ ublox_custom_init (MMPortProbe         *probe,
         return;
     }
 
-    /* Device hotplugged, wait for READY URC */
-    wait_for_ready (task);
+    if (ctx->wait_timeout_secs > 0) {
+        /* Device hotplugged and has a defined ready delay, wait for READY URC */
+        wait_for_ready (task);
+    }
 }
 
 /*****************************************************************************/
-- 
2.14.1



More information about the ModemManager-devel mailing list