<div dir="ltr"><div>Add support for querying the real-time clock to the Telit plugin.</div><div>Tested with a Telit HE910 modem.</div><div>---<br></div><div> plugins/telit/mm-broadband-modem-telit.c | 174 ++++++++++++++++++++++++++++++-</div><div> 1 file changed, 173 insertions(+), 1 deletion(-)</div><div><br></div><div>diff --git a/plugins/telit/mm-broadband-modem-telit.c b/plugins/telit/mm-broadband-modem-telit.c</div><div>index 5e1dbff..429a735 100644</div><div>--- a/plugins/telit/mm-broadband-modem-telit.c</div><div>+++ b/plugins/telit/mm-broadband-modem-telit.c</div><div>@@ -29,12 +29,15 @@</div><div> #include "mm-modem-helpers.h"</div><div> #include "mm-base-modem-at.h"</div><div> #include "mm-iface-modem.h"</div><div>+#include "mm-iface-modem-time.h"</div><div> #include "mm-broadband-modem-telit.h"</div><div> </div><div> static void iface_modem_init (MMIfaceModem *iface);</div><div>+static void iface_modem_time_init (MMIfaceModemTime *iface);</div><div> </div><div> G_DEFINE_TYPE_EXTENDED (MMBroadbandModemTelit, mm_broadband_modem_telit, MM_TYPE_BROADBAND_MODEM, 0,</div><div>-                        G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init));</div><div>+                        G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)</div><div>+                        G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_TIME, iface_modem_time_init));</div><div> </div><div> /*****************************************************************************/</div><div> /* Load access technologies (Modem interface) */</div><div>@@ -175,6 +178,164 @@ load_access_technologies (MMIfaceModem *self,</div><div> }</div><div> </div><div> /*****************************************************************************/</div><div>+/* Load network time (Time interface) */</div><div>+</div><div>+static gboolean</div><div>+parse_cclk_reply (const char *response,</div><div>+                  gchar **iso8601p,</div><div>+                  MMNetworkTimezone **tzp,</div><div>+                  GError **error)</div><div>+{</div><div>+    GRegex *r;</div><div>+    GMatchInfo *match_info = NULL;</div><div>+    GError *match_error = NULL;</div><div>+    guint year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;</div><div>+    gint tz = 0;</div><div>+    gboolean ret = FALSE;</div><div>+</div><div>+    g_assert (iso8601p || tzp); /* at least one */</div><div>+</div><div>+    /* Sample reply: +CCLK: "15/03/05,14:14:26-32" */</div><div>+    r = g_regex_new ("[+]CCLK: \"(\\d+)/(\\d+)/(\\d+),(\\d+):(\\d+):(\\d+)([-+]\\d+)\"", 0, 0, NULL);</div><div>+    g_assert (r != NULL);</div><div>+</div><div>+    if (!g_regex_match_full (r, response, -1, 0, 0, &match_info, &match_error)) {</div><div>+        if (match_error) {</div><div>+            g_propagate_error (error, match_error);</div><div>+            g_prefix_error (error, "Could not parse +CCLK results: ");</div><div>+        } else {</div><div>+            g_set_error_literal (error,</div><div>+                                 MM_CORE_ERROR,</div><div>+                                 MM_CORE_ERROR_FAILED,</div><div>+                                 "Couldn't match +CCLK reply");</div><div>+        }</div><div>+    } else {</div><div>+        /* Remember that g_match_info_get_match_count() includes match #0 */</div><div>+        g_assert (g_match_info_get_match_count (match_info) >= 8);</div><div>+</div><div>+        if (mm_get_uint_from_match_info (match_info, 1, &year) &&</div><div>+            mm_get_uint_from_match_info (match_info, 2, &month) &&</div><div>+            mm_get_uint_from_match_info (match_info, 3, &day) &&</div><div>+            mm_get_uint_from_match_info (match_info, 4, &hour) &&</div><div>+            mm_get_uint_from_match_info (match_info, 5, &minute) &&</div><div>+            mm_get_uint_from_match_info (match_info, 6, &second) &&</div><div>+            mm_get_int_from_match_info  (match_info, 7, &tz)) {</div><div>+            /* adjust year */</div><div>+            year += 2000;</div><div>+            /*</div><div>+             * tz = timezone offset in 15 minute intervals</div><div>+             */</div><div>+            if (iso8601p) {</div><div>+                /* Return ISO-8601 format date/time string */</div><div>+                *iso8601p = mm_new_iso8601_time (year, month, day, hour,</div><div>+                                                 minute, second,</div><div>+                                                 TRUE, (tz * 15));</div><div>+            }</div><div>+            if (tzp) {</div><div>+                *tzp = mm_network_timezone_new ();</div><div>+                mm_network_timezone_set_offset (*tzp, tz * 15);</div><div>+            }</div><div>+</div><div>+            ret = TRUE;</div><div>+        } else {</div><div>+            g_set_error_literal (error,</div><div>+                                 MM_CORE_ERROR,</div><div>+                                 MM_CORE_ERROR_FAILED,</div><div>+                                 "Failed to parse +CCLK reply");</div><div>+        }</div><div>+    }</div><div>+</div><div>+    if (match_info)</div><div>+        g_match_info_free (match_info);</div><div>+    g_regex_unref (r);</div><div>+</div><div>+    return ret;</div><div>+}</div><div>+</div><div>+static gchar *</div><div>+modem_time_load_network_time_finish (MMIfaceModemTime *self,</div><div>+                                     GAsyncResult *res,</div><div>+                                     GError **error)</div><div>+{</div><div>+    const gchar *response;</div><div>+    gchar *result = NULL;</div><div>+</div><div>+    response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);</div><div>+    if (response)</div><div>+        parse_cclk_reply (response, &result, NULL, error);</div><div>+    return result;</div><div>+}</div><div>+</div><div>+static void</div><div>+modem_time_load_network_time (MMIfaceModemTime *self,</div><div>+                              GAsyncReadyCallback callback,</div><div>+                              gpointer user_data)</div><div>+{</div><div>+    mm_base_modem_at_command (MM_BASE_MODEM (self),</div><div>+                              "+CCLK?",</div><div>+                              3,</div><div>+                              FALSE,</div><div>+                              callback,</div><div>+                              user_data);</div><div>+}</div><div>+</div><div>+/*****************************************************************************/</div><div>+/* Load network timezone (Time interface) */</div><div>+</div><div>+static MMNetworkTimezone *</div><div>+modem_time_load_network_timezone_finish (MMIfaceModemTime *self,</div><div>+                                         GAsyncResult *res,</div><div>+                                         GError **error)</div><div>+{</div><div>+    const gchar *response;</div><div>+    MMNetworkTimezone *tz = NULL;</div><div>+</div><div>+    response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, NULL);</div><div>+    if (response)</div><div>+        parse_cclk_reply (response, NULL, &tz, error);</div><div>+    return tz;</div><div>+}</div><div>+</div><div>+static void</div><div>+modem_time_load_network_timezone (MMIfaceModemTime *self,</div><div>+                                  GAsyncReadyCallback callback,</div><div>+                                  gpointer user_data)</div><div>+{</div><div>+    mm_base_modem_at_command (MM_BASE_MODEM (self),</div><div>+                              "+CCLK?",</div><div>+                              3,</div><div>+                              FALSE,</div><div>+                              callback,</div><div>+                              user_data);</div><div>+}</div><div>+</div><div>+/*****************************************************************************/</div><div>+/* Check support (Time interface) */</div><div>+</div><div>+static gboolean</div><div>+modem_time_check_support_finish (MMIfaceModemTime *self,</div><div>+                                 GAsyncResult *res,</div><div>+                                 GError **error)</div><div>+{</div><div>+    g_debug("modem_time_check_support_finish");</div><div>+    return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);</div><div>+}</div><div>+</div><div>+static void</div><div>+modem_time_check_support (MMIfaceModemTime *self,</div><div>+                          GAsyncReadyCallback callback,</div><div>+                          gpointer user_data)</div><div>+{</div><div>+    g_debug("modem_time_check_support");</div><div>+    mm_base_modem_at_command (MM_BASE_MODEM (self),</div><div>+                              "+CCLK?",</div><div>+                              3,</div><div>+                              TRUE,</div><div>+                              callback,</div><div>+                              user_data);</div><div>+}</div><div>+</div><div>+/*****************************************************************************/</div><div> </div><div> MMBroadbandModemTelit *</div><div> mm_broadband_modem_telit_new (const gchar *device,</div><div>@@ -205,6 +366,17 @@ iface_modem_init (MMIfaceModem *iface)</div><div> }</div><div> </div><div> static void</div><div>+iface_modem_time_init (MMIfaceModemTime *iface)</div><div>+{</div><div>+    iface->check_support = modem_time_check_support;</div><div>+    iface->check_support_finish = modem_time_check_support_finish;</div><div>+    iface->load_network_time = modem_time_load_network_time;</div><div>+    iface->load_network_time_finish = modem_time_load_network_time_finish;</div><div>+    iface->load_network_timezone = modem_time_load_network_timezone;</div><div>+    iface->load_network_timezone_finish = modem_time_load_network_timezone_finish;</div><div>+}</div><div>+</div><div>+static void</div><div> mm_broadband_modem_telit_class_init (MMBroadbandModemTelitClass *klass)</div><div> {</div><div> }</div><div>-- </div><div>2.2.0.rc0.207.ga3a616c</div><div><br></div></div>