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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jan 30 10:43:24 CST 2009


Author: mnicholson
Date: Fri Jan 30 10:43:24 2009
New Revision: 766

URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=766
Log:
Changed hfp_read* into more generic at_read*.

 * channels/chan_mobile.c (hfp_message_t): changed to at_message_t
 * channels/chan_mobile.c (hfp_read, hfp_read_full): replaced with at_read()
 and at_read_full()
 * channels/chan_mobile.c (at_read_full): added, handles AT commands and
 responses
 * channels/chan_mobile.c: changed calls to hfp_read() and hfp_read_full() to
 at_read() and at_read_full(), also updated for change from hfp_message_t to
 at_message_t

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=766&r1=765&r2=766
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Fri Jan 30 10:43:24 2009
@@ -277,19 +277,6 @@
 #define HFP_CIND_CALLSETUP_OUTGOING	2
 #define HFP_CIND_CALLSETUP_ALERTING	3
 
-typedef enum {
-	HFP_DISCONNECT = -2,
-	HFP_TIMEOUT = -1,
-	HFP_UNKNOWN = 0,
-	HFP_OK,
-	HFP_ERROR,
-	HFP_RING,
-	HFP_BRSF,
-	HFP_CIND,
-	HFP_CIEV,
-	HFP_CLIP,
-} hfp_message_t;
-
 /*
  * \brief This struct holds HFP features that we support.
  */
@@ -385,11 +372,32 @@
 static int hfp_send_cmgf(struct hfp_pvt *pvt, int mode);
 static int hfp_send_cnmi(struct hfp_pvt *pvt);
 
-static hfp_message_t hfp_read_full(struct hfp_pvt *pvt, char *buf, size_t count);
-static hfp_message_t hfp_read(struct hfp_pvt *pvt);
 static int hfp_read_brsf(struct hfp_pvt *pvt);
 static int hfp_read_cind(struct hfp_pvt *pvt);
 static int hfp_read_cind_test(struct hfp_pvt *pvt);
+
+/*
+ * Hayes AT command helpers
+ */
+typedef enum {
+	AT_DISCONNECT = -1,
+	AT_UNKNOWN = 0,
+	AT_OK,
+	AT_ERROR,
+	AT_RING,
+	AT_BRSF,
+	AT_CIND,
+	AT_CIEV,
+	AT_CLIP,
+	AT_CKPD,
+	AT_VGM,
+	AT_VGS,
+} at_message_t;
+
+static int at_match_prefix(char *buf, char *prefix);
+static at_message_t at_read_full(int rsock, char *buf, size_t count);
+static at_message_t at_read(int rsock);
+
 
 /*
  * channel stuff
@@ -906,7 +914,7 @@
 		return 0;
 	
 	ast_debug(1, "Dialed %c\n", digit);
-	if (hfp_send_dtmf(pvt->hfp, digit) || !hfp_wait(pvt->hfp) || hfp_read(pvt->hfp) != HFP_OK) {
+	if (hfp_send_dtmf(pvt->hfp, digit) || !hfp_wait(pvt->hfp) || at_read(pvt->rfcomm_socket) != AT_OK) {
 		return -1;
 	}
 
@@ -1389,6 +1397,80 @@
 }
 
 /*
+ * Hayes AT command helpers.
+ */
+
+/*
+ * \brief Match the given buffer with the given prefix.
+ * \param buf the buffer to match
+ * \param prefix the prefix to match
+ */
+static int at_match_prefix(char *buf, char *prefix)
+{
+	return !strncmp(buf, prefix, strlen(prefix));
+}
+
+/*
+ * \brief Read an AT message and clasify it.
+ * \param rsock an rfcomm socket
+ * \param buf the buffer to store the result in
+ * \param count the size of the buffer or the maximum number of characters to read
+ * \return the type of message received, in addition buf will contain the
+ * message received and will be null terminated
+ * \see at_read()
+ */
+static at_message_t at_read_full(int rsock, char *buf, size_t count)
+{
+	ssize_t s;
+	if ((s = rfcomm_read(rsock, buf, count - 1)) < 1)
+		return AT_DISCONNECT;
+	buf[s] = '\0';
+
+	if (!strcmp("OK", buf)) {
+		return AT_OK;
+	} else if (!strcmp("ERROR", buf)) {
+		return AT_ERROR;
+	} else if (!strcmp("RING", buf)) {
+		return AT_RING;
+	} else if (!strcmp("AT+CKPD=200", buf)) {
+		return AT_CKPD;
+	} else if (at_match_prefix(buf, "+CIEV:")) {
+		return AT_CIEV;
+	} else if (at_match_prefix(buf, "+BRSF:")) {
+		return AT_BRSF;
+	} else if (at_match_prefix(buf, "+CIND:")) {
+		return AT_CIND;
+	} else if (at_match_prefix(buf, "+CLIP:")) {
+		return AT_CLIP;
+	} else if (at_match_prefix(buf, "+VGM:")) {
+		return AT_VGM;
+	} else if (at_match_prefix(buf, "+VGS:")) {
+		return AT_VGS;
+	} else if (at_match_prefix(buf, "AT+VGM=")) {
+		return AT_VGM;
+	} else if (at_match_prefix(buf, "AT+VGS=")) {
+		return AT_VGS;
+	} else {
+		return AT_UNKNOWN;
+	}
+}
+
+/*
+ * \brief Read an AT message and clasify it.
+ * \param rsock an rfcomm socket
+ * \return the type of message received
+ * \see at_read_full()
+ */
+static at_message_t at_read(int rsock)
+{
+	/* this buffer is small as we only need the first few chars to identify
+	 * the message */
+	char buf[16];
+	return at_read_full(rsock, buf, sizeof(buf));
+}
+
+
+/*
  * bluetooth handsfree profile helpers
  */
 
@@ -1411,7 +1493,7 @@
 
 	/* if this is a blackberry, do CMER now */
 	if (pvt->blackberry) {
-		if (hfp_send_cmer(pvt, 1) || !hfp_wait(pvt) || hfp_read(pvt) != HFP_OK) {
+		if (hfp_send_cmer(pvt, 1) || !hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK) {
 			ast_debug(1, "[%s] error sending CMER, try setting 'blackberry=no'\n", pvt->owner->id);
 			return -1;
 		}
@@ -1437,20 +1519,20 @@
 
 	/* if this is not a blackberry send CMER now */
 	if (!pvt->blackberry) {
-		if (hfp_send_cmer(pvt, 1) || !hfp_wait(pvt) || hfp_read(pvt) != HFP_OK) {
+		if (hfp_send_cmer(pvt, 1) || !hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK) {
 			ast_debug(1, "[%s] error sending CMER\n", pvt->owner->id);
 			return -1;
 		}
 	}
 	
 	/* enalbe calling line identification notification */
-	if (hfp_send_clip(pvt, 1) || !hfp_wait(pvt) || hfp_read(pvt) != HFP_OK) {
+	if (hfp_send_clip(pvt, 1) || !hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK) {
 		ast_debug(1, "[%s] error enabling calling line notification\n", pvt->owner->id);
 		return -1;
 	}
 
 	/* send current gain levels */
-	if (hfp_send_vgs(pvt, 15) || !hfp_wait(pvt) || hfp_read(pvt) != HFP_OK) {
+	if (hfp_send_vgs(pvt, 15) || !hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK) {
 		ast_debug(1, "[%s] error synchronizing gain settings\n", pvt->owner->id);
 		return -1;
 	}
@@ -1471,13 +1553,13 @@
 static int hfp_init_sms(struct hfp_pvt *pvt)
 {
 	/* set the SMS operating mode to text mode */
-	if (hfp_send_cmgf(pvt, 1) || !hfp_wait(pvt) || hfp_read(pvt) != HFP_OK) {
+	if (hfp_send_cmgf(pvt, 1) || !hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK) {
 		ast_debug(1, "[%s] error setting CMGF\n", pvt->owner->id);
 		return -1;
 	}
 
 	/* turn on SMS new message indication */
-	if (hfp_send_cnmi(pvt) || !hfp_wait(pvt) || hfp_read(pvt) != HFP_OK) {
+	if (hfp_send_cnmi(pvt) || !hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK) {
 		ast_debug(1, "[%s] error setting CNMI\n", pvt->owner->id);
 		return -1;
 	}
@@ -1558,63 +1640,6 @@
 	ag->errors = brsf & HFP_AG_ERRORS ? 1 : 0;
 	
 	return ag;
-}
-
-/*
- * \brief Match the given buffer with the given prefix.
- * \param buf the buffer to match
- * \param prefix the prefix to match
- */
-static int hfp_match_prefix(char *buf, char *prefix)
-{
-	return !strncmp(buf, prefix, strlen(prefix));
-}
-
-/*
- * \brief Read an HFP message and clasify it.
- * \param pvt an hfp_pvt struct
- * \param buf the buffer to store the result in
- * \param count the size of the buffer or the maximum number of characters to read
- * \return the type of message received, in addition buf will contain the
- * message received and will be null terminated
- * \see hfp_read()
- */
-static hfp_message_t hfp_read_full(struct hfp_pvt *pvt, char *buf, size_t count)
-{
-	ssize_t s;
-	if ((s = rfcomm_read(pvt->rsock, buf, count - 1)) < 1)
-		return HFP_DISCONNECT;
-	buf[s] = '\0';
-
-	if (!strcmp("OK", buf)) {
-		return HFP_OK;
-	} else if (!strcmp("ERROR", buf)) {
-		return HFP_ERROR;
-	} else if (!strcmp("RING", buf)) {
-		return HFP_RING;
-	} else if (hfp_match_prefix(buf, "+CIEV:")) {
-		return HFP_CIEV;
-	} else if (hfp_match_prefix(buf, "+BRSF:")) {
-		return HFP_BRSF;
-	} else if (hfp_match_prefix(buf, "+CIND:")) {
-		return HFP_CIND;
-	} else if (hfp_match_prefix(buf, "+CLIP:")) {
-		return HFP_CLIP;
-	} else {
-		return HFP_UNKNOWN;
-	}
-}
-
-/*
- * \brief Read an HFP message and clasify it.
- * \param pvt an hfp_pvt struct
- * \return the type of message received
- * \see hfp_read_full()
- */
-static hfp_message_t hfp_read(struct hfp_pvt *pvt)
-{
-	char buf[16];
-	return hfp_read_full(pvt, buf, sizeof(buf));
 }
 
 
@@ -1763,7 +1788,7 @@
 	char buf[128];
 
 	/* read the BRSF data */
-	if (hfp_read_full(pvt, buf, sizeof(buf)) != HFP_BRSF)
+	if (at_read_full(pvt->rsock, buf, sizeof(buf)) != AT_BRSF)
 		return -1;
 
 	if (!sscanf(buf, "+BRSF:%d", &brsf))
@@ -1772,7 +1797,7 @@
 	hfp_int2brsf(brsf, &pvt->brsf);
 
 	/* read the OK message */
-	if (!hfp_wait(pvt) || hfp_read(pvt) != HFP_OK)
+	if (!hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK)
 		return -1;
 
 	return 0;
@@ -1816,7 +1841,7 @@
 	char buf[256];
 	char *indicator;
 
-	if (hfp_read_full(pvt, buf, sizeof(buf)) != HFP_CIND)
+	if (at_read_full(pvt->rsock, buf, sizeof(buf)) != AT_CIND)
 		return -1;
 
 	/* parse current state of all of our indicators.  The list is in the
@@ -1856,7 +1881,7 @@
 		hfp_parse_cind_indicator(pvt, group, indicator);
 	
 	/* read the OK message */
-	if (!hfp_wait(pvt) || hfp_read(pvt) != HFP_OK)
+	if (!hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK)
 		return -1;
 
 	return 0;
@@ -1873,7 +1898,7 @@
 	char buf[512];
 	char *indicator, *values;
 
-	if (hfp_read_full(pvt, buf, sizeof(buf)) != HFP_CIND)
+	if (at_read_full(pvt->rsock, buf, sizeof(buf)) != AT_CIND)
 		return -1;
 
 	pvt->nocallsetup = 1;
@@ -1965,7 +1990,7 @@
 	pvt->owner->no_callsetup = pvt->nocallsetup;
 	
 	/* read the OK message */
-	if (!hfp_wait(pvt) || hfp_read(pvt) != HFP_OK)
+	if (!hfp_wait(pvt) || at_read(pvt->rsock) != AT_OK)
 		return -1;
 
 	return 0;
@@ -2109,7 +2134,7 @@
 	char brsf, nsmode, *p, *p1;
 	char sms_src[13];
 	char sms_txt[160];
-	hfp_message_t hfp_msg;
+	at_message_t at_msg;
 
 	brsf = nsmode = 0;
 
@@ -2134,7 +2159,7 @@
 			t = 1000;
 
 		if ((waitfd = rfcomm_wait(pvt->rfcomm_socket, &t))) {
-			if ((hfp_msg = hfp_read_full(hfp, buf, sizeof(buf))) < 0) {
+			if ((at_msg = at_read_full(hfp->rsock, buf, sizeof(buf))) < 0) {
 				if (strerror_r(errno, buf, sizeof(buf)))
 					ast_debug(1, "[%s] error reading from device\n", pvt->id); 
 				else
@@ -2257,9 +2282,9 @@
 			case MBL_STATE_PREIDLE: /* Nothing handled here, wait for timeout, then off we go... */
 				break;
 			case MBL_STATE_IDLE:
-				if (hfp_msg == HFP_RING) {
+				if (at_msg == AT_RING) {
 					pvt->state = MBL_STATE_RING;
-				} else if (hfp_msg == HFP_CIEV
+				} else if (at_msg == AT_CIEV
 					&& hfp_parse_ciev(hfp, buf, &i) == HFP_CIND_CALLSETUP
 					&& i == HFP_CIND_CALLSETUP_ALERTING) {
 
@@ -2284,7 +2309,7 @@
 				}
 				break;
 			case MBL_STATE_OUTGOING:
-				if (hfp_msg == HFP_CIEV) {
+				if (at_msg == AT_CIEV) {
 					switch (hfp_parse_ciev(hfp, buf, &i)) {
 					case HFP_CIND_CALL:
 						if (i == HFP_CIND_CALL_NONE) {
@@ -2342,7 +2367,7 @@
 				}
 				break;
 			case MBL_STATE_RING3:
-				if (hfp_msg == HFP_CIEV) {
+				if (at_msg == AT_CIEV) {
 					switch (hfp_parse_ciev(hfp, buf, &i)) {
 					case HFP_CIND_CALL:
 						if (i) {  /* call active */
@@ -2369,7 +2394,7 @@
 				} 
 				break;
 			case MBL_STATE_INCOMING:
-				if (hfp_msg == HFP_CIEV
+				if (at_msg == AT_CIEV
 					&& hfp_parse_ciev(hfp, buf, &i) == HFP_CIND_CALL
 					&& i == HFP_CIND_CALL_NONE) {
 
@@ -2378,7 +2403,7 @@
 				}
 				break;
 			case MBL_STATE_HANGUP:
-				if (hfp_msg == HFP_OK
+				if (at_msg == AT_OK
 					|| (hfp_parse_ciev(hfp, buf, &i) == HFP_CIND_CALL
 						&& i == HFP_CIND_CALL_NONE)) {
 					close(pvt->sco_socket);




More information about the svn-commits mailing list