GPS Intermediate Driver – One of your best friends

I do believe that more and more Windows Mobile Applications will become Location Aware. Prior to Windows Mobile 5.0 it took a lot of work to deal with either integrated or external GPS hardware on Windows Mobile Devices. Even though GPS data is usually received through a serial port, you had to figure out which serial port to use, read raw NMEA data and interpret that data to retrieve for instance latitude and longitude information. Even more challenging was the fact that, most GPS functionality was exposed through a Stream Interface Device Driver. Using one of those drivers is easy enough, since it closely follows File IO API’s. In order to open a device you were calling CreateFile, specifying a device instead of a physical file. To retrieve raw NMEA data you repeatedly needed to call ReadFile, followed by parsing the NMEA data string. Finally once you were done you would call CloseHandle. Even though the Stream Interface Device Driver Model is easy to use, it also gave you some challenges, not limited to retrieving GPS data. First off, each application dealing with NMEA data most likely contained its own NMEA parser, meaning re-inventing the wheel frequently. Perhaps an even bigger challenge had to do with the nature of a Stream Interface Device Driver. Only one application at a time could get exclusive access to the GPS hardware. With Location Awareness becoming more popular, this is really a problem. After all, I don’t like to close my navigation software when I for instance want to start a social networking application that is location enabled as well.

Windows Mobile 5.0 and Windows Mobile 6 devices solve all of these problems thanks to the fact that they ship with the GPS Intermediate Driver (GPSID). Even though GPSID is not really a true device driver, it is a software layer implemented as a Windows CE service that sits between the GPS hardware’s device driver and the applications that want to make use of Location Awareness on your Windows Mobile Device. In other words, to the GSP hardware’s device driver, GPSID acts as the only application that will access the GPS hardware, and to applications on your Windows Mobile Device, GPSID acts as the entry point to the actual GPS hardware. For legacy applications, GPSID exposes a Virtual COM Port, so these applications can still access the GPS hardware without any modifications. GPSID can even return raw NMEA data to legacy applications. The only functionality available for legacy applications inside GPSID is a translation from a virtual COM port to the physical COM port on which the GPS Hardware operates, to assure that requests from a legacy application will actually arrive at the GPS Hardware.

For newly written applications, GPSID exposes its own API’s that allow accessing GPS Hardware on a higher level. Of course there are native API’s available like GPSOpenDevice, GPSGetPosition, GPSGetDeviceState and GPSCloseDevice. These API’s make use of Win32 events to allow your application to react on Postion and DeviceState changes when they occur rather than polling for information. In this way, you will preserve precious battery power.

You can also access GPSID from inside managed applications. When you install either the Windows Mobile 5.0 or the Windows Mobile 6 SDK’s, you will get lots of sample code. One of the samples not only shows you how to make use of GPSID, but it also contains a managed wrapper around GPSID functionality. You can find these samples in the following folder:

<Installation Folder>\<Windows Mobile SDK>\Samples\PocketPC\Cs\Gps

or

<Installation Folder>\<Windows Mobile SDK>\Samples\Smartphone\Cs\Gps

Of course, the sample is available for Visual Basic.NET as well.

Using GPSID, either in native or managed applications will give you a number of advantages. It is no longer necessary to parse raw NMEA data. GPSID will take care of that for you, and can for instance return latitude and longitude information in a data structure. Probably the biggest advantage of using GPSID is the fact that multiple applications can simultaneously make use of GPS Hardware, because GPSID implements a multiplexer to allow different applications to retrieve and make use of Location Information. To me, GPSID is an important and very valuable piece of software and I strongly recommend you to take a look at it, start playing with it and make sure to use GPSID inside your next Location Aware application.

In a number of consequent blog entries I will show you some samples on how to use GPSID both in native and managed applications.

Happy Coding!

Constanze