Jump to content

Bluetooth programming question


  • Please log in to reply
No replies to this topic

#1
aelinden

aelinden

    InsanelyMac Protégé

  • Members
  • Pip
  • 1 posts
I don't know if this really is a Mac specific question but since that's the system I'm programming in I'll ask anyway :-)

I'm writing a program that connects to a mobile phone (For now just Sony Ericsson dumbphones) through Bluetooth (Connects through a RFCOMM channel) and then sends AT-commands to control this phone. The purpose of this program is that people with disabilities that might have trouble working a mobile can use this program to perform calls, receive calls and modify a contact list.

The user interface is written in wxWidgets since it's supposed to be as cross platform as possible, and the phone manager is written in Objective-C++ using the OS X Bluetooth stack.

My problem now is that when a user calls a number and the number is busy, I'm not getting a BUSY reply back from the phone as the Sony Ericsson developer guide says should happen. Other messages from the phone gets received, like RING when an incoming call happens, or +CLIP when returning the number of the caller.

Here is the function responsible for reading incoming data:

-(void) rfcommChannelData:(IOBluetoothRFCOMMChannel *)rfcommChannel data:(void *)dataPtr length:(size_t)length {
  
	/*
	 * Fetch data
	 */
	char buf[256];
  
	strncpy(buf, (char*)dataPtr, length);
	buf[length] = '\0';
  
	std::string cppbuf(buf);
	cppbuf = cppbuf.substr(2, length-2);
  
	/*
	 * Incoming call
	 */
	if(cppbuf.substr(0,4).compare("RING") == 0) {
		NSLog(@"Incoming call!");
		// Fetch incoming number
		char ATCommand[40];
		strcpy(ATCommand, "AT+CLIP=1\r\n");
		[self sendrfcommData:ATCommand];
	  
		/*
		 * Number request reply
		 */
	} else if(cppbuf.substr(0,7).compare("+CLIP: ") == 0) {
		/*
		 * Incoming reply has syntax "+CLIP: "<number>",...
		 * To find the number, we first look up index for space
		 * and increment that value by 2. We then look up index for the
		 * first comma, and decrease that value by 1.
		 * The number is now the substring starting at startindex
		 * with length (endIndex - startIndex).
		 */
	  
		int startIndex = cppbuf.find(" ");
		startIndex+=2;
		int endIndex = cppbuf.find(",");
		--endIndex;
	  
		if(!call_window_shown) {
			call_window_shown = TRUE;
			incoming_call_func(incoming_call_object, cppbuf.substr(startIndex, endIndex-startIndex));
		}
	  
		/*
		 * User hung up
		 */
	} else if(cppbuf.substr(0,5).compare("+CHUP") == 0) {
		NSLog(@"Hanging up");
		call_window_shown = FALSE;
	  
		/*
		 * Busy reply
		 */
	} else if(cppbuf.substr(0,4).compare("BUSY") == 0) {
		NSLog(@"Busy!");
		call_window_shown = FALSE;
		aborted_call_func(aborted_call_object);	  
	  
		/*
		 * Aborted call
		 */
	} else if(cppbuf.substr(0,10).compare("NO CARRIER") == 0) {
		NSLog(@"No carrier!");
		call_window_shown = FALSE;
		aborted_call_func(aborted_call_object);
	} else
		std::cout << "Unhandled incoming data: " << cppbuf << std::endl;
}

As I mentioned, the RING (From phone), +CLIP (From phone), and +CHUP (From user interface) messages all gets read correctly, but when the called number is busy no BUSY reply is ever sent. I've tried printing the incoming data before any of the if-statements but BUSY is never received.

If anyone can see something wrong with this code or have any ideas, please let me know. I've been scratching my head for days trying to figure out why this issue exists.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy