Skip to content

Commit bc54c3f

Browse files
committed
gps/README improvements part complete.
1 parent 0842e3b commit bc54c3f

File tree

1 file changed

+81
-73
lines changed

1 file changed

+81
-73
lines changed

gps/README.md

Lines changed: 81 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
**NOTE: Under development. API may be subject to change**
2-
31
# 1. as_GPS
42

53
This repository offers a suite of asynchronous device drivers for GPS devices
@@ -15,10 +13,10 @@ on this excellent library [micropyGPS].
1513
* The read-write driver enables altering the configuration of GPS devices
1614
based on the popular MTK3329/MTK3339 chips.
1715
* 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.
2220
* Drivers may be extended via subclassing, for example to support additional
2321
sentence types.
2422

@@ -30,17 +28,17 @@ driver as they emit NMEA sentences on startup.
3028

3129
NMEA sentence parsing is based on [micropyGPS] but with significant changes.
3230

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+.
3533
* Sentence parsing is adapted for asynchronous use.
3634
* 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.
3937
* Some functionality is devolved to a utility module, reducing RAM usage where
4038
these functions are unused.
4139
* The read/write driver is a subclass of the read-only driver.
4240
* 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.
4442
* Hooks are provided for user-designed subclassing, for example to parse
4543
additional message types.
4644

@@ -152,7 +150,7 @@ and the Adafruit [Ultimate GPS Breakout] module. If memory errors are
152150
encountered on resource constrained devices install each file as a
153151
[frozen module].
154152

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
156154
file `as_rwGPS.py` must also be installed. The test/demo `ast_pbrw.py` may
157155
optionally be installed; this requires `aswitch.py` from the root of this
158156
repository.
@@ -185,7 +183,8 @@ Three mechanisms exist for responding to outages.
185183
Mandatory positional arg:
186184
* `sreader` This is a `StreamReader` instance associated with the UART.
187185
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.
189188
* `fix_cb` An optional callback. This runs after a valid message of a chosen
190189
type has been received and processed.
191190
* `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)
255254

256255
### 2.2.2 Course
257256

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`.
260259

261260
* `speed_string` Optional arg `unit=as_GPS.KPH`. Returns the current speed in
262261
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)
268267

269268
* `time_since_fix` No args. Returns time in milliseconds since last valid fix.
270269

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
272271
'hh:mm:ss.sss'. If `local` is `False` returns UTC time.
273272

274273
* `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)
284283

285284
On startup after a cold start it may take time before valid data is received.
286285
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.
288287

289288
* `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:
292292

293293
```python
294294
while True:
295295
await my_gps.data_received(position=True, altitude=True)
296-
# can now access these data values with confidence
296+
# Access these data values now
297297
```
298298

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
300300
`get_satellite_data` coroutine.
301301

302302
### 2.3.2 Satellite Data
@@ -345,24 +345,27 @@ The following are counts since instantiation.
345345
* `crc_fails` Usually 0 but can occur on baudrate change.
346346
* `clean_sentences` Number of sentences received without major failures.
347347
* `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).
351352

352353
### 2.4.3 Date and time
353354

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]
359361
* `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+.
360364

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`).
366369

367370
### 2.4.4 Satellite data
368371

@@ -394,28 +397,34 @@ and subsequent characters are stripped from the last. Thus if the string
394397
was received `reparse` would see
395398
`['GPGGA','123519','4807.038','N','01131.000','E','1','08','0.9','545.4','M','46.9','M','','']`
396399

397-
# 3. The GPS class read/write driver
400+
# 3. The GPS class read-write driver
398401

399402
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:
402405

403406
* Adafruit Ultimate GPS Breakout
404407
* Digilent PmodGPS
405408
* Sparkfun GPS Receiver LS20031
406409
* 43oh MTK3339 GPS Launchpad Boosterpack
407410

411+
A subset of the PMTK packet types is supported but this may be extended by
412+
subclassing.
413+
408414
## 3.1 Files
409415

410416
* `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.
413419
* `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:
419428
* Red: Toggles each time a GPS update occurs.
420429
* Green: ON if GPS data is being received, OFF if no data received for >10s.
421430
* Yellow: Toggles each 4s if navigation updates are being received.
@@ -452,6 +461,7 @@ loop.run_until_complete(test())
452461
This takes two mandatory positional args:
453462
* `sreader` This is a `StreamReader` instance associated with the UART.
454463
* `swriter` This is a `StreamWriter` instance associated with the UART.
464+
455465
Optional positional args:
456466
* `local_offset` Local timezone offset in hours realtive to UTC (GMT).
457467
* `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:
469479

470480
In the case of handled messages the list of text strings has length 2. The
471481
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]`.
473483

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).
477486

478487
The args presented to the fix callback are as described in
479488
[section 2.1](./README.md#21-constructor).
480489

481490
## 3.3 Public coroutines
482491

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
487496
[notes on timing](./README.md#7-notes-on-timing).
488497
* `enable` Determine the frequency with which each sentence type is sent. A
489498
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
493502
`gll=0`, `rmc=1`, `vtg=1`, `gga=1`, `gsa=1`, `gsv=5`, `chan=0`. The last
494503
represents GPS channel status. These values are the factory defaults.
495504
* `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.
517525

518526
**Antenna issues** In my testing the antenna functions have issues which
519527
hopefully will be fixed in later firmware versions. The `NO_ANTENNA` message

0 commit comments

Comments
 (0)