r1517 - trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src

zhiyong_sun at sita.openmoko.org zhiyong_sun at sita.openmoko.org
Tue Mar 27 13:52:09 CEST 2007


Author: zhiyong_sun
Date: 2007-03-27 13:52:01 +0200 (Tue, 27 Mar 2007)
New Revision: 1517

Modified:
   trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.c
   trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.h
   trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/openmoko-panel-gsm.c
Log:
fix lgsmd connection problem, success to get the value of gsm signal quality

Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.c
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.c	2007-03-27 08:34:31 UTC (rev 1516)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.c	2007-03-27 11:52:01 UTC (rev 1517)
@@ -5,6 +5,9 @@
 #include <libgsmd/libgsmd.h>
 #include <libgsmd/event.h>
 
+#include <glib/gmain.h>
+#include <glib/giochannel.h>
+
 #include "moko-gsm-conn.h"
 
 #undef FALSE
@@ -13,29 +16,66 @@
 #define TRUE 	1
 
 static struct lgsm_handle *lgsmh = NULL;
-static int signal_value = 0;
-static int updated = FALSE;
-static int gsm_conn_init = FALSE;
+static GPollFD GPfd;
+static int signal_value = -99;
 
-static int 
-incall_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
+static gboolean
+gsm_watcher_prepare (GSource * source, gint * timeout)
 {
-	printf("EVENT: Incoming call type = %u\n", aux->u.call.type);
-	return 0;
+  *timeout = -1;
+
+  return FALSE;
 }
 
+static gboolean
+gsm_watcher_check (GSource * source)
+{
+ if (GPfd.revents & (G_IO_IN | G_IO_PRI))
+  {
+    return TRUE;
+  }
+  else
+  {
+    return FALSE;
+  }
+
+}
+static gboolean
+gsm_watcher_dispatch (GSource * source,
+                      GSourceFunc callback, gpointer user_data)
+{
+  int rc;
+  char buf[STDIN_BUF_SIZE + 1];
+  int gsm_fd = lgsm_fd (lgsmh);
+  /* we've received something on the gsmd socket, pass it
+   * on to the library */
+
+  rc = read (gsm_fd, buf, sizeof (buf));
+  if (rc <= 0)
+  {
+    return FALSE;
+  }
+  else
+  {
+    rc = lgsm_handle_packet (lgsmh, buf, rc);
+  }
+  
+  return TRUE;
+}
+
 static int 
 sigq_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
 {
 	printf("EVENT: Signal Quality: %u\n", aux->u.signal.sigq.rssi);
-	//signal_value = aux->u.signal.sigq.rssi;
+	signal_value = aux->u.signal.sigq.rssi;
+	//FIXME: Call panel applet image change function here, instead of use g timeout function to check singal value
 	return 0;
 }
 
 static int 
 netreg_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
 {
-	printf("EVENT: Netreg ");
+  printf("EVENT: Netreg ");
 
 	switch (aux->u.netreg.state)
 	{
@@ -66,111 +106,53 @@
 	return 0;
 }
 
-static int 
-event_init(struct lgsm_handle *lh)
-{
-	int rc;
-
-	rc  = lgsm_evt_handler_register(lh, GSMD_EVT_IN_CALL, &incall_handler);
-	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_NETREG, &netreg_handler);
-	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_SIGNAL, &sigq_handler);
-
-	return rc;
-}
-
-static void
+static int
 gsm_connect_init()
 {
-    lgsmh = lgsm_init(LGSMD_DEVICE_GSMD);	
+  lgsmh = lgsm_init(LGSMD_DEVICE_GSMD);	
     
-    if (!lgsmh) 
-    { 
-       gsm_conn_init = FALSE;
-	//fprintf(stderr, "openmoko-panel-gsm:Can't connect to gsmd\n");
-	printf("Can't connect to gsmd\n");
-	return FALSE;
-    }
-    else 
-    {
-	event_init(lgsmh);
-	return TRUE;
-    }
+  if (!lgsmh) 
+  { 
+    printf("Can't connect to gsmd\n");
+    return FALSE;
+  }
+  else 
+  {
+    lgsm_evt_handler_register(lgsmh, GSMD_EVT_NETREG, &netreg_handler);
+    lgsm_evt_handler_register(lgsmh, GSMD_EVT_SIGNAL, &sigq_handler);
+    return TRUE;
+  }
 }
 
 int
-update_gsm_signal_qualite()
+moko_panel_gsm_signal_quality()
 {
-    printf("update_gsm_signal_qualite\n");
-    fd_set readset;
-    int rc;
-    char buf[STDIN_BUF_SIZE+1];
-    struct timeval t;
-    t.tv_sec=0;
-    t.tv_usec=0;
-
-    if (!gsm_conn_init)
-    	gsm_connect_init();
-    
-    if (!lgsmh){
-    	gsm_conn_init = FALSE;
-    	return FALSE;
-    	}
-    
-    int gsm_fd = lgsm_fd (lgsmh);
-
-    FD_SET(gsm_fd, &readset);
-    printf("select>\n");
-    rc = select(gsm_fd+1, &readset, NULL, NULL, &t);
-    printf("select<\n");
-    
-    if (FD_ISSET(gsm_fd, &readset)) 
-    {
-	printf("read>\n");
-	rc = read(gsm_fd, buf, sizeof(buf));
-	printf("read<\n");
-	if (rc <= 0) 
-	{
-	    printf("ERROR reding from gsm_fd\n");
-	    return FALSE;
-	}
-	else
-	{
-	    printf("data from gsm_fd\n");
-	    rc = lgsm_handle_packet (lgsmh, buf, rc);
-	    updated = TRUE;
-	    return TRUE;
-	}
-    }
+  return signal_value;
 }
 
-int
-moko_panel_gsm_quality(int *quality)
+void
+gsm_watcher_install (void)
 {
-    update_gsm_signal_qualite();
+  static GSourceFuncs gsm_watcher_funcs = {
+    gsm_watcher_prepare,
+    gsm_watcher_check,
+    gsm_watcher_dispatch,
+    NULL
+  };
+  /* FIXME: we never unref the watcher. */
+  GSource *gsm_watcher = g_source_new (&gsm_watcher_funcs, sizeof (GSource));
 
+  gsm_connect_init();
+    
+  if (!lgsmh)
+    return ;
 
+  GPfd.fd = lgsm_fd (lgsmh);
+  GPfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI;
+  GPfd.revents = 0;
 
-    if (updated)
-	{
-		/*switch (signal_value) //needs debug board to test signal value range.
-		{
-		}
-		*/
-	
+  g_source_add_poll (gsm_watcher, &GPfd);
+  g_source_attach (gsm_watcher, NULL);
 
-    	updated = FALSE;
-    	return TRUE;
-    }
-    else
-	{
-		printf ("This is a test resualt without libgsmd support\n");
-    	static int test = 0;
-
-    	*quality = test;
-
-		if ( ++test >= TOTAL_SIGNALS )
-			test = 0;
-
-    	return FALSE;
-	}
+  return;
 }

Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.h
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.h	2007-03-27 08:34:31 UTC (rev 1516)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.h	2007-03-27 11:52:01 UTC (rev 1517)
@@ -13,7 +13,8 @@
 	TOTAL_SIGNALS
 };
 
-int
-moko_panel_gsm_quality(int *quality);
+void gsm_watcher_install (void);
 
+int moko_panel_gsm_signal_quality(void);
+
 #endif /*_MOKO_PANEL_GSM_CONN_*/

Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/openmoko-panel-gsm.c
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/openmoko-panel-gsm.c	2007-03-27 08:34:31 UTC (rev 1516)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/openmoko-panel-gsm.c	2007-03-27 11:52:01 UTC (rev 1517)
@@ -38,13 +38,9 @@
 static gboolean
 timeout_cb (GsmApplet *applet)
 {
-
- /*   if (!moko_panel_gsm_quality (&gsm_quality)) //signal value not changed.
-		return TRUE;
-		*/
-	moko_panel_gsm_quality (&(applet->gsm_quality));
-	g_debug ("moko gsm quality = %d", applet->gsm_quality);
-
+  int sig_q = moko_panel_gsm_signal_quality ();
+  g_debug ("moko gsm quality = %d", sig_q);
+if (0){
 	switch (applet->gsm_quality)
 	{
 		case GSM_SIGNAL_ERROR :
@@ -75,7 +71,7 @@
 			gtk_image_set_from_file (applet->image, PKGDATADIR"/SignalStrength_00.png");
 			break;
 	}
-
+}
     /* Keep going */
     return TRUE;
 }
@@ -97,9 +93,13 @@
 
     t = time( NULL );
     local_time = localtime(&t);
+    //FIXME: Do not use g_timeout function, convert to use gsm signal handle callback.
     applet->timeout_id = g_timeout_add( 2000, (GSourceFunc) timeout_cb, applet);
 
     moko_panel_applet_set_widget( GTK_CONTAINER(mokoapplet), applet->image );
     gtk_widget_show_all( GTK_WIDGET(mokoapplet) );
+
+    gsm_watcher_install ();
+
     return GTK_WIDGET(mokoapplet);
 };





More information about the commitlog mailing list