modem-helpers: new +CFUN? response parser
This commit is contained in:
@@ -1858,6 +1858,85 @@ out:
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
gboolean
|
||||
mm_3gpp_parse_cfun_query_response (const gchar *response,
|
||||
guint *out_state,
|
||||
GError **error)
|
||||
{
|
||||
GRegex *r;
|
||||
GMatchInfo *match_info;
|
||||
GError *inner_error = NULL;
|
||||
guint state = G_MAXUINT;
|
||||
|
||||
g_assert (out_state != NULL);
|
||||
|
||||
/* Response may be e.g.:
|
||||
* +CFUN: 1,0
|
||||
* ..but we don't care about the second number
|
||||
*/
|
||||
r = g_regex_new ("\\+CFUN: (\\d+)(?:,(?:\\d+))?(?:\\r\\n)?", 0, 0, NULL);
|
||||
g_assert (r != NULL);
|
||||
|
||||
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
|
||||
if (inner_error)
|
||||
goto out;
|
||||
|
||||
if (!g_match_info_matches (match_info)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse +CFUN response: %s", response);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!mm_get_uint_from_match_info (match_info, 1, &state)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Couldn't read power state value");
|
||||
goto out;
|
||||
}
|
||||
|
||||
*out_state = state;
|
||||
|
||||
out:
|
||||
if (match_info)
|
||||
g_match_info_free (match_info);
|
||||
g_regex_unref (r);
|
||||
|
||||
if (inner_error) {
|
||||
g_propagate_error (error, inner_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_3gpp_parse_cfun_query_generic_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 0:
|
||||
*out_state = MM_MODEM_POWER_STATE_OFF;
|
||||
return TRUE;
|
||||
case 1:
|
||||
*out_state = MM_MODEM_POWER_STATE_ON;
|
||||
return TRUE;
|
||||
case 4:
|
||||
*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;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
static MMSmsStorage
|
||||
storage_from_str (const gchar *str)
|
||||
{
|
||||
|
Reference in New Issue
Block a user