Re: [PATCH 3/5] cinterion: setup GPS port only if GPS support detected

2017-05-30 Thread Aleksander Morgado
On 17/05/17 15:24, Aleksander Morgado wrote:
> i.e. if AT^SGPSS not supported, we don't even add traces handler to
> the GPS data port.
> ---

This has been merged to git master.

>  plugins/cinterion/mm-broadband-modem-cinterion.c   |  14 ---
>  .../cinterion/mm-broadband-modem-qmi-cinterion.c   |  16 
>  plugins/cinterion/mm-common-cinterion.c| 103 
> ++---
>  plugins/cinterion/mm-common-cinterion.h|   2 -
>  4 files changed, 47 insertions(+), 88 deletions(-)
> 
> diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c 
> b/plugins/cinterion/mm-broadband-modem-cinterion.c
> index 4a4e18bf..fc9a3356 100644
> --- a/plugins/cinterion/mm-broadband-modem-cinterion.c
> +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c
> @@ -1586,18 +1586,6 @@ after_sim_unlock (MMIfaceModem *self,
>  }
>  
>  
> /*/
> -/* Setup ports (Broadband modem class) */
> -
> -static void
> -setup_ports (MMBroadbandModem *self)
> -{
> -/* Call parent's setup ports first always */
> -MM_BROADBAND_MODEM_CLASS 
> (mm_broadband_modem_cinterion_parent_class)->setup_ports (self);
> -
> -mm_common_cinterion_setup_gps_port (self);
> -}
> -
> -/*/
>  /* Create Bearer (Modem interface) */
>  
>  typedef struct {
> @@ -1868,11 +1856,9 @@ static void
>  mm_broadband_modem_cinterion_class_init (MMBroadbandModemCinterionClass 
> *klass)
>  {
>  GObjectClass *object_class = G_OBJECT_CLASS (klass);
> -MMBroadbandModemClass *broadband_modem_class = MM_BROADBAND_MODEM_CLASS 
> (klass);
>  
>  g_type_class_add_private (object_class, sizeof 
> (MMBroadbandModemCinterionPrivate));
>  
>  /* Virtual methods */
>  object_class->finalize = finalize;
> -broadband_modem_class->setup_ports = setup_ports;
>  }
> diff --git a/plugins/cinterion/mm-broadband-modem-qmi-cinterion.c 
> b/plugins/cinterion/mm-broadband-modem-qmi-cinterion.c
> index 05f92e4f..2410d091 100644
> --- a/plugins/cinterion/mm-broadband-modem-qmi-cinterion.c
> +++ b/plugins/cinterion/mm-broadband-modem-qmi-cinterion.c
> @@ -35,18 +35,6 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQmiCinterion, 
> mm_broadband_modem_qmi_cin
>  G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, 
> iface_modem_location_init))
>  
>  
> /*/
> -/* Setup ports (Broadband modem class) */
> -
> -static void
> -setup_ports (MMBroadbandModem *self)
> -{
> -/* Call parent's setup ports first always */
> -MM_BROADBAND_MODEM_CLASS 
> (mm_broadband_modem_qmi_cinterion_parent_class)->setup_ports (self);
> -
> -mm_common_cinterion_setup_gps_port (self);
> -}
> -
> -/*/
>  
>  MMBroadbandModemQmiCinterion *
>  mm_broadband_modem_qmi_cinterion_new (const gchar *device,
> @@ -85,8 +73,4 @@ iface_modem_location_init (MMIfaceModemLocation *iface)
>  static void
>  mm_broadband_modem_qmi_cinterion_class_init 
> (MMBroadbandModemQmiCinterionClass *klass)
>  {
> -MMBroadbandModemClass *broadband_modem_class = MM_BROADBAND_MODEM_CLASS 
> (klass);
> -
> -/* Virtual methods */
> -broadband_modem_class->setup_ports = setup_ports;
>  }
> diff --git a/plugins/cinterion/mm-common-cinterion.c 
> b/plugins/cinterion/mm-common-cinterion.c
> index 91af530f..ce337bd9 100644
> --- a/plugins/cinterion/mm-common-cinterion.c
> +++ b/plugins/cinterion/mm-common-cinterion.c
> @@ -16,6 +16,7 @@
>  
>  #include "mm-common-cinterion.h"
>  #include "mm-base-modem-at.h"
> +#include "mm-log.h"
>  
>  static MMIfaceModemLocation *iface_modem_location_parent;
>  
> @@ -70,6 +71,38 @@ get_location_context (MMBaseModem *self)
>  }
>  
>  
> /*/
> +/* GPS trace received */
> +
> +static void
> +trace_received (MMPortSerialGps *port,
> +const gchar *trace,
> +MMIfaceModemLocation *self)
> +{
> +/* Helper to debug GPS location related issues. Don't depend on a real 
> GPS
> + * fix for debugging, just use some random values to update */
> +#if 0
> +if (g_str_has_prefix (trace, "$GPGGA")) {
> +GString *str;
> +GDateTime *now;
> +
> +now = g_date_time_new_now_utc ();
> +str = g_string_new ("");
> +g_string_append_printf (str,
> +
> "$GPGGA,%02u%02u%02u,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47",
> +g_date_time_get_hour (now),
> +g_date_time_get_minute (now),
> +g_date_time_get_second (now));
> +mm_iface_modem_location_gps_update (self, str->str);
> +g_string_free (str, TRUE);
> +g_date_time_unref (now);
> +

[PATCH 3/5] cinterion: setup GPS port only if GPS support detected

2017-05-17 Thread Aleksander Morgado
i.e. if AT^SGPSS not supported, we don't even add traces handler to
the GPS data port.
---
 plugins/cinterion/mm-broadband-modem-cinterion.c   |  14 ---
 .../cinterion/mm-broadband-modem-qmi-cinterion.c   |  16 
 plugins/cinterion/mm-common-cinterion.c| 103 ++---
 plugins/cinterion/mm-common-cinterion.h|   2 -
 4 files changed, 47 insertions(+), 88 deletions(-)

diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c 
b/plugins/cinterion/mm-broadband-modem-cinterion.c
index 4a4e18bf..fc9a3356 100644
--- a/plugins/cinterion/mm-broadband-modem-cinterion.c
+++ b/plugins/cinterion/mm-broadband-modem-cinterion.c
@@ -1586,18 +1586,6 @@ after_sim_unlock (MMIfaceModem *self,
 }
 
 /*/
-/* Setup ports (Broadband modem class) */
-
-static void
-setup_ports (MMBroadbandModem *self)
-{
-/* Call parent's setup ports first always */
-MM_BROADBAND_MODEM_CLASS 
(mm_broadband_modem_cinterion_parent_class)->setup_ports (self);
-
-mm_common_cinterion_setup_gps_port (self);
-}
-
-/*/
 /* Create Bearer (Modem interface) */
 
 typedef struct {
@@ -1868,11 +1856,9 @@ static void
 mm_broadband_modem_cinterion_class_init (MMBroadbandModemCinterionClass *klass)
 {
 GObjectClass *object_class = G_OBJECT_CLASS (klass);
-MMBroadbandModemClass *broadband_modem_class = MM_BROADBAND_MODEM_CLASS 
(klass);
 
 g_type_class_add_private (object_class, sizeof 
(MMBroadbandModemCinterionPrivate));
 
 /* Virtual methods */
 object_class->finalize = finalize;
-broadband_modem_class->setup_ports = setup_ports;
 }
diff --git a/plugins/cinterion/mm-broadband-modem-qmi-cinterion.c 
b/plugins/cinterion/mm-broadband-modem-qmi-cinterion.c
index 05f92e4f..2410d091 100644
--- a/plugins/cinterion/mm-broadband-modem-qmi-cinterion.c
+++ b/plugins/cinterion/mm-broadband-modem-qmi-cinterion.c
@@ -35,18 +35,6 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemQmiCinterion, 
mm_broadband_modem_qmi_cin
 G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_LOCATION, 
iface_modem_location_init))
 
 /*/
-/* Setup ports (Broadband modem class) */
-
-static void
-setup_ports (MMBroadbandModem *self)
-{
-/* Call parent's setup ports first always */
-MM_BROADBAND_MODEM_CLASS 
(mm_broadband_modem_qmi_cinterion_parent_class)->setup_ports (self);
-
-mm_common_cinterion_setup_gps_port (self);
-}
-
-/*/
 
 MMBroadbandModemQmiCinterion *
 mm_broadband_modem_qmi_cinterion_new (const gchar *device,
@@ -85,8 +73,4 @@ iface_modem_location_init (MMIfaceModemLocation *iface)
 static void
 mm_broadband_modem_qmi_cinterion_class_init (MMBroadbandModemQmiCinterionClass 
*klass)
 {
-MMBroadbandModemClass *broadband_modem_class = MM_BROADBAND_MODEM_CLASS 
(klass);
-
-/* Virtual methods */
-broadband_modem_class->setup_ports = setup_ports;
 }
diff --git a/plugins/cinterion/mm-common-cinterion.c 
b/plugins/cinterion/mm-common-cinterion.c
index 91af530f..ce337bd9 100644
--- a/plugins/cinterion/mm-common-cinterion.c
+++ b/plugins/cinterion/mm-common-cinterion.c
@@ -16,6 +16,7 @@
 
 #include "mm-common-cinterion.h"
 #include "mm-base-modem-at.h"
+#include "mm-log.h"
 
 static MMIfaceModemLocation *iface_modem_location_parent;
 
@@ -70,6 +71,38 @@ get_location_context (MMBaseModem *self)
 }
 
 /*/
+/* GPS trace received */
+
+static void
+trace_received (MMPortSerialGps *port,
+const gchar *trace,
+MMIfaceModemLocation *self)
+{
+/* Helper to debug GPS location related issues. Don't depend on a real GPS
+ * fix for debugging, just use some random values to update */
+#if 0
+if (g_str_has_prefix (trace, "$GPGGA")) {
+GString *str;
+GDateTime *now;
+
+now = g_date_time_new_now_utc ();
+str = g_string_new ("");
+g_string_append_printf (str,
+
"$GPGGA,%02u%02u%02u,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47",
+g_date_time_get_hour (now),
+g_date_time_get_minute (now),
+g_date_time_get_second (now));
+mm_iface_modem_location_gps_update (self, str->str);
+g_string_free (str, TRUE);
+g_date_time_unref (now);
+return;
+}
+#endif
+
+mm_iface_modem_location_gps_update (self, trace);
+}
+
+/*/
 /* Location capabilities loading (Location interface) */
 
 typedef struct {
@@ -107,8 +140,15 @@ sgpss_test_ready (MMBaseModem  *self,
 location_ctx = get_location_context (self);
 if