Personal tools
You are here: Home Members gillesgigan gumstix GPS scripts
Document Actions

GPS scripts

by Gilles Gigan last modified 2009-02-20 13:26

This page explains how to use the python GPS scripts

How to read command lines

Command lines are made up of several parts, a command name followed by some arguments that control the execution of the command. Different parts are separated by spaces.Example:

command argument1 argument 2 argument2

Some of the arguments may be mandatory, some maybe optional. In the rest of this page, the following syntax is used:

Optional argument blocks are written in square brackets:

[ argument1 ]

Mandatory argument blocks are written between angle brackets:

 < argument1 >

Example:

./nmea_parser.py <-i file1> <-o file2> [-c] [-d]

The previous line shows that the "nmea_parser.py" command must be given an argument of the form  "-i"  followed by a filename, another one of the form "-o" followed by a filename. The "-c" and "-d" arguments are optional.

Contents

The gps_scripts directory is located at /media/card/gps_scripts on the gumstix's SD card. A file called "nmea_output_test" in the gps_scripts directory contains a sample of nmea sentences from both the echo sounder and the GPS. Its contents will be used in examples below.

The gps_scripts directory contains the following:

combine_ttys.py

This script combines the output of multiple tty into a single file.
Usage:
combine_tty.py <tty1[,speed,size,parity,stop]>  <tty2[,speed,size,parity,stop]> <output_file>
where:
"tty1" and "tty2" are valid tty device files,
the tty speed (in baud), data size (in bits), parity (0: none, 1:odd, 2:even), and number of stop bits (0,1,2) may be specified, immediatly following the device file and separated by comas.
output_file is a filename where the combined output will be written to, or use "-" to write to standard output instead of a file
Example:
./combine_tty.py /dev/ttyS1,4800,8,0,1 /dev/ttyS2 -
The above command will combine the output of serial ports 1 and 2, and write the combine data to the standard output (the screen here)

nmea_parser.py

This script is used to filter a list of nmea sentences, keep only interesting bits, and write them to the standard output. This list of nmea sentences to filter is read from the standard input.
Usage:
nmea_parser.py <[-c]Type:field1,field2,field3,...>
where:
Type is a NMEA sentence type (see below for supported types)
fieldX is a valid field found in the type mentioned before (see below for supported fields)
-c must appear only once (no space between "-c" and the type), and indicates that the output must be aggregated by this field.

Supported Types and their associated fields:
  • GLL: 'status', 'UTC', 'long_dec', 'lat_minutes', 'lat_dec', 'raw_lat', 'lat_seconds', 'long_degrees', 'long_minutes', 'timeOfFix', 'long_seconds', 'EW', 'NS', 'lat_degrees', 'raw_long'
  • VTG: 'speedK', 'speedN', 'degree2', 'degree1'
  • MTW: 'unit', 'temp'
  • RMC: 'status', 'UTC', 'long_dec', 'lat_minutes', 'lat_dec', 'raw_lat', 'lat_seconds', 'long_degrees', 'speedN', 'long_minutes', 'degree1', 'timeOfFix', 'date', 'long_seconds', 'EW', 'NS', 'lat_degrees', 'raw_long'
  • GGA: 'UTC', 'long_dec', 'hdop', 'lat_minutes', 'lat_dec', 'raw_lat', 'nb_sat', 'lat_seconds', 'long_degrees', 'lat_degrees', 'long_minutes', 'timeOfFix', 'long_seconds', 'EW', 'NS', 'quality', 'altitude', 'raw_long'
  • DBT: 'depth_feet', 'depth_fathom', 'depth_metres'
Examples:
./nmea_parser.py GLL:UTC,lat_dec,long_dec < ./nmea_output_test
will read nmea sentences from the "nmea_output_test" file and keep only the GLL sentences. From these sentences, only the UTC, latitude and longitude in decimal form will be printed:
UTC|014152.00,lat_dec|-19.329548,long_dec|146.760101333,
UTC|014154.00,lat_dec|-19.3295453333,long_dec|146.760098333,
UTC|014155.00,lat_dec|-19.3295441667,long_dec|146.760096833,
UTC|014156.00,lat_dec|-19.3295428333,long_dec|146.760095167,

./nmea_parser.py GLL:UTC,lat_dec,long_dec GGA:nb_sat < ./nmea_output_test
will read nmea sentences from the "nmea_output_test" file and keep only the GLL and GGA sentences. From GLL sentences, only the UTC, latitude and longitude in decimal form will be printed. From the GGA sentences, only the "nb_sat" will be printed:
UTC|014151.00,lat_dec|-19.3295646667,long_dec|146.760126667,
nb_sat|11,
UTC|014152.00,lat_dec|-19.329567,long_dec|146.760101333,
nb_sat|10,
UTC|014153.00,lat_dec|-19.3295466667,long_dec|146.760099833,
nb_sat|09,
UTC|014154.00,lat_dec|-19.3295453333,long_dec|146.760098333,
nb_sat|09,
UTC|014155.00,lat_dec|-19.3295441667,long_dec|146.760096833,
UTC|014156.00,lat_dec|-19.3295453333,long_dec|146.760098333,
UTC|014157.00,lat_dec|-19.3295441667,long_dec|146.760098333,
nb_sat|09,




It may useful to combine (aggregate) the output by a type of sentence, so that in the previous output for example, a single line contains ALL the requested sentence types and fields, and successive duplicates are eliminated. To do this, add "-c" in front of the sentence type to be used as agregate (no space between "-c" and the sentence type). The previous command becomes:
./nmea_parser.py -cGLL:UTC,lat_dec,long_dec GGA:nb_sat < ./nmea_output_test
which produces this:
UTC|014051.00,nb_sat|11,long_dec|146.760126667,lat_dec|-19.3295646667,
UTC|014052.00,nb_sat|10,long_dec|146.760101333,lat_dec|-19.329567,
UTC|014053.00,nb_sat|09,long_dec|146.760099833,lat_dec|-19.3295466667,
UTC|014054.00,nb_sat|09,long_dec|146.760099833,lat_dec|-19.3295453333,
UTC|014055.00,nb_sat|09,long_dec|146.760099833,lat_dec|-19.3295441667,
UTC|014056.00,nb_sat|09,long_dec|146.760099833,lat_dec|-19.3295453333,
UTC|014057.00,nb_sat|09,long_dec|146.760099833,lat_dec|-19.3295441667,

socat-net.sh

This script creates a TCP server listening on port 3334. When a client connects, socat-net sends the contents of a file or the standard input.
Usage:
./socat-net.sh <file>
where "file" is either a valid file name or "-" to read form the standard input.
Examples:
./socat-net.sh nmea_output_test
will send the contents of the "nmea_output_test" file to connected clients. The following command has the same effect:
cat ./nmea_output_test | ./socat-net.sh -

socat-file.sh

This script does the opposite of socat-net.sh. It connects to a TCP server listening on port 3334, reads lines from the server and writes them to a file or to the standard output.
Usage:
./socat-file.sh <file>
where "file" is either a valid file name or "-" to written to the standard output.
Examples:
./socat-file.sh -
Assuming socat-net.sh is running, the above command will connect to the server, print whatever it receives from it on the screen.


Putting it all together

The following commands assume you are in the gps_scripts directory, and that the echo sounder is plugged in and working.
To combine the output of the echo sounder (connected to /dev/ttyS1) and the GPS (connected to /dev/ttyS2) and create a TCP server which sends the combined output to connected clients:
./combine_ttys.py /dev/ttyS1,4800,8,0,1 /dev/ttyS2 - | ./socat-net.sh -
While the server is running, to write a dump to a file called "raw_dump" of whatever the server is sending:
./socat-file.sh raw_dump
While the server is running, to connect to it, aggregate the depth, temperature, latitude and longitude to UTC and writes it to a file called "depth_temp_data":
./socat-file.sh - | ./nmea_parser.py -cGLL:UTC,lat_dec,long_dec MTW:temp DBT:depth_metres > depth_temp_data
To interrupt any of the above commands while they are running, press Control - C

Starting and stopping the GPS scripts and webcam server


/media/card/start_gps_webcam.sh
Use Ctrl-C to stop everything



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: