Project to replace the OEM CD changer in the boot of my convertible E46 BMW with a Linux mp3 player and the IBUS

SourceForge.net Logo
Sourceforge project page with CVS

News

New entries at the top

Update 16 May 2006

Spent most of the last month trying to improve the boot time. I have the computer out of the car and on the bench. I will post a table soon, but in short, I've reprogrammed the PIC for the power supply, replaced the bios with LinuxBios v2, and I have roughly haved the boot time to 14seconds. That's the time from power on (which will be unlocking the car with the remote), to the cd emulator sending the announce message.
Also fixed a bug to do with scrolling the message.
When I had the computer in the car I noticed there was an audible rattle above 50mph, I think this is either the VoomPC case vibrating on the home made bracket, or the bracket vibrating against the car. So I bought a piece of rubber sheet from RS.

Update 18 April 2006

Having a lot of music to navigate with just a few buttons and a single line display is a problem. So far I have put in move next/previous track, move next "album" (which moves to the next directory) and I've recently added move to next top level directory. If your media is arranged into genre's, then you can switch genres with one button push. The display shows the name of the directory when switching.
Also added scrolling messages, with speed configurable in the settings.xml. Introduced the concept of a background message. If a message is sent to the queue to be displayed, it is shown for a configurable number of seconds before the next message is pulled from the queue. If there are no messages in the queue, then the background message is displayed. Currently this is composed of the artist and title from ID3 tags, or just the name of the file if neither can be found. Only the background message scrolls at present.

Update 10 April 2006

Fixed a fundamental bug in the ibus code, which caused it to hang sometimes if there was no data available on the IBUS. Hopefully this will make it more reliable.
Put in the move previous, so that now seems to work fine. Also added ID3 tag handling using libid3tag, so I can now get the title out and display it. Thats not working yet, so I'll need to look into that next. Fixed a bug in the synccode web page, so that it shuts down the currently running cdemulator.

Update 7 April 2006

Not done too much lately. I've put in the move next track, and partially done the move previous track. This will work like a depth last, left to right tree traversal. So the cdemulator is configure with a media root. This is the top level directory and the media can be contained in this and any sub directories. The player will first play the tracks in the root and then go down into the first (alphabetical) directory and play the tracks there. Then it will recurse into any sub direcories in this directory and so on. When there are no more subdirectories it move back on one level. It will follow symbolic links, allowing the categorization of media by anything you like - genre, year, etc.
I've also started on the message queue display loop. This will allow any part of the cdemulator, or any other program, to submit a string to be displayed on the head unit. This uses a kernel message queue, and is a FIFO (first in first out) IPC (interprocess communication) device. Each message will be displayed for a configurable amount of time before being discarded and the next message displayed. I will put in the ability to either scroll messages or jump through the text (at word boundaries) to allow for messages longer than the display (12 characters IIRC).

Update 30 March 2006

Now that I can start the cdemulator program in a test mode, i.e. on my desktop, I have been getting to grips with the basic mp3 player controls. I have a IPC message queue which I can use to talk to the cdemulator to simulate messages appearing on the ibus, and I have a tester program which sends IBUS messages. Also did some tidying up on the starting of the mp3 player. The player is now defined in the settings file, and is invoked from a fork/close/dup sequence so I can capture the output. That all appears to work quite well so far, even if Eclipse sometimes leaves my program running when I stop the debugger. Next plan is to map the ibus messages for the button presses to commands in the cdemulator, so I can at least move to the next track.

Update 28 March 2006

Had a few problems recently. Firstly the computer would sometimes not boot. I took it out of the car and it booted fine on the bench, so I put it back. A week later it stops booting again, so I plugged in my monitor to see the BIOS message. It said there was no valid boot disk, so I removed it from the car and sure enough the IDE cable was a bit loose. I pushed it back in and put the computer back in the car. It didn't boot again. I fiddled with the cable through the holes in the VoomPC case and it booted. I think the problem is that the VoomPC case only allows me to mount the harddrive in one direction and that is with the cables pointing down. As the car vibrates, the connector slowly comes down and out due to gravity. I am going to drill some more holes in the case so I can mount it the other way up.
The other problem I have is with the VIA8235 sound chip. It reports ALSA underruns of at least 0ms, whatever that means. It also seems to reset the volume levels to 0 sometimes. Strangely if I give it an invalid dmix configuration in the asound.conf then it seems to work ok. I am having an ongoing discussion on the alsa user list at the moment, so I hope to get this resolved.
On a more positive note, I have started the IPC message queue work so I can get the cdemulator to do stuff from other programs. My first use of this is to get an IBUS simulator working so I can develop the CD player in the house.

Update 25 March 2006

Been playing with the syncing of the media and the car web site. Right now the web site just lets you update itself and the code. The code current consists of the cdemulater (which sends the IBUS commands and plays mp3s) and the docker which syncs the media when the car is in range of the media center. There is still a little playing around to do with the permissions and sudo-ing from php, but it works well enough even if it is not very secure. I am not too worried about the security at the moment - the wireless is only configure to connect to my WEP protected access point, so I imagine it would be pretty difficult to get in.
Also got some ALSA underruns which I have posted to the ALSA users group, so I hope I can get that sorted out.
It only plays in random mode at the moment and none of the buttons are configure to do anything. Sometimes it doesn't play at all so that needs looking at first.
I found a wire, red/yellow, going to the light cluster which gets power when the care is unlocked and loses power when it is locked. This seems ideal for the M1-ATX "ignition" line as it will get the computer booting as soon as possible. The only problem is that if the car is unlocked, and not started, then after a few minutes, maybe 15, then it loses power. This is not too serious as the only reason for keeping the computer turned on in this scenario is to finish syncing the media. The docker program does this already and will not allow shutting down until it has finished. (Unless the M1-ATX shuts it down first. Currently in 2 hours as I have it on the B only setting).

Update 9 March 2006

Created a bracket to hold the VoomPC case. I used a bit of aluminium sheet (about 1-1.5mm thick) and bent and cut it to resemble the OEM bracket the holds the cd changer. It is basically an L shape in cross section, has 4 holes in the base and 5 holes in the side. One hole in the side is for securing to the car and the other 4 are for mounting the VoomPC case.
I have currently got the case mounted with the slots towards the rear of the car, and in this configuration I can get reception with a pcmcia card (actually a CardBus Belkin FD6020/atmel) at my access point. The signal is travelling through the sheet metal body work of the car, the metal garage door, and a double cavity wall. That's good news for me as I don't have to get a card with a seperate aerial.
Next problem I have been thinking about is the ignition signal for the M1-ATX. I don't have a fuse box above the battery in my car, so its not immediately obvious where to get an ignition signal. I was thinking of using the IBUS negative edge to trigger a latch to turn on an "ignition signal" and the negative edge of the real ignition signal to trigger another latch to turn off this ignition signal. But the lack of an obvious ignition wire to tap into made me think about alternatives. So now I am thinking that the boot latch may get a signal when the car is unlocked, and it may lose it when the car is locked. I need to test this theory next before moving on. With a bit of luck I could just use this signal to connect to the M1-ATX white "ignition" wire.

Update 28 February 2006

Bit of a delay since the last update. Two reasons: went skiiing; bust my knee. Anyway I assembled the EPIA MII 6000, with the 80Gb drive and M1-ATX power supply. No problems with the assembly, although the connector for the drive is quite tight against one of the power supply mounts.

Running on the bench

Not ready to install in the car yet, so I have the board running on the bench using and old non-ATX power supply. I just connect to the "ignition" wire to the 12V line (yellow wire) to simulate the ignition switch with a crocodile clip.

Update 6 February 2006

Finally got some text to appear in the head unit/radio of my E46. There's space for 12 characters. I use the message :

0xc8 0xxx 0x80 0x23 0x42 0x07 "text"


which is normally used by the telephone system I suppose. 0xxx is the length of the packet as per normal Ibus message format. But will do for me to display menu navigation stuff and ID3 tags etc.
Ordered a bunch of stuff from www.linitx.com today . They shipped it same day, so this looks like a good company. I bought :

Other changes are that I now have every message echo'ed successfully now I am using the resler interface. No doubt I could use the echo to do software collision detection with the USB interface as well - that's mostly coded already, just the retry loop is missing.
Must do some reading on the LinuxBios project and the DiskOnChip stuff as I want a really fast boot, and this promises sub 5 seconds.

Update 1 February 2006

Not made a lot of changes recently. I put in some code to stop playing and to move to the next track. There is no library management code, so moving to the next track does not actually do anything yet. I want to get some text to display in the OBC text bar before deciding how to navigate the media library. I did tidy up a bit of the start up code, and its now a bit more reliable, although sometimes it does not get recognised straight away, but I have to wait for the 30 seconds poll to come round again. I'll need to look into that sometime, but it may be related to collision problems on the IBUS. I am waiting for my reslers interface which should come in a day or so to see if that has the same problem.
I've been looking at the circuit diagrams for the resler interface in the meantime to see how it handles collisions. If the gif on his website is correct, the SENSTA line is connected to the DSR on the RS232. So if there is a collision, its as though the DCE is offline. I'm not convinced this is enough to get 100% results, as I wonder what happens if there is a collision just in the middle of the transmission. Does the packet get split? If hardware control is enabled, I imagine the data just gets buffered until the DCE is online again which to me suggest that the packet would get split. What would be needed in the software I think, is to have the whole packet resent, if the DSR goes low at any point during transmission. Using linux I'm not sure its possible to get an interrupt for DSR outside of a kernel module, I've had a look and its available in ioctl, but not as an interrupt. I need to keep looking and maybe post a question in some forum.

I've also had a look around at networking options for syncing the media library up when the car gets in range of your house. I would like to go for pre-N but I don't think there are any linux drivers, except using ndiswrapper. That's a shame as I think pre-N has better range which could be really important given that the ariel will be in the boot.
The last week (and this week) it has been around 0 Centigrade outside in the evenings here (NW London) and so now I'm nursing a light cold. At least I'm getting some time indoors before the reslers interface arrives :-)

Update 27 January 2006

Plugged the audio connector in and after fixing some stupid mistakes in the code I got the emulator playing mp3s in the car. Created a project on sourceforge where I will put the source code. For some reason I cannot get a message to display on the OBC display. I am becoming suspicious about the collision problems on the IBUS with this USB adapter. The resler serial adapter should come next week, so that should help track things down. Also the pdf in hacktheibus does not seem to fit my car when it comes to the cd player announcing itself: after the announce message, I get a Stop playing message which I respond to with the status of not playing. If I don't do that then I get a "no magazine" message in the OBC display.
Pleased about getting the audio out. I could now put a box in and listen to mp3s, well just one at the moment as I haven't thought too much about how I'm going to do the navigation through hunderds of songs with just a few buttons and a single line display.

Update 24 January 2006

Wired up a connector for the audio. I used a common 3.5mm Jack to 2x phono connector. I cut off the phono connetors and soldered the wires up to a 3 pin x 2 row .1 inch pitch header plug which I mounted on an old PCB. I wired the red up to pin 4, the white up to pin 1, etc, as it says in the CDAI_connectors.pdf that is in the hacktheibus files section on groups.yahoo.
Hopefully will get the chance to try it out tomorrow.

Update 23 January 2006

Made a bit of progress over the last week. I can now get the laptop to play an mp3 on request from the radio console in the car. So I think the communication is basically working. I don't know if there is any collision detection going on, the IBA software uses the RTS signal for this, but in my case that doesn't work. In fact seeing as I use a USB device which connects to the IBUS what does RTS actually mean?
The other day the laptop would not send anything at all out, so I'm a bit worried about the cause of that. Just have to wait and see if it happens again. At the moment I run with the termio set up like this:


void init_ibus(char *serial_device)
{
/* open the device to be non-blocking (read will return immediatly) */
fd = open(serial_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd <0) {perror(serial_device); exit(-1); }

/* install the signal handler before making the device asynchronous */
saio.sa_handler = signal_handler_IO;
(void)sigemptyset(&saio.sa_mask);
saio.sa_flags = 0;
saio.sa_restorer = NULL;
sigaction(SIGIO,&saio,NULL);

/* allow the process to receive SIGIO */
fcntl(fd, F_SETOWN, getpid());
/* Make the file descriptor asynchronous (the manual page says only
O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
fcntl(fd, F_SETFL, FASYNC);

tcgetattr(fd,&oldtio); /* save current port settings */
/* set new port settings for canonical input processing */
newtio.c_cflag = BAUDRATE | PARENB | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
/* newtio.c_oflag &= ~OPOST;*/
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VMIN]=1;
newtio.c_cc[VTIME]=0;
tcflush(fd, TCIOFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
clear_ibus();
}

Update 16 January 2006

I've been working on the linux software for a couple of hours. I am using C on Linux with a null modem cable plugged into a laptop running Windows and the IBus Analyser software. I have it receiving data but the IBus Analyser (IBA) reports that the bus is busy all the time so it sends each packet 10 times. Most likely because my null modem cable does not have RTS and CTS connected. I wired them up tonight and should get another go in the next day or so.

Update 15 January 2006

First problem:
How to get at the cables for the cd changer:
Moved to the Installation page.

Update 9 January 2006

First entry. Fed up with only being able to listen to 6 cds at a time in my convertible 3 series BMW. Basically I am too lazy to change the CDs so I end up with the same ones in the car for ages. Anyway CDs are for luddites.
What I really want is an mp3 player, and as a plus I would like some GPS. So I thought I'd have a go at building my own Linux machine, sticking an mp3 jukebox on it, and hooking it up to the IBus interface. Plenty of people have done similar things, so I should be able to get this working - if it holds my interest long enough.
So far I have located the CD changer (in the boot!) and bought a USB IBus adapter from EE Design Kits. There seem to be 2 options for the adapter, USB and RS232. The IBus is a serial connection, so either maps closely at a physical level. RS232 would mean a smaller linux kerenl, but as I want to add more devices like GPS later, then I may have to go to USB anyway. We'll see how it goes. I ordered the part about a week ago so next update will be when it arrives.