From 7078587f58b2fbf8356931cc2425d78c8bee0136 Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Thu, 20 Oct 2016 11:33:58 +0200 Subject: [PATCH] telit: optimized supported and current band code 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 ++++-------------- .../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 665668f5..c8c1f4bd 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[0-9\\-,]*)\\)(,\\s*\\((?P.*)\\))?" -#define SUPP_BAND_4G_MODEM_RESPONSE_REGEX "#BND:\\s*\\((?P.*)\\),\\s*\\((?P.*)\\),\\s*\\((?P\\d+-\\d+)\\)" -#define CURR_BAND_RESPONSE_REGEX "#BND:\\s*(?P\\d+)(,\\s*(?P\\d+))?" -#define CURR_BAND_4G_MODEM_RESPONSE_REGEX "#BND:\\s*(?P\\d+),\\s*(?P\\d+),\\s*(?P\\d+)" +#define SUPP_BAND_RESPONSE_REGEX "#BND:\\s*\\((?P[0-9\\-,]*)\\)(,\\s*\\((?P[0-9\\-,]*)\\))?(,\\s*\\((?P[0-9\\-,]*)\\))?" +#define CURR_BAND_RESPONSE_REGEX "#BND:\\s*(?P\\d+)(,\\s*(?P\\d+))?(,\\s*(?P\\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 03b1bc7a..2da60c11 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, {}}, };