Wolfmans Howlings

A programmers Blog about Ruby, Rails and a few other issues

Porting xgps to Qtopia for the Freerunner

Posted by Jim Morris Wed, 27 Aug 2008 21:46:34 GMT

Background

I was getting bored waiting for Trolltech to release the next version of Qtopia for the Freerunner, so I ported the xgps client from gpsd's distribution to Qtopia.

As you may know by now, Qtopia does not have X11 so none of the existing X11 based or GTK based GPS clients work. I was exploring GPSD because I wanted to to be able to get a one time position for my sunset calculator which requires your current latitude and longitude. Although GPSD is not well suited for that (thats a whole other blog entry), I did notice you can connect to it over the ethernet, so I was playing with cgps and xgps that you find in the GPSD tar file, running on my desktop, talking to gpsd running on my Freerunner.

So wanting to dust of my Qt skills (which were so ancient I barely even recognize Qt4) I decided to port xgps to Qt.

I first did a pretty straight forward port to my Desktop Qt4/X11.

I designed the form using designer, then plugged in the code taken as closely as I could from xgps. This was not 1:1 by any means as XLib and Qt are not similar ;) I ended up just taking the ideas and algorithms from the xgps program and recoding.

So that took a day or so, as I was relearning Qt as I went, I have to say the documentation for Qt is excellent, unlike another graphics library I could mention (I'm looking at you GTK).

I got the basics working, and as my GPS fix inside was not very good (works about 50/50), I found you could also point any gpsd based client at gpsd.rellim.com and always get good data from there, this is great for testing.

So I had qtgps (for want of a better name) running on my desktop, looking pretty much the same as xgps, with the satellite list the sky view and of course the basic Fix data.

qtgps on workstation

Now the trick to port it to FR, so I could run this on my FR.

The UI wasn't going to fit on the FR screen so I revamped the UI in Designer, by basically dragging all the views into a tabbed frame. So the satellite list, the sky view, the position information and the movement information all had their own tab, this fits pretty well on a tiny screen.

qtgps on workstation qtgps on workstation qtgps on workstation qtgps on workstation

Other than that I didn't have to do much. I had to create a new qtgps.pro file for Qtopia, as the qmake qt one is somewhat different. I had to use the skeleton main.cpp that all Qtopia apps seem to use, but the bulk of the code remains the same.

Sending signals from callbacks

I did have an interesting time trying to figure out how to emit a signal from the gps callback thread to the main window, not sure if I chose the right way to do it but it worked... I created a singleton QObject based class, and allowed it to be called statically, then that does the emit. This is used to signal the main display thread that new gps data has arrived. (Note this won't work if the singleton can be called concurrently from multiple threads, Google c++ singleton pattern to see how to do that).

// Singleton for sending signal from a callback
class ExtSig : public QObject
{
    Q_OBJECT
    public:
        static ExtSig *self();
        void send(struct gps_data_t* p, char* buf);

    signals:
        void sendit(struct gps_data_t* p, char* buf);

    private:
        ExtSig();
};

// Singleton defns for emiting a signal from a callback
ExtSig::ExtSig(){}
ExtSig *ExtSig::self()
{
    static ExtSig inst;
    return &inst;
}

void ExtSig::send(struct gps_data_t* p, char* buf)
{
    emit sendit(p, buf);
}

// in callbeck call...
// signal the GUI thread we have new gps data
    ExtSig::self()->send(p, buf);

Howto build your own applications

Ok so how can you write your own Qtopia applications? There are at least two ways, 1) use the VMPlayer based Toolchain that Trolltech provide, or 2) setup your Linux workstation to use the toolkit. 1) is easier, and just works on pretty much anything that runs VMPlayer and has a lot of memory. 2) is faster and used less memory. I chose 2) but I did play with 1).

I won't go into how to do 1) as it is pretty much straight forward, just download the iso, and install it (either from a loopback device or from a burned CD).

The second method is not so well documented (if at all) so here is what I did to make it work on a Ubuntu Hardy i686 32-bit workstation with KDE installed..

Download the toolchain and install it into /opt/toolchains, it seems it must be there otherwise it doesn't quite work.

Then download the latest qtopia snapshot and put that in a working directory and set QTOPIA_DEPOT_PATH to that directory.

Then create a build directory for the qtopia build and set the QPEDIR environment variable to that path.

In my case I have QTOPIA_DEPOT_PATH=/opt/QtopiaSDK/qtopia-opensource-src-4.3.2-snapshot-20080815 and QPEDIR=/opt/QtopiaSDK/build/qtopia-4.3.2

Now we need to build the qtopia snapshot, you can use the result to copy to /opt/Qtopia on your FR, or not, but you need to do this to get the tools to build your own apps.

Now follow these steps to build Qtopia:-

> cd $QPEDIR
> $QTOPIA_DEPOT_PATH/configure -device ficgta01
> make
> make install

Go get some coffee or Dinner :) this will take a while.....

Now you will have a full Qtopia build in $QPEDIR/image

You can use the following script to copy this to your FR, it is modified from Trolltechs update script. It will keep your settings. However you will have needed to have flashed to the 0808 version of Qtopia and kernel for this to work.

#!/bin/sh
QTOPIA_DIR=$QPEDIR/image
QTOPIA_IMAGE=qtopia.tar.gz
PHONEIP=192.168.0.200
# sudo ifconfig usb0 192.168.0.200 up

tar -C $QTOPIA_DIR czvf $QTOPIA_IMAGE
cat $QTOPIA_IMAGE | ssh "root@$PHONEIP" '(set -x;rm -f /tmp/restart-qtopia;killall qpe; mkdir -p /opt/Qtopia;rm -rf /opt/Qtopia/*; cd /opt/Qtopia;gunzip |tar xvf -;/etc/init.d/qpe start &)'

Whether you do that or just keep the Trolltech released image you are now ready to write your own apps. I recommend you study the Qt docs Qtopia is pretty much Qt4.3 at the moment.

As an example you can use the qtgps.tar.gz as an example app or use $QTOPIA_DEPOT_PATH/examples/application

I created a build/myapps directory, and then tar xvfz qtgps.tar.gz into that directory. Then...

> cd build/myapps/qtgps
> $QPEDIR/bin/qtopiamake
> make

This will create a qtgps excutable that you can copy to your FR and run.

A nice trick I found is to run a GUI app from the ssh into FR you can do this...

> ssh 192.168.0.200
> . /opt/Qtopia/qpe.env
> ./qtgps

The app will popup on the FR screen, you could also run it from the terminal on the FR or from the file manager on the FR.

To create a new application you can do this..

> cd build/myapps/mynewapplication
> ... edit some .cpp and .h files
> $QPEDIR/bin/qtopiamake -project
> ... edit mynewapplication.pro appropriately
> $QPEDIR/bin/qtopiamake
> make

The skeleton main.cpp should look like this...

#include "mynewapp.h"
#include <qtopiaapplication.h>

QTOPIA_ADD_APPLICATION(QTOPIA_TARGET,MyNewApp)
QTOPIA_MAIN

The rest of the files are up to you. I like to create the UI using designer...

> $QPEDIR/bin/designer mynewapp.ui

look in either example.cpp or qtgps.cpp and qtgps.h on how to initialize a designer based UI.

There are lots of example apps on the Trolltech docs site.

Running app on the workstation

If you want to run the app locally rather than on your FR, you can use $QPEDIR/bin/qvfb

You will need to build a native version of qtopia to do that, which can be done by repeating the above steps but in a new build directory do:-

> export QPEDIR=build/qtopia-native
> mkdir $QPEDIR
> cd $QPEDIR
> $QTOPIA_DEPOT_PATH/configure -device i686fb
> make
> make install

and then rebuild your app for the native machine...

> cd build/myapps/qtgps
> make clean
> $QPEDIR/bin/qtopiamake
> make

Then run the native version of your app, but you will need to do the following to make the size correct...

> export QWS_DISPLAY=QVFb:mmWidth43:mmHeight58:0
> $QPEDIR/bin/qvfb -width 480 -height 640 &
> sleep 2
> ./qtgps -qws gpsd.rellim.com

This will run qtgps on the local workstation in a simulation of the FR screen (without qtopia), using gps data from gpsd.rellim.com.

Packaging

UPDATED I figured out how to install.

This document explains how to install a package so it shows up in the applications list, here is how I actually did it.

I created a directory called feed in my work directory, and set the path to $HTTPDIR. Then I ran a simple web server (I used boa but any will do), that points to $HTTPDIR to serve files.

Then I built the qpk package...

> cd $WORKDIR/qtgps
> make packages
> $QPEDIR/bin/mkPackages $HTTPDIR

Then make sure the web server is running, on the FR goto the Software Packages App, add the following server to the server lists http://192.168.0.200:8000, this presumes you are connected via USB and you ran the webserver at port 8000. Then click download, and you should see qtgps in the list, select it for install, and it will get installed. From then on you can replace the qtgps binary it installs with any new builds. It will be under /home/root/packages/somelongrandomstring/bin/qtgps

If you are using the vmplayer version of the SDK, then you can simply do this...

> sdk -b
> sdk -p
> sdk -i

Where to get the source

The source code to this project is now on github http://github.com/wolfmanjm/qtopiagps/tree/master

Installing required libraries for the toolchain

UPDATE I forgot to mention how I got the libgps stuff into the toolchain. I found a hack, first I built gpsd-dev using mokomakefile then I did this...

dpkg-deb -X build/tmp/deploy/glibc/ipk/armv4t/gpsd-dev_2.34-r9_armv4t.ipk  /opt/QtopiaSDK/opt/toolchains/arm920t-eabi/arm-angstrom-linux-gnueabi

This worked for this case and setup the .so links correctly. You could also copy the libgps.so from your FR.

Another user (Radek Barton) did it this way, but I haven't tested this...

1. Download lastest gpsd source code at http://download.berlios.de/gpsd/gpsd-2.37.tar.gz and unpack it somewhere.
2. Add line #include <linux/limits.h> to gpsd.h-head file.
3. Modify line 15 of gps.h file from <limits.h> to <linux/limits.h>
4. configure with command: PATH=/opt/toolchains/arm920t-eabi/bin:$PATH ./configure --host=arm-angstrom-linux-gnueabi
5. Then make, make install, etc.

For those that cannot do that, then download this tar file to /pathtodownload/...

and...

> cd /
> tar xzvf /pathtodownload/libgps.tar.gz

This presumes that your Qtopia toolchain is in /opt/toolchains

Posted in  | Tags , ,  | 6 comments | no trackbacks

Ruby 1.8.6 on Openmoko Freerunner

Posted by Jim Morris Mon, 11 Aug 2008 06:09:00 GMT

I finally got around to building ruby 1.8.6 for my FR. I modified the ruby bitbake files that I found in the Mokomakefile openembedded directory. I am not sure how one actually is meant to do this, as the OE site is down and the docs don't explain it. So I just replcaed the 1.8.5 ones with the 1.8.6 ones. I also managed to fix a bug in the 1.8.5 BB recipe that was causing socket to not build.

I also got the ruby dbus library to work, although I don't know what to do with it yet :)

So until I figure out how you are meant to add a new version to OE, I have put the ipk here.

If you want ruby 1.9 you can find it here

To install it just ssh into your FR and type

> wget http://blog.wolfman.com/files/ruby_1.8.6-p287-r1_armv4t.ipk
> opkg install ruby_1.8.6-p287-r1_armv4t.ipk

If you want to install gem then you need to ssh into the FR and do this...

> wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
> tar xzvf rubygems-1.2.0.tgz
> cd rubygems-1.2.0
> ruby setup.rb --no-rdoc --no-ri

I recommend you do the no doc and no ri otherwise it takes forever.

As for dbus...

> wget https://trac.luon.net/data/ruby-dbus/releases/ruby-dbus-0.2.1.tar.gz
> tar xzvf ruby-dbus-0.2.1.tar.gz
> cd ruby-dbus-0.2.1
> ruby setup.rb config
> ruby setup.rb setup
> ruby setup.rb install

look in the examples to see how to use it, I tries this...

> ruby examples/utils/listnames.rb --system
    org.freedesktop.DBus
    :1.3
    :1.4
    org.freedesktop.Avahi
    :1.0
    org.bluez
    :1.1
    :1.6
    :1.2
    org.freedesktop.Hal

So it seems to work.

Let me know what you do with it.

I also built jove, my favorite mini-emacs editor, this is just an executable just copy to /usr/bin Use instead of vi or nano.

Posted in  | Tags ,  | no comments | no trackbacks

OpenMoko Freerunner after a few weeks

Posted by Jim Morris Tue, 22 Jul 2008 20:20:08 GMT

Well I have had this thing for a few weeks now, and I have burned a lot of hours playing with it :) (Wish I could bill someone for those hours it would have paid for the phone 4 times over!)

I started with 2007.2 the built in image, and upgraded it initially with dfu-util, then with opkg update && opkg upgrade.

I installed a bunch of things and tweaked it to death (literally).

I got Jalimo java installed and working, and wrote the simple SWT app which worked nicely. The only change to the instructions are you need to add -force-depends to the opkg command.

As reported in my other blog article I got WIFI/WPA2 working, and finally got GPRS working.

I have not tried to pair with a bluetooth headset yet, although got far enough to see that the device could be seen using the scan command.

I played with all the varieties of on screen keyboards available, but really couldn't use any of them as they are so small, and my eyes are not that good anymore. I have seen some promising mentions of works in progress for keyboards, but the ones in the Qtopia distribution are the best, plus they have handwriting recognition which is a little fussy but looks like it can be trained.

The GPS problems were fixed by an amazing community and OpenMoko effort, which I have never seen before. There is a S/W fix, and a H/W fix which I suspect most people will not be able to do, soldering surface mount components is not for the faint of heart!

I spent several hours trying to build the OpenEmbedded and the MokoMakefile development environments, so I could start to contribute, but have still not been able to get them to finish building the native toolchain needed to build any of the apps.

I get several errors, some of which I found workarounds to by googling but eventually hit dead ends in both cases which I could not solve and have not been reported or solved by the community. I am using a stock KUbuntu 8.08 Hardy Heron desktop, which should be pretty mainstream, so I don't know what is wrong. The pre built toolchain OpenMoko provides for building apps does work however, but you can't build soft keyboards, or system components that route (at least I couldn't find a way to do it). I'll continue to hammer away at MokoMakefile and see if I can eventually get it going, of course I'll post my findings to the Wiki or dev mailing list if I succeed.

If someone could provide a VMPlayer image of a working OE or Mokomakefile environment that would help a lot of us. (Trolltech/Qtopia do provide exactly that for their development tools).

So after several opkg upgrades and tweaks, I finally killed my highly customized rootfs, X would no longer boot, sound was dead etc etc.

I tried to backup the image using these instructions, but always got an error halfway through, I suspect my flash image of rootfs may have been corrupted. Anyway I lost all that work :(

I tried flashing ASU, but it seems too much a work in progress more so than 2007.8.

Then I tried Qtopia now this is much more to my liking. The interface is clean, intuitive and seems to work pretty well. There are still a few rough edges which Trolltech seem to be taking care of, but it mostly works pretty well. The on screen input methods (which there are several of) are very good, even the keyboard has a nice touch where it zooms into the keys you are touching. It also has the tiny tiny QWERTY keyboard if you prefer that style and your eyes still work.

The downside is of course you lose access to all the applications currently under development for the GTK based 2007.2, but Qtopia does have a growing number of applications, and of course you can write your own.

I am going to experiment a little with trying to run GTK based apps under Qtopia, I know I can do that on my KDE (aka QT) desktop, so why not under Qtopia? I'll update this if I get it to work.

UPDATE Oh ok the reason you can't do that is that Qtopia is not running X Windows, so running GTK is not an option, bummer. I suppose you could render GTK into a QT canvas or something but that is more work than I am prepared to do at the moment.

The current show stoppers for me, which stops me being able to use this a phone are...

  • Nasty buzzing noise on both ends of the call
  • Bluetooth pairing with a headset not easily available.

I'm sure people are working on these issues, and I wait patiently for them to get fixed so I can dump my aging Motorola V600. I'd actually try to pitch in myself but I can't get the development environment to work!

Oh well guess I better get back to my paying job :)

Posted in ,  | Tags ,  | 4 comments | no trackbacks

Upgrading Ubuntu Gutsy to Hardy

Posted by Jim Morris Sun, 13 Jul 2008 11:32:03 GMT

I did my duty and upgraded from Gutsy to Hardy, after letting Hardy settle for a while. For the most part it was painless (unlike the last upgrade to Gutsy!).

Unfortunately the sound was now broken I have a HDA-Intel AD198x Analog chip set.

Then I discovered (just when I needed it of course) that my Samsung ML-2010 USB printer didn't print anymore.

I would get this weird error...

Unable to open device hal:///org/freedesktop/Hal/devices/...

After Googling I found this, he was half right, I don't know why but it works, except that I needed to do...

sudo chmod 700 /usr/lib/cups/backend/usb
sudo chmod 700 /usr/lib/cups/backend/hal
sudo killall -HUP cupsd
sudo /etc/init.d/cupsys restart

ie both usb and hal.

That fixed it... Amazing!

Now why won't my audio work???

Ok now it does work, go figure. The only things I changed were added this to /etc/modprobe.d/alsa-base

options snd-hda-intel model=3stack-dig

and made sure that Front was checked in the mixer and turned up.

Not sure which of those fixed it though.

Posted in  | Tags , ,  | 3 comments | no trackbacks

Older posts: 1 2 3 ... 10