aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-08-12 18:03:32 +0200
committerAleksander Morgado <aleksander@aleksander.es>2016-10-12 13:24:09 +0200
commit1c69a847ae0ac2435d48525714bccdc699fab72b (patch)
tree31da44c95fdb2d68c1b6736fefa51b3a80ac9987
parentc165f24514e1d5ab05c08dd7480241955006b2fa (diff)
ublox: new +UBANDSEL=X command builder
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.c55
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.h6
-rw-r--r--plugins/ublox/tests/test-modem-helpers-ublox.c59
3 files changed, 120 insertions, 0 deletions
diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c
index 1190cd68..0dc71c06 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.c
+++ b/plugins/ublox/mm-modem-helpers-ublox.c
@@ -732,6 +732,61 @@ out:
}
/*****************************************************************************/
+/* UBANDSEL=X command builder */
+
+static gint
+ubandsel_num_cmp (const guint *a, const guint *b)
+{
+ return (*a - *b);
+}
+
+gchar *
+mm_ublox_build_ubandsel_set_command (GArray *bands,
+ GError **error)
+{
+ GString *command = NULL;
+ GArray *ubandsel_nums;
+ guint i;
+
+ if (bands->len == 1 && g_array_index (bands, MMModemBand, 0) == MM_MODEM_BAND_ANY)
+ return g_strdup ("+UBANDSEL=0");
+
+ ubandsel_nums = g_array_sized_new (FALSE, FALSE, sizeof (guint), G_N_ELEMENTS (band_configuration));
+ for (i = 0; i < G_N_ELEMENTS (band_configuration); i++) {
+ guint j;
+
+ for (j = 0; j < bands->len; j++) {
+ MMModemBand band;
+
+ band = g_array_index (bands, MMModemBand, j);
+
+ if (band == band_configuration[i].bands_2g[0] || band == band_configuration[i].bands_2g[1] ||
+ band == band_configuration[i].bands_3g[0] || band == band_configuration[i].bands_3g[1] ||
+ band == band_configuration[i].bands_4g[0] || band == band_configuration[i].bands_4g[1]) {
+ g_array_append_val (ubandsel_nums, band_configuration[i].ubandsel_value);
+ break;
+ }
+ }
+ }
+
+ if (ubandsel_nums->len == 0) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
+ "Given band combination is unsupported");
+ g_array_unref (ubandsel_nums);
+ return NULL;
+ }
+
+ if (ubandsel_nums->len > 1)
+ g_array_sort (ubandsel_nums, (GCompareFunc) ubandsel_num_cmp);
+
+ /* Build command */
+ command = g_string_new ("+UBANDSEL=");
+ for (i = 0; i < ubandsel_nums->len; i++)
+ g_string_append_printf (command, "%s%u", i == 0 ? "" : ",", g_array_index (ubandsel_nums, guint, i));
+ return g_string_free (command, FALSE);
+}
+
+/*****************************************************************************/
/* Get mode to apply when ANY */
MMModemMode
diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h
index bd4f5e2b..06520597 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.h
+++ b/plugins/ublox/mm-modem-helpers-ublox.h
@@ -101,6 +101,12 @@ GArray *mm_ublox_parse_ubandsel_response (const gchar *response,
GError **error);
/*****************************************************************************/
+/* UBANDSEL=X command builder */
+
+gchar *mm_ublox_build_ubandsel_set_command (GArray *bands,
+ GError **error);
+
+/*****************************************************************************/
/* Get mode to apply when ANY */
MMModemMode mm_ublox_get_modem_mode_any (const GArray *combinations);
diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c
index 91738582..67620a23 100644
--- a/plugins/ublox/tests/test-modem-helpers-ublox.c
+++ b/plugins/ublox/tests/test-modem-helpers-ublox.c
@@ -670,6 +670,61 @@ test_ubandsel_response_one (void)
}
/*****************************************************************************/
+/* +UBANDSEL=x command builder */
+
+static void
+common_validate_ubandsel_request (const MMModemBand *bands,
+ guint n_bands,
+ const gchar *expected_request)
+{
+ GError *error = NULL;
+ GArray *bands_array;
+ gchar *request;
+
+ bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), n_bands);
+ g_array_append_vals (bands_array, bands, n_bands);
+
+ request = mm_ublox_build_ubandsel_set_command (bands_array, &error);
+ g_assert_no_error (error);
+ g_assert (request);
+
+ g_assert_cmpstr (request, ==, expected_request);
+
+ g_array_unref (bands_array);
+ g_free (request);
+}
+
+static void
+test_ubandsel_request_any (void)
+{
+ const MMModemBand bands[] = {
+ MM_MODEM_BAND_ANY
+ };
+
+ common_validate_ubandsel_request (bands, G_N_ELEMENTS (bands), "+UBANDSEL=0");
+}
+
+static void
+test_ubandsel_request_2g (void)
+{
+ const MMModemBand bands[] = {
+ MM_MODEM_BAND_G850, MM_MODEM_BAND_EGSM, MM_MODEM_BAND_DCS, MM_MODEM_BAND_PCS
+ };
+
+ common_validate_ubandsel_request (bands, G_N_ELEMENTS (bands), "+UBANDSEL=850,900,1800,1900");
+}
+
+static void
+test_ubandsel_request_1800 (void)
+{
+ const MMModemBand bands[] = {
+ MM_MODEM_BAND_DCS, MM_MODEM_BAND_U1800, MM_MODEM_BAND_EUTRAN_III
+ };
+
+ common_validate_ubandsel_request (bands, G_N_ELEMENTS (bands), "+UBANDSEL=1800");
+}
+
+/*****************************************************************************/
void
_mm_log (const char *loc,
@@ -721,5 +776,9 @@ int main (int argc, char **argv)
g_test_add_func ("/MM/ublox/ubandsel/response/three", test_ubandsel_response_three);
g_test_add_func ("/MM/ublox/ubandsel/response/four", test_ubandsel_response_four);
+ g_test_add_func ("/MM/ublox/ubandsel/request/any", test_ubandsel_request_any);
+ g_test_add_func ("/MM/ublox/ubandsel/request/2g", test_ubandsel_request_2g);
+ g_test_add_func ("/MM/ublox/ubandsel/request/1800", test_ubandsel_request_1800);
+
return g_test_run ();
}