You will only see the public (readable) repos here until you login.
Browse Source

Added example code

Joachim M. Giæver 2 years ago
parent
commit
79f4c2504b
5 changed files with 859 additions and 0 deletions
  1. 380 0
      doc/gps.html
  2. 35 0
      doc/index.html
  3. 19 0
      gps/README.md
  4. 10 0
      gps/__init__.py
  5. 415 0
      gps/gps.py

+ 380 - 0
doc/gps.html

@@ -0,0 +1,380 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html><head><title>Python: module gps</title>
+<meta charset="utf-8">
+</head><body bgcolor="#f0f0f8">
+
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
+<tr bgcolor="#7799ee">
+<td valign=bottom>&nbsp;<br>
+<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>gps</strong></big></big></font></td
+><td align=right valign=bottom
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/joachim/Development/INF-3910-3/GPS/gps/gps.py">/home/joachim/Development/INF-3910-3/GPS/gps/gps.py</a></font></td></tr></table>
+    <p></p>
+<p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ee77aa">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
+    
+<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
+<td width="100%"><dl>
+<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
+</font></dt><dd>
+<dl>
+<dt><font face="helvetica, arial"><a href="gps.html#Data">Data</a>
+</font></dt><dt><font face="helvetica, arial"><a href="gps.html#Location">Location</a>
+</font></dt><dt><font face="helvetica, arial"><a href="gps.html#NMEA">NMEA</a>
+</font></dt><dt><font face="helvetica, arial"><a href="gps.html#Value">Value</a>
+</font></dt><dd>
+<dl>
+<dt><font face="helvetica, arial"><a href="gps.html#Course">Course</a>
+</font></dt><dt><font face="helvetica, arial"><a href="gps.html#Distance">Distance</a>
+</font></dt><dt><font face="helvetica, arial"><a href="gps.html#HDOP">HDOP</a>
+</font></dt><dt><font face="helvetica, arial"><a href="gps.html#Position">Position</a>
+</font></dt><dt><font face="helvetica, arial"><a href="gps.html#Speed">Speed</a>
+</font></dt></dl>
+</dd>
+</dl>
+</dd>
+</dl>
+ <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="Course">class <strong>Course</strong></a>(<a href="gps.html#Value">Value</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt><a href="#Value">Value</a>:&nbsp;<a href="#Course">Course</a>/direction<br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%"><dl><dt>Method resolution order:</dt>
+<dd><a href="gps.html#Course">Course</a></dd>
+<dd><a href="gps.html#Value">Value</a></dd>
+<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
+</dl>
+<hr>
+Methods defined here:<br>
+<dl><dt><a name="Course-__init__"><strong>__init__</strong></a>(self, v, t)</dt></dl>
+
+<hr>
+Methods inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><a name="Course-__float__"><strong>__float__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Course-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Course-rad"><strong>rad</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value&nbsp;in&nbsp;radians.</tt></dd></dl>
+
+<dl><dt><a name="Course-time"><strong>time</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;measurment&nbsp;time.</tt></dd></dl>
+
+<dl><dt><a name="Course-unit"><strong>unit</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;unit</tt></dd></dl>
+
+<dl><dt><a name="Course-value"><strong>value</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value</tt></dd></dl>
+
+<hr>
+Data descriptors inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="Data">class <strong>Data</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt>Reads&nbsp;and&nbsp;stores&nbsp;data&nbsp;from&nbsp;the&nbsp;GPS<br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%">Methods defined here:<br>
+<dl><dt><a name="Data-__init__"><strong>__init__</strong></a>(self, pins<font color="#909090">=('P3', 'P4')</font>, baud<font color="#909090">=9600</font>)</dt></dl>
+
+<dl><dt><a name="Data-get_location"><strong>get_location</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;location-data.&nbsp;Should&nbsp;be&nbsp;used&nbsp;when&nbsp;new_location&nbsp;returns&nbsp;True.</tt></dd></dl>
+
+<dl><dt><a name="Data-new_location"><strong>new_location</strong></a>(self, ttw<font color="#909090">=5</font>)</dt><dd><tt>Waits&nbsp;for&nbsp;the&nbsp;GPS&nbsp;to&nbsp;return&nbsp;data&nbsp;with&nbsp;an&nbsp;'time&nbsp;to&nbsp;wait'-interval.<br>
+&nbsp;<br>
+Returns&nbsp;True&nbsp;if&nbsp;there&nbsp;is&nbsp;a&nbsp;new&nbsp;VALID&nbsp;location.</tt></dd></dl>
+
+<hr>
+Data descriptors defined here:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="Distance">class <strong>Distance</strong></a>(<a href="gps.html#Value">Value</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt><a href="#Value">Value</a>:&nbsp;<a href="#Distance">Distance</a><br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%"><dl><dt>Method resolution order:</dt>
+<dd><a href="gps.html#Distance">Distance</a></dd>
+<dd><a href="gps.html#Value">Value</a></dd>
+<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
+</dl>
+<hr>
+Methods defined here:<br>
+<dl><dt><a name="Distance-__init__"><strong>__init__</strong></a>(self, v, u, t)</dt></dl>
+
+<hr>
+Methods inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><a name="Distance-__float__"><strong>__float__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Distance-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Distance-rad"><strong>rad</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value&nbsp;in&nbsp;radians.</tt></dd></dl>
+
+<dl><dt><a name="Distance-time"><strong>time</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;measurment&nbsp;time.</tt></dd></dl>
+
+<dl><dt><a name="Distance-unit"><strong>unit</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;unit</tt></dd></dl>
+
+<dl><dt><a name="Distance-value"><strong>value</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value</tt></dd></dl>
+
+<hr>
+Data descriptors inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="HDOP">class <strong>HDOP</strong></a>(<a href="gps.html#Value">Value</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt><a href="#HDOP">HDOP</a>:&nbsp;Horizontal&nbsp;dilution&nbsp;of&nbsp;precision.<br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%"><dl><dt>Method resolution order:</dt>
+<dd><a href="gps.html#HDOP">HDOP</a></dd>
+<dd><a href="gps.html#Value">Value</a></dd>
+<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
+</dl>
+<hr>
+Methods defined here:<br>
+<dl><dt><a name="HDOP-__init__"><strong>__init__</strong></a>(self, v, t)</dt></dl>
+
+<dl><dt><a name="HDOP-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="HDOP-__str__"><strong>__str__</strong></a>(self)</dt></dl>
+
+<hr>
+Methods inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><a name="HDOP-__float__"><strong>__float__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="HDOP-rad"><strong>rad</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value&nbsp;in&nbsp;radians.</tt></dd></dl>
+
+<dl><dt><a name="HDOP-time"><strong>time</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;measurment&nbsp;time.</tt></dd></dl>
+
+<dl><dt><a name="HDOP-unit"><strong>unit</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;unit</tt></dd></dl>
+
+<dl><dt><a name="HDOP-value"><strong>value</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value</tt></dd></dl>
+
+<hr>
+Data descriptors inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="Location">class <strong>Location</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt><a href="#Location">Location</a>:<br>
+&nbsp;&nbsp;&nbsp;&nbsp;Tries&nbsp;to&nbsp;read&nbsp;data&nbsp;received&nbsp;from&nbsp;the&nbsp;GPS.<br>
+&nbsp;&nbsp;&nbsp;&nbsp;Sometimes&nbsp;the&nbsp;GPS&nbsp;will&nbsp;return&nbsp;data&nbsp;for&nbsp;som<br>
+&nbsp;&nbsp;&nbsp;&nbsp;of&nbsp;the&nbsp;segments,&nbsp;e.g&nbsp;it&nbsp;may&nbsp;happens&nbsp;that<br>
+&nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;wont&nbsp;receive&nbsp;the&nbsp;GPGGA-segment&nbsp;every&nbsp;time.<br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%">Methods defined here:<br>
+<dl><dt><a name="Location-__init__"><strong>__init__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Location-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Location-altitude"><strong>altitude</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;altitude</tt></dd></dl>
+
+<dl><dt><a name="Location-course"><strong>course</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;course</tt></dd></dl>
+
+<dl><dt><a name="Location-hdop"><strong>hdop</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;precision</tt></dd></dl>
+
+<dl><dt><a name="Location-height"><strong>height</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;height</tt></dd></dl>
+
+<dl><dt><a name="Location-latitude"><strong>latitude</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;latitude</tt></dd></dl>
+
+<dl><dt><a name="Location-longitude"><strong>longitude</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;longitude.</tt></dd></dl>
+
+<dl><dt><a name="Location-satellites"><strong>satellites</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;amount&nbsp;of&nbsp;satellites&nbsp;the&nbsp;GPS&nbsp;is&nbsp;connected&nbsp;to.</tt></dd></dl>
+
+<dl><dt><a name="Location-set"><strong>set</strong></a>(self, msgid, segment)</dt><dd><tt>Sets&nbsp;data&nbsp;based&nbsp;on&nbsp;the&nbsp;segment&nbsp;received<br>
+msgid,&nbsp;[]byte:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;segment&nbsp;type,&nbsp;e.g&nbsp;b'$GPGGA'<br>
+segment,&nbsp;[]byte:&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;segment&nbsp;itself</tt></dd></dl>
+
+<dl><dt><a name="Location-speed"><strong>speed</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;speed</tt></dd></dl>
+
+<dl><dt><a name="Location-valid"><strong>valid</strong></a>(self)</dt><dd><tt>Returns&nbsp;wether&nbsp;or&nbsp;not&nbsp;the&nbsp;location&nbsp;is&nbsp;valid</tt></dd></dl>
+
+<hr>
+Data descriptors defined here:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="NMEA">class <strong>NMEA</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt>Just&nbsp;a&nbsp;class&nbsp;to&nbsp;describe&nbsp;the&nbsp;type&nbsp;of&nbsp;the&nbsp;received&nbsp;entry.<br>
+We&nbsp;should&nbsp;consider&nbsp;removing&nbsp;this&nbsp;to&nbsp;save&nbsp;space.<br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%">Methods defined here:<br>
+<dl><dt><a name="NMEA-__init__"><strong>__init__</strong></a>(self, id)</dt></dl>
+
+<hr>
+Data descriptors defined here:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="Position">class <strong>Position</strong></a>(<a href="gps.html#Value">Value</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt><a href="#Value">Value</a>:&nbsp;<a href="#Position">Position</a><br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%"><dl><dt>Method resolution order:</dt>
+<dd><a href="gps.html#Position">Position</a></dd>
+<dd><a href="gps.html#Value">Value</a></dd>
+<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
+</dl>
+<hr>
+Methods defined here:<br>
+<dl><dt><a name="Position-__init__"><strong>__init__</strong></a>(self, v, u, t)</dt></dl>
+
+<dl><dt><a name="Position-__sub__"><strong>__sub__</strong></a>(self, other)</dt><dd><tt>Returns&nbsp;a&nbsp;new&nbsp;position&nbsp;with&nbsp;the&nbsp;subtracted&nbsp;value</tt></dd></dl>
+
+<hr>
+Methods inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><a name="Position-__float__"><strong>__float__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Position-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Position-rad"><strong>rad</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value&nbsp;in&nbsp;radians.</tt></dd></dl>
+
+<dl><dt><a name="Position-time"><strong>time</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;measurment&nbsp;time.</tt></dd></dl>
+
+<dl><dt><a name="Position-unit"><strong>unit</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;unit</tt></dd></dl>
+
+<dl><dt><a name="Position-value"><strong>value</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value</tt></dd></dl>
+
+<hr>
+Data descriptors inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="Speed">class <strong>Speed</strong></a>(<a href="gps.html#Value">Value</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt><a href="#Value">Value</a>:&nbsp;<a href="#Speed">Speed</a><br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%"><dl><dt>Method resolution order:</dt>
+<dd><a href="gps.html#Speed">Speed</a></dd>
+<dd><a href="gps.html#Value">Value</a></dd>
+<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
+</dl>
+<hr>
+Methods defined here:<br>
+<dl><dt><a name="Speed-__init__"><strong>__init__</strong></a>(self, v, u, t)</dt></dl>
+
+<dl><dt><a name="Speed-to_kmh"><strong>to_kmh</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;speed&nbsp;in&nbsp;Km/h</tt></dd></dl>
+
+<dl><dt><a name="Speed-to_knot"><strong>to_knot</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;speed&nbsp;in&nbsp;knot</tt></dd></dl>
+
+<hr>
+Methods inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><a name="Speed-__float__"><strong>__float__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Speed-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Speed-rad"><strong>rad</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value&nbsp;in&nbsp;radians.</tt></dd></dl>
+
+<dl><dt><a name="Speed-time"><strong>time</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;measurment&nbsp;time.</tt></dd></dl>
+
+<dl><dt><a name="Speed-unit"><strong>unit</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;unit</tt></dd></dl>
+
+<dl><dt><a name="Speed-value"><strong>value</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value</tt></dd></dl>
+
+<hr>
+Data descriptors inherited from <a href="gps.html#Value">Value</a>:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table> <p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="Value">class <strong>Value</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
+    
+<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
+<td colspan=2><tt>Defines&nbsp;a&nbsp;value&nbsp;received&nbsp;from&nbsp;the&nbsp;GPS<br>
+v,&nbsp;float:&nbsp;&nbsp;&nbsp;floating&nbsp;value<br>
+u,&nbsp;string:&nbsp;&nbsp;unit&nbsp;(e.g&nbsp;m,&nbsp;knot&nbsp;etc)<br>
+t,&nbsp;tuple:&nbsp;&nbsp;&nbsp;time&nbsp;when&nbsp;measured.<br>&nbsp;</tt></td></tr>
+<tr><td>&nbsp;</td>
+<td width="100%">Methods defined here:<br>
+<dl><dt><a name="Value-__float__"><strong>__float__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Value-__init__"><strong>__init__</strong></a>(self, v, u, t<font color="#909090">=(0, 0, 0.0)</font>)</dt></dl>
+
+<dl><dt><a name="Value-__repr__"><strong>__repr__</strong></a>(self)</dt></dl>
+
+<dl><dt><a name="Value-rad"><strong>rad</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value&nbsp;in&nbsp;radians.</tt></dd></dl>
+
+<dl><dt><a name="Value-time"><strong>time</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;measurment&nbsp;time.</tt></dd></dl>
+
+<dl><dt><a name="Value-unit"><strong>unit</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;unit</tt></dd></dl>
+
+<dl><dt><a name="Value-value"><strong>value</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;value</tt></dd></dl>
+
+<hr>
+Data descriptors defined here:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+</td></tr></table></td></tr></table>
+</body></html>

+ 35 - 0
doc/index.html

@@ -0,0 +1,35 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html><head><title>Python: module __init__</title>
+<meta charset="utf-8">
+</head><body bgcolor="#f0f0f8">
+
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
+<tr bgcolor="#7799ee">
+<td valign=bottom>&nbsp;<br>
+<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>__init__</strong></big></big></font></td
+><td align=right valign=bottom
+><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/joachim/Development/INF-3910-3/GPS/gps/__init__.py">/home/joachim/Development/INF-3910-3/GPS/gps/__init__.py</a></font></td></tr></table>
+    <p><tt>Package:&nbsp;gps<br>
+&nbsp;<br>
+Reads&nbsp;and&nbsp;parse&nbsp;data&nbsp;received&nbsp;from&nbsp;the&nbsp;GPS&nbsp;module.<br>
+&nbsp;<br>
+Note:&nbsp;&nbsp;&nbsp;This&nbsp;package&nbsp;should&nbsp;be&nbsp;re-written&nbsp;to&nbsp;reuse&nbsp;objects<br>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;save&nbsp;resources.</tt></p>
+<p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#55aa55">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
+    
+<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
+<td width="100%"><strong>__author__</strong> = 'Joachim M. Giaever'<br>
+<strong>__email__</strong> = 'jgi004@post.uit.no'</td></tr></table><p>
+<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#7799ee">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
+    
+<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
+<td width="100%">Joachim&nbsp;M.&nbsp;Giaever</td></tr></table>
+</body></html>

+ 19 - 0
gps/README.md

@@ -0,0 +1,19 @@
+GPS
+===
+Usage example, from in a folder hierachy:
+
+./main.py
+./gps
+
+main.py
+```
+from gps import gps
+
+if __name__ == "__main__":
+
+    gps = gps.Data()
+
+    while True:
+        if gps.new_location():
+            location = gps.get_location()
+```

+ 10 - 0
gps/__init__.py

@@ -0,0 +1,10 @@
+'''
+Package: gps
+
+Reads and parse data received from the GPS module.
+
+Note:   This package should be re-written to reuse objects
+        to save resources.
+'''
+__author__ = "Joachim M. Giaever"
+__email__ = "jgi004@post.uit.no"

+ 415 - 0
gps/gps.py

@@ -0,0 +1,415 @@
+try:
+    import machine
+    import time
+    import struct
+except:
+    pass
+
+'''
+Parsing
+'''
+
+class NMEA(object):
+    '''
+    Just a class to describe the type of the received entry.
+    We should consider removing this to save space.
+    '''
+    def __init__(self, id):
+        self.__id = str(id)
+
+class Value(object):
+    ''' 
+    Defines a value received from the GPS
+    v, float:   floating value
+    u, string:  unit (e.g m, knot etc)
+    t, tuple:   time when measured.
+    '''
+    def __init__(self, v, u, t=(0,0,0.0)):
+        self.__val = float(v)
+        self.__unit = u
+        self.__time = t
+
+    def value(self):
+        '''
+        Returns the value
+        '''
+        return self.__val
+
+    def unit(self):
+        '''
+        Returns the unit
+        '''
+        return self.__unit
+
+    def time(self):
+        '''
+        Returns the measurment time.
+        '''
+        return self.__time
+
+    def rad(self):
+        '''
+        Returns the value in radians.
+        '''
+        return self.__val * math.pi / 180
+
+    def __repr__(self):
+        return "%f %s" % (self.value(), self.unit())
+
+    def __float__(self):
+        return float(self.__val)
+
+class Distance(Value):
+    '''
+    Value: Distance
+    '''
+    def __init__(self, v, u, t):
+        super().__init__(v, u, t)
+
+class Position(Value):
+    '''
+    Value: Position
+    '''
+    def __init__(self, v, u, t):
+        super().__init__(v if u in ("N", "E") else -v, u, t)
+
+    def __sub__(self, other):
+        '''
+        Returns a new position with the subtracted value
+        '''
+        return Position(self.value() - other.value())
+
+class Speed(Value):
+    '''
+    Value: Speed
+    '''
+    def __init__(self, v, u, t):
+        super().__init__(v, u, t)
+
+    def to_kmh(self):
+        '''
+        Returns the speed in Km/h
+        '''
+        if self.unit() in ("knot", "N"):
+            return Speed(self.value() * 1.85200, "kmh", self.time())
+        return self
+
+    def to_knot(self):
+        '''
+        Returns the speed in knot
+        '''
+        if self.unit() in ("kmh", "K"):
+            return Speed(self.value() / 1.85200, "knot", self.time())
+        return self
+
+class HDOP(Value):
+    '''
+    HDOP: Horizontal dilution of precision.
+    '''
+    def __init__(self, v, t):
+        super().__init__(v, "", t)
+
+    def __str__(self):
+        if self.value() < 1:
+            return "Ide."
+        elif self.value() <= 2:
+            return "Exe."
+        elif self.value() <= 5:
+            return "Good"
+        elif self.value() <= 10:
+            return "Mod."
+        elif self.value() <= 20:
+            return "Fair"
+        else:
+            return "Poor"
+
+    def __repr__(self):
+        return self.__str__()
+
+class Course(Value):
+    '''
+    Value: Course/direction
+    '''
+    def __init__(self, v, t):
+        super().__init__(v, "D", t)
+
+class Location(object):
+    '''
+    Location:
+        Tries to read data received from the GPS.
+        Sometimes the GPS will return data for som
+        of the segments, e.g it may happens that
+        it wont receive the GPGGA-segment every time.
+    '''
+    def __init__(self):
+        self.__valid = False
+        self.__lat = None
+        self.__long = None
+        self.__alt = None
+        self.__height = None
+        self.__speed = None
+        self.__course = None
+        self.__satellites = -1
+        self.__hdop = None
+
+    def __repr__(self):
+        return "Satelittes: %s, Quality: %s, %s\n\tLat/long: %s/%s\n\tAlt/h: %s/%s\n\tSpeed/course: %s/%s" % (
+            self.__satellites, self.__hdop, repr(self.__valid),
+            self.__lat, self.__lat,
+            self.__alt, self.__height,
+            self.__speed, self.__course,
+        )
+
+    def set(self, msgid, segment):
+        '''
+        Sets data based on the segment received
+        msgid, []byte:      the segment type, e.g b'$GPGGA'
+        segment, []byte:    the segment itself
+        '''
+        data = segment.split(",")
+        if msgid == b'$GPGGA':
+            if len(data) >= 6 and data[5] in ("1", "2", "6"):
+                t = self.__time_from_seg(data[0])
+                self.__set_lat(data[1], data[2], t)
+                self.__set_long(data[3], data[4], t)
+
+                if self.__satellites < 0 and self.__seg_set(data, 6):
+                    self.__satellites = int(data[6])
+
+                if self.__seg_set(data, 7):
+                    self.__set_hdop(data[7], t)
+
+                if self.__seg_set(data, 8):
+                    self.__alt = Distance(data[8], "M" if not self.__seg_set(data, 9) else data[9], t)
+
+                if self.__seg_set(data, 10):
+                    self.__height = Distance(data[10], "M" if not self.__seg_set(data, 11) else data[10], t)
+        elif msgid == b'$GPGLL':
+            if len(data) >= 6 and data[5] == "A":
+                t = self.__time_from_seg(data[4])
+                self.__set_lat(data[0], data[1], t)
+                self.__set_long(data[2], data[3], t)
+        elif msgid == b'$GPRMC':
+            if len(data) >= 6 and data[1] == "A":
+                t = self.__time_from_seg(data[0])
+                self.__set_lat(data[2], data[3], t)
+                self.__set_long(data[4], data[5], t)
+                self.__set_speed(data[6], "N", t)
+                self.__set_course(data[7], t)
+        elif msgid == b'$GPVTG':
+            if len(data) >= 7 and data[2] == "T":
+                self.__set_speed(data[4], data[6], (0, 0, 0.0))
+                self.__set_course(data[5], data[0], (0, 0, 0.0))
+        elif msgid == b'$GPGSV':
+            if self.__seg_set(data, 2) and data[0] == data[1]:
+                self.__satellites = int(data[2])
+        elif msgid == b'$GPMSS':
+            pass
+
+        # This location is only valid when it was possible to set lat/long
+        self.__valid = False if self.__lat is None or self.__long is None else True
+
+        return self.valid()
+
+    def valid(self):
+        '''
+        Returns wether or not the location is valid
+        '''
+        return self.__valid
+
+    def __seg_set(self, d, i):
+        '''
+        Set position i from segment-part.
+        d, []strings:   segments in parts
+        i, integer:     position to read
+        '''
+        return len(d) >= (i + 1) and len(d[i]) != 0 and "*" not in d[i]
+
+    def __set_hdop(self, v, t):
+        '''
+        Set Horizontal dilution of precision if the HDOP
+        is missing or newer than the previous measured.
+
+        Note:   We may have several segments returning this values,
+                which are (may have been) measured at different times.
+        '''
+        if len(v) == 0:
+            return None
+
+        if self.__hdop is None or self.__hdop.time() < t:
+            self.__hdop = HDOP(v, t)
+
+    def __set_speed(self, v, u, t):
+        '''
+        Set speed, but only if the speed is missing or the
+        previous measured speed is older.
+
+        Note:   We may have several segments returning this values,
+                which are (may have been) measured at different times.
+        '''
+        if len(v) == 0:
+            return None
+
+        if self.__speed is None or self.__speed.time() < t:
+            self.__speed = Speed(v, u, t)
+
+    def __set_course(self, v, t):
+        '''
+        Set course, but only if the course is missing or the
+        previous measured speed is older.
+
+        Note:   We may have several segments returning this values,
+                which are (may have been) measured at different times.
+        '''
+
+        if len(v) == 0:
+            return None
+
+        if self.__course is None or self.__course.time() < t:
+            self.__course = Course(v, t)
+
+    def __set_lat(self, v, d, t):
+        '''
+        Set latitude, but only if the latitude is missing or the
+        previous measured speed is older.
+
+        Note:   We may have several segments returning this values,
+                which are (may have been) measured at different times.
+        '''
+        if len(v) == 0:
+            return None
+
+        if self.__lat is None or self.__lat.time() < t:
+            self.__lat = Position(float(v[0:2]) + (float(v[2:]) / 60), d, t)
+
+    def __set_long(self, v, d, t):
+        '''
+        Set longitude, but only if the longitude is missing or the
+        previous measured speed is older.
+
+        Note:   We may have several segments returning this values,
+                which are (may have been) measured at different times.
+        '''
+        if len(v) == 0:
+            return None
+
+        if self.__long is None or self.__long.time() < t:
+            self.__long = Position(float(v[0:3]) + (float(v[3:]) / 60), d, t)
+
+    def __time_from_seg(self, ts):
+        '''
+        Get the time tuple from the time-segment
+        '''
+        return (int(ts[0:2]), int(ts[2:4]), float(ts[4:]))
+
+    def longitude(self):
+        '''
+        Returns the longitude.
+        '''
+        return self.__lat.value() if self.__lat is not None else False
+
+    def latitude(self):
+        '''
+        Returns the latitude
+        '''
+        return self.__long.value() if self.__long is not None else False
+
+    def altitude(self):
+        '''
+        Returns the altitude
+        '''
+        return self.__alt.value() if self.__alt is not None else False
+
+    def height(self):
+        '''
+        Returns the height
+        '''
+        return self.__height.value() if self.__height is not None else False
+
+    def speed(self):
+        '''
+        Returns the speed
+        '''
+        return self.__speed.value() if self.__speed is not None else False
+
+    def course(self):
+        '''
+        Returns the course
+        '''
+        return self.__course.value() if self.__course is not None else False
+
+    def satellites(self):
+        '''
+        Returns the amount of satellites the GPS is connected to.
+        '''
+        return self.__satellites if self.__satellites >= 0 else False
+
+    def hdop(self):
+        '''
+        Returns the precision
+        '''
+        return self.__hdop if self.__hdop is not None else False
+
+
+class Data(object):
+    '''
+    Reads and stores data from the GPS
+    '''
+    def __init__(self, pins=("P3", "P4"), baud=9600):
+        if machine: # Fix for pydoc
+            self.__com = machine.UART(1, pins=pins, baudrate=baud)
+        self.__location = None
+        self.__last_update = time.time()
+
+    def new_location(self, ttw=5):
+        '''
+        Waits for the GPS to return data with an 'time to wait'-interval.
+
+        Returns True if there is a new VALID location.
+        '''
+        if time.time() - (self.__last_update + ttw) < 0:
+            return False
+
+        self.__data = Location()
+        data = []
+
+        while self.__com.any():
+            tmp_data = self.__com.readline()
+
+            if tmp_data[0:1] == b'$':
+                self.__update(data)
+                data = [tmp_data]
+            elif len(data) != 0:
+                data.append(tmp_data)
+        else:
+            self.__update(data)
+
+        if self.__data.valid():
+            print(self.__data)
+        
+        return self.__data.valid()
+
+    def get_location(self):
+        '''
+        Returns the location-data. Should be used when new_location returns True.
+        '''
+        return self.__data
+
+    def __update(self, data):
+        '''
+        Prepares the segments for reading.
+        '''
+        if len(data) == 0:
+            return False
+
+        data = b''.join(data)
+
+        if data[len(data)-1:len(data)] not in (b'\n', b'\r'):
+            print("False data: %s" % (str(data),))
+            return False
+
+        if data[len(data)-1:len(data)] != b'\n':
+            data += '\n'
+
+        if self.__data.set(data[0:6], ("%s" % (data[7:len(data)-2],))[2:-1]):
+            self.__last_update = time.time()