LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (http://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   Tools to parse NMEA GPS data : grep & awk (http://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/tools-to-parse-nmea-gps-data-grep-and-awk-820677/)

mjolnir 07-19-2010 08:20 AM

Tools to parse NMEA GPS data : grep & awk
 
Recently I decided to fire up an old gps unit (Earthmate GPS BT-20) I had laying around and see if I could get it to run with Ubuntu 10.04.

Plug in the unit and give it time to acquire a fix then check dmesg to see what device name it has been given. If desired you can assign the device a permanent location with udev. In my case the unit was located at /dev/ttyUSB4.
Code:

carl@wizard:~$ cat /dev/ttyUSB4
$GPGGA,115931.000,xxxx.xxxxx,N,xxxxx.xxxxx,W,1,09,1.2,173.59,M,-31.9,M,,*53
$GPGSV,3,1,12,01,65,295,00,09,25,043,39,12,16,095,31,14,60,290,40*71
$GPGSV,3,2,12,18,48,101,34,19,08,281,00,21,19,168,31,22,76,034,35*74
$GPGSV,3,3,12,24,61,244,38,27,14,039,31,30,14,131,38,31,20,202,00*74
$GPGSA,A,3,14,22,24,18,09,21,27,12,30,,,,2.1,1.2,1.7*31
$GPRMC,115932.000,A,xxxx.xxx,N,xxxxx.xxx,W,0.0,0.0,190710,0.0,E*77
$GPGGA,115932.000,xxxx.xxxxx,N,xxxxx.xxxxx,W,1,09,1.2,173.59,M,-31.9,M,,*5A
$GPGSV,3,1,12,01,65,295,00,09,25,043,40,12,16,095,30,14,60,290,40*7E
$GPGSV,3,2,12,18,48,101,35,19,08,281,00,21,19,168,30,22,76,034,35*74
$GPGSV,3,3,12,24,61,244,38,27,14,039,31,30,14,131,38,31,20,202,00*74
$PSTMECH,14,7,22,7,00,0,24,7,18,7,09,7,21,7,00,0,27,7,00,0,12,7,30,7*56

These are NMEA sentences. To save to a file open a terminal and run
Code:

cat /dev/ttyUSB4> file.txt
Use control-C to stop the process.

Code:

cat /dev/ttyUSB4 | grep --line-buffered  GPGGA > earth.txt
will write selected lines, in this case GPGGA to a file.

Code:

awk -F, '/\$GPGGA/ {print  strftime("%Y-%m-%d "),  $2, (substr($3,0,2) + (substr($3,3) / 60.0)) $4,  (substr($5,0,3) + (substr($5,4) / 60.0)) $6, $10; fflush();}' /dev/ttyUSB4 > earth1.txt
This command will cut out the info I want: time,lat/long, altitude and add the date.

I got part of the awk string here: http://wiki.openmoko.org/wiki/Gettin...put_with_gllin

and the rest of it here: http://stackoverflow.com/questions/2...-lines-of-text

especially the part about line buffered input.


All times are GMT -5. The time now is 07:19 PM.