Wednesday 4 February 2009

Priming the Openmoko U-Blox GPS Chip

I just wrote a little companion application to the YGPS Satellites app, or indeed any other application that uses the GPS chip on Openmoko. This new app speeds up the time-to-fix by communicating with the UBlox Online Assist server to download ephemeris data via the internet rather than waiting for the same information to be available via the GPS feeds. For me it speeds up the time-to-fix to a few seconds in some cases, less than a minute in most, while without it it can take up to 10 minutes to get a fix (has something to do with my desk being indoors, only facing a window).

The technical details for the U-Blox Online Assist feature can be found in detail on the Openmoko GPS pages.

To use the application you will have to get a free account with UBlox, because the requests require a user name and password. To obtain an account, send an empty email to agps-account@u-blox.com. I received my account password soon later by (apparently) automated email.

The app itself is headless, i.e. has no user-interface as such and is not installed to be launched by a user on its own. It consists of a BroadcastReceiver that waits for messages from other applications (such as my updated YGPSSats.apk) and then tries to interact with the UBlox server and primes the chip. It communicates back to the user with a few toasts. A preferences dialog allows the user to enter his Ublox Account details.

An updated version of my YGPSSats.apk checks whether the YGPSUblogs.apk is installed and then gives two additional menu options, one for setting the account details and an approximate location, the other for priming the chip. The updated YGPSSats also conveys (onStop()) the last known location to the ublox app, so that the next time the location details are as accurate as possible. (If you travelled far without the app on, set the location manually via settings).

The most likely error the app encounters is not having internet access, but sometimes there seems to be garbled responses. If you get an error and you believe you have internet access, simply try again. There seems to be no harm in priming a chip that already has a lock-on.

Installation


You will need the new version of my YGPSSats.apk, which contains the interface code to the ublox app. Users on phones other than Openmoko Freerunner will not see the new menu options. See below for installation hints if you are on the Koolu-RC3 image.

The you will need the YGPSUBlox.apk itself. This app will not show up in the launcher, but once it is installed you will get new menu options on the YGPS Satellites app.



Current limitations and work-arounds


Entering text into preferences dialog


The current Android version on Openmoko might not allow you to enter text into a preferences dialog. If this is the case run:
 adb pull /data/data/com.yunnanexplorer.android.gps.openmoko/shared_prefs/com.yunnanexplorer.android.gps.openmoko_preferences.xml prefs.xml

Then edit the prefs.xml file to add the following two lines:
<string name="ublox_password">your password here</string>
<string name="ublox_username">your email account name here</string>

The upload the prefs.xml file to your device with
adb push prefs.xml /data/data/com.yunnanexplorer.android.gps.openmoko/shared_prefs/com.yunnanexplorer.android.gps.openmoko_preferences.xml

When first starting you should also supply your approximate location and an accuracy estimate. The YGPS Satellites application automatically
saves your last location to these fields, so once you have a fix when running YGPS Satellites, the next time you start up (and have not moved to far
from your last location, this information should be good enough. If you start up your GPS at a distant point, you should either set the new location
or just wait for a natural GPS fix.

Installation on Koolu Beta-3


The new Koolu-beta 3 image has the YGPS app installed in the systems folder, meaning that it cannot be uninstalled or upgraded by a user.
To change this mount the rootfs in read/write-mode and remove the app from the system folder

adb shell
mount -o remount,rw rootfs /
cd /system/app
rm YGPSSats.apk

The application should then be automatically removed and can thus be reinstalled















Sunday 1 February 2009

Visualizing the GPS Satellite Status

In a previous blog I mentioned that J Larimer J Larimer posted a way on how to get to the satellite status information that is captured by Android from the NMEA GSV messages.

I now put a little app together that visualises the satellite status in a way some GPS units do this. This is how it looks like on my OpenMoko:


On the OpenMoko this APK will run if a patch I posted on the Koolu Android Forum is applied to the Android Openmoko build as otherwise the GPS GSV NMEA messages are not parsed at all.

I do not have a G1 phone, but J Latimer's post suggested that the messages are correctly parsed on the device and that the updates are propagated through the Android stack. I would love to hear from someone if this works for you on the G1. Maybe even send a screenshot.

The APK for this app can be downloaded from here and the source is here.

Friday 9 January 2009

Android GPS Internals: Satellite Status Updates

Trudging through the Android source code one will find that in addition to the location updates, the location library also provides updates on the state of satellites. But this functionality is hidden from developers, unless one delves into a bit of hacking as demonstrated here.

First of all a quick recap of how the GPS functionality works. On the G1 phone there is a library libgps.so which provides the interface to the GPS hardware. The code for this is not open source and is not available. However, what we do know is that this library communicates with Android over a set of callbacks, which are defined in
hardware/libhardware/include/hardware/gps.h.

In the emulator this hardware functionality is replicated in gps_qemu.cpp and can parse two of the many GPS NMEA sentences which are then sent on to trigger location updates. This allows users to trigger updates through the geo nmea messages mentioned in the documentation. However, satellite status updates are not part of this and any such message is just eaten.

However, changing this is not that difficult: it requires adding code to parse NMEA GPGSV messages in the qemu code and triggering the status update callback. I made an inital attempt at these changes for my OpenMoko Freerunner, which I posted in the Koolu Forums.