1
- ** NOTE: Under development. API may be subject to change**
2
-
3
1
# 1. as_GPS
4
2
5
3
This repository offers a suite of asynchronous device drivers for GPS devices
@@ -15,10 +13,10 @@ on this excellent library [micropyGPS].
15
13
* The read-write driver enables altering the configuration of GPS devices
16
14
based on the popular MTK3329/MTK3339 chips.
17
15
* The above drivers are portable between [ MicroPython] and Python 3.5 or above.
18
- * Timing drivers for [ MicroPython] targets based on STM chips (e.g. the [ Pyboad ] )
19
- extend the capabilities of the read-only and read-write drivers to provide
20
- precision timing. The RTC may be calibrated and set to achieve timepiece-level
21
- accuracy.
16
+ * Timing drivers for [ MicroPython] only extend the capabilities of the
17
+ read-only and read-write drivers to provide precision μs class GPS timing. On
18
+ STM-based hosts (e.g. the Pyboard) the RTC may be set from GPS and calibrated
19
+ to achieve timepiece-level accuracy.
22
20
* Drivers may be extended via subclassing, for example to support additional
23
21
sentence types.
24
22
@@ -30,17 +28,17 @@ driver as they emit NMEA sentences on startup.
30
28
31
29
NMEA sentence parsing is based on [ micropyGPS] but with significant changes.
32
30
33
- * As asynchronous drivers they require ` uasyncio ` on [ MicroPython] . They use
34
- asyncio under Python 3.5+.
31
+ * As asynchronous drivers they require ` uasyncio ` on [ MicroPython] or asyncio
32
+ under Python 3.5+.
35
33
* Sentence parsing is adapted for asynchronous use.
36
34
* Rollover of local time into the date value enables worldwide use.
37
- * RAM allocation is reduced by various techniques: this reduces heap
38
- fragmentation, improving application reliability on RAM constrained devices.
35
+ * RAM allocation is cut by various techniques to lessen heap fragmentation.
36
+ This improves application reliability on RAM constrained devices.
39
37
* Some functionality is devolved to a utility module, reducing RAM usage where
40
38
these functions are unused.
41
39
* The read/write driver is a subclass of the read-only driver.
42
40
* Timing drivers are added offering time measurement with μs resolution and
43
- high absolute accuracy. These are implemented by subclassing.
41
+ high absolute accuracy. These are implemented by subclassing these drivers .
44
42
* Hooks are provided for user-designed subclassing, for example to parse
45
43
additional message types.
46
44
@@ -152,7 +150,7 @@ and the Adafruit [Ultimate GPS Breakout] module. If memory errors are
152
150
encountered on resource constrained devices install each file as a
153
151
[ frozen module] .
154
152
155
- For the [ read/write driver] ( ./README.md#3-the-gps-class-read/ write-driver ) the
153
+ For the [ read/write driver] ( ./README.md#3-the-gps-class-read- write-driver ) the
156
154
file ` as_rwGPS.py ` must also be installed. The test/demo ` ast_pbrw.py ` may
157
155
optionally be installed; this requires ` aswitch.py ` from the root of this
158
156
repository.
@@ -185,7 +183,8 @@ Three mechanisms exist for responding to outages.
185
183
Mandatory positional arg:
186
184
* ` sreader ` This is a ` StreamReader ` instance associated with the UART.
187
185
Optional positional args:
188
- * ` local_offset ` Local timezone offset in hours realtive to UTC (GMT).
186
+ * ` local_offset ` Local timezone offset in hours realtive to UTC (GMT). May be
187
+ an integer or float.
189
188
* ` fix_cb ` An optional callback. This runs after a valid message of a chosen
190
189
type has been received and processed.
191
190
* ` cb_mask ` A bitmask determining which sentences will trigger the callback.
@@ -255,8 +254,8 @@ gps = as_GPS.AS_GPS(sreader, fix_cb=callback, cb_mask= as_GPS.RMC | as_GPS.VTG)
255
254
256
255
### 2.2.2 Course
257
256
258
- * ` speed ` Optional arg ` unit=KPH ` . Returns the current speed in the specified
259
- units. Options: ` as_GPS.KPH ` , ` as_GPS.MPH ` , ` as_GPS.KNOT ` .
257
+ * ` speed ` Optional arg ` unit=as_GPS. KPH ` . Returns the current speed in the
258
+ specified units. Options: ` as_GPS.KPH ` , ` as_GPS.MPH ` , ` as_GPS.KNOT ` .
260
259
261
260
* ` speed_string ` Optional arg ` unit=as_GPS.KPH ` . Returns the current speed in
262
261
the specified units. Options ` as_GPS.KPH ` , ` as_GPS.MPH ` , ` as_GPS.KNOT ` .
@@ -268,7 +267,7 @@ gps = as_GPS.AS_GPS(sreader, fix_cb=callback, cb_mask= as_GPS.RMC | as_GPS.VTG)
268
267
269
268
* ` time_since_fix ` No args. Returns time in milliseconds since last valid fix.
270
269
271
- * ` time_string ` Arg ` local ` default ` True ` . Returns the current time in form
270
+ * ` time_string ` Optional arg ` local= True` . Returns the current time in form
272
271
'hh:mm: ss .sss'. If ` local ` is ` False ` returns UTC time.
273
272
274
273
* ` date_string ` Optional arg ` formatting=MDY ` . Returns the date as
@@ -284,19 +283,20 @@ gps = as_GPS.AS_GPS(sreader, fix_cb=callback, cb_mask= as_GPS.RMC | as_GPS.VTG)
284
283
285
284
On startup after a cold start it may take time before valid data is received.
286
285
During and shortly after an outage messages will be absent. To avoid reading
287
- stale data reception of messages can be checked before accessing data.
286
+ stale data, reception of messages can be checked before accessing data.
288
287
289
288
* ` data_received ` Boolean args: ` position ` , ` course ` , ` date ` , ` altitude ` .
290
- All default ` False ` . The coroutine will pause until valid messages of the
291
- specified types have been received. For example:
289
+ All default ` False ` . The coroutine will pause until at least one valid message
290
+ of each specified types has been received. This example will pause until new
291
+ position and altitude messages have been received:
292
292
293
293
``` python
294
294
while True :
295
295
await my_gps.data_received(position = True , altitude = True )
296
- # can now access these data values with confidence
296
+ # Access these data values now
297
297
```
298
298
299
- No check is provided for satellite data as this is checked by the
299
+ No option is provided for satellite data: this functionality is provided by the
300
300
` get_satellite_data ` coroutine.
301
301
302
302
### 2.3.2 Satellite Data
@@ -345,24 +345,27 @@ The following are counts since instantiation.
345
345
* ` crc_fails ` Usually 0 but can occur on baudrate change.
346
346
* ` clean_sentences ` Number of sentences received without major failures.
347
347
* ` parsed_sentences ` Sentences successfully parsed.
348
- * ` unsupported_sentences ` This is incremented if a sentence is received with a
349
- valid format and checksum, but is not supported by the class. This value will
350
- also increment if these are supported in a subclass (see section 5).
348
+ * ` unsupported_sentences ` This is incremented if a sentence is received which
349
+ has a valid format and checksum, but is not supported by the class. This
350
+ value will also increment if these are supported in a subclass. See
351
+ [ section 6] ( ./README.md#6-developer-notes ) .
351
352
352
353
### 2.4.3 Date and time
353
354
354
- * ` utc ` [ hrs: int, mins: int, secs: int] UTC time e.g. [ 23, 3, 58] . Note
355
- that some GPS hardware may only provide integer seconds. The MTK3339 chip
356
- provides a float whose value is always an integer.
357
- * ` local_time ` [ hrs: int, mins: int, secs: int] Local time.
358
- * ` date ` [ day: int, month: int, year: int] e.g. [ 23, 3, 18]
355
+ * ` utc ` (property) [ hrs: int, mins: int, secs: int] UTC time e.g.
356
+ [ 23, 3, 58] . Note the integer seconds value. The MTK3339 chip provides a float
357
+ buts its value is always an integer. To achieve accurate subsecond timing see
358
+ [ section 4] ( ./README.md#4-using-gps-for-accurate-timing ) .
359
+ * ` local_time ` (property) [ hrs: int, mins: int, secs: int] Local time.
360
+ * ` date ` (property) [ day: int, month: int, year: int] e.g. [ 23, 3, 18]
359
361
* ` local_offset ` Local time offset in hrs as specified to constructor.
362
+ * ` epoch_time ` Integer. Time since the epoch. Epoch start depends on whether
363
+ running under MicroPython or Python 3.5+.
360
364
361
- The ` utc ` bound variable updates on receipt of RMC, GLL or GGA messages.
362
-
363
- The ` date ` and ` local_time ` variables are updated when an RMC message is
364
- received. A local time offset will affect the ` date ` value where the offset
365
- causes the local time to pass midnight.
365
+ The ` utc ` , ` date ` and ` local_time ` properties updates on receipt of RMC
366
+ messages. If a nonzero ` local_offset ` value is specified the ` date ` value will
367
+ update when local time passes midnight (local time and date are computed from
368
+ ` epoch_time ` ).
366
369
367
370
### 2.4.4 Satellite data
368
371
@@ -394,28 +397,34 @@ and subsequent characters are stripped from the last. Thus if the string
394
397
was received ` reparse ` would see
395
398
` ['GPGGA','123519','4807.038','N','01131.000','E','1','08','0.9','545.4','M','46.9','M','',''] `
396
399
397
- # 3. The GPS class read/ write driver
400
+ # 3. The GPS class read- write driver
398
401
399
402
This is a subclass of ` AS_GPS ` and supports all its public methods, coroutines
400
- and bound variables. It provides limited support for sending PMTK command
401
- packets to GPS modules based on the MTK3329/MTK3339 chip. These include:
403
+ and bound variables. It provides support for sending PMTK command packets to
404
+ GPS modules based on the MTK3329/MTK3339 chip. These include:
402
405
403
406
* Adafruit Ultimate GPS Breakout
404
407
* Digilent PmodGPS
405
408
* Sparkfun GPS Receiver LS20031
406
409
* 43oh MTK3339 GPS Launchpad Boosterpack
407
410
411
+ A subset of the PMTK packet types is supported but this may be extended by
412
+ subclassing.
413
+
408
414
## 3.1 Files
409
415
410
416
* ` as_rwGPS.py ` Supports the ` GPS ` class. This subclass of ` AS_GPS ` enables
411
- writing a limited subset of the MTK commands used on many popular devices .
412
- * ` as_GPS.py ` The library containing the base class.
417
+ writing PMTK packets .
418
+ * ` as_GPS.py ` The library containing the ` AS_GPS ` base class.
413
419
* ` as_GPS_utils.py ` Additional formatted string methods.
414
- * ` ast_pbrw.py ` Test script which changes various attributes. This will pause
415
- until a fix has been achieved. After that changes are made for about 1 minute,
416
- then it runs indefinitely reporting data at the REPL and on the LEDs. It may
417
- be interrupted with ` ctrl-c ` when the default baudrate will be restored.
418
- LED's:
420
+ * ` ast_pbrw.py ` Test script which changes various attributes.
421
+
422
+ The test script will pause until a fix has been achieved. After that changes
423
+ are made for about 1 minute, after which it runs indefinitely reporting data at
424
+ the REPL and on the LEDs. It may be interrupted with ` ctrl-c ` when the default
425
+ baudrate will be restored.
426
+
427
+ LED's:
419
428
* Red: Toggles each time a GPS update occurs.
420
429
* Green: ON if GPS data is being received, OFF if no data received for >10s.
421
430
* Yellow: Toggles each 4s if navigation updates are being received.
@@ -452,6 +461,7 @@ loop.run_until_complete(test())
452
461
This takes two mandatory positional args:
453
462
* ` sreader ` This is a ` StreamReader ` instance associated with the UART.
454
463
* ` swriter ` This is a ` StreamWriter ` instance associated with the UART.
464
+
455
465
Optional positional args:
456
466
* ` local_offset ` Local timezone offset in hours realtive to UTC (GMT).
457
467
* ` fix_cb ` An optional callback which runs each time a valid fix is received.
@@ -469,21 +479,20 @@ If implemented the message callback will receive the following positional args:
469
479
470
480
In the case of handled messages the list of text strings has length 2. The
471
481
first is 'version', 'enabled' or 'antenna' followed by the value of the
472
- relevant bound variable e.g. [ 'antenna', 3] .
482
+ relevant bound variable e.g. ` ['antenna', 3] ` .
473
483
474
- For unhandled messages text strings are as received, except that element 0 has
475
- the '$' symbol removed. The last element is the last informational string - the
476
- checksum has been verified and is not in the list.
484
+ For unhandled messages text strings are as received, processed as per
485
+ [ section 2.5] ( ./README.md#25-subclass-hooks ) .
477
486
478
487
The args presented to the fix callback are as described in
479
488
[ section 2.1] ( ./README.md#21-constructor ) .
480
489
481
490
## 3.3 Public coroutines
482
491
483
- * ` baudrate ` Arg: baudrate. Must be 4800, 9600, 14400, 19200, 38400, 57600 or
484
- 115200 . See below.
485
- * ` update_interval ` Arg: interval in ms. Default 1000. Must be between 100 and
486
- 10000 . If the rate is to be increased see
492
+ * ` baudrate ` Arg: baudrate. Must be 4800, 9600, 14400, 19200, 38400, 57600
493
+ or 115200. See below.
494
+ * ` update_interval ` Arg: interval in ms. Default 1000. Must be between 100
495
+ and 10000. If the rate is to be increased see
487
496
[ notes on timing] ( ./README.md#7-notes-on-timing ) .
488
497
* ` enable ` Determine the frequency with which each sentence type is sent. A
489
498
value of 0 disables a sentence, a value of 1 causes it to be sent with each
@@ -493,27 +502,26 @@ The args presented to the fix callback are as described in
493
502
` gll=0 ` , ` rmc=1 ` , ` vtg=1 ` , ` gga=1 ` , ` gsa=1 ` , ` gsv=5 ` , ` chan=0 ` . The last
494
503
represents GPS channel status. These values are the factory defaults.
495
504
* ` command ` Arg: a command from the following set:
496
-
497
- * ` as_rwGPS.HOT_START ` Use all available data in the chip's NV Store.
498
- * ` as_rwGPS.WARM_START ` Don't use Ephemeris at re-start.
499
- * ` as_rwGPS.COLD_START ` Don't use Time, Position, Almanacs and Ephemeris data
500
- at re-start.
501
- * ` as_rwGPS.FULL_COLD_START ` A 'cold_start', but additionally clear
502
- system/user configurations at re-start. That is, reset the receiver to the
503
- factory status.
504
- * ` as_rwGPS.STANDBY ` Put into standby mode. Sending any command resumes
505
- operation.
506
- * ` as_rwGPS.DEFAULT_SENTENCES ` Sets all sentence frequencies to factory
507
- default values as listed under ` enable ` .
508
- * ` as_rwGPS.VERSION ` Causes the GPS to report its firmware version. This will
509
- appear as the ` version ` bound variable when the report is received.
510
- * ` as_rwGPS.ENABLE ` Causes the GPS to report the enabled status of the various
511
- message types as set by the ` enable ` coroutine. This will appear as the
512
- ` enable ` bound variable when the report is received.
513
- * ` as_rwGPS.ANTENNA ` Causes the GPS to send antenna status messages. The
514
- status value will appear in the ` antenna ` bound variable each time a report is
515
- received.
516
- * ` as_rwGPS.NO_ANTENNA ` Turns off antenna messages.
505
+ * ` as_rwGPS.HOT_START ` Use all available data in the chip's NV Store.
506
+ * ` as_rwGPS.WARM_START ` Don't use Ephemeris at re-start.
507
+ * ` as_rwGPS.COLD_START ` Don't use Time, Position, Almanacs and Ephemeris data
508
+ at re-start.
509
+ * ` as_rwGPS.FULL_COLD_START ` A 'cold_start', but additionally clear
510
+ system/user configurations at re-start. That is, reset the receiver to the
511
+ factory status.
512
+ * ` as_rwGPS.STANDBY ` Put into standby mode. Sending any command resumes
513
+ operation.
514
+ * ` as_rwGPS.DEFAULT_SENTENCES ` Sets all sentence frequencies to factory
515
+ default values as listed under ` enable ` .
516
+ * ` as_rwGPS.VERSION ` Causes the GPS to report its firmware version. This will
517
+ appear as the ` version ` bound variable when the report is received.
518
+ * ` as_rwGPS.ENABLE ` Causes the GPS to report the enabled status of the various
519
+ message types as set by the ` enable ` coroutine. This will appear as the
520
+ ` enable ` bound variable when the report is received.
521
+ * ` as_rwGPS.ANTENNA ` Causes the GPS to send antenna status messages. The
522
+ status value will appear in the ` antenna ` bound variable each time a report is
523
+ received.
524
+ * ` as_rwGPS.NO_ANTENNA ` Turns off antenna messages.
517
525
518
526
** Antenna issues** In my testing the antenna functions have issues which
519
527
hopefully will be fixed in later firmware versions. The ` NO_ANTENNA ` message
0 commit comments