Re: [PATCH] Coldstart fix v2 and dynamic signal quality



well... now there IS a patch attached also...

Per Hallsmark wrote:
Hello,

Here's a patch to the MBM plugin making a nicer coldstart patch than v1 (adding cleanup of allocations) and dynamic signal quality via unsolicited responses (no need for polling)

We also get info about roaming active or not, is it possible to display somehow? (not sure if the english cows sounds like swedish but here they roam, so why not a roaming cow vers a silent cow? :-D )

Regards,
Per

_______________________________________________
NetworkManager-list mailing list
NetworkManager-list gnome org
http://mail.gnome.org/mailman/listinfo/networkmanager-list

--- foss/modemmanager/mainline/plugins/mm-modem-mbm.c	2008-10-29 16:35:58.000000000 +0100
+++ src/modemmanager/plugins/mm-modem-mbm.c	2008-10-29 19:00:52.000000000 +0100
@@ -3,6 +3,8 @@
   Additions to NetworkManager, network-manager-applet and modemmanager
   for supporting Ericsson modules like F3507g.
 
+  Copyright (C) 2008 Ericsson MBM
+
   Author: Per Hallsmark <per hallsmark se>
           Bjorn Runaker <bjorn runaker ericsson com>
 
@@ -23,10 +25,12 @@
 
 */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <string.h>
 #include <stdlib.h>
 #include <arpa/inet.h>
 #include <dbus/dbus-glib.h>
@@ -43,6 +47,10 @@ static gpointer mm_modem_mbm_parent_clas
 
 typedef struct {
     char *network_device;
+    GRegex *boot_trig_regex;
+    GRegex *msg_waiting_regex;
+    GRegex *ciev_regex;
+    gpointer std_parser;
     guint32 signal_quality;
 } MMModemMbmPrivate;
 
@@ -132,7 +140,7 @@ set_apn (MMModemGsmNetwork *modem,
 }
 
 static void
-do_register_done (MMSerial *serial,
+do_cmer_done (MMSerial *serial,
                  GString *response,
                  GError *error,
                  gpointer user_data)
@@ -146,6 +154,20 @@ do_register_done (MMSerial *serial,
 }
 
 static void
+do_register_done (MMSerial *serial,
+                 GString *response,
+                 GError *error,
+                 gpointer user_data)
+{
+    MMCallbackInfo *info = (MMCallbackInfo *) user_data;
+
+    if (error)
+        info->error = g_error_copy (error);
+
+    mm_serial_queue_command (serial, "AT+CMER=3,0,0,1", 10, do_cmer_done, info);
+}
+
+static void
 do_register (MMModemGsmNetwork *modem,
              const char *network_id,
              MMModemFn callback,
@@ -264,6 +286,7 @@ get_network_mode_done (MMSerial *serial,
 {
     MMCallbackInfo *info = (MMCallbackInfo *) user_data;
 
+    g_debug("get_network_mode_done");
     if (error)
         info->error = g_error_copy (error);
     else {
@@ -273,10 +296,10 @@ get_network_mode_done (MMSerial *serial,
         guint32 result = 0;
 
         if (parse_erinfo (response->str, &mode, &gsm_rinfo, &umts_rinfo)) {
-            if (umts_rinfo == 2)
-                result = MM_MODEM_GSM_NETWORK_MODE_HSDPA;
-            else if (umts_rinfo && !gsm_rinfo)
-                result = MM_MODEM_GSM_NETWORK_MODE_3G;
+        	if (umts_rinfo == 2)
+        		result = MM_MODEM_GSM_NETWORK_MODE_HSDPA;
+        	else if (umts_rinfo && !gsm_rinfo)
+        		result = MM_MODEM_GSM_NETWORK_MODE_3G;
             else if (umts_rinfo && gsm_rinfo)
                 result = MM_MODEM_GSM_NETWORK_MODE_PREFER_3G;
             else if (gsm_rinfo)
@@ -299,7 +322,7 @@ get_network_mode (MMModemGsmNetwork *mod
                   gpointer user_data)
 {
     MMCallbackInfo *info;
-
+    g_debug("get_network_mode");
     info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
     mm_serial_queue_command (MM_SERIAL (modem), "AT*ERINFO?", 3, get_network_mode_done, info);
 }
@@ -325,7 +348,7 @@ get_signal_quality_done (MMSerial *seria
         reply += 7;
 
         if (sscanf (reply, "%d,%d", &battch, &signal)) {
-            /* Normalize the quality */
+           /* Normalize the quality */
             signal = signal * 100 / 5;
 
             MM_MODEM_MBM_GET_PRIVATE (serial)->signal_quality = signal;
@@ -345,6 +368,7 @@ get_signal_quality (MMModemGsmNetwork *m
 {
     MMCallbackInfo *info;
 
+	g_debug("mbm get_signal_quality");
     if (mm_serial_is_connected (MM_SERIAL (modem))) {
         g_message ("Returning saved signal quality %d", MM_MODEM_MBM_GET_PRIVATE (modem)->signal_quality);
         callback (MM_MODEM (modem), MM_MODEM_MBM_GET_PRIVATE (modem)->signal_quality, NULL, user_data);
@@ -358,8 +382,61 @@ get_signal_quality (MMModemGsmNetwork *m
 /*****************************************************************************/
 
 static void
+boot_trig (const char *str, gpointer data)
+{
+    mm_serial_queue_command (MM_SERIAL(data), "AT*ENAP=1,1", 10, NULL, NULL);
+}
+
+static void
+ciev_trig (const char *str, gpointer data)
+{
+    int event, value;
+    guint32 quality;
+
+    if (!str) {
+        return;
+    }
+
+    event = str[0] - '0';
+    value = str[2] - '0';
+
+    switch (event) {
+    case 2: // signal quality, value 0-5
+        quality = value * 100 / 5;
+        mm_modem_gsm_network_signal_quality (MM_MODEM(data), quality);
+        break;
+    case 9: // roaming, value 0 or 1
+        g_debug("%s: roaming %s\n", __FUNCTION__, value?"active":"inactive");
+        break;
+    default:
+        g_debug("%s: got unknown event %d with value %d\n", __FUNCTION__, event, value);
+    }
+}
+
+static gboolean
+mbm_parse_response (gpointer data, GString *response, GError **error)
+{
+    MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (data);
+
+    mm_util_strip_string (response, priv->boot_trig_regex, boot_trig, data);
+    mm_util_strip_string (response, priv->ciev_regex, ciev_trig, data);
+    mm_util_strip_string (response, priv->msg_waiting_regex, NULL, data);
+
+    return mm_serial_parser_v1_parse (priv->std_parser, response, error);
+}
+
+static void
 mm_modem_mbm_init (MMModemMbm *self)
 {
+    MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (self);
+
+    priv->boot_trig_regex = g_regex_new ("\\r\\n\\+PACSP0\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+    priv->msg_waiting_regex = g_regex_new ("\\r\\n[\\*]EMWI\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+    priv->ciev_regex = g_regex_new ("\\r\\n\\+CIEV: (.,.)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+
+    priv->std_parser = (gpointer)mm_serial_parser_v1_new ();
+
+    mm_serial_set_response_parser (MM_SERIAL (self), mbm_parse_response, self, NULL);
 }
 
 static void
@@ -440,6 +517,9 @@ finalize (GObject *object)
     MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (object);
 
     g_free (priv->network_device);
+    mm_serial_parser_v1_destroy (priv->std_parser);
+    g_regex_unref (priv->boot_trig_regex);
+    g_regex_unref (priv->msg_waiting_regex);
 
     G_OBJECT_CLASS (mm_modem_mbm_parent_class)->finalize (object);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]