ublox: new +UBANDSEL? response parser
This commit is contained in:
@@ -644,6 +644,93 @@ mm_ublox_get_supported_bands (const gchar *model,
|
||||
return bands;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* +UBANDSEL? response parser */
|
||||
|
||||
static void
|
||||
append_bands (GArray *bands,
|
||||
guint ubandsel_value)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (band_configuration); i++)
|
||||
if (ubandsel_value == band_configuration[i].ubandsel_value)
|
||||
break;
|
||||
|
||||
if (i == G_N_ELEMENTS (band_configuration)) {
|
||||
mm_warn ("Unknown band configuration value given: %u", ubandsel_value);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Note: we don't care if the device doesn't support one of these modes;
|
||||
* the generic logic will filter out all bands not supported before
|
||||
* exposing them in the DBus property */
|
||||
|
||||
if (band_configuration[i].bands_2g[0]) {
|
||||
g_array_append_val (bands, band_configuration[i].bands_2g[0]);
|
||||
if (band_configuration[i].bands_2g[1])
|
||||
g_array_append_val (bands, band_configuration[i].bands_2g[1]);
|
||||
}
|
||||
|
||||
if (band_configuration[i].bands_3g[0]) {
|
||||
g_array_append_val (bands, band_configuration[i].bands_3g[0]);
|
||||
if (band_configuration[i].bands_3g[1])
|
||||
g_array_append_val (bands, band_configuration[i].bands_3g[1]);
|
||||
}
|
||||
|
||||
if (band_configuration[i].bands_4g[0]) {
|
||||
g_array_append_val (bands, band_configuration[i].bands_4g[0]);
|
||||
if (band_configuration[i].bands_4g[1])
|
||||
g_array_append_val (bands, band_configuration[i].bands_4g[1]);
|
||||
}
|
||||
}
|
||||
|
||||
GArray *
|
||||
mm_ublox_parse_ubandsel_response (const gchar *response,
|
||||
GError **error)
|
||||
{
|
||||
GArray *array_values = NULL;
|
||||
GArray *array = NULL;
|
||||
gchar *dupstr = NULL;
|
||||
GError *inner_error = NULL;
|
||||
guint i;
|
||||
|
||||
if (!g_str_has_prefix (response, "+UBANDSEL")) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse +UBANDSEL response: '%s'", response);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Response may be e.g.:
|
||||
* +UBANDSEL: 850,900,1800,1900
|
||||
*/
|
||||
dupstr = g_strchomp (g_strdup (mm_strip_tag (response, "+UBANDSEL:")));
|
||||
|
||||
array_values = mm_parse_uint_list (dupstr, &inner_error);
|
||||
if (!array_values)
|
||||
goto out;
|
||||
|
||||
/* Convert list of ubandsel numbers to MMModemBand values */
|
||||
array = g_array_new (FALSE, FALSE, sizeof (MMModemBand));
|
||||
for (i = 0; i < array_values->len; i++)
|
||||
append_bands (array, g_array_index (array_values, guint, i));
|
||||
|
||||
if (!array->len) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"No known band selection values matched in +UBANDSEL response: '%s'", response);
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
if (inner_error) {
|
||||
g_propagate_error (error, inner_error);
|
||||
g_clear_pointer (&array, g_array_unref);
|
||||
}
|
||||
g_clear_pointer (&array_values, g_array_unref);
|
||||
g_free (dupstr);
|
||||
return array;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Get mode to apply when ANY */
|
||||
|
||||
|
@@ -94,6 +94,12 @@ GArray *mm_ublox_filter_supported_modes (const gchar *model,
|
||||
GArray *mm_ublox_get_supported_bands (const gchar *model,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* UBANDSEL? response parser */
|
||||
|
||||
GArray *mm_ublox_parse_ubandsel_response (const gchar *response,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Get mode to apply when ANY */
|
||||
|
||||
|
@@ -591,6 +591,84 @@ test_supported_bands_sara_u280 (void)
|
||||
common_validate_supported_bands ("SARA-U280", expected_bands, G_N_ELEMENTS (expected_bands));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Test +UBANDSEL? response parser */
|
||||
|
||||
static void
|
||||
common_validate_ubandsel_response (const gchar *str,
|
||||
const MMModemBand *expected_bands,
|
||||
guint n_expected_bands)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GArray *bands;
|
||||
gchar *bands_str;
|
||||
GArray *expected_bands_array;
|
||||
gchar *expected_bands_str;
|
||||
|
||||
bands = mm_ublox_parse_ubandsel_response (str, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (bands);
|
||||
mm_common_bands_garray_sort (bands);
|
||||
bands_str = mm_common_build_bands_string ((MMModemBand *)(bands->data), bands->len);
|
||||
g_array_unref (bands);
|
||||
|
||||
expected_bands_array = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), n_expected_bands);
|
||||
g_array_append_vals (expected_bands_array, expected_bands, n_expected_bands);
|
||||
mm_common_bands_garray_sort (expected_bands_array);
|
||||
expected_bands_str = mm_common_build_bands_string ((MMModemBand *)(expected_bands_array->data), expected_bands_array->len);
|
||||
g_array_unref (expected_bands_array);
|
||||
|
||||
g_assert_cmpstr (bands_str, ==, expected_bands_str);
|
||||
g_free (bands_str);
|
||||
g_free (expected_bands_str);
|
||||
}
|
||||
|
||||
static void
|
||||
test_ubandsel_response_four (void)
|
||||
{
|
||||
const MMModemBand expected_bands[] = {
|
||||
/* 850 */ MM_MODEM_BAND_G850, MM_MODEM_BAND_U850, MM_MODEM_BAND_EUTRAN_V,
|
||||
/* 900 */ MM_MODEM_BAND_EGSM, MM_MODEM_BAND_U900, MM_MODEM_BAND_EUTRAN_VIII,
|
||||
/* 1800 */ MM_MODEM_BAND_DCS, MM_MODEM_BAND_U1800, MM_MODEM_BAND_EUTRAN_III,
|
||||
/* 1900 */ MM_MODEM_BAND_PCS, MM_MODEM_BAND_U1900, MM_MODEM_BAND_EUTRAN_II,
|
||||
};
|
||||
|
||||
common_validate_ubandsel_response ("+UBANDSEL: 850,900,1800,1900\r\n", expected_bands, G_N_ELEMENTS (expected_bands));
|
||||
}
|
||||
|
||||
static void
|
||||
test_ubandsel_response_three (void)
|
||||
{
|
||||
const MMModemBand expected_bands[] = {
|
||||
/* 850 */ MM_MODEM_BAND_G850, MM_MODEM_BAND_U850, MM_MODEM_BAND_EUTRAN_V,
|
||||
/* 900 */ MM_MODEM_BAND_EGSM, MM_MODEM_BAND_U900, MM_MODEM_BAND_EUTRAN_VIII,
|
||||
/* 1800 */ MM_MODEM_BAND_DCS, MM_MODEM_BAND_U1800, MM_MODEM_BAND_EUTRAN_III,
|
||||
};
|
||||
|
||||
common_validate_ubandsel_response ("+UBANDSEL: 850,900,1800\r\n", expected_bands, G_N_ELEMENTS (expected_bands));
|
||||
}
|
||||
|
||||
static void
|
||||
test_ubandsel_response_two (void)
|
||||
{
|
||||
const MMModemBand expected_bands[] = {
|
||||
/* 850 */ MM_MODEM_BAND_G850, MM_MODEM_BAND_U850, MM_MODEM_BAND_EUTRAN_V,
|
||||
/* 900 */ MM_MODEM_BAND_EGSM, MM_MODEM_BAND_U900, MM_MODEM_BAND_EUTRAN_VIII,
|
||||
};
|
||||
|
||||
common_validate_ubandsel_response ("+UBANDSEL: 850,900\r\n", expected_bands, G_N_ELEMENTS (expected_bands));
|
||||
}
|
||||
|
||||
static void
|
||||
test_ubandsel_response_one (void)
|
||||
{
|
||||
const MMModemBand expected_bands[] = {
|
||||
/* 850 */ MM_MODEM_BAND_G850, MM_MODEM_BAND_U850, MM_MODEM_BAND_EUTRAN_V,
|
||||
};
|
||||
|
||||
common_validate_ubandsel_response ("+UBANDSEL: 850\r\n", expected_bands, G_N_ELEMENTS (expected_bands));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
@@ -638,5 +716,10 @@ int main (int argc, char **argv)
|
||||
g_test_add_func ("/MM/ublox/supported-bands/lisa-u200", test_supported_bands_lisa_u200);
|
||||
g_test_add_func ("/MM/ublox/supported-bands/sara-u280", test_supported_bands_sara_u280);
|
||||
|
||||
g_test_add_func ("/MM/ublox/ubandsel/response/one", test_ubandsel_response_one);
|
||||
g_test_add_func ("/MM/ublox/ubandsel/response/two", test_ubandsel_response_two);
|
||||
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);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user