[svn-commits] mnicholson: branch mnicholson/chan-mobile-refactor r741 - /team/mnicholson/ch...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jan 26 11:15:21 CST 2009


Author: mnicholson
Date: Mon Jan 26 11:15:21 2009
New Revision: 741

URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=741
Log:
Rewrote the do_monitor_* functions for the new rfcomm_wait and rfcomm_read
functions.

Modified:
    team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c

Modified: team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c
URL: http://svn.digium.com/svn-view/asterisk-addons/team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c?view=diff&rev=741&r1=740&r2=741
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Mon Jan 26 11:15:21 2009
@@ -1316,7 +1316,8 @@
 	char monitor = 1;
 	char buf[256];
 	char cid_num[AST_MAX_EXTENSION], *pcids, *pcide;
-	int s, t, i, smsi;
+	int t, i, smsi, waitfd;
+	ssize_t s;
 	int group, group2;
 	int callp = 0, callsetupp;
 	char brsf, nsmode, *p, *p1;
@@ -1331,20 +1332,33 @@
 	while (monitor) {
 
 		if (pvt->state == MBL_STATE_DIAL1)
-			t = pvt->dial_timeout;
+			t = pvt->dial_timeout * 1000;
 		else if (pvt->state == MBL_STATE_HANGUP)
-			t = 2;
+			t = 2000;
 		else if (pvt->state == MBL_STATE_OUTSMS1)
-			t = 2;
+			t = 2000;
 		else if (pvt->state == MBL_STATE_OUTSMS2)
-			t = 10;
+			t = 10000;
 		else
-			t = 1;
-
-		s = rfcomm_read(pvt, buf, 0, t);
-
-		if ((s > 0) && (buf[0] != 0x0) && (buf[0] != '\r')) {
-			ast_debug(1, "rfcomm_read() (%s) [%s]\n", pvt->id, buf);
+			t = 1000;
+
+		waitfd = rfcomm_wait(pvt->rfcomm_socket, &t);
+
+		if (waitfd == pvt->rfcomm_socket) {
+			s = rfcomm_read(pvt->rfcomm_socket, buf, sizeof(buf));
+
+			if (s < 1) {
+				monitor = 0;
+				continue;
+			}
+
+			ast_debug(1, "rfcomm_read() (%s) [%.*s]\n", pvt->id, s, buf);
+
+			if (s < sizeof(buf))
+				buf[s] = '\0';
+			else
+				buf[sizeof(buf) - 1] = '\0';
+
 			switch (pvt->state) {
 			case MBL_STATE_INIT:
 				if (strstr(buf, "+BRSF:")) {
@@ -1608,7 +1622,7 @@
 				}
 			}
 
-		} else if (s == 0) { /* Timeouts */
+		} else if (waitfd = -1) { /* Timeouts */
 			if (pvt->state == MBL_STATE_INIT2) { /* Some devices dont respond to AT+CIND? properly. RIM Blackberry 4 example */
 				pvt->state++;
 				rfcomm_write(pvt->rfcomm_socket, "AT+CMER=3,0,0,1\r");
@@ -1662,7 +1676,7 @@
 				ast_log(LOG_ERROR, "Failed to send SMS to %s on device %s\n", pvt->dial_number, pvt->id);
 				pvt->state = MBL_STATE_IDLE;
 			}
-		} else if (s == -1) {
+		} else if (waitfd == 0) {
 			if (option_verbose > 2)
 				ast_verbose(VERBOSE_PREFIX_3  "Bluetooth Device %s has disconnected, reason (%d).\n", pvt->id, errno); 
 			monitor = 0;
@@ -1698,20 +1712,35 @@
 	struct mbl_pvt *pvt = (struct mbl_pvt *)data;
 	char monitor = 1;
 	char buf[256];
-	int s, t;
+	int t, waitfd;
+	ssize_t s;
 
 	pvt->state = MBL_STATE_PREIDLE;
 
 	while (monitor) {
 
 		if (pvt->state == MBL_STATE_RING2)
-			t = 2;
+			t = 2000;
 		else
-			t = 1;
-		s = rfcomm_read(pvt, buf, 0, t);
-
-		if ((s > 0) && (buf[0] != 0x0) && (buf[0] != '\r')) {
-			ast_debug(1, "rfcomm_read() (%s) [%s]\n", pvt->id, buf);
+			t = 1000;
+		
+		waitfd = rfcomm_wait(pvt->rfcomm_socket, &t);
+
+		if (waitfd == pvt->rfcomm_socket) {
+			s = rfcomm_read(pvt->rfcomm_socket, buf, sizeof(buf));
+
+			if (s < 1) {
+				monitor = 0;
+				continue;
+			}
+
+			ast_debug(1, "rfcomm_read() (%s) [%.*s]\n", pvt->id, s, buf);
+
+			if (s < sizeof(buf))
+				buf[s] = '\0';
+			else
+				buf[sizeof(buf) - 1] = '\0';
+
 			switch (pvt->state) {
 			case MBL_STATE_RING2:
 				if (strstr(buf, "AT+CKPD=")) {
@@ -1734,7 +1763,7 @@
 			} else if (strstr(buf, "AT+VGM=")) {
 				rfcomm_write(pvt->rfcomm_socket, "\r\nOK\r\n");
 			}
-		} else if (s == 0) {	/* Timeouts */
+		} else if (waitfd == -1) {	/* Timeouts */
 			if (pvt->state == MBL_STATE_PREIDLE) {
 				pvt->connected = 1;
 				ast_verbose(VERBOSE_PREFIX_3 "Bluetooth Device %s initialised and ready.\n", pvt->id);
@@ -1751,7 +1780,7 @@
 			} else if (pvt->state == MBL_STATE_RING2) {
 				rfcomm_write(pvt->rfcomm_socket, "\r\nRING\r\n");
 			}
-		} else if (s == -1) {
+		} else if (waitfd == 0) {
 			if (option_verbose > 2)
 				ast_verbose(VERBOSE_PREFIX_3  "Bluetooth Device %s has disconnected, reason (%d).\n", pvt->id, errno); 
 			monitor = 0;




More information about the svn-commits mailing list