aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-08-09 09:56:56 +0200
committerAleksander Morgado <aleksander@aleksander.es>2016-10-12 11:29:52 +0200
commit9d78f05cbd437169a6f4ca406166edbcc4042316 (patch)
tree2865f3ce92c232f8bcfbad5c58a8b941fa4629a8
parent5d2e89e7129fadc92474fc55a87a84f7e6c98e12 (diff)
ublox: new +URAT=X command builder
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.c46
-rw-r--r--plugins/ublox/mm-modem-helpers-ublox.h6
-rw-r--r--plugins/ublox/tests/test-modem-helpers-ublox.c45
3 files changed, 85 insertions, 12 deletions
diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c
index b82b2d0c..1edd7a50 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.c
+++ b/plugins/ublox/mm-modem-helpers-ublox.c
@@ -552,3 +552,49 @@ out:
*out_preferred = preferred;
return TRUE;
}
+
+/*****************************************************************************/
+/* URAT=X command builder */
+
+static gboolean
+append_rat_value (GString *str,
+ MMModemMode mode,
+ GError **error)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (ublox_combinations); i++) {
+ if (ublox_combinations[i] == mode) {
+ g_string_append_printf (str, "%u", i);
+ return TRUE;
+ }
+ }
+
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "No AcT value matches requested mode");
+ return FALSE;
+}
+
+gchar *
+mm_ublox_build_urat_set_command (MMModemMode allowed,
+ MMModemMode preferred,
+ GError **error)
+{
+ GString *command;
+
+ command = g_string_new ("+URAT=");
+ if (!append_rat_value (command, allowed, error)) {
+ g_string_free (command, TRUE);
+ return NULL;
+ }
+
+ if (preferred != MM_MODEM_MODE_NONE) {
+ g_string_append (command, ",");
+ if (!append_rat_value (command, preferred, error)) {
+ g_string_free (command, TRUE);
+ return NULL;
+ }
+ }
+
+ return g_string_free (command, FALSE);
+}
diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h
index a0ee611c..dcac084e 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.h
+++ b/plugins/ublox/mm-modem-helpers-ublox.h
@@ -86,5 +86,11 @@ gboolean mm_ublox_parse_urat_read_response (const gchar *response,
MMModemMode *out_preferred,
GError **error);
+/*****************************************************************************/
+/* URAT=X command builder */
+
+gchar *mm_ublox_build_urat_set_command (MMModemMode allowed,
+ MMModemMode preferred,
+ GError **error);
#endif /* MM_MODEM_HELPERS_UBLOX_H */
diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c
index 2c0d1bb2..7aa091f9 100644
--- a/plugins/ublox/tests/test-modem-helpers-ublox.c
+++ b/plugins/ublox/tests/test-modem-helpers-ublox.c
@@ -354,32 +354,37 @@ test_mode_filtering_sara_u280 (void)
}
/*****************************************************************************/
-/* URAT? response parser */
+/* URAT? response parser and URAT=X command builder */
typedef struct {
- const gchar *str;
+ const gchar *command;
+ const gchar *response;
MMModemMode allowed;
MMModemMode preferred;
-} UratReadResponseTest;
+} UratTest;
-static const UratReadResponseTest urat_read_response_tests[] = {
+static const UratTest urat_tests[] = {
{
- .str = "+URAT: 1,2\r\n",
+ .command = "+URAT=1,2",
+ .response = "+URAT: 1,2\r\n",
.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G),
.preferred = MM_MODEM_MODE_3G,
},
{
- .str = "+URAT: 4,0\r\n",
+ .command = "+URAT=4,0",
+ .response = "+URAT: 4,0\r\n",
.allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G),
.preferred = MM_MODEM_MODE_2G,
},
{
- .str = "+URAT: 0\r\n",
+ .command = "+URAT=0",
+ .response = "+URAT: 0\r\n",
.allowed = MM_MODEM_MODE_2G,
.preferred = MM_MODEM_MODE_NONE,
},
{
- .str = "+URAT: 6\r\n",
+ .command = "+URAT=6",
+ .response = "+URAT: 6\r\n",
.allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_4G),
.preferred = MM_MODEM_MODE_NONE,
},
@@ -390,18 +395,33 @@ test_urat_read_response (void)
{
guint i;
- for (i = 0; i < G_N_ELEMENTS (urat_read_response_tests); i++) {
+ for (i = 0; i < G_N_ELEMENTS (urat_tests); i++) {
MMModemMode allowed = MM_MODEM_MODE_NONE;
MMModemMode preferred = MM_MODEM_MODE_NONE;
GError *error = NULL;
gboolean success;
- success = mm_ublox_parse_urat_read_response (urat_read_response_tests[i].str,
+ success = mm_ublox_parse_urat_read_response (urat_tests[i].response,
&allowed, &preferred, &error);
g_assert_no_error (error);
g_assert (success);
- g_assert_cmpuint (urat_read_response_tests[i].allowed, ==, allowed);
- g_assert_cmpuint (urat_read_response_tests[i].preferred, ==, preferred);
+ g_assert_cmpuint (urat_tests[i].allowed, ==, allowed);
+ g_assert_cmpuint (urat_tests[i].preferred, ==, preferred);
+ }
+}
+
+static void
+test_urat_write_command (void)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (urat_tests); i++) {
+ gchar *command;
+ GError *error = NULL;
+
+ command = mm_ublox_build_urat_set_command (urat_tests[i].allowed, urat_tests[i].preferred, &error);
+ g_assert_no_error (error);
+ g_assert_cmpstr (command, ==, urat_tests[i].command);
}
}
@@ -446,6 +466,7 @@ int main (int argc, char **argv)
g_test_add_func ("/MM/ublox/urat/test/response/lisa-u200", test_mode_filtering_lisa_u200);
g_test_add_func ("/MM/ublox/urat/test/response/sara-u280", test_mode_filtering_sara_u280);
g_test_add_func ("/MM/ublox/urat/read/response", test_urat_read_response);
+ g_test_add_func ("/MM/ublox/urat/write/command", test_urat_write_command);
return g_test_run ();
}