modem-helpers: new +CESQ response parser
This commit is contained in:
@@ -1856,6 +1856,98 @@ out:
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* +CESQ response parser */
|
||||
|
||||
gboolean
|
||||
mm_3gpp_parse_cesq_response (const gchar *response,
|
||||
guint *out_rxlev,
|
||||
guint *out_ber,
|
||||
guint *out_rscp,
|
||||
guint *out_ecn0,
|
||||
guint *out_rsrq,
|
||||
guint *out_rsrp,
|
||||
GError **error)
|
||||
{
|
||||
GRegex *r;
|
||||
GMatchInfo *match_info;
|
||||
GError *inner_error = NULL;
|
||||
guint rxlev = 0;
|
||||
guint ber = 0;
|
||||
guint rscp = 0;
|
||||
guint ecn0 = 0;
|
||||
guint rsrq = 0;
|
||||
guint rsrp = 0;
|
||||
gboolean success = FALSE;
|
||||
|
||||
g_assert (out_rxlev);
|
||||
g_assert (out_ber);
|
||||
g_assert (out_rscp);
|
||||
g_assert (out_ecn0);
|
||||
g_assert (out_rsrq);
|
||||
g_assert (out_rsrp);
|
||||
|
||||
/* Response may be e.g.:
|
||||
* +CESQ: 99,99,255,255,20,80
|
||||
*/
|
||||
r = g_regex_new ("\\+CESQ: (\\d+),(\\d+),(\\d+),(\\d+),(\\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 && g_match_info_matches (match_info)) {
|
||||
if (!mm_get_uint_from_match_info (match_info, 1, &rxlev)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't read RXLEV");
|
||||
goto out;
|
||||
}
|
||||
if (!mm_get_uint_from_match_info (match_info, 2, &ber)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't read BER");
|
||||
goto out;
|
||||
}
|
||||
if (!mm_get_uint_from_match_info (match_info, 3, &rscp)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't read RSCP");
|
||||
goto out;
|
||||
}
|
||||
if (!mm_get_uint_from_match_info (match_info, 4, &ecn0)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't read Ec/N0");
|
||||
goto out;
|
||||
}
|
||||
if (!mm_get_uint_from_match_info (match_info, 5, &rsrq)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't read RSRQ");
|
||||
goto out;
|
||||
}
|
||||
if (!mm_get_uint_from_match_info (match_info, 6, &rsrp)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't read RSRP");
|
||||
goto out;
|
||||
}
|
||||
success = TRUE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse +CESQ response: %s", response);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*out_rxlev = rxlev;
|
||||
*out_ber = ber;
|
||||
*out_rscp = rscp;
|
||||
*out_ecn0 = ecn0;
|
||||
*out_rsrq = rsrq;
|
||||
*out_rsrp = rsrp;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
gboolean
|
||||
|
@@ -264,6 +264,16 @@ gboolean mm_3gpp_parse_cfun_query_generic_response (const gchar *response
|
||||
MMModemPowerState *out_state,
|
||||
GError **error);
|
||||
|
||||
/* +CESQ response parser */
|
||||
gboolean mm_3gpp_parse_cesq_response (const gchar *response,
|
||||
guint *out_rxlev,
|
||||
guint *out_ber,
|
||||
guint *out_rscp,
|
||||
guint *out_ecn0,
|
||||
guint *out_rsrq,
|
||||
guint *out_rsrp,
|
||||
GError **error);
|
||||
|
||||
/* Additional 3GPP-specific helpers */
|
||||
|
||||
MMModem3gppFacility mm_3gpp_acronym_to_facility (const gchar *str);
|
||||
|
@@ -3081,6 +3081,7 @@ test_cgcontrdp_response (void)
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
<<<<<<< HEAD
|
||||
/* Test CFUN? response */
|
||||
|
||||
typedef struct {
|
||||
@@ -3111,6 +3112,79 @@ test_cfun_response (void)
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
g_assert_cmpuint (cfun_query_tests[i].state, ==, state);
|
||||
=======
|
||||
/* Test +CESQ responses */
|
||||
|
||||
typedef struct {
|
||||
const gchar *str;
|
||||
guint rxlev;
|
||||
guint ber;
|
||||
guint rscp;
|
||||
guint ecn0;
|
||||
guint rsrq;
|
||||
guint rsrp;
|
||||
} CesqResponseTest;
|
||||
|
||||
static const CesqResponseTest cesq_response_tests[] = {
|
||||
{
|
||||
.str = "+CESQ: 99,99,255,255,20,80",
|
||||
.rxlev = 99,
|
||||
.ber = 99,
|
||||
.rscp = 255,
|
||||
.ecn0 = 255,
|
||||
.rsrq = 20,
|
||||
.rsrp = 80
|
||||
},
|
||||
{
|
||||
.str = "+CESQ: 99,99,95,40,255,255",
|
||||
.rxlev = 99,
|
||||
.ber = 99,
|
||||
.rscp = 95,
|
||||
.ecn0 = 40,
|
||||
.rsrq = 255,
|
||||
.rsrp = 255
|
||||
},
|
||||
{
|
||||
.str = "+CESQ: 10,6,255,255,255,255",
|
||||
.rxlev = 10,
|
||||
.ber = 6,
|
||||
.rscp = 255,
|
||||
.ecn0 = 255,
|
||||
.rsrq = 255,
|
||||
.rsrp = 255
|
||||
}
|
||||
};
|
||||
|
||||
static void
|
||||
test_cesq_response (void)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (cesq_response_tests); i++) {
|
||||
GError *error = NULL;
|
||||
gboolean success;
|
||||
guint rxlev = G_MAXUINT;
|
||||
guint ber = G_MAXUINT;
|
||||
guint rscp = G_MAXUINT;
|
||||
guint ecn0 = G_MAXUINT;
|
||||
guint rsrq = G_MAXUINT;
|
||||
guint rsrp = G_MAXUINT;
|
||||
|
||||
success = mm_3gpp_parse_cesq_response (cesq_response_tests[i].str,
|
||||
&rxlev, &ber,
|
||||
&rscp, &ecn0,
|
||||
&rsrq, &rsrp,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
|
||||
g_assert_cmpuint (cesq_response_tests[i].rxlev, ==, rxlev);
|
||||
g_assert_cmpuint (cesq_response_tests[i].ber, ==, ber);
|
||||
g_assert_cmpuint (cesq_response_tests[i].rscp, ==, rscp);
|
||||
g_assert_cmpuint (cesq_response_tests[i].ecn0, ==, ecn0);
|
||||
g_assert_cmpuint (cesq_response_tests[i].rsrq, ==, rsrq);
|
||||
g_assert_cmpuint (cesq_response_tests[i].rsrp, ==, rsrp);
|
||||
>>>>>>> fa0bc3bc... modem-helpers: new +CESQ response parser
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3380,6 +3454,8 @@ int main (int argc, char **argv)
|
||||
g_test_suite_add (suite, TESTCASE (test_cfun_response, NULL));
|
||||
g_test_suite_add (suite, TESTCASE (test_cfun_generic_response, NULL));
|
||||
|
||||
g_test_suite_add (suite, TESTCASE (test_cesq_response, NULL));
|
||||
|
||||
g_test_suite_add (suite, TESTCASE (test_parse_uint_list, NULL));
|
||||
|
||||
result = g_test_run ();
|
||||
|
Reference in New Issue
Block a user