[PATCH v2 1/1] helpers: extend +WS46=? response parser to support ranges
Daniele Palmas
dnlplm at gmail.com
Fri Jun 16 12:57:18 UTC 2017
Telit LTE modems could reply to +WS46=? with:
+WS46: (12,22,25,28-31)
This patch extends +WS46=? response parser to support ranges.
---
v2: used mm_parse_uint_list as suggested by Aleksander
---
src/mm-modem-helpers.c | 25 ++++++++++++-------------
src/tests/test-modem-helpers.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 73822e1..5e257a8 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -887,12 +887,14 @@ mm_3gpp_parse_ws46_test_response (const gchar *response,
GError **error)
{
GArray *modes = NULL;
+ GArray *tech_values = NULL;
GRegex *r;
GError *inner_error = NULL;
GMatchInfo *match_info = NULL;
gchar *full_list = NULL;
- gchar **split;
+ guint val;
guint i;
+ guint j;
gboolean supported_4g = FALSE;
gboolean supported_3g = FALSE;
gboolean supported_2g = FALSE;
@@ -914,17 +916,13 @@ mm_3gpp_parse_ws46_test_response (const gchar *response,
goto out;
}
- split = g_strsplit (full_list, ",", -1);
+ if (!(tech_values = mm_parse_uint_list (full_list, &inner_error)))
+ goto out;
+
modes = g_array_new (FALSE, FALSE, sizeof (MMModemMode));
- for (i = 0; split && split[i]; i++) {
- guint val;
- guint j;
-
- if (!mm_get_uint_from_str (split[i], &val)) {
- g_warning ("Invalid +WS46 mode reported: %s", split[i]);
- continue;
- }
+ for (i = 0; i < tech_values->len; i++) {
+ val = g_array_index (tech_values, guint, i);
for (j = 0; j < G_N_ELEMENTS (ws46_modes); j++) {
if (ws46_modes[j].ws46 == val) {
@@ -942,11 +940,9 @@ mm_3gpp_parse_ws46_test_response (const gchar *response,
}
if (j == G_N_ELEMENTS (ws46_modes))
- g_warning ("Unknown +WS46 mode reported: %s", split[i]);
+ g_warning ("Unknown +WS46 mode reported: %u", val);
}
- g_strfreev (split);
-
if (modes->len == 0) {
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "No valid modes reported");
g_clear_pointer (&modes, g_array_unref);
@@ -976,6 +972,9 @@ mm_3gpp_parse_ws46_test_response (const gchar *response,
}
out:
+ if (tech_values)
+ g_array_unref (tech_values);
+
g_free (full_list);
g_clear_pointer (&match_info, g_match_info_free);
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index 5928412..5fdded4 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -215,6 +215,36 @@ test_ws46_response_telit_le866 (void)
test_ws46_response (str, expected, G_N_ELEMENTS (expected));
}
+static void
+test_ws46_response_range_1 (void)
+{
+ static const MMModemMode expected[] = {
+ MM_MODEM_MODE_2G | MM_MODEM_MODE_3G,
+ MM_MODEM_MODE_2G | MM_MODEM_MODE_4G,
+ MM_MODEM_MODE_3G | MM_MODEM_MODE_4G,
+ };
+ const gchar *str = "+WS46: (29-31)";
+
+ test_ws46_response (str, expected, G_N_ELEMENTS (expected));
+}
+
+static void
+test_ws46_response_range_2 (void)
+{
+ static const MMModemMode expected[] = {
+ MM_MODEM_MODE_2G,
+ MM_MODEM_MODE_3G,
+ MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G,
+ MM_MODEM_MODE_4G,
+ MM_MODEM_MODE_2G | MM_MODEM_MODE_3G,
+ MM_MODEM_MODE_2G | MM_MODEM_MODE_4G,
+ MM_MODEM_MODE_3G | MM_MODEM_MODE_4G,
+ };
+ const gchar *str = "+WS46: (12,22,25,28-31)";
+
+ test_ws46_response (str, expected, G_N_ELEMENTS (expected));
+}
+
/*****************************************************************************/
/* Test CMGL responses */
@@ -3715,6 +3745,8 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_ws46_response_generic_2g3g_v2, NULL));
g_test_suite_add (suite, TESTCASE (test_ws46_response_cinterion, NULL));
g_test_suite_add (suite, TESTCASE (test_ws46_response_telit_le866, NULL));
+ g_test_suite_add (suite, TESTCASE (test_ws46_response_range_1, NULL));
+ g_test_suite_add (suite, TESTCASE (test_ws46_response_range_2, NULL));
g_test_suite_add (suite, TESTCASE (test_cops_response_tm506, NULL));
g_test_suite_add (suite, TESTCASE (test_cops_response_gt3gplus, NULL));
--
2.7.4
More information about the ModemManager-devel
mailing list