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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Feb 2 14:03:04 CST 2009


Author: mnicholson
Date: Mon Feb  2 14:03:04 2009
New Revision: 770

URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=770
Log:
added headset profile helper functions and modified do_monitor_headset() to use them

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=770&r1=769&r2=770
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Mon Feb  2 14:03:04 2009
@@ -377,6 +377,16 @@
 static int hfp_read_cind_test(struct hfp_pvt *pvt);
 
 /*
+ * bluetooth headset profile helpers
+ */
+static int hsp_send_ok(int rsock);
+static int hsp_send_error(int rsock);
+static int hsp_send_vgs(int rsock, int gain);
+static int hsp_send_vgm(int rsock, int gain);
+static int hsp_send_ring(int rsock);
+
+
+/*
  * Hayes AT command helpers
  */
 typedef enum {
@@ -1997,6 +2007,62 @@
 		return -1;
 
 	return 0;
+}
+
+
+/*
+ * Bluetooth Headset Profile helpers
+ */
+
+/*
+ * \brief Send an OK AT response.
+ * \param rsock the rfcomm socket to use
+ */
+static int hsp_send_ok(int rsock)
+{
+	return rfcomm_write(rsock, "\r\nOK\r\n");
+}
+
+/*
+ * \brief Send an ERROR AT response.
+ * \param rsock the rfcomm socket to use
+ */
+static int hsp_send_error(int rsock)
+{
+	return rfcomm_write(rsock, "\r\nERROR\r\n");
+}
+
+/*
+ * \brief Send a speaker gain unsolicited AT response
+ * \param rsock the rfcomm socket to use
+ * \param gain the speaker gain value
+ */
+static int hsp_send_vgs(int rsock, int gain)
+{
+	char cmd[32];
+	snprintf(cmd, sizeof(cmd), "\r\n+VGS=%d\r\n", gain);
+	return rfcomm_write(rsock, cmd);
+}
+
+/*
+ * \brief Send a microphone gain unsolicited AT response
+ * \param rsock the rfcomm socket to use
+ * \param gain the microphone gain value
+ */
+static int hsp_send_vgm(int rsock, int gain)
+{
+	char cmd[32];
+	snprintf(cmd, sizeof(cmd), "\r\n+VGM=%d\r\n", gain);
+	return rfcomm_write(rsock, cmd);
+}
+
+/*
+ * \brief Send a RING unsolicited AT response.
+ * \param rsock the rfcomm socket to use
+ */
+static int hsp_send_ring(int rsock)
+{
+	return rfcomm_write(rsock, "\r\nRING\r\n");
 }
 
 
@@ -2550,7 +2616,7 @@
 	char monitor = 1;
 	char buf[256];
 	int t;
-	ssize_t s;
+	at_message_t at_msg;
 
 	pvt->state = MBL_STATE_PREIDLE;
 
@@ -2562,35 +2628,46 @@
 			t = 1000;
 		
 		if (rfcomm_wait(pvt->rfcomm_socket, &t)) {
-			if ((s = rfcomm_read(pvt->rfcomm_socket, buf, sizeof(buf) - 1)) < 1) {
-				ast_verb(3, "Bluetooth Device %s has disconnected, reason (%d).\n", pvt->id, errno); 
+			if ((at_msg = at_read_full(pvt->rfcomm_socket, buf, sizeof(buf))) < 0) {
+				if (strerror_r(errno, buf, sizeof(buf)))
+					ast_debug(1, "[%s] error reading from device\n", pvt->id); 
+				else
+					ast_debug(1, "[%s] error reading from device: %s (%d)\n", pvt->id, buf, errno); 
+
 				monitor = 0;
 				continue;
 			}
-			buf[s] = '\0';
-			ast_debug(1, "rfcomm_read() (%s) [%s]\n", pvt->id, buf);
+			ast_debug(1, "[%s] %s\n", pvt->id, buf);
 
 			switch (pvt->state) {
 			case MBL_STATE_RING2:
-				if (strstr(buf, "AT+CKPD=")) {
+				if (at_msg == AT_CKPD) {
 					ast_queue_control(pvt->owner, AST_CONTROL_ANSWER);
 					pvt->state = MBL_STATE_INCOMING;
-					rfcomm_write(pvt->rfcomm_socket, "\r\n+VGS=13\r\n");
-					rfcomm_write(pvt->rfcomm_socket, "\r\n+VGM=13\r\n");
+					if (hsp_send_vgs(pvt->rfcomm_socket, 13) || hsp_send_vgm(pvt->rfcomm_socket, 13)) {
+						ast_debug(1, "[%s] error sending VGS/VGM\n", pvt->id); 
+						monitor = 0;
+					}
 				}
 				break;
 			case MBL_STATE_INCOMING:
-				if (strstr(buf, "AT+CKPD=")) {
+				if (at_msg == AT_CKPD) {
 					ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
 				}
 				break;
 			default:
 				break;
 			}
-			if (strstr(buf, "AT+VGS=")) {
-				rfcomm_write(pvt->rfcomm_socket, "\r\nOK\r\n");
-			} else if (strstr(buf, "AT+VGM=")) {
-				rfcomm_write(pvt->rfcomm_socket, "\r\nOK\r\n");
+			if (at_msg == AT_VGS || at_msg == AT_VGM) {
+				/* XXX should we respond ok here?  We don't
+				 * actually do anything with the command...
+				 */
+				hsp_send_ok(pvt->rfcomm_socket);
+			} else if (at_msg == AT_UNKNOWN) {
+				if (hsp_send_error(pvt->rfcomm_socket)) {
+					ast_debug(1, "[%s] error sending ERROR\n", pvt->id); 
+					monitor = 0;
+				}
 			}
 		} else {	/* Timeouts */
 			if (pvt->state == MBL_STATE_PREIDLE) {
@@ -2607,7 +2684,10 @@
 					ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
 				}
 			} else if (pvt->state == MBL_STATE_RING2) {
-				rfcomm_write(pvt->rfcomm_socket, "\r\nRING\r\n");
+				if (hsp_send_ring(pvt->rfcomm_socket)) {
+					ast_debug(1, "[%s] error sending RING\n", pvt->id); 
+					monitor = 0;
+				}
 			}
 		}
 
@@ -2622,6 +2702,7 @@
 	pvt->monitor_thread = AST_PTHREADT_NULL;
 
 	manager_event(EVENT_FLAG_SYSTEM, "MobileStatus", "Status: Disconnect\r\nDevice: %s\r\n", pvt->id);
+	ast_verb(3, "Bluetooth Device %s has disconnected\n", pvt->id); 
 
 	pvt->adapter->inuse = 0;
 




More information about the svn-commits mailing list