aboutsummaryrefslogtreecommitdiff
path: root/plugins/ublox
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2017-08-22 11:12:48 +0200
committerAleksander Morgado <aleksander@aleksander.es>2017-09-15 10:31:21 -0700
commita0768a13f66a33cbad3d03b4ff067ec4c2fd88a3 (patch)
tree74fdaa3d9dab9ff36e86b34d1a1a40fc5f2acc0d /plugins/ublox
parent826c5ad74a882dd8a74448c1ed8b5ea031713836 (diff)
ublox: new AT+UACT=X command builder
Diffstat (limited to 'plugins/ublox')
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.c49
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.h6
-rw-r--r--plugins/ublox/tests/test-modem-helpers-ublox.c69
3 files changed, 124 insertions, 0 deletions
diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c
index cf7a295f..34ec9b4e 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.c
+++ b/plugins/ublox/mm-modem-helpers-ublox.c
@@ -920,6 +920,18 @@ uact_num_to_band (guint num)
return MM_MODEM_BAND_UNKNOWN;
}
+static guint
+uact_band_to_num (MMModemBand band)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (uact_band_config); i++) {
+ if (band == uact_band_config[i].band)
+ return uact_band_config[i].num;
+ }
+ return 0;
+}
+
/*****************************************************************************/
/* UACT? response parser */
@@ -1107,6 +1119,43 @@ out:
}
/*****************************************************************************/
+/* UACT=X command builder */
+
+gchar *
+mm_ublox_build_uact_set_command (GArray *bands,
+ GError **error)
+{
+ GString *command;
+
+ /* Build command */
+ command = g_string_new ("+UACT=,,,");
+
+ if (bands->len == 1 && g_array_index (bands, MMModemBand, 0) == MM_MODEM_BAND_ANY)
+ g_string_append (command, "0");
+ else {
+ guint i;
+
+ for (i = 0; i < bands->len; i++) {
+ MMModemBand band;
+ guint num;
+
+ band = g_array_index (bands, MMModemBand, i);
+ num = uact_band_to_num (band);
+ if (!num) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
+ "Band unsupported by this plugin: %s", mm_modem_band_get_string (band));
+ g_string_free (command, TRUE);
+ return NULL;
+ }
+
+ g_string_append_printf (command, "%s%u", i == 0 ? "" : ",", num);
+ }
+ }
+
+ return g_string_free (command, FALSE);
+}
+
+/*****************************************************************************/
/* URAT? response parser */
gboolean
diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h
index 516e49f6..a4b73108 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.h
+++ b/plugins/ublox/mm-modem-helpers-ublox.h
@@ -122,6 +122,12 @@ gboolean mm_ublox_parse_uact_test (const gchar *response,
GError **error);
/*****************************************************************************/
+/* UACT=X command builder */
+
+gchar *mm_ublox_build_uact_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 bb54cc17..b50ac8f7 100644
--- a/plugins/ublox/tests/test-modem-helpers-ublox.c
+++ b/plugins/ublox/tests/test-modem-helpers-ublox.c
@@ -886,6 +886,71 @@ test_uact_test_2g3g4g_2 (void)
}
/*****************************************************************************/
+/* +UACT=x command builder */
+
+static void
+common_validate_uact_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_uact_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_uact_request_any (void)
+{
+ const MMModemBand bands[] = {
+ MM_MODEM_BAND_ANY
+ };
+
+ common_validate_uact_request (bands, G_N_ELEMENTS (bands), "+UACT=,,,0");
+}
+
+static void
+test_uact_request_2g (void)
+{
+ const MMModemBand bands[] = {
+ MM_MODEM_BAND_EGSM, MM_MODEM_BAND_DCS,
+ };
+
+ common_validate_uact_request (bands, G_N_ELEMENTS (bands), "+UACT=,,,900,1800");
+}
+
+static void
+test_uact_request_3g (void)
+{
+ const MMModemBand bands[] = {
+ MM_MODEM_BAND_UTRAN_1, MM_MODEM_BAND_UTRAN_8,
+ };
+
+ common_validate_uact_request (bands, G_N_ELEMENTS (bands), "+UACT=,,,1,8");
+}
+
+static void
+test_uact_request_4g (void)
+{
+ const MMModemBand bands[] = {
+ MM_MODEM_BAND_EUTRAN_1, MM_MODEM_BAND_EUTRAN_3, MM_MODEM_BAND_EUTRAN_7, MM_MODEM_BAND_EUTRAN_8, MM_MODEM_BAND_EUTRAN_20
+ };
+
+ common_validate_uact_request (bands, G_N_ELEMENTS (bands), "+UACT=,,,101,103,107,108,120");
+}
+
+/*****************************************************************************/
/* Test +UGCNTRD responses */
typedef struct {
@@ -1023,6 +1088,10 @@ int main (int argc, char **argv)
g_test_add_func ("/MM/ublox/uact/test/2g3g", test_uact_test_2g3g);
g_test_add_func ("/MM/ublox/uact/test/2g3g4g", test_uact_test_2g3g4g);
g_test_add_func ("/MM/ublox/uact/test/2g3g4g/2", test_uact_test_2g3g4g_2);
+ g_test_add_func ("/MM/ublox/uact/request/any", test_uact_request_any);
+ g_test_add_func ("/MM/ublox/uact/request/2g", test_uact_request_2g);
+ g_test_add_func ("/MM/ublox/uact/request/3g", test_uact_request_3g);
+ g_test_add_func ("/MM/ublox/uact/request/4g", test_uact_request_4g);
g_test_add_func ("/MM/ublox/ugcntrd/response", test_ugcntrd_response);
return g_test_run ();