I apologize for the lack of details in my last post. This time
formatting program is a piece of a larger program I am trying to write
to de-clutter GPS transmission. I have a GPS receiver that transmits
its readings via bluetooth. I've been able to use pySerial and store
X number of bytes, then write that to a file (the next step will be
finding a way to write the stream to a file directly). The raw GPS
data is tranmitted in the NMEA format (http://vancouver-webpages.com/
peter/nmeafaq.txt):
$GPRMC,024830,V,,N,,E,,,260108,,,N*58
$GPVTG,,T,,M,,N,,K,N*2C
$GPGGA,024831,LAT_GOES_HERE,N,LONG_GOES_HERE,E,0,00,,,M,,M,,*61
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,3,1,09,09,,,37,13,,,00,18,,,00,23,,,00*75
$GPGSV,3,2,09,01,,,00,29,,,00,14,,,00,26,,,00*7A
$GPGSV,3,3,09,12,,,00,,,,,,,,,,,,*73
$GPRMC,024831,V,LAT_GOES_HERE,N,LONG_GOES_HERE,E,,,260108,,,N*59
$GPVTG,,T,,M,,N,,K,N*2C
the "$GPGGA" and "$GPRMC" lines are the ones that will give you your
Latitude and Longitude data --or the would if I had a signal.
All the entries are comma delimited, so I used the split(',') function
to parse the appropriate statements. Here's the code for that:
=============================
input = open('c:\sample_readout.txt','r') #location of the Raw GPS
data
output = open('c:\GPSout.txt', 'w')
output.write("Timestamp \t Latitude \t Longitude \t Velocity")
s = input.readlines()
for line in s:
if line.startswith('$GPGGA'):
InputTuple = line.split(',')
time = InputTuple[1]
lat = InputTuple[2]+' '+InputTuple[3]
long = InputTuple[4]+' '+InputTuple[5]
out = '\n '+ time + '\t\t' + lat + '\t\t\t' + long
output.writelines(out)
elif line.startswith('$GPRMC'):
InputTuple = line.split(',')
time = InputTuple[1]
lat = InputTuple[3]+' '+InputTuple[4]
long = InputTuple[5]+' '+InputTuple[6]
out = '\n '+ time + '\t\t' + lat + '\t\t\t' + long
output.writelines(out)
elif line.startswith('$GPVTG'): #this will give grounp speed in
knts and [7] gives kmph
InputTuple = line.split(',')
out = '\n ' + '\t\t' + InputTuple[5]
output.writelines(out)
input.close()
output.close()
========================
The time stamp for both the GPRMC and GPGGA lines will be stored in
InputTuple[1].
Right now, this program will read the GPS data file and pull out the
necessary information. I wanted the Format.py program to function as
a module so that I could call Format.FormatTime(time) to change the
HHMMSS GPS data to HH:MM:SS, for readability. The next step was to
write a FormatCoord function (within the Format module) to do the same
for lat/long data.
Now that I've explained the structure, the argument of
Format.FormatTime() will be InputTuple[1] (the timestamp). I want to
be able to call that function in the GPS program to read the contents
of InputTuple[1] and write the HH:MM:SS data to the file.
I've incorporated some of your recommendations into my program already
and it looks much better. Thanks to everyone for your suggestions.
Jimmy
--
http://mail.python.org/mailman/listinfo/python-list