ublox: new u-blox specific +CFUN? response parser

This commit is contained in:
Aleksander Morgado
2016-10-12 11:29:52 +02:00
parent d7fdda2247
commit 151d608eec
3 changed files with 77 additions and 0 deletions
+32
View File
@@ -241,6 +241,38 @@ out:
return TRUE;
}
/*****************************************************************************/
/* CFUN? response parser */
gboolean
mm_ublox_parse_cfun_response (const gchar *response,
MMModemPowerState *out_state,
GError **error)
{
guint state;
if (!mm_3gpp_parse_cfun_query_response (response, &state, error))
return FALSE;
switch (state) {
case 1:
*out_state = MM_MODEM_POWER_STATE_ON;
return TRUE;
case 0:
/* minimum functionality */
case 4:
/* airplane mode */
case 19:
/* minimum functionality with SIM deactivated */
*out_state = MM_MODEM_POWER_STATE_LOW;
return TRUE;
default:
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Unknown +CFUN state: %u", state);
return FALSE;
}
}
/*****************************************************************************/
/* URAT=? response parser */
+7
View File
@@ -58,6 +58,13 @@ gboolean mm_ublox_parse_uipaddr_response (const gchar *response,
gchar **out_ipv6_link_local_address,
GError **error);
/*****************************************************************************/
/* CFUN? response parser */
gboolean mm_ublox_parse_cfun_response (const gchar *response,
MMModemPowerState *out_state,
GError **error);
/*****************************************************************************/
/* URAT=? response parser */
@@ -181,6 +181,42 @@ test_uipaddr_response (void)
}
}
/*****************************************************************************/
/* Test CFUN? response */
typedef struct {
const gchar *str;
MMModemPowerState state;
} CfunQueryTest;
static const CfunQueryTest cfun_query_tests[] = {
{ "+CFUN: 1", MM_MODEM_POWER_STATE_ON },
{ "+CFUN: 1,0", MM_MODEM_POWER_STATE_ON },
{ "+CFUN: 0", MM_MODEM_POWER_STATE_LOW },
{ "+CFUN: 0,0", MM_MODEM_POWER_STATE_LOW },
{ "+CFUN: 4", MM_MODEM_POWER_STATE_LOW },
{ "+CFUN: 4,0", MM_MODEM_POWER_STATE_LOW },
{ "+CFUN: 19", MM_MODEM_POWER_STATE_LOW },
{ "+CFUN: 19,0", MM_MODEM_POWER_STATE_LOW },
};
static void
test_cfun_response (void)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (cfun_query_tests); i++) {
GError *error = NULL;
gboolean success;
MMModemPowerState state = MM_MODEM_POWER_STATE_UNKNOWN;
success = mm_ublox_parse_cfun_response (cfun_query_tests[i].str, &state, &error);
g_assert_no_error (error);
g_assert (success);
g_assert_cmpuint (cfun_query_tests[i].state, ==, state);
}
}
/*****************************************************************************/
/* Test URAT=? responses and model based filtering */
@@ -398,9 +434,11 @@ int main (int argc, char **argv)
g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/MM/ublox/uusbconf/response", test_uusbconf_response);
g_test_add_func ("/MM/ublox/ubmconf/response", test_ubmconf_response);
g_test_add_func ("/MM/ublox/uipaddr/response", test_uipaddr_response);
g_test_add_func ("/MM/ublox/cfun/response", test_cfun_response);
g_test_add_func ("/MM/ublox/urat/test/response/2g", test_urat_test_response_2g);
g_test_add_func ("/MM/ublox/urat/test/response/2g3g", test_urat_test_response_2g3g);
g_test_add_func ("/MM/ublox/urat/test/response/2g3g4g", test_urat_test_response_2g3g4g);