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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jan 28 15:51:50 CST 2009


Author: mnicholson
Date: Wed Jan 28 15:51:50 2009
New Revision: 760

URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=760
Log:
modified rfcomm_read() in chan_mobile to handle reading AT commands in addition
to SMS prompts and AT responses

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=760&r1=759&r2=760
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Wed Jan 28 15:51:50 2009
@@ -1088,14 +1088,15 @@
  * \param count the size of the buffer or the maximum number of characters to read
  *
  * Here we need to read complete '\r\n' terminated rfcomm result code from the
- * rfcomm socket. Only the content of the result code is returned, the '\r\n'
- * parts are discarded.  The rfcomm connection to the device is asynchronous,
- * so there is no guarantee that responses will be returned in a single read()
- * call. We handle this by blocking until we can read an entire response.  If
- * the given buffer is not large enough to hold the response, what does not fit
- * in the buffer will be dropped.
+ * rfcomm socket, or a '\r' terminated AT command. Only the content of the
+ * result code or command is returned, the '\r\n' and '\r' parts are discarded.
+ * The rfcomm connection to the device is asynchronous, so there is no
+ * guarantee that responses will be returned in a single read() call. We handle
+ * this by blocking until we can read an entire response.  If the given buffer
+ * is not large enough to hold the response, what does not fit in the buffer
+ * will be dropped.
  *
- * \note an exception is made for the special message '\r\n> ', which is used
+ * \note An exception is made for the special message '\r\n> ', which is used
  * to prompt for an SMS message
  */
 static ssize_t rfcomm_read(int rsock, char *buf, size_t count)
@@ -1112,14 +1113,9 @@
 		if (res == 0)
 			break;
 		
-		/* check for '\r\n' */
-		if (got_cr && c == '\n') {
-			if (have_msg)
-				break;
-
-			got_cr = 0;
-			have_msg = 1;
-			continue;
+		/* check for '\r\n' or '\r'*/
+		if (got_cr && c == '\n' && have_msg) {
+			break;
 		} else if (got_cr) {
 			if (c != '\r')
 				got_cr = 0;
@@ -1130,8 +1126,14 @@
 				*buf++ = '\r';
 			}
 		} else if (c == '\r') {
-			got_cr = 1;
-			continue;
+			if (have_msg) {
+				/* possible start of ending '\r\n' */
+				got_cr = 1;
+				continue;
+			} else if (in_count) {
+				/* end of at command */
+				break;
+			}
 		}
 
 		/* store this character, if there is space in the buffer */
@@ -1141,8 +1143,15 @@
 		}
 
 		/* check for sms prompt */
-		if (in_count == 2 && !strncmp(buf - 2, "> ", 2))
+		if (in_count == 2 && !strncmp(buf - 2, "> ", 2)) {
 			break;
+		} else if (in_count == 2 && !strncmp(buf - 2, "\r\n", 2)) {
+			/* got initial \r\n */
+			buf -= 2;
+			in_count = 0;
+			have_msg = 1;
+			got_cr = 0;
+		}
 	}
 
 	if (res < 1)




More information about the svn-commits mailing list