"""
gpsduel - Records output of 2 gps modules simultaneously
Can optionally filter for certain NMEA sentence types.
Just add the option(s) of the type(s) you want to see.
:Copyright: Copyright 2007 Dean Hall. All rights reserved.
:Author: Dean Hall
:Revision: 0.1
:Date: 2007/07/19
usage: gpsduel [-cghlstv]
-c Filter in $GPRMC sentence type.
-g Filter in $GPGGA sentence type.
-h Prints this help message
-l Filter in $GPGLL sentence type
-s Filter in $GPGSA sentence type.
-t Filter in $GPVTG sentence type.
-v Filter in $GPGSV sentence type.
--rmc Filter in $GPRMC sentence type.
--gga Filter in $GPGGA sentence type.
--gll Filter in $GPGLL sentence type
--gsa Filter in $GPGSA sentence type.
--vtg Filter in $GPVTG sentence type.
--gsv Filter in $GPGSV sentence type.
"""
DEVICES = {
"Holux": "/dev/cu.usbserial",
"EverMore": "/dev/cu.SLAB_USBtoUART",
}
DEFAULT_BAUD = 19200
import getopt, os, sys
import serial
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "cghlstv",
["rmc", "gga", "help", "gll", "gsa", "vtg",
"gsv"])
except getopt.GetoptError:
print __doc__
sys.exit(2)
sentencefilter = []
for o, a in opts:
if o in ("-h", "--help"):
print __doc__
sys.exit()
elif o in ("-c", "--rmc"):
sentencefilter.append("RMC")
elif o in ("-g", "--gga"):
sentencefilter.append("GGA")
elif o in ("-l", "--gll"):
sentencefilter.append("GLL")
elif o in ("-s", "--gsa"):
sentencefilter.append("GSA")
elif o in ("-t", "--vtg"):
sentencefilter.append("VTG")
elif o in ("-v", "--gsv"):
sentencefilter.append("GSV")
cwd = os.path.curdir
foE = open(os.path.join(cwd, "gpsduelEverMoreData.nmea"), "w")
foH = open(os.path.join(cwd, "gpsduelHoluxData.nmea"), "w")
fiE = serial.Serial(DEVICES["EverMore"], DEFAULT_BAUD)
fiH = serial.Serial(DEVICES["Holux"], DEFAULT_BAUD)
try:
lineE = fiE.readline()
lineH = fiH.readline()
while lineE or lineH:
lineE = fiE.readline()
lineH = fiH.readline()
if not sentencefilter:
foE.write(lineE)
foH.write(lineH)
else:
if lineE[3:6] in sentencefilter:
foE.write(lineE)
if lineH[3:6] in sentencefilter:
foH.write(lineH)
except KeyboardInterrupt:
pass
finally:
fiE.close()
fiH.close()
foE.close()
foH.close()
if __name__ == "__main__":
main()