Added VERY baic gpx logging
This commit is contained in:
parent
4633881ee4
commit
5d0db20ca2
38
render.py
38
render.py
|
@ -2,10 +2,31 @@ from ipyleaflet import Map, Marker
|
||||||
import pynmea2
|
import pynmea2
|
||||||
import serial
|
import serial
|
||||||
import io
|
import io
|
||||||
|
import gpxpy
|
||||||
|
import gpxpy.gpx
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
|
||||||
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=5.0)
|
def signal_handler(sig, frame):
|
||||||
|
gpx_file.write(gpx.to_xml())
|
||||||
|
gpx_file.truncate()
|
||||||
|
gpx_file.close()
|
||||||
|
print("Quitting")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
gpx_file = open('track.gpx', 'w')
|
||||||
|
gpx_file.seek(0)
|
||||||
|
gpx = gpxpy.gpx.GPX()
|
||||||
|
gpx_track = gpxpy.gpx.GPXTrack()
|
||||||
|
gpx.tracks.append(gpx_track)
|
||||||
|
gpx_segment = gpxpy.gpx.GPXTrackSegment()
|
||||||
|
gpx_track.segments.append(gpx_segment)
|
||||||
|
|
||||||
|
ser = serial.Serial('/dev/ttyACM1', 9600, timeout=5.0)
|
||||||
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
|
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
|
||||||
last_time = 00
|
last_time = 0
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -13,7 +34,8 @@ while True:
|
||||||
msg = pynmea2.parse(line)
|
msg = pynmea2.parse(line)
|
||||||
latitude = msg.latitude
|
latitude = msg.latitude
|
||||||
longitude = msg.longitude
|
longitude = msg.longitude
|
||||||
time = msg.timestamp
|
# altitude = msg.altitude
|
||||||
|
# time = f"{msg.datestamp}T{msg.timestamp}Z"
|
||||||
except serial.SerialException as e:
|
except serial.SerialException as e:
|
||||||
# print('Device error: {}'.format(e))
|
# print('Device error: {}'.format(e))
|
||||||
break
|
break
|
||||||
|
@ -23,13 +45,21 @@ while True:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
if last_time == 00:
|
if last_time == 0:
|
||||||
center = (latitude, longitude)
|
center = (latitude, longitude)
|
||||||
m = Map(center=center, zoom=15)
|
m = Map(center=center, zoom=15)
|
||||||
marker = Marker(location=center, draggable=False)
|
marker = Marker(location=center, draggable=False)
|
||||||
m.add_layer(marker)
|
m.add_layer(marker)
|
||||||
display(m)
|
display(m)
|
||||||
last_time = time
|
last_time = time
|
||||||
|
last_latitude=latitude
|
||||||
|
last_longitude=longitude
|
||||||
|
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(latitude, longitude))
|
||||||
else:
|
else:
|
||||||
marker.location = (latitude, longitude)
|
marker.location = (latitude, longitude)
|
||||||
last_time = time
|
last_time = time
|
||||||
|
if not last_latitude==latitude or not last_longitude==longitude:
|
||||||
|
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(latitude, longitude))
|
||||||
|
print("Added gpx point")
|
||||||
|
last_latitude=latitude
|
||||||
|
last_longitude=longitude
|
||||||
|
|
Loading…
Reference in a new issue