10.4 Listening to a GPS

 <  Day Day Up  >  

Listening to a GPS from a Linux box is as simple as listening to any serial device: plug it in, make sure the driver (if any) is loaded, open the port, and read the stream. We tried connecting both the PocketMap CF GPS (using a CF-to-PCMCIA adapter) and the Deluo USB GPS. The PocketMap GPS was detected automatically as a serial port; we needed to load the Prolific 2303 USB/Serial module ( modprobe pl2303 ) for the Deluo GPS to be recognized (it appeared on /dev/ttyUSB0 , as did the Nokia 6200 described in Chapter 9).

Most GPS devices use a format called NMEA 0183; however, many of them include proprietary extensions. The NMEA standard specifies a transport of RS-232 at 4,800 kbps, 8 data bits, 1 stop bit, and no parity, but some devices support higher speeds. The Deluo GPS that we used sends standard NMEA sentences in the sequence GPGGA-GPGSA-GPGSV-GPRMC. Each sentence is a line of comma-separated text that begins with $ TYPE (where TYPE is the NMEA 0183 sentence type) and ends with a checksum value, as shown in Example 10-1.

Example 10-1. Sample output from the Deluo GPS
 $GPGGA,071110.000,3242.8536,N,11709.7626,W,1,05,01.5,00104.2,M,-34.0,M,,*50 $GPGSA,A,3,22,16,,14,20,,,,,25,,,02.5,01.5,02.1*05 $GPGSV,3,1,10,22,11,117,35,16,13,151,35,11,44,256,,14,26,056,35*78 $GPGSV,3,2,10,20,32,316,34,01,22,266,,30,09,052,,02,07,172,*76 $GPGSV,3,3,10,23,30,110,33,25,70,061,39*77 $GPRMC,071110.000,A,3242.8536,N,11709.7626,W,000.0,000.0,100204,013.0,E*7D 

The checksum is a two-digit hexadecimal value that's created by XORing the ASCII values of each character in the sentence, except for the leading $ and * that precede the checksum itself. For example, the Perl code shown in Example 10-2 verifies the checksum of each line in Example 10-1.

Example 10-2. Verifying NMEA 0183 sentence checksums
 #!/usr/bin/perl -w # # gpscksum.pl--verify each NMEA 0183 sentence in standard input #    use strict;    my $count=1; while (<>) {   my ($string, $cksum);   if (/^$(.*)\*([0-9A-Fa-f][0-9A-Fa-f])/)   {     $string = ; # everything between leading $ and checksum     $cksum  = ; # hex checksum from NMEA sentence   } else   {     die "Malformed NMEA 0183 sentence: $_\n";   }      # Calculate the checksum   my $my_cksum;   for (my $i = 0; $i < length ($string); $i++)   {     $my_cksum ^= ord(substr($string, $i, 1))   }      # Compare the checksums   if ($my_cksum != hex($cksum))   {     print "Checksum for line $count doesn't match: ",       $my_cksum, "!=", hex($cksum), "\n";   }   $count++; } 

The following tables describe the NMEA 0183 sentences listed in Example 10-1. Items in the Example column are drawn directly from Example 10-1. Table 10-1 describes the elements of the GPGGA sentence (GPS fix data). This sentence gives you information about the current position fix.

Table 10-1. GPGGA sentence

Column(s)

Example

Description

1

071110.000(7:11:10)

Current time UTC (HHMMSS.mmm)

2, 3

3242.8536, N(32 °42.8836' N)

Latitude

4,5

11709.7626, W(117 °9.7626' Wt)

Longitude

6

1

Fix quality (0=no fix, 1=GPS, 2=differential GPS)

7

05

Number of satellites used for fix

8

01.5

Horizontal dilution of precision

9,10

00104.2,M(104.2 meters )

Altitude

11,12

-34.0, M(-34 meters)

Difference between mean sea level and the ellipsoid modeled by WGS-84 (http://www.wgs84.com/)

13

(empty)

Age of differential GPS data (if any)

14

(empty)

Differential station ID

15

50

Checksum (preceded by * rather than a comma)

Table 10-2 describes the GPGSA (active satellites) sentence. This sentence summarizes information about the satellites used to determine your current fix.

Table 10-2. GPGSA sentence

Column(s)

Example

Description

1

A

Selection mode (A=Automatic, M=Manual)

2

3

Fix mode (1=no fix; 2=2-dimensional; 3=3-dimensional)

3-14

22,16,,14,20,,,,,25,,

Satellite IDs (blanks indicate satellites not in view)

15

02.5

Positional dilution of precision

16

01.5

Horizontal dilution of precision

17

02.1

Vertical dilution of precision

18

05

Checksum (preceded by * rather than a comma)

Table 10-3 describes the GPGSV (satellites in view) sentence, which may appear multiple times. This sentence provides detailed information about each satellite, describing up to four satellites per line.

Table 10-3. GPGSV sentence

Column(s)

Example

Description

1

3

Number of GPGSV sentences

2

1

Current sentence number

3

10

Number of satellites in view

4

22

Satellite number

5

11

Satellite elevation in degrees

6

117

Satellite azimuth in degrees

7

35

Signal-to-noise ratio

8-11

16,13,151,35

Repeat of 4-7 for another satellite

12-14

11,44,256,

Repeat of 4-7 for another satellite

15-18

14,26,056,35

Repeat of 4-7 for another satellite

19

78

Checksum (preceded by * rather than a comma)

Table 10-4 describes the GPRMC (transit information) sentence, which provides navigational data such as ground speed and course traveled.

Table 10-4. GPRMC Sentence

Column(s)

Example

Description

1

071110.000

(7:11:10)

Time of fix

2

A

Navigation receiver warning (A=OK; V=receiver warning)

3,4

3242.8536, N

(32 °42.8836' N)

Latitude

5,6

11709.7626, W

(117 °9.7626' W)

Longitude

7

000.0

Ground speed in knots

8

000.0

Course made good (degrees)

9

100204

(10 February 2004)

Date of fix

10,11

013.0, E

(13 °E)

Magnetic variation

12

7D

Checksum (preceded by * rather than a comma)

10.4.1 References


Peter Bennett's NMEA FAQ

http://vancouver-webpages.com/peter/nmeafaq.txt


Walter Piechulla's Understanding NMEA 0183

http://www.walterpiechulla.de/nmea0183.html

10.4.2 GPSd

GPSd listens to a GPS receiver and republishes the GPS information on the network in an easy-to-read format. It's included with GpsDrive, described later in this chapter, but you can also download it and install it yourself from the GPSd home page at http://www.pygps.org/gpsd/gpsd.html.

To launch GPSd, specify the serial port with -p and ( optionally ) the speed with -s . If you use the -D option to specify a debugging level above 1, GPSd will stay in the foreground and display debugging info (if you are using an RS-232 connection for your GPS, the port will be a standard serial port such as /dev/ttys0 ):

 $  sudo gpsd -D9 -p /dev/ttyUSB0 -s 4800  command line options:   debug level:        9   gps device name:    /dev/ttyUSB0   gps device speed:   12   gpsd port:          2947   latitude:           3600.000N   longitude:          12300.000W 

It doesn't start reading from the GPS until it gets a connection from a client. The simplest way to connect is via telnet to port 2947. GPSd understands several simple commands followed by a carriage return, as shown in Table 10-5.

Table 10-5. Commands supported by GPSd

Command

Response from GPSd

P

Latitude and longitude

D

Date and time

A

Altitude in meters

V

Speed in knots

S

Status (0=no GPS; 1=no fix; 2=2D fix; 3=3D Fix)

M

Mode (0=no GPS; 1=GPS; 2=differential GPS)

R

Enter raw mode (dumps NMEA 0183 sentences)

The first time you ask for latitude and longitude after launching GPSd, you might not get a valid result (and it may take a while to get a fix anyhow). But on subsequent requests , you should get valid data:

 bjepson@debian:~$  telnet localhost 2947  Trying 127.0.0.1... Connected to debian. Escape character is '^]'.  p  GPSD,P=0.000000 0.000000  p  GPSD,P=32.714227 -117.162708 

Here's a sample session showing some of the other commands:

 bjepson@debian:~$  telnet localhost 2947  Trying 127.0.0.1... Connected to debian. Escape character is '^]'.  d  GPSD,D=02/10/2004 07:11:14  a  GPSD,A=103.500000  v  GPSD,V=0.000000  r  GPSD,R=1 $GPGSA,A,3,22,16,,14,20,,,,,25,,,02.5,01.5,02.1*05 $GPGSV,3,1,10,22,11,117,36,16,13,151,35,11,44,256,,14,26,056,36*78 $GPGSV,3,2,10,20,32,316,30,01,22,266,,30,09,052,,02,07,172,*72 $GPGSV,3,3,10,23,30,110,35,25,70,061,39*71 $GPRMC,071119.000,A,3242.8539,N,11709.7626,W,000.0,000.0,100204,013.0,E*7B  r  $GPGGA,071120.000,3242.8539,N,11709.7626,W,1,05,01.5,00103.1,M,-34.0,M,,*58 $GPGSA,A,3,22,16,,14,20,,,,,25,,,02.5,01.5,02.1*05    GPSD,R=0 

But to really have fun with GPSd, you can use GPSd-aware applications such as Kismet and GpsDrive, described in the following sections.

 <  Day Day Up  >  


Linux Unwired
Linux Unwired
ISBN: 0596005830
EAN: 2147483647
Year: 2004
Pages: 100

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net