[PATCH] Telit: Optimized supported and current band code

Carlo Lobrano c.lobrano at gmail.com
Thu Oct 20 09:33:58 UTC 2016


In place of two slightly different regexes for 2g/3g and 2g/3g/4g modems
we now use only one regex with conditional patterns for both supported
and current Bands detection.

Adding also minor fix in test code
---
 plugins/telit/mm-modem-helpers-telit.c            | 18 ++++--------------
 plugins/telit/tests/test-mm-modem-helpers-telit.c |  2 +-
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/plugins/telit/mm-modem-helpers-telit.c b/plugins/telit/mm-modem-helpers-telit.c
index 665668f..c8c1f4b 100644
--- a/plugins/telit/mm-modem-helpers-telit.c
+++ b/plugins/telit/mm-modem-helpers-telit.c
@@ -161,11 +161,8 @@ mm_telit_parse_csim_response (const guint step,
 
     return retries;
 }
-
-#define SUPP_BAND_RESPONSE_REGEX          "#BND:\\s*\\((?P<Bands2G>[0-9\\-,]*)\\)(,\\s*\\((?P<Bands3G>.*)\\))?"
-#define SUPP_BAND_4G_MODEM_RESPONSE_REGEX "#BND:\\s*\\((?P<Bands2G>.*)\\),\\s*\\((?P<Bands3G>.*)\\),\\s*\\((?P<Bands4G>\\d+-\\d+)\\)"
-#define CURR_BAND_RESPONSE_REGEX          "#BND:\\s*(?P<Bands2G>\\d+)(,\\s*(?P<Bands3G>\\d+))?"
-#define CURR_BAND_4G_MODEM_RESPONSE_REGEX "#BND:\\s*(?P<Bands2G>\\d+),\\s*(?P<Bands3G>\\d+),\\s*(?P<Bands4G>\\d+)"
+#define SUPP_BAND_RESPONSE_REGEX          "#BND:\\s*\\((?P<Bands2G>[0-9\\-,]*)\\)(,\\s*\\((?P<Bands3G>[0-9\\-,]*)\\))?(,\\s*\\((?P<Bands4G>[0-9\\-,]*)\\))?"
+#define CURR_BAND_RESPONSE_REGEX          "#BND:\\s*(?P<Bands2G>\\d+)(,\\s*(?P<Bands3G>\\d+))?(,\\s*(?P<Bands4G>\\d+))?"
 
 /*****************************************************************************/
 /* #BND response parser
@@ -235,18 +232,11 @@ mm_telit_parse_bnd_response (const gchar *response,
     switch (band_type) {
         case LOAD_SUPPORTED_BANDS:
             /* Parse #BND=? response */
-            if (modem_is_4g)
-                r = g_regex_new (SUPP_BAND_4G_MODEM_RESPONSE_REGEX, G_REGEX_RAW, 0, NULL);
-            else
-                r = g_regex_new (SUPP_BAND_RESPONSE_REGEX, G_REGEX_RAW, 0, NULL);
+            r = g_regex_new (SUPP_BAND_RESPONSE_REGEX, G_REGEX_RAW, 0, NULL);
             break;
         case LOAD_CURRENT_BANDS:
             /* Parse #BND? response */
-            if (modem_is_4g)
-                r = g_regex_new (CURR_BAND_4G_MODEM_RESPONSE_REGEX, G_REGEX_RAW, 0, NULL);
-            else
-                r = g_regex_new (CURR_BAND_RESPONSE_REGEX, G_REGEX_RAW, 0, NULL);
-            break;
+            r = g_regex_new (CURR_BAND_RESPONSE_REGEX, G_REGEX_RAW, 0, NULL);
         default:
             break;
     }
diff --git a/plugins/telit/tests/test-mm-modem-helpers-telit.c b/plugins/telit/tests/test-mm-modem-helpers-telit.c
index 03b1bc7..2da60c1 100644
--- a/plugins/telit/tests/test-mm-modem-helpers-telit.c
+++ b/plugins/telit/tests/test-mm-modem-helpers-telit.c
@@ -117,7 +117,7 @@ typedef struct {
 static BNDFlagsTest band_flag_test[] = {
     {"0-3", 4, {0, 1, 2, 3} },
     {"0,3", 2, {0, 3} },
-    {"0,2-3,5-7,9", 2, {0, 2, 3, 5, 6, 7, 9} },
+    {"0,2-3,5-7,9", 7, {0, 2, 3, 5, 6, 7, 9} },
     { NULL, 0, {}},
 };
 
-- 
2.7.4



More information about the ModemManager-devel mailing list