Sunday, August 31, 2008

USB Networking on the Neo Freerunner

Well the new version of the open moko software isn't much better; they changed a lot in the interface but it still has some serious bugs.

This version of the software has a bug that causes my phone to suspend every 30 seconds when the USB cable is connected, even if you have suspend set to "disabled". Guys you have GOT to fix these bugs! Seriously. I was honestly better off before I upgraded, in terms of reliability.

In order to do much with the Neo Freerunner, you really have to have USB networking set up. I found some instructions that work nicely on Ubuntu. However, if the phone suspends at any time during the process (as mine does constantly due to the bug I was talking about), then -poof- your USB device magically goes away and you lose your ifconfig settings or crash your ssh session!

Unfortunately you have to have USB networking set up in order to run the install scripts to put Debian onto the SD card. Maybe I can type in a command that will force it not to suspend, but I have to do it faster than thirty seconds over SSH because it looks like they took the terminal app out of the newer release. (The one thing that was actually any good in the old release, and they take it out? WTF?)

I'm almost ready to flash Qtopia over the open moko software and forget about it, but I did really want to see what apps the open moko distribution would have available if I could get networking so the package manager will work.

My Neo Freerunner Arrives

It's here! It's finally here! My Secret Decoder Ring Neo Freerunner!

When you open the box, you're greeted by a quote from the Tao De Ching. I keep that same book on my desk. How cool is that?

The quote seems to be about the empty hole in the bottom of the phone. Funny, I figured that was where the rope goes.

Here's what you get in the box: a stylus, USB cable, a charger with plugs for various countries, and a 512MB SD card. The back side of the green card says "Thank you for your efforts to Free The Phone."

The Neo Freerunner comes with the coolest stylus I've ever seen. On the top side of the device is a laser pointer and a bright LED flashlight. The bottom of the device has a clever mechanism which when twisted one way extends a plastic stylus tip, but when twisted the other way reveals a ballpoint pen tip. Not quite a Sonic Screwdriver but close! I ended up using the flashlight on this thing just a few hours later when a thunderstorm knocked our light out.

The display on the phone is really quite beautiful.

Getting the OpenMoko

As our cell phone contracts expire soon, I wanted to take the opportunity to get a phone that I can hack the software on (I've been quite frustrated by the horrible software on my Sprint phone). I've wanted an OpenMoko Freerunner phone because it runs Linux and you have true freedom to change the software on the phone as you like, but I wasn't sure if I could convince my wife we should spend money on it. She surprised me, however, by promising me one for my birthday!

Actually buying an OpenMoko Freerunner turns out to be a bit difficult. The "Store" section of the openmoko site simply showed "Sold Out" with a claim that more phones would be coming in July, but it was already August and they hadn't updated that message. You have to go through one of their 3rd-party distributors. There's a catch: the only US 3rd-party distributor (GP2X) doesn't actually sell the latest version of the phone!! They are selling the Neo 1973, which is a prototype to the Neo Freerunner. Due to the similar sounding names, it would be easy to accidently buy the older hardware, which lacks some features and already isn't always supported in newer software releases. Read carefully before you buy!

As of today when I look on the site, it seems you can now buy the new phones directly from OpenMoko, but when we ordered mine earlier this month, the only place that had it was the Canadian distributor, Koolu. Having never bought anything from another country before, my wife and I were unsure how to pay for something in Canadian dollars with a US checking account, but it turns out the exchange rate is all handled automatically. We didn't have any problems with the Canadian company, Koolu, but we had a string of problems trying to go through the US company PayPal to get the phone paid for. First PayPal froze my wife's PayPal account because they flagged it as suspicious activity (because it was my wife's name on the account but the ship to was my name). After jumping through a bunch of arbitrary hoops to get my wife's PayPal account unlocked, PayPal dropped the transaction anyway because too much time had passed. So I ended up buying the phone on my account and PayPal ran it as an echeck instead of a credit card, which is not what I wanted. It turns out if you are PayPal customer, there is no way to tell PayPal to run it as credit, even though if you are not a PayPal customer, PayPal will run it as credit! What kind of crap company denies a service to their members that they will give to nonmembers? So I canceled the original transaction and re-ran it as credit and not as a PayPal member, and finally got the phone. However, instead of refunding my first transaction, PayPal double charged me, wiping out my bank account. The funds PayPal sucked from my bank account were there in my PayPal account, true, but I had only intended to pass money through PayPal, not deposit it there. PayPal wasn't going to return my money from the canceled transaction unless I specifically asked for it back. As long as I don't notice what they did, PayPal effectively had an interest-free loan from me. Bastards.

Monday, August 25, 2008

I Feel Stupid And Triumphant

For years I haven't been able to run Linux on my laptop because my wireless card is not supported on Ubuntu. Dell used several different Broadcom chipsets in different runs of the laptop I got, and I had the bad luck to get the ONE chipset that is completely unsupported on Linux. The model stepping BEFORE this wireless card works, and the one after, but this one just proved to be too tough a nut to crack for the Linux driver people. By a ridiculous stroke of bad luck it ALSO has a Windows driver which can't be used with the NDIS wrapper. Trust me I've tried everything; many sleepless nights to no avail.

But in an unrelated project, I've been playing with these WRAP PC Engines router boards that I got for free because they were lightning damaged. A couple of them had mini-PCI wireless cards attached to them. These cards use Atheros chipsets, which are the most well-supported wireless chips under Linux. They would fit in my laptop, but I didn't think they worked because I could never get them to work in any of the WRAP boards. Plus I imagined tearing down the laptop to find the wireless card inside it would be a pain in the butt, so I put off actually swapping in a card to check if it worked.

When I upgraded the RAM in my laptop today I found out that the wireless card is not hidden in the bowels of the machine; it's just located under the same access panel with the RAM! I also had had the WRAP boards out and I noticed that the Atheros wireless cards I had weren't just crappy wireless "B" cards, they were really wireless "G". So I finally swapped one in and it worked! I'm writing this post from Ubuntu Linux now on my laptop, wirelessly! Yipee!

Then I realized that I could have done this six months ago. Now I feel stupid.

Sunday, August 24, 2008

C++ Iterators

A friend of mine and I are collaborating on a game in the C++ programming language. The part I'm writing is a general purpose engine that will be used on both the game server and the game client, so I decided to use templates to allow basic game objects to be replaced with entirely different classes in the client and server, yet still use all the same code on top of them.

In the process of moving my code from regular classes to template classes, I uncovered a fundamental language wart or compiler flaw. It has to do with a problem I ran into using STL iterators. Before I go into what the problem is, let me explain iterators a bit.

The people who wrote C++'s standard template library want to break you of the habit of writing things like:

for (int i=0; i < vec.size(); i++)

Instead you should write this:

for (vector< int >::iterator i=vec.begin(); i != vec.end(); i++)

Do you see the improvement? No? It's supposed to simplify code for traversing containers--except that it's twice as much typing! OK, well it also gives your code portability to use different containers besides vector ...theoretically... except that we have to specify "vector" directly in the for loop to say what kind of iterator it is! Oops.

The real motivation behind iterators is that it unifies the concepts for the people who write the container classes. I won't say the users of the container classes can't use iterators in ways that also provide benefit, but the users also bear a burden of extra boilerplate that adds as much work as it saves. This is the sort of thing Bjarne Stroustroup means when he talks about the compiler vendors and library/tools group being overrepresented on the C++ standards committee compared to actual users of C++. At least we users are finally going to get the auto keyword in C++0x, which will allow us to just write the word "auto" in place of the vector::iterator gobbledygook.

But being the good little C++ citizen that I am, I've taken the trouble to use iterators in all my code, even if it is a lot more typing. That's how when I moved my engine definition into templates, I got burned badly.

Where before I had this:

for (vector< GameObj >::iterator i=vec.begin(); i != vec.end(); i++)

I now have:

template < typename T >
... ...
for (vector< T >::iterator i=vec.begin(); i != vec.end(); i++)

What is supposed to happen is that when I instantiate the code with T=GameObj or T=OtherGameObj, the code will get built at the point I instantiated it and the result of the latter will look like the former except with either GameObj or OtherGameObj substituted for T.

Instead, it turns out that you can't (at least on my compiler) use a template argument like T to specify the type argument to a container iterator. You can declare the container using that T, but you cannot access the iterator of the container you just created! On some containers like vector you can just go back to the old notation, but for containers like map<>, iterators are the only way to loop over the container. This is a Really F*ing Big Problem. This is like laying the foundation for a building and realizing you didn't leave room in the floor plan for any doors. The irony is that iterators from the standard template library don't work with template arguments! This is like forgetting to leave room for doors in the plans for a f*ing door factory!