gnome-gps: a simple GTK+ GPS monitor

Screen shot of gnome-gps

Updated July 2011

I intended this more as a learning experience, but as it corrects several defects in other gps/gis programs, I am turning it loose on the world under same terms as gpsd, i.e. under the BSD license. Readers may find it useful for studying GTK+ programming (or not…) as well as libgps programming (again, or not…).

I use this as I travel to keep an eye on altitude, speed and quality of the fix, none of which is readily available in other GPS display programs I use. Here, "readily available" means in large enough font that I can glance at the laptop and read it without squinting.

Requirements

This version is designed to work with gpsd 3.0, gps protocol version 5.0, once the gpsd folks turn that loose. Until then, you will likely want the head version of gpsd from the git repo. This version identifies itself like so:

charles@yendi:~$ gnome-gps -V

gnome-gps: Copyright © 2009-2011 Charles Curley
This program is released under the same terms as gpsd itself, i.e.
under the BSD License. See the file Copying in the gpsd distribution.

This program comes with ABSOLUTELY NO WARRANTY.
0.91, compiled for gpsd API version 5.0.
Usage: gnome-gps [-d d] [-m] [-k] [-p port] [-u] [-v] [-V] [host]
charles@yendi:~$ 

Running it in verbose mode reveals, among other things, GPSD version: 3.0~dev Rev: release-2.96-631-g43a0117, Protocol 3.4. There is a compile time check for gpsd API 5.0 or greater.

I compile and run this on Ubuntu 10.10, "Maverick Meerkat". The version of gpsd in the repos is 2.94-2, which is not compatible. If you have it installed, uninstall it. Note that it is a dependency of KDE. See the gpsd troubleshooting notes on Ubuntu/Debian.

Features

There are several features common to gps display programs, like the ability to display data in various units. The program can save settings to a resource file, a dot file named after the program. (If you rename the executable, you change the name of the dot file that executable will look for.)

One thing that is unusual about this program is that most of the time it uses a progress bar to show the relative proportion of visible satellites and the number used in the fix. It also uses the progress bar for user information, such as announcing when it makes a connection to gpsd.

The program doesn't display the quality of the fix as text. Rather, it changes the background color:

  • Red, no fix or other problem.
  • Yellow, two dimensional fix.
  • Green, three dimensional fix.

Your GPS receiver may send a bogus time when it has just fired up. This program will display that bogus time.

The code detects the loss of a connection to gpsd, and puts an appropriate message into the progress bar. It also will detect when gpsd has lost contact with the GPS receiver, and places a different appropriate message in the progress bar. It will recover once the fault is repaired. These features rely on code in the 5.0 protocol.

You can specify a font from the GUI. You can also force the program to attempt to reconnect to gpsd, or to another gpsd. Since recovery from loss of a connection should be automatic, the resynch option should be useful mainly to change the host and/or port of the gpsd connection. The defaults are "localhost" and the port indicated by the gpsd code at compile time, TCP port 2947.

No ./configure or ./autogen folderol. "make" is all you need.

Bugs

The window will expand nicely if the user selects a larger font. However, I haven't found out how to make it shrink when the user selects a smaller font. Workaround: manually resize it. Volunteers?

It would be nice if one could preserve the location of the window on the screen in the resource file. Volunteers?

Much as I dislike Gnome's pseudo-registry, it might be nice to move to that to preserve options.

Internationalization: there is none.

Options

A somewhat more detailed look at the options:

  • [-d d] ("degrees") Specify display of lat and long in one of d: degrees and decimal degrees (ddd.ddddd), m: degrees, minutes and decimal minutes (ddd mm.mmmm), s: degrees, minutes, seconds, and decimal seconds (dd mm ss.ss).
  • [-m] ("metric") Set metric units.
  • [-k] ("knots") Set the speed unit to knots, others to appropriate US measurements.
  • [-p port] Specify the port at which to attach. The default is the gpsd standard, as provided by the gpsd code at compilation.
  • [-u] ("US") Set units to US units, including statutory miles.
  • [-v] ("Verbose") Set verbose mode: print lots of stuff to stdout, including fixes.
  • [-V] ("Version") Print out the version and other information, and exit.
  • [host] Specify an optional host. The default is "localhost".

Once you have set these options, using command line switches as above, or from the menus, you can preserve them with control s, or, using the mouse, File -> Save.

The Code

The code is available.

Notes on specific files.

The Icon File

The icon code, "icon.image.c". I took a screen capture of the program running. I then generated the C source with:

gdk-pixbuf-csource gnome-gps.logo.png  > icon.image.c

I then removed the keyword "static" and added a #include for <gtk/gtk.h> and added the file to the make file.

Changes

2011-07-02: We now use make and have several files. We now distribute by bzipped tarball. And a more recent version of the code.

2011-02-06: Update to 5.0. Added an icon. Changes to match changes in the API. Many bug fixes. We now show the driver information in the title.

2010-10-28: Added a note about bogus times at GPS startup.

2010-06-27: Better detect a missing GPS receiver and a new GPS receiver. Prototypes for all functions. Better resych () factoring. Use the progress bar for more error messages, e.g. GPS receivers or gpsd going AWOL. Other cleanup.

2010-05-16: Added void casts where appropriate. Cleaned up the style a bit. Made error messaging when the GPS receiver goes away a bit clearer.