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!

Thursday, July 31, 2008

Host Offline

I was trying to think of a catchy title for my first post after being away so long. Due some ironic glitch in my blogging software, "Host Offline" appeared as the default text in the title box. Why, yes, I have been!

I've had so much going on that I haven't had any time to blog about it! In the last two months I graduated college, moved, got married, and started a new job. My routine changed a lot and I haven't figured out where blogging fits in to it. Two a.m. used to be my prime writing time, but these days I'm in bed by ten so I can get up early for work. I almost decided to give up this blog, but I found out my father reads it (hi dad!), so I think I'll give it another go.

Life's been great. Melissa and I had a beautiful wedding, no family members disowned each other over the wedding planning stress, and then we had a wonderful week in Jamaica to unwind. (I'll put some wedding pictures up... eventually...) When I got back I started my new job as a programmer for an insurance company and it's turned out to be a good gig, they run a clean shop and treat people right. The only unfortunate thing is that I work during the day and Melissa works at night (she's a nurse). Our hours mean I leave for work before she gets home, and she leaves just as I get home.

Melissa found us a nice apartment in Norman, which IMO is the best city in Oklahoma. I got all my stuff moved up here and - this is really shocking: I'm actually organized! Kinda. I'm still a big pack rat and leave a lot of clutter around, but all my junk box goodies are in individual draws, bins, or containers. If you name something, I can lay my hands on it in 2 minutes without rummaging. I had had a week off by myself before the wedding, and I busted ass to get my organization project finished then because it could be years before I get another opportunity like that. While sorting my 100's of TTL chips into individual bins by part number, I suddenly remembered that I had actually started sorting them 10 years ago, and hadn't finished. So this is a once-in-a-decade event.

These days I'm working on a MMO game engine, and hand-wiring an 8-bit computer, among other things, on evenings when my wife is at work. I used to think it was not possible to get anything constructive done in short shifts, but I've actually gotten pretty good at working on my projects now for just 30 minutes or an hour at a time. Having my junk box organized helps.

Tuesday, May 20, 2008

My New Old 64-bit AMD

It might be a sign it's time to upgrade when you find a better computer in the dumpster!

Melissa (my future wife) and I just moved to a nice little apartment in Norman. One of the perks of living in "the city" is people throw out way better stuff here. Just our first day in the apartment I spotted a computer tower sitting next to the dumpster. I was surprised Melissa didn't say anything when I came back from taking out the trash, carrying something larger back into the house than what was in the bag when I went out. She rolled her eyes but let me keep my new little "toy". Maybe she's used to it by now, or just tired of trying to talk me out of it! Because I'm a bit of a junk collector - it runs in the family. But I just get such a charge out of taking things that were broken/worthless and turning them into something that can be used.

This one was a real find - a 64 bit AMD Athlon 3200+; only a few years old. I was hoping it was a dual-core; it wasn't, but the board supports one, and as it is this processor is still slightly faster than my current best computer (a 2.6 GHz Pentium 4). Even though the clock speed of my Pentium is greater, AMD chips get more work done in each clock cycle, and this AMD one is 64 bit vs. my old one which is only 32 bit.

I can only imagine what kind of hot rig the previous owner must have if he throws away a good 64 bit machine! Perhaps he thought it was broken? Dead computers are almost always salvageable; usually a dying hard drive or finicky power supply is the only ailment, but I guess owners get so frustrated with such problems that they get pissed and throw out the whole thing. Or they don't understand that the CPU tower has interchangeable components inside it, many of which contain no moving parts and theoretically never wear out. This guy obviously knew at least a little about computers, because he removed the RAM, which I was sad to see missing because I'm always short of DDR sticks.

I cannibalized some RAM from one of my other computers, and I'm super excited now because the junk-computer seems to work fine!

In order to furnish this new computer, I'm going to basically split my best computer in half and make two: my best computer had 2 GB of RAM and matched hard drives in a mirror RAID; so I'm just going to put 1 GB of RAM in each and break the mirror. Sure it was fun setting up the mirror RAID a few months ago... (What am I saying? It was a pain in the ass setting up a software RAID to work with both Windows and Linux! Way more trouble than it's worth!) Anyhow as I was saying it's been fun playing with a RAID, but I can get more use out of the drives separately at the moment.

(Gosh, how do you break a mirror RAID? Do you just yank out one drive and just make the system deal with it?)

Unfortunately there'll be no pictures of this project. My beat up old camera finally died its last death. Cracked LCD, confused CPU, and it won't stay on anymore no matter how high I boost the voltage (it previously had an undervolt problem that I fixed by adding a 3rd battery). Even I can't fix it.