i modified a script for google earth that i found that expected nmea data from the serial port
Code:
gpspipe -r | gegpsd
had to install python-serial:
Code:
sudo apt-get install python-serial
/usr/local/bin/gegpsd
Code:
#!/usr/bin/python
# Copyright (C) 2007 by Jaroslaw Zachwieja <grok!warwick.ac.uk>
# Copyright (C) 2008 by TJ <linux!tjworld.net>
# modified 2009 by synace to use stdin for use with gpspipe
# Published under the terms of GNU General Public License v2 or later.
# License text available at http://www.gnu.org/licenses/licenses.html#GPL
import serial
import string
import sys
import getopt
def main():
# defaults
file = '/dev/shm/gps.kml'
print "Serving data from stdin to %s" % (file)
latitude = 0
longitude = 0
speed = 0
heading_in = 0
altitude = 0
range = 1000
tilt = 30
while 1:
line = sys.stdin.readline()
datablock = line.split(',')
if line[0:6] == '$GPRMC':
latitude_in = string.atof(datablock[3])
longitude_in = string.atof(datablock[5])
try:
altitude = string.atof(datablock[8])
except ValueError:
# use last good value
altitude = altitude
speed_in = string.atof(datablock[7])
try:
heading_in = string.atof(datablock[8])
except ValueError:
# use last good value
heading_in = heading_in
if datablock[4] == 'S':
latitude_in = -latitude_in
if datablock[6] == 'W':
longitude_in = -longitude_in
latitude_degrees = int(latitude_in/100)
latitude_minutes = latitude_in - latitude_degrees*100
longitude_degrees = int(longitude_in/100)
longitude_minutes = longitude_in - longitude_degrees*100
latitude = latitude_degrees + (latitude_minutes/60)
longitude = longitude_degrees + (longitude_minutes/60)
speed = int(speed_in * 1.852)
range = ( ( speed / 100 ) * 350 ) + 650
tilt = ( ( speed / 120 ) * 43 ) + 30
heading = heading_in
if speed < 10:
range = 200
tilt = 30
heading = 0
output = """<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
<name>%s km/h</name>
<description>^</description>
<LookAt>
<longitude>%s</longitude>
<latitude>%s</latitude>
<range>%s</range>
<tilt>%s</tilt>
<heading>%s</heading>
</LookAt>
<Point>
<coordinates>%s,%s,%s</coordinates>
</Point>
</Placemark>
</kml>""" % (speed,longitude,latitude,range,tilt,heading,longitude,latitude,altitude)
f=open(file, 'w')
f.write(output)
f.close()
if __name__ == "__main__":
main()
since the kml file is written every second or so, i put it on ramdisk.
i also modified /lib/udev/gpsd.hotplug
Code:
elif action == 'add':
gpsdcmd = "gpsd -F " + CONTROL_SOCKET
syslog.syslog("launching %s" % gpsdcmd)
os.system(gpsdcmd)
# by synace: patch to add a kml file for google earth into /dev/shm/gps.kml
googlecmd = "gpspipe -r | gegpsd"
os.system(googlecmd)
connect = gpsd_control_connect()
and /lib/udev/gpsd.hotplug.wrapper
Code:
# wait for /usr & /var & /dev/shm to be mounted
wait_for_file /usr/bin/python && \
wait_for_file /var/run && \
wait_for_file /dev/shm && \
exec /lib/udev/gpsd.hotplug "$ACTION" "$DEVNAME"
this doesn't seem to wait though.. it either starts before /dev/shm is there (or my GPS is taking too long to start streaming data).. any thoughts??
Bookmarks