broadband-modem: default implementation of the network time interface

Add a default implementation that queries the real-time clock using the
AT+CCLK? command.  Also set AT+CTZU=1 in case a modem requires it.
This commit is contained in:
Jason Simmons
2015-03-13 15:30:58 -07:00
committed by Aleksander Morgado
parent a92566ec0e
commit 3ad64c8f5a
4 changed files with 253 additions and 0 deletions

View File

@@ -2340,6 +2340,77 @@ test_supported_capability_filter (void *f, gpointer d)
g_array_unref (combinations);
}
/*****************************************************************************/
/* Test +CCLK responses */
typedef struct {
const gchar *str;
gboolean ret;
gboolean test_iso8601;
gboolean test_tz;
gchar *iso8601;
gint32 offset;
} CclkTest;
static const CclkTest cclk_tests[] = {
{ "+CCLK: \"14/08/05,04:00:21+40\"", TRUE, TRUE, FALSE,
"2014-08-05T04:00:21+10:00", 600 },
{ "+CCLK: \"14/08/05,04:00:21+40\"", TRUE, FALSE, TRUE,
"2014-08-05T04:00:21+10:00", 600 },
{ "+CCLK: \"14/08/05,04:00:21+40\"", TRUE, TRUE, TRUE,
"2014-08-05T04:00:21+10:00", 600 },
{ "+CCLK: \"15/02/28,20:30:40-32\"", TRUE, TRUE, FALSE,
"2015-02-28T20:30:40-08:00", -480 },
{ "+CCLK: \"15/02/28,20:30:40-32\"", TRUE, FALSE, TRUE,
"2015-02-28T20:30:40-08:00", -480 },
{ "+CCLK: \"15/02/28,20:30:40-32\"", TRUE, TRUE, TRUE,
"2015-02-28T20:30:40-08:00", -480 },
{ "+CCLK: \"XX/XX/XX,XX:XX:XX+XX\"", FALSE, TRUE, FALSE,
NULL, MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN },
{ NULL, FALSE, FALSE, FALSE, NULL, MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN }
};
static void
test_cclk_response (void)
{
guint i;
for (i = 0; cclk_tests[i].str; i++) {
GError *error = NULL;
gchar *iso8601 = NULL;
MMNetworkTimezone *tz = NULL;
gboolean ret;
ret = mm_parse_cclk_response (cclk_tests[i].str,
cclk_tests[i].test_iso8601 ? &iso8601 : NULL,
cclk_tests[i].test_tz ? &tz : NULL,
&error);
g_assert (ret == cclk_tests[i].ret);
g_assert (ret == (error ? FALSE : TRUE));
g_clear_error (&error);
if (cclk_tests[i].test_iso8601)
g_assert_cmpstr (cclk_tests[i].iso8601, ==, iso8601);
if (cclk_tests[i].test_tz) {
g_assert (mm_network_timezone_get_offset (tz) == cclk_tests[i].offset);
g_assert (mm_network_timezone_get_dst_offset (tz) == MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN);
g_assert (mm_network_timezone_get_leap_seconds (tz) == MM_NETWORK_TIMEZONE_LEAP_SECONDS_UNKNOWN);
}
if (iso8601)
g_free (iso8601);
if (tz)
g_object_unref (tz);
}
}
/*****************************************************************************/
void
@@ -2501,6 +2572,8 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_supported_capability_filter, NULL));
g_test_suite_add (suite, TESTCASE (test_cclk_response, NULL));
result = g_test_run ();
reg_test_data_free (reg_data);