howto
Posted on 07-23-2008 under
howto,
linux
I had been delaying this for a long time. Since I very rarely boot into Windows these days, it has been a real pain to access my phone’s memory card. I don’t have a card reader so I can’t do that either.
Earlier on I had looked into several ways I could do this, but nothing was clean and simple (like it should be). There was literally no way you could get away without having to put your hands right into the guts of the Linux OS and play around with devices and source code. And since, more often than not compiling source code fails because of some obscure dependency issues, I dropped the idea in favor of sanity.
Things have become a lot better since then. Thanks to Debian’s packaging system all you need to do is issue some commands and install something called openobex. I’m going to discuss what I did in order to get my Nokia 6630 to work with my Debian box using the USB cable that came with it. Start by updating your database and installing what we need.
# aptitude update# aptitude install obexftp obexfs
To check if your phone is being detected properly
# obexftp -u -l
Which should give you something like,
Found 2 USB OBEX interfaces
Interface 0:
Manufacturer: Nokia
Product: Nokia 6630
Interface description: SYNCML-SYNC
Interface 1:
Manufacturer: Nokia
Product: Nokia 6630
Interface description: PC Suite Services
Use '-u interface_number' to connect
Connecting...Segmentation fault
We need one piece of info from this list: the right interface. As you can see, Interface 1 describes itself as “PC Suite Service”, and this is what we will connect to.
Next we issue a command to list the parent directory on the phone.
# obexftp -u 1 -l
Connecting...done
Receiving "(null)"... <?xml version="1.0"?>
<!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd"
[ <!ATTLIST folder mem-type CDATA #IMPLIED>
<!ATTLIST folder label CDATA #IMPLIED> ]>
<folder-listing version="1.0">
<folder name="C:" user-perm="RW" mem-type="DEV" label="Phone memory"/>
<folder name="E:" user-perm="RW" mem-type="MMC" label="NO NAME "/>
</folder-listing>done
Disconnecting...done
We got our folder listing!! … But its all in XML. You can make out the folder names C: and E: in the last few lines. These represent the phone’s memory and the memory card respectively.
You could now use obexftp to copy files to and from your phone (read the man page for more details). An example:
# obexftp -u 1 -c E:/Music -p Take\ A\ Message.mp3
Connecting...done
Sending "E:"... Sending "Music"... done
Sending "Take A Message.mp3".../done
Disconnecting...done
This is all well and good but not really what we’re looking for. As much as I love the command line, and swear by its efficiency, I do like to use a GUI interface to manage my files. Never fear, obexfs is here!
ObexFS allows you to mount your phone so that it behaves like a normal directory. You can then access the directory in any file manager you want. It does this by using a little something called Filesystem in User Space.
First you will have to load the fuse module
# modprobe fuse
Create a directory
# mkdir /media/phone
Then
# obexfs -u 1 /media/phone
Where 1 is our interface number from before. Getting a file listing should show you the directories C and E.
# ls /media/phone
Oh glee! But wait, we’re not finished yet. If you’ve noticed we’ve been logged in as root the whole time. If you log out and try to access the mounted filesystem, you will not be able to do so as normal user! We have to fix this now.
First you’ll have to add yourself to the fuse group.
# usermod -a fuse zohair
Replace zohair with your username, of course.
Then add the following lines to /etc/fstab. (Note how the spaces in the command line disappear in the fstab listing)
obexfs#-u1 /media/phone fuse allow_other 0 0
The allow_other option is needed because by default only the user issuing the mount command can view a fuse filesystem. But we want everyone to see it.
# mount /media/phone
Done. Log out of root and access the files as normal user. If you can read but not write change the file permissions of /media/phone (or wherever you choose to mount your phone). You might have to unmount it in order to do so.
# umount /media/phone
# chmod 775 /media/phone
I’m not entirely sure that an unmount is necessay. The chmod option gives the owner (root) and the group (normal user) read, write and execute access while letting others only read and write.
REFERENCES:
EDITS:
- July 27, 2008: Corrected the usermod command line to use the -a switch instead of -G. Thanks Bruno.
- July 28, 2008: Added chmod instructions
Posted on 04-16-2008 under
electronics,
howto,
linux
After two days of banging my head against the wall, interspersed with issuing ineffectual commands, I’ve finally done it. (See shot below).

The cable drivers available with the Xilinx 9.1i software suite just won’t compile on my system. Apparently they use some proprietary functionality that does not support any kernel other than 2.4. And since I have 2.6 installed…
I had help from here, here and here.
Here’s a rundown of how I made it run on my system, which is a Debian 4.0 testing, with the following output for uname -a
Linux galileo 2.6.24-1-686 #1 SMP Thu Mar 27 17:45:04 UTC 2008 i686 GNU/Linux
I used bash throughout. If you use another shell, some commands may change.
1.
In order to avoid problems later, install libusb-dev and fxload.
aptitude install libusb-dev fxload
2.
Make a directory somewhere to store the driver’s sources.
mkdir ~/tmp/xildriver
cd ~/tmp/xildriver
3.
Download the source tarball.
wget "http://git.zerfleddert.de/cgi-bin/gitweb.cgi/
usb-driver?a=snapshot;h=HEAD;sf=tgz" -O usb-driver.tar.gz
(without the line breaks)
tar zxvf usb-driver.tar.gz
cd usb-driver
4.
Compile the driver.
make
5.
copy the library to a lib directory.
su
cp *.so /usr/local/lib/
exit
This step is totally optional. Just make sure you substitute the right path in the next step.
6.
make the linker aware of the new library
export LD_PRELOAD=/usr/local/lib/libusb-driver.so
This step will need to be repeated every time you login. Or you can add it to your shell’s rc file. For bash this is /home/user/.bashrc.
All the previous steps are common to all tutorials and sources I’ve mentioned earlier. Its also given in the README file that comes with the source. After this though, its all from Verhaegen’s email.
7.
Make a new udev rule file
I absolutely do not understand this step, but I believe it has something to do with how the USB cable is detected.
su
vim /etc/udev/50-xilinx-usb-osdriver.rules # a new file with arbitrary
#name ("50" is recommended)
Now paste this into the file and save it.
ACTION=="add", BUS=="usb", SYSFS{idVendor}=="03fd", MODE="666"
If you don’t know how to use vim, use nano instead ( or learn it). If you would rather use a graphical editor, then exit from root user and type
kdesu kwrite /etc/udev/50-xilinx-usb-osdriver.rules
Now restart udev.
/etc/init.d/udev restart
8.
Get the bus and number of the USB cable.
Plug the board in and type
lsusb | grep Xilinx
Note the bus number and the device number. Here’s my output
Bus 005 Device 016: ID 03fd:0008 Xilinx, Inc.
9.
Update firmware
If the ID in the above line is not 03fd:0008 in your case, do the following.
su
/sbin/fxload -v -t fx2 -I /home/zohair/installed/Xilinx91i/bin/
lin/xusbdfwu.hex -D /proc/bus/usb/005/016
Again without the linebreaks.
Replace your bus and device numbers from the above step into this command.
10.
Start impact (as normal user of course)
~/installed/Xilinx91i/bin/lin/impact
Impact should detect your cable automatically. If it does not go to Output->Cable Setup: and choose Xilinx USB cable.
If it still does not work, there are some more instructions in Verhaegen’s email (steps 13 onwards).
Credits
Credits go to Michael Gernoth who took the time out to make these drivers. And also to Paul Verhaegen’s excellent email and Luzerne GANHIR . Thanks guys.
Posted on 09-03-2007 under
howto,
software,
web crawling
Some time back, I was working on a project involving the ARM microcontroller, and I really needed resources on the ARM. During one of my extensive webcrawls, I found this wonderful site. This was the most comprehensive collection of ARM related technical information I had seen at that time. I had to have it.
Problem? How to download the entire site. The site is basically a mirror of one of the CD-ROMS that the Digital Systems Laboratory at the University of New South Wales hands out to their students. Who has the time to descend through all those directories and download each and every file? Even if I used Flashgot, I’d still have to click on each and every folder. (Here’s another example of this sort of problem, I needed the API documentation on my hard drive to browse offline.) Short of outsourcing this job to some sweat shop in South East Asia, I needed to find some sort of automated solution.
A few friends suggested some software that could work. But none of them did. They always had some sort of limit. Some would not let you descend more than an arbitrary number of folders. Others would refuse to resume over the previous night’s work. There had to be something I could use.
As a huge Linux/Unix fanboy, I decided to give the commandline a try. Logging on to Mandriva (my Linux distro at that time), I pulled up the command line. A few mistrials and some googling later, I found wget. This gem of a tool can descend into directories upto infinity, and can resume downloads where it left off, easily. It can work in the background, even when you’re logged off. You can also run it occasionally to keep your local downloaded copy synchronized. The man page of this tool shows the power you can wield; if you understand how to use it.
$man wget
Ok. Hold on just a minute. You dont have Linux. How the heck are you supposed to do this? You use cygwin. Its a fully functional Unix command line that runs over Windows. Interested people can go to Lifehacker and read their “Introduction to Cygwin” parts I, II and III, but this is not needed for what I’m about to show you. All you need is a Cygwin installation with wget. What you’ll need to do is download the Cygwin installer from their site, and install it (but remember to select the wget command when you see the package options).
Once you’ve got that done, you can run wget
$wget www.google.com
will get you the first page on www.google.com. Meh. I could have done that with Firefox. Here comes the good part. (Warning. This can flood your harddrive, if you try to download the Internet.)
$wget -r -l inf -nc -c -k -p <insert website address here>
The -r option is for using recursive mode. This will make wget descend into directories. -l inf means that wget should go to a maximum of infinity levels of depth. Which is what we need. -nc and -c together make wget not overwrite existing files, but incomplete files are resumed. -k edits links in the html files downloaded to point to local copies, so that the webpages become usable for local browsing. Finally -p makes wget get all parts of the webpage to make it complete (eg. images etc.)
See, its as simple as typing one line. You could also copy and paste it directly from this page, if you’re too lazy to type. And the result is that you get a complete locally browsable copy. There are lots more options for you to explore. wget is definitely a very powerful tool. Try it out and you’ll see that the command line is very frickin’ powerful.
Now you know.
Posted on 08-26-2007 under
best practices,
howto,
software
We engineers have all been faced with the same predicament at one point or the other. Management types always like to play with buzzwords and make our lives hell. One of the most frequently used ones is “documentation”. Now we can all argue whether documenting code is good or not. Some people may go as far as to say that it is the leading cause of scientific progress and might even yield the cure for cancer some day.
Skepticism (and stupid jokes) aside, there are a lot of different ways one can document one’s code. Heck, I’ve changed from one writing style to another in a matter of weeks, if not days. This snippet’s from last year.
/********************************************************
* check.h
* Menu system functions
* Fri, 01 December, 2006
* Ver: 01 December, 2006
* A menu system for the project.
*********************************************************/
Notice the contrast brought about by the lines of asterisks above and below the comment. This is so that comment blocks should stand out from the rest of the code. Turns out it also made the source code a real pain to read. Also comments in code files don’t make very impressive, presentable documentation, and you still have to write manuals and what not.
Recently I have had the fortune of learning to use doxygen. Doxygen takes your source files as input, processes all your comments and spits out really professional looking documentation in a variety of formats. You can get html, Latex and even pdf outputs (with the right tools of course), although html is more than enough for normal use.
What this means is that all your precious time that you would otherwise have wasted making manuals is now saved. It just takes a bit of practice to learn the special tags that you need to place in your code to help doxygen, and then its a breeze. Here’s an example of the excellent looking documentation you can produce using doxygen.
Installation
Its pretty easy to get started with doxygen. For windows, download and install doxygen and graphviz. For Linux, either download the tarballs, or use your package manager. For Debian do the following
# aptitude install doxygen graphviz
Usage
Installing doxygen also installs doxywizard. You can start this by using the start menu in windows or typing
$ doxywizard
in Linux. ( I would also recommend adding this to your kde or gnome menu). This GUI is pretty useful. It can load your doxyfiles and quickly responds to changes, allowing you to change documentation pretty fast.

I would also recommend downloading the doxygen documentation. (You can view chm files in Linux using Kchmviewer).
Doxygen can work magic but it does need something to go on. There are two things you need to give to doxygen.
First you’ll have to tell doxygen where your source code actually is, and how the documentation is to be generated. This is done using a file called a “doxyfile” which contains a list of assignement statements. Its pretty straightforward if you’ve ever used a config file before. If you haven’t, doxywizard will save your day (you hippy).
Using doxywizard’s “Wizard” or “Expert” options you can choose various options for your documentation. This includes stuff like what’s the projects name, where it’s source code is located, and what type of output you want (tick the “Use dot tool from Graphviz” option in the “Diagrams” tab; you’ll thank me later). Its pretty self-explanatory. You’ll have to save the doxyfile now. I name my files “doxyfile” (amazingly enough). For your first try, since you wouldn’t have used doxygen tags, select “All entities” in the “Mode” tab of the Wizard.
Second you have to have some source code (duh!). You can indicate this in your doxywizard configuration. Right now you dont need to worry about doxytags but we’ll come to it later.
Generating the docs is as easy as hitting the start button. This should usually yield no errors at all, but if there are warnings, they’ll be placed in a text file by the name of warnings.txt. If you generated an html documentation, open index.html in the html directory. See that wasnt too hard was it?.
Using Doxytags
That was pretty bland right. Especially since there was no description on any of the documented elements. Doxygen does recognize whats a function and whats a variable and acts accordingly (the graphs were nice weren’t they?). But it still does not know what you want to say about your code. It doesn’t know what aRandomVar does, does it? You are the only one who can tell doxygen that.
Doxytags are not that hard to learn. Reading the manual a little bit (don’t wince), will get you started very quickly. Basically, any comment that you enclose in a special construct is treated as doxygen comments. Doxygen will search such code blocks for tags. If you have already taken my advice and are using Programmer’s Notepad on Windows, you’ll see that it changes the color of doxygen comments. Also, it highlights doxytags that you use which makes it very easy to write doxygen-friendly comments. If you’re on Linux and using KDE then you’ve got it made. Install KDevelop and everything you need is in there. The default KDE editor (Kate) also does doxygen syntax highlighting.
Once you’ve learned how to tag your comments, you’ll be making professional looking documentation easily. There’s a lot of functionality squeezed into this tool. I’ll leave it up to you to find and use it. For example, how would you add text to your main page, or how to document non-code elements like a communications protocol on a separate page. (You’ll notice that doxygen only generates a page for each code file). You can also change the default stylesheet to make the documentation look like your very own.
This discussion has only touched on changing configuration options using doxywizard. There are loads more options in the doxyfile. This includes the options to remove folder names from your documentation’s file listing. Open doxyfile in an editor, and change the option STRIP_FROM_PATH to the path name that you wanna remove from your documentation. Check out all the other options as well.
Best Practices
This post is my first entry to the new category I’ve named “Best Practices”. Using doxygen not only helps you in generating documentation, it is also a very good way of writing standard comments. Its practically an industry standard. Most of the open source code you’ll find contains doxygen tags. So its not just an option to learn them, it could well be a necessity. Adding doxytags to your code, makes it very easy for someone else to run doxygen on it, if they can’t get your standard documentation. So using doxygen is a good practice, and should be adopted whenever you write code.
There are some more best practices I would like to share. Keep watching this space.
Posted on 08-08-2007 under
howto
Wanna keep up with the latest news on your mobile phone? Read on for the very simple way to do this and it doesn’t cost you a cent. Okay so you do have to send a message to a UK number when you register (only once) but thats all.
What you do is, you sign up for a free account on Twitter, then register your phone number. They’ll ask you to send a message to a number in the UK after which you should start receiving messages from Twitter.
The basic idea behind Twitter is that you can write something on the site, and all of your friends and followers will automatically receive your message. Once you’ve registered you’re phone on Twitter you can direct your messages to your phone.
Fine till here, but what about getting freshly baked news? Here’s where this little site called twitterfeed comes in. Twitterfeed allows you to set up any RSS feed to send notifications to Twitter. (If you’ve just crawled from under a rock, look up RSS first). So whatever news source you want, all you have to do is create a notification feed for it. More details about the process are on twitterfeed if you want to set up your own RSS feeds.
But you’re probably looking for the big news sites like BBC, CNN etc. Chances are, feeds have already been created on twitter for these sites. All you have to “follow” them on twitter, and you’ll start receiving their news feeds.
Here are some feeds to get you going:
Theres also stuff other than news, on twitter. For example, this is a good idea
If you find any more twitter links, please put them in the comments.
Be warned though. These sites update very often, and you’ll find yourself running out of message space on your phone very quickly. I have had more than 50 messages on my phone on some occasions. Especially if you were to turn your phone off for a while and then turn it back on again, you’ll get flooded. Do change your message ringtone to something less annoying because you’re going to hear it a lot. Also, deleting Twitter messages as you read them is a good tactic for controlling memory consumption. You can also limit your subscribed feeds to what you absolutely need. For example BBC South Asia generates much less traffic than Dawn News. And sometimes Dawn News repeats itself.
Also, these news reports will only be headlines. Sometimes there are a few words from the body of the news article and the rest is cut off. There is however a link at the end of the message, that you can follow, if your phone has GPRS, for the full story.
Thats it. Now you’ve got news on the go. And you don’t have to pay more than Rs.10 for the registration SMS. Enjoy.