added Jupyter
This commit is contained in:
parent
4ac401d70c
commit
4846cfdef8
99
MacVersion.ipynb
Normal file
99
MacVersion.ipynb
Normal file
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5e0cac75",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from ipyleaflet import Map, Marker\n",
|
||||
"import pynmea2\n",
|
||||
"import serial\n",
|
||||
"import io\n",
|
||||
"import gpxpy\n",
|
||||
"import gpxpy.gpx\n",
|
||||
"import signal\n",
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"def signal_handler(sig, frame):\n",
|
||||
" gpx_file.write(gpx.to_xml())\n",
|
||||
" gpx_file.truncate()\n",
|
||||
" gpx_file.close()\n",
|
||||
" print(\"Quitting\")\n",
|
||||
" sys.exit(0)\n",
|
||||
"\n",
|
||||
"gpx_file = open('track.gpx', 'w')\n",
|
||||
"gpx_file.seek(0)\n",
|
||||
"gpx = gpxpy.gpx.GPX()\n",
|
||||
"gpx_track = gpxpy.gpx.GPXTrack()\n",
|
||||
"gpx.tracks.append(gpx_track)\n",
|
||||
"gpx_segment = gpxpy.gpx.GPXTrackSegment()\n",
|
||||
"gpx_track.segments.append(gpx_segment)\n",
|
||||
"\n",
|
||||
"ser = serial.Serial('/dev/cu.usbmodem14201', 9600, timeout=5.0)\n",
|
||||
"sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))\n",
|
||||
"last_time = 0\n",
|
||||
"\n",
|
||||
"signal.signal(signal.SIGINT, signal_handler)\n",
|
||||
"\n",
|
||||
"while True:\n",
|
||||
" try:\n",
|
||||
" line = sio.readline().rstrip('\\n') # Remove newline character\n",
|
||||
" msg = pynmea2.parse(line)\n",
|
||||
" latitude = msg.latitude\n",
|
||||
" longitude = msg.longitude\n",
|
||||
" # altitude = msg.altitude\n",
|
||||
" # time = f\"{msg.datestamp}T{msg.timestamp}Z\"\n",
|
||||
" except serial.SerialException as e:\n",
|
||||
" # print('Device error: {}'.format(e))\n",
|
||||
" break\n",
|
||||
" except pynmea2.ParseError as e:\n",
|
||||
" # print('Parse error: {}'.format(e))\n",
|
||||
" continue\n",
|
||||
" except Exception as e:\n",
|
||||
" continue\n",
|
||||
" else:\n",
|
||||
" if last_time == 0:\n",
|
||||
" center = (latitude, longitude)\n",
|
||||
" m = Map(center=center, zoom=15)\n",
|
||||
" marker = Marker(location=center, draggable=False)\n",
|
||||
" m.add_layer(marker)\n",
|
||||
" display(m)\n",
|
||||
" last_time = time\n",
|
||||
" last_latitude=latitude\n",
|
||||
" last_longitude=longitude\n",
|
||||
" gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(latitude, longitude))\n",
|
||||
" else:\n",
|
||||
" marker.location = (latitude, longitude)\n",
|
||||
" last_time = time\n",
|
||||
" if not last_latitude==latitude or not last_longitude==longitude:\n",
|
||||
" gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(latitude, longitude))\n",
|
||||
" print(\"Added gpx point\")\n",
|
||||
" last_latitude=latitude\n",
|
||||
" last_longitude=longitude\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
Loading…
Reference in a new issue