1
- ** WARNING : Under development and subject to change **
1
+ ** NOTE : Under development. API may be subject to change**
2
2
3
3
# 1. as_GPS
4
4
5
5
This is an asynchronous device driver for GPS devices which communicate with
6
6
the driver via a UART. GPS NMEA sentence parsing is based on this excellent
7
- library [ micropyGPS] .
7
+ library [ micropyGPS] . It was adapted for asynchronous use; also to reduce RAM
8
+ use and frequency of allocations and to correctly process local time values.
8
9
9
10
The driver is designed to be extended by subclassing, for example to support
10
11
additional sentence types. It is compatible with Python 3.5 or later and also
11
12
with [ MicroPython] . Testing was performed using a [ pyboard] with the Adafruit
12
13
[ Ultimate GPS Breakout] board.
13
14
14
15
Most GPS devices will work with the read-only driver as they emit NMEA
15
- sentences on startup. An optional read-write driver is provided for
16
+ sentences on startup. The read-only driver is designed for use on resource
17
+ constrained hosts. An optional read-write subclass is provided for
16
18
MTK3329/MTK3339 chips as used on the above board. This enables the device
17
19
configuration to be altered.
18
20
19
- A further driver , for the Pyboard and other boards based on STM processors,
20
- provides for using the GPS device for precision timing. The chip's RTC may be
21
+ Further subclasses , for the Pyboard and other boards based on STM processors,
22
+ provide for using the GPS device for precision timing. The chip's RTC may be
21
23
precisely set and calibrated using the PPS signal from the GPS chip.
22
24
23
25
###### [ Main README] ( ../README.md )
@@ -78,10 +80,13 @@ The following are relevant to the default read-only driver.
78
80
79
81
* ` as_GPS.py ` The library. Supports the ` AS_GPS ` class for read-only access to
80
82
GPS hardware.
83
+ * ` as_GPS_utils.py ` Additional formatted string methods for ` AS_GPS ` .
81
84
* ` ast_pb.py ` Test/demo program: assumes a MicroPython hardware device with
82
85
GPS connected to UART 4.
83
86
* ` log_kml.py ` A simple demo which logs a route travelled to a .kml file which
84
87
may be displayed on Google Earth.
88
+
89
+ Special tests:
85
90
* ` astests.py ` Test with synthetic data. Run on CPython 3.x or MicroPython.
86
91
* ` astests_pyb.py ` Test with synthetic data on UART. GPS hardware replaced by
87
92
a loopback on UART 4. Requires CPython 3.5 or later or MicroPython and
@@ -95,11 +100,12 @@ Additional files relevant to the read/write driver are listed
95
100
96
101
### 1.4.1 Micropython
97
102
98
- To install on "bare metal" hardware such as the Pyboard copy the file
99
- ` as_GPS.py ` onto the device's filesystem and ensure that ` uasyncio ` is
100
- installed. The code has been tested on the Pyboard with ` uasyncio ` V2 and the
101
- Adafruit [ Ultimate GPS Breakout] module. If memory errors are encountered on
102
- resource constrained devices install as a [ frozen module] .
103
+ To install on "bare metal" hardware such as the Pyboard copy the files
104
+ ` as_GPS.py ` and ` as_GPS_utils.py ` onto the device's filesystem and ensure that
105
+ ` uasyncio ` is installed. The code was tested on the Pyboard with ` uasyncio ` V2
106
+ and the Adafruit [ Ultimate GPS Breakout] module. If memory errors are
107
+ encountered on resource constrained devices install each file as a
108
+ [ frozen module] .
103
109
104
110
For the [ read/write driver] ( ./README.md#3-the-gps-class-read/write-driver ) the
105
111
file ` as_rwGPS.py ` must also be installed. For the
@@ -108,9 +114,9 @@ should also be copied across.
108
114
109
115
### 1.4.2 Python 3.5 or later
110
116
111
- On platforms with an underlying OS such as the Raspberry Pi ensure that
112
- ` as_GPS.py ` (and optionally ` as_rwGPS.py ` ) is on the Python path and that the
113
- Python version is 3.5 or later.
117
+ On platforms with an underlying OS such as the Raspberry Pi ensure that the
118
+ required driver files are on the Python path and that the Python version is 3.5
119
+ or later.
114
120
115
121
# 2. The AS_GPS Class read-only driver
116
122
@@ -124,7 +130,7 @@ Three mechanisms exist for responding to outages.
124
130
* Check the ` time_since_fix ` method [ section 2.2.3] ( ./README.md#223-time-and-date ) .
125
131
* Pass a ` fix_cb ` callback to the constructor (see below).
126
132
* Cause a coroutine to pause until an update is received: see
127
- [ section 3.2 ] ( ./README.md#231-data-validity ) . This ensures current data.
133
+ [ section 2.3.1 ] ( ./README.md#231-data-validity ) . This ensures current data.
128
134
129
135
## 2.1 Constructor
130
136
@@ -138,7 +144,9 @@ Optional positional args:
138
144
Default ` RMC ` : the callback will occur on RMC messages only (see below).
139
145
* ` fix_cb_args ` A tuple of args for the callback (default ` () ` ).
140
146
141
- Note:
147
+ Notes:
148
+ ` local_offset ` correctly alters the date where time passes the 00.00.00
149
+ boundary.
142
150
If ` sreader ` is ` None ` a special test mode is engaged (see ` astests.py ` ).
143
151
144
152
### 2.1.1 The fix callback
@@ -206,20 +214,21 @@ gps = as_GPS.AS_GPS(sreader, fix_cb=callback, cb_mask= as_GPS.RMC | as_GPS.VTG)
206
214
the specified units. Options ` as_GPS.KPH ` , ` as_GPS.MPH ` , ` as_GPS.KNOT ` .
207
215
208
216
* ` compass_direction ` No args. Returns current course as a string e.g. 'ESE'
209
- or 'NW'
217
+ or 'NW'. Note that this requires the file ` as_GPS_utils.py ` .
210
218
211
219
### 2.2.3 Time and date
212
220
213
221
* ` time_since_fix ` No args. Returns time in milliseconds since last valid fix.
214
222
223
+ * ` time_string ` Arg ` local ` default ` True ` . Returns the current time in form
224
+ 'hh:mm: ss .sss'. If ` local ` is ` False ` returns UTC time.
225
+
215
226
* ` date_string ` Optional arg ` formatting=MDY ` . Returns the date as
216
227
a string. Formatting options:
217
228
` as_GPS.MDY ` returns 'MM/DD/YY'.
218
229
` as_GPS.DMY ` returns 'DD/MM/YY'.
219
230
` as_GPS.LONG ` returns a string of form 'January 1st, 2014'.
220
-
221
- * ` time_string ` Arg ` local ` default ` True ` . Returns the current time in form
222
- 'hh:mm: ss .sss'. If ` local ` is ` False ` returns UTC time.
231
+ Note that this requires the file ` as_GPS_utils.py ` .
223
232
224
233
## 2.3 Public coroutines
225
234
@@ -280,7 +289,7 @@ The sentence type which updates a value is shown in brackets e.g. (GGA).
280
289
* ` geoid_height ` Height of geoid (mean sea level) in metres above WGS84
281
290
ellipsoid. (GGA).
282
291
* ` magvar ` Magnetic variation. Degrees. -ve == West. Current firmware does not
283
- produce this data and it will always read zero.
292
+ produce this data: it will always read zero.
284
293
285
294
### 2.4.2 Statistics and status
286
295
@@ -490,18 +499,47 @@ Other `PMTK` messages are passed to the optional message callback as described
490
499
491
500
Many GPS chips (e.g. MTK3339) provide a PPS signal which is a pulse occurring
492
501
at 1s intervals whose leading edge is a highly accurate time reference. It may
493
- be used to set and to calibrate the Pyboard realtime clock (RTC).
502
+ be used to set and to calibrate the Pyboard realtime clock (RTC). Note that
503
+ these drivers are for STM based targets only (at least until the ` machine `
504
+ library supports an ` RTC ` class).
494
505
495
506
## 4.1 Files
496
507
497
- * ` as_tGPS.py ` The library. Supports the ` GPS_Timer ` class .
508
+ * ` as_tGPS.py ` The library. Provides ` GPS_Timer ` and ` GPS_RWTimer ` classes .
498
509
* ` as_GPS_time.py ` Test scripts for above.
499
510
500
- ## 4.2 GPS_Timer class Constructor
511
+ ## 4.2 GPS_Timer and GPS_RWTimer classes
512
+
513
+ These classes inherit from ` AS_GPS ` and ` GPS ` respectively, with read-only and
514
+ read/write access to the GPS hardware. All public methods and bound variables of
515
+ the base classes are supported. Additional functionality is detailed below.
516
+
517
+ ### 4.2.1 GPS_Timer class Constructor
501
518
502
- This takes the following arguments :
503
- * ` gps ` An instance of the ` AS_GPS ` (read-only) or ` GPS ` (read/write) classes .
519
+ Mandatory positional args :
520
+ * ` sreader ` The ` StreamReader ` instance associated with the UART .
504
521
* ` pps_pin ` An initialised input ` Pin ` instance for the PPS signal.
522
+ Optional positional args:
523
+ * ` local_offset ` See ` AS_GPS ` details for these args.
524
+ * ` fix_cb `
525
+ * ` cb_mask `
526
+ * ` fix_cb_args `
527
+ * ` led ` Default ` None ` . If an ` LED ` instance is passed, this will toggle each
528
+ time a PPS interrupt is handled.
529
+
530
+ ### 4.2.2 GPS_RWTimer class Constructor
531
+
532
+ This takes three mandatory positional args:
533
+ * ` sreader ` The ` StreamReader ` instance associated with the UART.
534
+ * ` swriter ` The ` StreamWriter ` instance associated with the UART.
535
+ * ` pps_pin ` An initialised input ` Pin ` instance for the PPS signal.
536
+ Optional positional args:
537
+ * ` local_offset ` See ` GPS ` details.
538
+ * ` fix_cb `
539
+ * ` cb_mask `
540
+ * ` fix_cb_args `
541
+ * ` msg_cb `
542
+ * ` msg_cb_args `
505
543
* ` led ` Default ` None ` . If an ` LED ` instance is passed, this will toggle each
506
544
time a PPS interrupt is handled.
507
545
@@ -538,6 +576,10 @@ RTC to achieve timepiece quality results. Note that calibration is lost on
538
576
power down: solutions are either to use an RTC backup battery or to store the
539
577
calibration factor in a file (or in code) and re-apply it on startup.
540
578
579
+ Crystal oscillator frequency (and hence calibration factor) is temperature
580
+ dependent. For the most accurate possible results allow the Pyboard to reach
581
+ working temperature before calibrating.
582
+
541
583
# 5. Supported Sentences
542
584
543
585
* GPRMC GP indicates NMEA sentence
@@ -580,11 +622,14 @@ messages came in. This time could be longer depending on data. So if an update
580
622
rate higher than the default 1 second is to be used, either the baudrate must
581
623
be increased or the satellite information messages should be disabled.
582
624
583
- The PPS signal (not used by this driver) on the MTK3339 occurs only when a fix
584
- has been achieved. The leading edge always occurs before a set of messages are
585
- output. So, if the leading edge is to be used for precise timing, 1s should be
586
- added to the ` timestamp ` value (beware of possible rollover into minutes and
587
- hours).
625
+ The PPS signal on the MTK3339 occurs only when a fix has been achieved. The
626
+ leading edge occurs on a 1s boundary with high absolute accuracy. It therefore
627
+ follows that the RMC message carrying the time/date of that second arrives
628
+ after the leading edge (because of processing and UART latency). It is also
629
+ the case that on a second boundary minutes, hours and the date may roll over.
630
+
631
+ Further, the local_time offset can affect the date. These drivers aim to handle
632
+ these factors.
588
633
589
634
[ MicroPython ] :https://micropython.org/
590
635
[ frozen module ] :https://learn.adafruit.com/micropython-basics-loading-modules/frozen-modules
0 commit comments