| April 21, 2009 9:00 PM PDT | |
Preface
The Intel® Mobile Internet Device (MID) platform provides a full internet experience in a pocket-sized form factor. Combining Moblin-based operating systems with the Intel® Atom™ processor, MIDs are able to run any application that has been built for the x86 architecture, including Adobe Flash 10* and Adobe AIR 1.5*. While the features of the devices that are and will be on the market vary depending on OEM and target market, there are several features that the devices share in common: small form factor, emphasis on internet connectivity rather than extensive storage, and alternate input methods.
Although there are ultra-mobile computing devices in the market that run Microsoft Windows XP* or Windows Vista* and that are built on the same hardware platform as those running a Moblin-based operating systems such as Midinux or Ubuntu* Mobile Edition, this series of whitepapers focuses entirely on the Moblin-based MIDs. For information on how to retrieve this information from Windows operating systems, please consult that platform’s documentation.
The functionality described in this paper is also provided via the Platform Awareness Service, a light-weight, D-Bus initiated platform information provider. However, because the final software stack for each Moblin device is influenced heavily by the OEM and Service Providers, this service may not be pre-installed on some Moblin-based devices. We have therefore written these whitepapers in order to simplify access to this information on platforms that do not have this service installed.
For further information on how to use D-Bus to retrieve information from the Platform Awareness Service, please refer to the Platform Awareness Service DBus documentation.
Introduction
One of the features of the Intel® MID platform is its support for GPS-based location awareness. While an OEM of Service Provider makes the decision about whether to include a GPS device in their MID, the ability to provide location-based services (LBS)—including context specific advertising and Point of Interaction sales—is compelling.
In addition to GPS data, there are several other ways to compute the location of a device, including IP address provider mapping, cell tower triangulation, Wifi access point proximity, etc. This paper focuses exclusively on retrieving data from the GPS device.
How to get Location Information in Linux
GPS information is not easily accessible in Linux, but it is available. Some GPS devices can connect via Bluetooth, but most will be connected via a USB or serial port. Finding out which port the device is mapped to can be rather difficult. For help on setting up a Bluetooth device, try http://gpsd.berlios.de/bt.html. Linux’s HAL (Hardware Abstraction Layer) might be useful for finding a device connected by USB or serial. You can use HAL to find out which serial devices the system recognizes, and where to access them:
hal-find-by-capability --capability serial
HAL will return a device name for each serial device that if finds (for example: /org/freedesktop/Hal/devices/usb_device_1546_1a4_noserial1_if0_serial_unknown_0). From here you can find the path to access the device:
hal-get-property
--udi /org/freedesktop/Hal/devices/usb_device_1546_1a4_noserial_if0_serial_unknown_0
--key serial.device
This will generally map to a /dev/tty* location. You can listen to the serial device directly. For example, a GPS device connected to /dev/ttyACM0 can be seen by doing the following:
cat /dev/ttyACM0
In most cases, you’ll see rather cryptic NMEA 0183 sentences that are hard to understand. See example NMEA sentances below:
$GPTPV,2005-02-11T04:40:51.231Z,?,4916.45N,123.12W,2.3,70.1,52.0,01.0,02.1,23.1,0.6,,,8,A
$GPSVU,2005-02-11T04:40:51.231Z,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00,14,25,170,00,16,57,208,39!,18,67,296,40!,19,40,246,00,22,42,067,42,24,14,311,43!,27,05,244,00
This data can be parsed and translated into geographic data.
Using gpsd
gpsd is a service daemon that can listen to a USB, serial, or Bluetooth GPS device and provide the user with meaningful location information. For more detailed information, visit http://gpsd.berlios.de/.
gpsd will connect to the GPS device and parse the device’s data into location coordinates, so you don’t have to do it manually. This takes away all of the hassle of having to translate the NMEA 0183 sentences that were shown above. gpsd also allows multiple GPS clients to have access to the GPS data at the same time. If you design your application to grab the data directly from the serial port, other applications will not be able to access the GPS data.
For these reasons, the Platform Awareness Service has been implemented to use gpsd for its location-based information.
Install and Launch gpsd
You can download gpsd for Linux directly from the website listed above or install it directly from your favorite package manager repository.
Once gpsd is installed, it must be run with a parameter indicating the location of the GPS device. In this case the path was /dev/ttyUSB0. For debugging purposes, it may be good to initially include the following optional flags:
gpsd -n -N -D 2 /dev/ttyUSB0
-n: begin polling the GPS device immediately; otherwise it will wait for a client to connect before it polls the GPS
-N: don’t daemonize; run in foreground; good for debugging
-D 2: set the debug level of information
Note: gpsd can be set to run as a daemon and can also be configured to launch upon startup of the device.
Getting Location data from gpsd
There are a couple of ways to get location data from gpsd.
1. Libgps
Libgps is an interface library (in C) that manages communication with the daemon. There’s also libgpsmm, a C++ wrappper for libgps. The libgps documentation is available at http://gpsd.berlios.de/libgps.html.
Libgps gives you the freedom to poll gpsd as often or as infrequent as you’d like. You can also create a callback method that is called anytime the GPS information is updated (like a signal).
2. D-Bus
Listening for a D-Bus signal coming from gpsd can get you this same information. In version 2.37 of gpsd, there are only two implemented D-Bus calls that an application can use. You can call initialize_dbus_connection(), then you can listen for a send_dbus_fix() signal, which includes all of the GPS’s data in a giant struct.
Using Libgps
A client application may choose to listen for D-Bus messages that come from gpsd, or it may use the libgps interface library to communicate with gpsd. The Platform Awareness Service uses libgps’s polling method to get location information. This allows clients to determine how often they want location updates.
To connect to gpsd, you must use the gps_open() function to connect to port 2947 of the host computer. Then the gps_set_raw_hook() method allows you to define a function to be executed each time a gps_query / gps_poll command is run.
#include
gboolean isConn2GPSD = FALSE;
struct gps_data_t *gpsdata = 0;
void connectToGPSD() {
if (gpsdata == NULL) {
// ran for first time: initialization
char* server = "localhost";
char* port = "2947"; // default port
gpsdata = gps_open(server, port);
if (gpsdata != NULL) {
isConn2GPSD = TRUE;
gps_set_raw_hook(gpsdata, (void *)updateGPSdata_cb);
}
}
updateGPSdata_cb is the function that is executed anytime I poll gpsd. myGPSdata stores the location data that I’m interested in.
struct GPSdata {
double latitude;
double longitude;
double altitude;
} myGPSdata;
void *updateGPSdata_cb() {
if (gpsdata->fix.mode > 1) {
// if there's a fix
myGPSdata.latitude = gpsdata->fix.latitude;
myGPSdata.longitude = gpsdata->fix.longitude;
myGPSdata.altitude = gpsdata->fix.altitude;
}
}
The gpsdata struct that is populated by gpsd carries more than just latitude, longitude, and altitude information. The only place I could find a description of this struct was inside the source code of gpsd.
With this code in place, an application is free to poll gpsd for location information at its own leisure. It only needs to call the gps_query / gps_poll methods that are available from libgps.
Writing Location-Aware Applications
In a world where more and more computational power is going into handheld devices, location-based software is being developed at a rapid rate. Hopefully this paper covered enough detail to get you started on writing your own location-aware applications for Linux.
For more complete information about compiler optimizations, see our Optimization Notice.
Comments (0) 
Trackbacks (0)
Leave a comment 
To obtain technical support, please go to Software Support.
Author
Christopher Bird (Intel)
|
