ublox: new AT+UACT=X command builder
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -1106,6 +1118,43 @@ out:
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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 */
|
||||
|
||||
|
@@ -121,6 +121,12 @@ gboolean mm_ublox_parse_uact_test (const gchar *response,
|
||||
GArray **bands_4g,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* UACT=X command builder */
|
||||
|
||||
gchar *mm_ublox_build_uact_set_command (GArray *bands,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Get mode to apply when ANY */
|
||||
|
||||
|
@@ -885,6 +885,71 @@ test_uact_test_2g3g4g_2 (void)
|
||||
expected_bands_4g, G_N_ELEMENTS (expected_bands_4g));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* +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 */
|
||||
|
||||
@@ -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 ();
|
||||
|
Reference in New Issue
Block a user