huawei: new ^PREFMODE? response parser
This commit is contained in:
@@ -366,6 +366,52 @@ mm_huawei_parse_prefmode_test (const gchar *response,
|
||||
return out;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^PREFMODE response parser */
|
||||
|
||||
const MMHuaweiPrefmodeCombination *
|
||||
mm_huawei_parse_prefmode_response (const gchar *response,
|
||||
const GArray *supported_mode_combinations,
|
||||
GError **error)
|
||||
{
|
||||
gint mode;
|
||||
guint i;
|
||||
|
||||
/* Format:
|
||||
*
|
||||
* ^PREFMODE: <mode>
|
||||
*/
|
||||
|
||||
response = mm_strip_tag (response, "^PREFMODE:");
|
||||
if (!sscanf (response, "%d", &mode)) {
|
||||
/* Dump error to upper layer */
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Unexpected PREFMODE response: '%s'",
|
||||
response);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Look for current modes among the supported ones */
|
||||
for (i = 0; i < supported_mode_combinations->len; i++) {
|
||||
const MMHuaweiPrefmodeCombination *combination;
|
||||
|
||||
combination = &g_array_index (supported_mode_combinations,
|
||||
MMHuaweiPrefmodeCombination,
|
||||
i);
|
||||
if (mode == combination->prefmode)
|
||||
return combination;
|
||||
}
|
||||
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"No PREFMODE combination found matching the current one (%d)",
|
||||
mode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SYSCFG test parser */
|
||||
|
||||
|
||||
@@ -63,6 +63,13 @@ typedef struct {
|
||||
GArray *mm_huawei_parse_prefmode_test (const gchar *response,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^PREFMODE response parser */
|
||||
|
||||
const MMHuaweiPrefmodeCombination *mm_huawei_parse_prefmode_response (const gchar *response,
|
||||
const GArray *supported_mode_combinations,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SYSCFG test parser */
|
||||
|
||||
|
||||
@@ -373,6 +373,61 @@ test_prefmode (void)
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Test ^PREFMODE? responses */
|
||||
|
||||
typedef struct {
|
||||
const gchar *str;
|
||||
const gchar *format;
|
||||
MMModemMode allowed;
|
||||
MMModemMode preferred;
|
||||
} PrefmodeResponseTest;
|
||||
|
||||
static const PrefmodeResponseTest prefmode_response_tests[] = {
|
||||
{
|
||||
.str = "^PREFMODE:2\r\n",
|
||||
.format = "^PREFMODE:(2,4,8)\r\n",
|
||||
.allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_2G),
|
||||
.preferred = MM_MODEM_MODE_2G
|
||||
},
|
||||
{
|
||||
.str = "^PREFMODE:4\r\n",
|
||||
.format = "^PREFMODE:(2,4,8)\r\n",
|
||||
.allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_2G),
|
||||
.preferred = MM_MODEM_MODE_3G
|
||||
},
|
||||
{
|
||||
.str = "^PREFMODE:8\r\n",
|
||||
.format = "^PREFMODE:(2,4,8)\r\n",
|
||||
.allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_2G),
|
||||
.preferred = MM_MODEM_MODE_NONE
|
||||
}
|
||||
};
|
||||
|
||||
static void
|
||||
test_prefmode_response (void)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (prefmode_response_tests); i++) {
|
||||
GArray *combinations = NULL;
|
||||
const MMHuaweiPrefmodeCombination *found;
|
||||
GError *error = NULL;
|
||||
|
||||
combinations = mm_huawei_parse_prefmode_test (prefmode_response_tests[i].format, NULL);
|
||||
g_assert (combinations != NULL);
|
||||
|
||||
found = mm_huawei_parse_prefmode_response (prefmode_response_tests[i].str,
|
||||
combinations,
|
||||
&error);
|
||||
g_assert (found != NULL);
|
||||
g_assert_cmpuint (found->allowed, ==, prefmode_response_tests[i].allowed);
|
||||
g_assert_cmpuint (found->preferred, ==, prefmode_response_tests[i].preferred);
|
||||
|
||||
g_array_unref (combinations);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Test ^SYSCFG=? responses */
|
||||
|
||||
@@ -739,6 +794,7 @@ int main (int argc, char **argv)
|
||||
g_test_add_func ("/MM/huawei/sysinfo", test_sysinfo);
|
||||
g_test_add_func ("/MM/huawei/sysinfoex", test_sysinfoex);
|
||||
g_test_add_func ("/MM/huawei/prefmode", test_prefmode);
|
||||
g_test_add_func ("/MM/huawei/prefmode/response", test_prefmode_response);
|
||||
g_test_add_func ("/MM/huawei/syscfg", test_syscfg);
|
||||
g_test_add_func ("/MM/huawei/syscfgex", test_syscfgex);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user