[asterisk-addons-commits] mnicholson: branch mnicholson/chan-mobile-refactor r738 - /team/mnicholson/ch...

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Fri Jan 23 16:04:27 CST 2009


Author: mnicholson
Date: Fri Jan 23 16:04:27 2009
New Revision: 738

URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=738
Log:
make rfcomm_write take a socket instead of the mbl_pvt struct

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=738&r1=737&r2=738
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Fri Jan 23 16:04:27 2009
@@ -217,7 +217,7 @@
 static void do_alignment_detection(struct mbl_pvt *pvt, char *buf, int buflen);
 
 static int rfcomm_connect(bdaddr_t src, bdaddr_t dst, int remote_channel);
-static int rfcomm_write(struct mbl_pvt *pvt, char *buf);
+static int rfcomm_write(int rfcomm_socket, char *buf);
 static int rfcomm_read(struct mbl_pvt *pvt, char *buf, char flush, int timeout);
 
 static int sco_connect(bdaddr_t src, bdaddr_t dst);
@@ -386,7 +386,7 @@
 	}
 
 	snprintf(buf, sizeof(buf), "%s\r", a->argv[3]);
-	rfcomm_write(pvt, buf);
+	rfcomm_write(pvt->rfcomm_socket, buf);
 
 	return CLI_SUCCESS;
 }
@@ -691,7 +691,7 @@
 
 	if ((pvt->state == MBL_STATE_INCOMING || pvt->state == MBL_STATE_OUTGOING || pvt->state == MBL_STATE_DIAL1 || pvt->state == MBL_STATE_RING3) && pvt->type == MBL_TYPE_PHONE) {
 		if (pvt->do_hangup) {
-			rfcomm_write(pvt, "AT+CHUP\r");
+			rfcomm_write(pvt->rfcomm_socket, "AT+CHUP\r");
 		}
 		pvt->state = MBL_STATE_HANGUP;
 		pvt->hangup_count = 0;
@@ -713,7 +713,7 @@
 
 	pvt = ast->tech_pvt;
 
-	rfcomm_write(pvt, "ATA\r");
+	rfcomm_write(pvt->rfcomm_socket, "ATA\r");
 
 	ast_setstate(ast, AST_STATE_UP);
 
@@ -757,7 +757,7 @@
 	case '*':
 	case '#':
 		snprintf(buf, sizeof(buf), "AT+VTS=%c\r", digit);
-		rfcomm_write(pvt, buf);
+		rfcomm_write(pvt->rfcomm_socket, buf);
 		break;
 	default:
 		ast_log(LOG_WARNING, "Unknown digit '%c'\n", digit);
@@ -1010,18 +1010,18 @@
 
 }
 
-static int rfcomm_write(struct mbl_pvt *pvt, char *buf)
+static int rfcomm_write(int rfcomm_socket, char *buf)
 {
 
 	char *p;
 	ssize_t num_write;
 	int len;
 
-	ast_debug(1, "rfcomm_write() (%s) [%s]\n", pvt->id, buf);
+	ast_debug(1, "rfcomm_write() (%d) [%s]\n", rfcomm_socket, buf);
 	len = strlen(buf);
 	p = buf;
 	while (len > 0) {
-		if ((num_write = write(pvt->rfcomm_socket, p, len)) == -1) {
+		if ((num_write = write(rfcomm_socket, p, len)) == -1) {
 			ast_debug(1, "rfcomm_write() error [%d]\n", errno);
 			return 0;
 		}
@@ -1322,7 +1322,7 @@
 
 	brsf = nsmode = 0;
 
-	if (!rfcomm_write(pvt, "AT+BRSF=4\r"))
+	if (!rfcomm_write(pvt->rfcomm_socket, "AT+BRSF=4\r"))
 		monitor = 0;
 
 	while (monitor) {
@@ -1347,15 +1347,15 @@
 				if (strstr(buf, "+BRSF:")) {
 					brsf = 1;
 				} else if (strstr(buf, "ERROR") && !nsmode) {	/* Hmmm, Non-Standard Phone, just continue */
-					rfcomm_write(pvt, "AT+CIND=?\r");
+					rfcomm_write(pvt->rfcomm_socket, "AT+CIND=?\r");
 					pvt->state++;
 					nsmode = 1;
 				} else if (strstr(buf, "OK") && brsf) {
 					if (pvt->blackberry) {
-						rfcomm_write(pvt, "AT+CMER=3,0,0,1\r");
+						rfcomm_write(pvt->rfcomm_socket, "AT+CMER=3,0,0,1\r");
 						pvt->state = MBL_STATE_INIT3;
 					} else {
-						rfcomm_write(pvt, "AT+CIND=?\r");
+						rfcomm_write(pvt->rfcomm_socket, "AT+CIND=?\r");
 						pvt->state++;
 					}
 				}
@@ -1390,7 +1390,7 @@
 					ast_debug(1, "CIEV_CALL=%d CIEV_CALLSETUP=%d\n", callp, callsetupp);
 				}
 				if (strstr(buf, "OK")) {
-					rfcomm_write(pvt, "AT+CIND?\r");
+					rfcomm_write(pvt->rfcomm_socket, "AT+CIND?\r");
 					pvt->state++;
 				}
 				break;
@@ -1403,10 +1403,10 @@
 					}
 				} else if (strstr(buf, "OK")) {
 					if (pvt->blackberry) {
-						rfcomm_write(pvt, "AT+CLIP=1\r");
+						rfcomm_write(pvt->rfcomm_socket, "AT+CLIP=1\r");
 						pvt->state = MBL_STATE_INIT4;
 					} else {
-						rfcomm_write(pvt, "AT+CMER=3,0,0,1\r");
+						rfcomm_write(pvt->rfcomm_socket, "AT+CMER=3,0,0,1\r");
 						pvt->state++;
 					}
 				}
@@ -1414,23 +1414,23 @@
 			case MBL_STATE_INIT3:
 				if (strstr(buf, "OK")) {
 					if (pvt->blackberry) {
-						rfcomm_write(pvt, "AT+CIND=?\r");
+						rfcomm_write(pvt->rfcomm_socket, "AT+CIND=?\r");
 						pvt->state = MBL_STATE_INIT1;
 					} else {
-						rfcomm_write(pvt, "AT+CLIP=1\r");
+						rfcomm_write(pvt->rfcomm_socket, "AT+CLIP=1\r");
 						pvt->state++;
 					}
 				}
 				break;
 			case MBL_STATE_INIT4:
 				if (strstr(buf, "OK")) {
-					rfcomm_write(pvt, "AT+VGS=15\r");
+					rfcomm_write(pvt->rfcomm_socket, "AT+VGS=15\r");
 					pvt->state++;
 				}
 				break;
 			case MBL_STATE_INIT5:
 				if (strstr(buf, "OK")) {
-					rfcomm_write(pvt, "AT+CMGF=1\r");
+					rfcomm_write(pvt->rfcomm_socket, "AT+CMGF=1\r");
 					pvt->state++;
 				}
 				break;
@@ -1438,7 +1438,7 @@
 				if (strstr(buf, "ERROR")) {	/* No SMS Support ! */
 					pvt->state = MBL_STATE_PREIDLE;
 				} else if (strstr(buf, "OK")) {
-					rfcomm_write(pvt, "AT+CNMI=2,1,0,1,0\r");
+					rfcomm_write(pvt->rfcomm_socket, "AT+CNMI=2,1,0,1,0\r");
 					pvt->state++;
 				}
 				break;
@@ -1505,7 +1505,7 @@
 							pvt->state = MBL_STATE_RING3;
 					} else {
 						ast_log(LOG_ERROR, "Unable to allocate channel for incoming call.\n");
-						rfcomm_write(pvt, "AT+CHUP\r");
+						rfcomm_write(pvt->rfcomm_socket, "AT+CHUP\r");
 						pvt->state = MBL_STATE_IDLE;
 					}
 				}
@@ -1520,7 +1520,7 @@
 						pvt->state = MBL_STATE_RING3;
 				} else {
 					ast_log(LOG_ERROR, "Unable to allocate channel for incoming call.\n");
-					rfcomm_write(pvt, "AT+CHUP\r");
+					rfcomm_write(pvt->rfcomm_socket, "AT+CHUP\r");
 					pvt->state = MBL_STATE_IDLE;
 				}
 				break;
@@ -1599,7 +1599,7 @@
 					smsi = atoi(p);
 					if (smsi > 0) {
 						snprintf(buf, sizeof(buf), "AT+CMGR=%d\r", smsi);
-						rfcomm_write(pvt, buf);
+						rfcomm_write(pvt->rfcomm_socket, buf);
 						pvt->state = MBL_STATE_INSMS;
 					}
 				}
@@ -1608,17 +1608,17 @@
 		} else if (s == 0) { /* Timeouts */
 			if (pvt->state == MBL_STATE_INIT2) { /* Some devices dont respond to AT+CIND? properly. RIM Blackberry 4 example */
 				pvt->state++;
-				rfcomm_write(pvt, "AT+CMER=3,0,0,1\r");
+				rfcomm_write(pvt->rfcomm_socket, "AT+CMER=3,0,0,1\r");
  			} else if (pvt->state == MBL_STATE_INIT3) { /* Some devices dont respond to AT+CMER=3,0,0,1 properly. VK 2020 for example */
 				pvt->state++;
-				rfcomm_write(pvt, "AT+CLIP=1\r");
+				rfcomm_write(pvt->rfcomm_socket, "AT+CLIP=1\r");
 			} else if (pvt->state == MBL_STATE_PREIDLE) {
 				pvt->connected = 1;
 				ast_verbose(VERBOSE_PREFIX_3 "Bluetooth Device %s initialised and ready.\n", pvt->id);
 				pvt->state = MBL_STATE_IDLE;
 			} else if (pvt->state == MBL_STATE_DIAL) {
 				snprintf(buf, sizeof(buf), "ATD%s;\r", pvt->dial_number);
-				if (!rfcomm_write(pvt, buf)) {
+				if (!rfcomm_write(pvt->rfcomm_socket, buf)) {
 					ast_log(LOG_ERROR, "Dial failed on %s state %d\n", pvt->owner->name, pvt->state);
 					ast_queue_control(pvt->owner, AST_CONTROL_CONGESTION);
 					pvt->state = MBL_STATE_IDLE;
@@ -1638,18 +1638,18 @@
 						ast_debug(1, "Device %s failed to hangup after 6 tries, disconnecting.\n", pvt->id);
 						monitor = 0;
 					}
-					rfcomm_write(pvt, "AT+CHUP\r");
+					rfcomm_write(pvt->rfcomm_socket, "AT+CHUP\r");
 					pvt->hangup_count++;
 				} else
 					pvt->state = MBL_STATE_IDLE;
 			} else if (pvt->state == MBL_STATE_OUTSMS) {
 				snprintf(buf, sizeof(buf), "AT+CMGS=\"%s\"\r", pvt->dial_number);
-				rfcomm_write(pvt, buf);
+				rfcomm_write(pvt->rfcomm_socket, buf);
 				pvt->state = MBL_STATE_OUTSMS1;
 			} else if (pvt->state == MBL_STATE_OUTSMS1) {
 				if (pvt->rfcomm_buf[0] == '>') {
 					snprintf(buf, sizeof(buf), "%s%c", pvt->sms_txt, 0x1a);
-					rfcomm_write(pvt, buf);
+					rfcomm_write(pvt->rfcomm_socket, buf);
 					pvt->state = MBL_STATE_OUTSMS2;
 				} else {
 					ast_log(LOG_ERROR, "Failed to send SMS to %s on device %s\n", pvt->dial_number, pvt->id);
@@ -1714,8 +1714,8 @@
 				if (strstr(buf, "AT+CKPD=")) {
 					ast_queue_control(pvt->owner, AST_CONTROL_ANSWER);
 					pvt->state = MBL_STATE_INCOMING;
-					rfcomm_write(pvt, "\r\n+VGS=13\r\n");
-					rfcomm_write(pvt, "\r\n+VGM=13\r\n");
+					rfcomm_write(pvt->rfcomm_socket, "\r\n+VGS=13\r\n");
+					rfcomm_write(pvt->rfcomm_socket, "\r\n+VGM=13\r\n");
 				}
 				break;
 			case MBL_STATE_INCOMING:
@@ -1727,9 +1727,9 @@
 				break;
 			}
 			if (strstr(buf, "AT+VGS=")) {
-				rfcomm_write(pvt, "\r\nOK\r\n");
+				rfcomm_write(pvt->rfcomm_socket, "\r\nOK\r\n");
 			} else if (strstr(buf, "AT+VGM=")) {
-				rfcomm_write(pvt, "\r\nOK\r\n");
+				rfcomm_write(pvt->rfcomm_socket, "\r\nOK\r\n");
 			}
 		} else if (s == 0) {	/* Timeouts */
 			if (pvt->state == MBL_STATE_PREIDLE) {
@@ -1746,7 +1746,7 @@
 					ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
 				}
 			} else if (pvt->state == MBL_STATE_RING2) {
-				rfcomm_write(pvt, "\r\nRING\r\n");
+				rfcomm_write(pvt->rfcomm_socket, "\r\nRING\r\n");
 			}
 		} else if (s == -1) {
 			if (option_verbose > 2)




More information about the asterisk-addons-commits mailing list