< February 2006 >
SuMoTuWeThFrSa
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
262728    
Thu, 23 Feb 2006:

Halfway through debugging APC last night, I started to get seriously bored with the complete lack of success I was having. So I just kicked back and implemented a new feature for pnet. So far pnet's System.IO.Ports implementation has support for regular serial ports, USB ports and Infrared ports - I wanted it to work with bluetooth. For no good reason, the thought popped into my head - backup my phone numbers with a program.

So I started to recall all the AT commands I'd studied so hard while doing mobile phone testing in Wipro. I didn't have a document for GSM AT commands, neither was I sure how to set up a serial simulation via bluetooth. I cheated a bit by doing a strings libgnokii.so | grep "^AT" but I knew what those commands did. After starting the bluetooth daemon, I discovered that hciconfig/hciattach is *NOT* the tool to attach stuff to hci0. The point to note is that you need to know the bdaddr of the phone you want to hook into.

[root@phoenix ~]# rfcomm -i hci0 connect rfcomm0  00:13:70:C3:AA:7A 
Connected /dev/rfcomm0 to 00:13:70:C3:AA:7A on channel 1
Press CTRL-C for hangup

Now this is what happens when I give rfcomm0 as the resource in pnet's System.IO.Ports implementation.

Uncaught exception: System.ArgumentException: Arg_PortName
Parameter name: value
        at System.IO.Ports.SerialPort.set_PortName(String) in ./IO/Ports/SerialPort.cs:574
        at System.IO.Ports.SerialPort..ctor(String, Int32, Parity, Int32, StopBits)
        at System.IO.Ports.SerialPort..ctor(String, Int32)
        at Phonebooker..ctor(String) in phonebooker.cs:52
        at Driver.Main(String[]) in phonebooker.cs:22

Because the terminal I/O device should work with the same API no matter whether it is USB, bluetooth or regular serial ports, there was no real change to the entire code to make it work. Let's just say that it just works and leave it at that.

Then it was smooth sailing to write a small app which would read/write data from the serial port. Essentially the code looks something like the following.

port.Write(command+"\r");

while(port.BytesToRead > 0)
{
	String line = port.ReadLine();
	if(line.StartsWith("ERROR") || 
		line.StartsWith("OK"))
	{
		break;
	}
}

With these four AT commands

  • AT+CSCS='8859-1'
  • AT+CPBS
  • AT+CPBR?
  • AT+CPBR=n
I can select the charset and phonebook I want, check phonebook status and read the nth entry in there. And that basically is what the whole program does.

Just a quick reminder, you need the latest CVS head code of pnet and pnetlib to test this toy out :)

--
If you find a solution and become attached to it, the solution may become your next problem.

posted at: 12:19 | path: /hacks | permalink | Tags: , ,