[Goodies-commits] r2561 - xfce4-cellmodem-plugin/trunk/panel-plugin

Alvaro Lopes alvieboy at xfce.org
Fri Mar 23 21:02:30 CET 2007


Author: alvieboy
Date: 2007-03-23 20:02:30 +0000 (Fri, 23 Mar 2007)
New Revision: 2561

Modified:
   xfce4-cellmodem-plugin/trunk/panel-plugin/cellmodem.c
   xfce4-cellmodem-plugin/trunk/panel-plugin/cellmodem.h
   xfce4-cellmodem-plugin/trunk/panel-plugin/modem_driver_generic.c
Log:
Use expect to get correct answers from modem

Modified: xfce4-cellmodem-plugin/trunk/panel-plugin/cellmodem.c
===================================================================
--- xfce4-cellmodem-plugin/trunk/panel-plugin/cellmodem.c	2007-03-23 09:41:58 UTC (rev 2560)
+++ xfce4-cellmodem-plugin/trunk/panel-plugin/cellmodem.c	2007-03-23 20:02:30 UTC (rev 2561)
@@ -24,9 +24,10 @@
 
 /* Prototypes */
 
-static gboolean cellmodem_t_send_at_command( cellmodem_t *monitor,
-					     modem_reply_callback_t callback,
-					     const gchar *command );
+static gboolean cellmodem_t_send_at_command(cellmodem_t *monitor,
+					    modem_reply_callback_t callback,
+					    const gchar *command,
+					    const gchar *expect);
 static gboolean get_network_info( cellmodem_t *monitor );
 static void cellmodem_t_is_registered( cellmodem_t *monitor );
 
@@ -998,7 +999,7 @@
 static void
 cellmodem_t_is_registered( cellmodem_t *monitor )
 {
-    cellmodem_t_send_at_command(monitor, &cellmodem_t_registration_callback, "+CREG?" );
+    cellmodem_t_send_at_command(monitor, &cellmodem_t_registration_callback, "+CREG?", "+CREG:" );
     cellmodem_t_switch_status( monitor, MODEM_WAIT_CREG_RESPONSE );
 }
 
@@ -1019,7 +1020,7 @@
 static void
 cellmodem_t_identify_network( cellmodem_t *monitor )
 {
-    cellmodem_t_send_at_command(monitor, &cellmodem_t_identify_callback, "+COPS?" );
+    cellmodem_t_send_at_command(monitor, &cellmodem_t_identify_callback, "+COPS?", "+COPS:" );
     cellmodem_t_switch_status( monitor, MODEM_WAIT_COPS_RESPONSE );
 
 }
@@ -1041,7 +1042,7 @@
 static void
 cellmodem_t_get_quality( cellmodem_t *monitor )
 {
-    cellmodem_t_send_at_command(monitor, &cellmodem_t_quality_callback, "+CSQ" );
+    cellmodem_t_send_at_command(monitor, &cellmodem_t_quality_callback, "+CSQ", "+CSQ:" );
     cellmodem_t_switch_status( monitor, MODEM_WAIT_CSQ_RESPONSE );
 }
 
@@ -1062,7 +1063,7 @@
 static void
 cellmodem_t_get_pin_status( cellmodem_t *monitor )
 {
-    cellmodem_t_send_at_command(monitor, &cellmodem_t_pin_callback, "+CPIN?" );
+    cellmodem_t_send_at_command(monitor, &cellmodem_t_pin_callback, "+CPIN?", "+CPIN:" );
     cellmodem_t_switch_status( monitor, MODEM_WAIT_CPIN_RESPONSE );
 
 }
@@ -1081,7 +1082,7 @@
 static void
 cellmodem_t_get_ohcip_status( cellmodem_t *monitor )
 {
-    cellmodem_t_send_at_command(monitor, &cellmodem_t_ohcip_callback, "_OHCIP?" );
+    cellmodem_t_send_at_command(monitor, &cellmodem_t_ohcip_callback, "_OHCIP?","_OHCIP:" );
     cellmodem_t_switch_status( monitor, MODEM_WAIT_OHCIP_RESPONSE );
 }
 
@@ -1094,7 +1095,7 @@
 
     if (cellmodem_t_open_modem( monitor ) == TRUE) {
 
-	cellmodem_t_send_at_command(monitor, &cellmodem_t_setpin_callback, g->str );
+	cellmodem_t_send_at_command(monitor, &cellmodem_t_setpin_callback, g->str, NULL );
 	g_string_free( g, TRUE );
 
 	cellmodem_t_switch_status( monitor, MODEM_WAIT_PINE_RESPONSE );
@@ -1121,7 +1122,6 @@
 cellmodem_t_modem_handle_response( cellmodem_t *monitor, char *buffer )
 {
     char *bstart;
-    DEBUG("In handle response");
 
     if ( monitor->resp.reply_callback == NULL ) {
         DEBUG("No callback defined!!!!");
@@ -1168,7 +1168,7 @@
         DEBUG("Done handling error");
 	return TRUE;
     }
-
+    
     if ( is_AT_success_reply( bstart ) ) {
         DEBUG("Got AT OK reply");
 	monitor->resp.reply_callback( TRUE,
@@ -1181,6 +1181,18 @@
 	return TRUE;
     }
 
+    /*
+     Check expectation. If expectation does not match,
+     we should add this message to some asynchronous event handling.
+     */
+
+    if ( monitor->resp.reply_expect ) {
+	if ( strncmp( bstart, monitor->resp.reply_expect, strlen(monitor->resp.reply_expect))!=0) {
+	    DEBUG("Ignoring reply from modem: '%s'\n", bstart);
+            return TRUE;
+	}
+    }
+
     g_string_append( monitor->resp.reply_buffer, bstart );
     g_string_append( monitor->resp.reply_buffer, "\n" );
 
@@ -1283,6 +1295,7 @@
  * @param monitor The cellmodem object
  * @param callback The callback which is to be called when modem replies.
  * @param command The AT command (without the 'AT' prefix and without CR/LF)
+ * @param expect The response to expect from modem (matched at the start).
  *
  * This will call the modem driver to send the command to the modem. The pvt
  * field will be set to the cellmodem object.
@@ -1292,16 +1305,16 @@
  */
 
 static gboolean
-cellmodem_t_send_at_command( cellmodem_t *monitor,
+cellmodem_t_send_at_command(cellmodem_t *monitor,
 			    modem_reply_callback_t callback,
-			    const gchar *command  )
+			    const gchar *command,
+			    const gchar *expect)
 {
 
     monitor->resp.reply_callback = callback;
     monitor->resp.reply_pvt = monitor;
+    monitor->resp.reply_expect = expect; /* Constant and static - no need to strdup */
 
-    DEBUG("Callback set to %p", callback );
-
     snprintf(monitor->lastcmd, 128, "AT%s", command );
 
     /* TODO - check if we already have a timeout */

Modified: xfce4-cellmodem-plugin/trunk/panel-plugin/cellmodem.h
===================================================================
--- xfce4-cellmodem-plugin/trunk/panel-plugin/cellmodem.h	2007-03-23 09:41:58 UTC (rev 2560)
+++ xfce4-cellmodem-plugin/trunk/panel-plugin/cellmodem.h	2007-03-23 20:02:30 UTC (rev 2561)
@@ -104,7 +104,8 @@
 typedef struct
 {
     modem_reply_callback_t reply_callback;
-    void *reply_pvt;
+	void *reply_pvt;
+    const gchar *reply_expect;
     GString *reply_buffer;
 } modem_response_data_t;
 

Modified: xfce4-cellmodem-plugin/trunk/panel-plugin/modem_driver_generic.c
===================================================================
--- xfce4-cellmodem-plugin/trunk/panel-plugin/modem_driver_generic.c	2007-03-23 09:41:58 UTC (rev 2560)
+++ xfce4-cellmodem-plugin/trunk/panel-plugin/modem_driver_generic.c	2007-03-23 20:02:30 UTC (rev 2561)
@@ -67,18 +67,18 @@
 
     return TRUE;
 }
-
+/*
 static void flush_modem( int fd )
 {
     fd_set rds;
     struct timeval tv= { 0, 200000 };
 
     FD_ZERO(&rds);
-    FD_SET(&rds, fd);
+    FD_SET(fd, &rds);
     while (select(2, &rds, NULL, NULL, &tv) > 0) {
     }
 }
-
+*/
 static void generic_close( modem_instance_t instance )
 {
     struct generic_modem_t *modem = (struct generic_modem_t*)instance;




More information about the Goodies-commits mailing list