driver_nmea.adoc 11.4 KB
Newer Older
James Browning's avatar
James Browning committed
1
= Generic NMEA GPS Receiver
2
include::html.include[]
3

James Browning's avatar
James Browning committed
4
== Synopsis
5

6
["verse",subs="normal"]
7
Name: nmea
8
Reference ID: GPS
9 10
Serial Port: /dev/gps__u__; 4800-115200bps, 8N1
Serial Port: /dev/gpspps__u__; for PPS
11
Features: +tty_clk+
12

James Browning's avatar
James Browning committed
13
== Description
14

15 16 17
This driver supports GPS receivers with the +$GPRMC+, +$GPGLL+,
+$GPGGA+, +$GPZDA+ and +$GPZDG+ NMEA sentences by default.  Note that
Accord's custom NMEA sentence +$GPZDG+ reports using the GPS timescale,
18 19 20
while the rest of the sentences report UTC.  The difference between the
two is a whole number of seconds which increases with each leap second
insertion in UTC.  To avoid problems mixing UTC and GPS timescales, the
21
driver disables processing of UTC sentences once +$GPZDG+ is received.
22 23 24 25 26

The driver expects the receiver to be set up to transmit at least one
supported sentence every second.

The accuracy depends on the receiver used. Inexpensive GPS models are
27
available with a claimed PPS signal accuracy of 1 µs or better relative
28 29 30 31
to the broadcast signal. However, in most cases the actual accuracy is
limited by the precision of the timecode and the latencies of the serial
interface and operating system.

32
If the operating system supports PPSAPI
33 34
(http://www.ietf.org/rfc/rfc2783.txt[RFC 2783]), the +flag1 1+ option
enables its use.
35

36 37
If there is a /dev/gpspps__u__ it is tried first for PPS, before /dev/gps__u__.

38 39
The various GPS sentences that this driver recognises look like this
(others are quietly ignored):
40 41 42 43 44 45 46 47 48 49 50 51 52

.Accepted NMEA sentences
[options="header"]
|=============================================================================
|Sentence                                                             |Vendor
|$GPRMC,UTC,POS_STAT,LAT,LAT_REF,LON,LON_REF,SPD,HDG,DATE,MAG_VAR,MAG_REF*CS<cr><lf>|
|$GPGLL,LAT,LAT_REF,LON,LON_REF,UTC,POS_STAT*CS<cr><lf>|
|$GPGGA,UTC,LAT,LAT_REF,LON,LON_REF,FIX_MODE,SAT_USED,HDOP,ALT,ALT_UNIT,GEO,G_UNIT,D_AGE,D_REF*CS<cr><lf>|
|$GPZDA,UTC,DD,MM,YYYY,TH,TM,*CS<cr><lf>|
|$GPZDG,GPSTIME,DD,MM,YYYY,AA.BB,V*CS<cr><lf>|Accord
|=============================================================================

.NMEA data items
Hal Murray's avatar
Hal Murray committed
53
[cols="15%,85%",options="header"]
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
[options="header"]
|=============================================================================
|Symbol  | Meaning and Format
|UTC     |Time of day on UTC timescale. Hours, minutes and seconds [fraction
(opt.)]. (hhmmss[.fff])
|POS_STAT|Position status. (A = Data valid, V = Data invalid)
|LAT     |Latitude (llll.ll)
|LAT_REF |Latitude direction. (N = North, S = South)
|LON     |Longitude (yyyyy.yy)
|LON_REF |Longitude direction (E = East, W = West)
|SPD     |Speed over ground. (knots) (x.x)
|HDG     |Heading/track made good (degrees True) (x.x)
|DATE    |Date (ddmmyy)
|MAG_VAR |Magnetic variation (degrees) (x.x)
|MAG_REF |Magnetic variation (E = East, W = West)
|FIX_MODE|Position Fix Mode (0 = Invalid, >0 = Valid)
|SAT_USED|Number of Satellites used in solution
|HDOP    |Horizontal Dilution of Precision
|ALT     |Antenna Altitude
|ALT_UNIT|Altitude Units (Metres/Feet)
|GEO     |Geoid/Elipsoid separation
|G_UNIT  |Geoid units (M/F)
|D_AGE   |Age of last DGPS Fix
|D_REF   |Reference ID of DGPS station
|GPSTIME |Time of day on GPS timescale. Hours, minutes and seconds [fraction
(opt.)]. (hhmmss[.f])
|DD      |Day of the month (1-31)
|MM      |Month of the year (1-12)
|YYYY    |Year
|AA.BB   |Denotes the signal strength (should be < 05.00)
|V       |GPS sync status
 '0' => INVALID time,
 '1' => accuracy of +/- 20ms,
 '2' => accuracy of +/- 100ns
|CS      |Checksum
|<cr><lf>|Sentence terminator.
|=============================================================================

James Browning's avatar
James Browning committed
92
== The \'mode' byte
93

94
Specific GPS sentences and bitrates may be selected by setting bits of the \'mode' in the refclock configuration line:
95 96 97 98 99

.mode byte bits and bit groups
[cols="10%,10%,10%,70%",options="header"]
|=============================================================================
|Bit    | Decimal | Hex | Meaning
Hal Murray's avatar
Hal Murray committed
100
|0      |1        |1    |process +$GPRMC+
101 102 103
|1      |2        |2    |process +$GPGGA+
|2      |4        |4    |process +$GPGLL+
|3      |8        |8    |process +$GPZDA+ or +$GPZDG+
104 105
|7      |128      |0x80 |
Write the sub-second fraction of the receive time stamp to the clockstat
106
file for all recognized NMEA sentences. This can provide a useful
107
value for fudge time2
108 109
*Caveat:* This will fill your clockstat file rather fast. Use it only
temporarily to get the numbers for the NMEA sentence of your choice.
110
|8      |256      |0x100|process +$PGRMF+
111 112 113 114 115 116
|9-15   |         |0xFE00   |reserved - leave 0
|16     |65536    |0x10000 | Append extra statistics to the clockstats line. Details below.
|=============================================================================


The default (mode 0) is to process all supported sentences at a
117
linespeed of 9600 bps, which results in the first one received and
Eric S. Raymond's avatar
Eric S. Raymond committed
118 119
recognized in each cycle being used.  If only specific sentences should
be recognized, then the mode byte must be chosen to enable only the
120
selected ones.  Multiple sentences may be selected by adding their mode
121
bit values, but of those enabled, only the first received sentence
122 123 124
in a cycle will be used.  Using more than one sentence per cycle is
impossible, because

125
* there is only the link:#fudgetime2[time2] option available to compensate
126 127
  for transmission delays but every sentence would need a different one

128
and
129

130
* using more than one sentence per cycle overstuffs the internal data
131
  filters.
132

133
The driver uses 9600 bps by default, unless
134
NTPsec was built in Classic strict-compatibility mode, in which
135
case the old default of 4800 bps is used. Faster bitrates can be
136
selected using the +baud+ option.
137 138

*Caveat:* Using higher line speeds does not necessarily increase the
139
precision of the timing device.  9600 bps is useful to accommodate an
140 141 142 143 144 145
amount of data that does not fit into a 1-second cycle at 4800 bps;
some GPSes (especially when emitting skyview sentences) emit more than
this.  Any device that is exclusively used for time synchronisation
purposes should be configured to transmit the relevant data only,
e.g. one +$GPRMC+ or +$GPZDA+ per second; this will slightly reduce
jitter by reducing variation in transmission times.
146

James Browning's avatar
James Browning committed
147
== Monitor Data
148 149

The last GPS sentence that is accepted or rejected is written to the
150
clockstats file and available with +ntpq -c clockvar+. (Logging the
151 152 153 154 155 156 157 158
rejected sentences lets you see/debug why they were rejected.) Filtered
sentences are not logged.

If the 0x10000 mode bit is on and clockstats is enabled, several extra
counters will be appended to the NMEA sentence that gets logged. For
example:

----------------------------------------------------------------------------
159
56299 76876.691 nmea(0) $GPGGA,212116.000,3726.0785,N,12212.2605,W,1,05,2.0,17.0,M,-25.7,M,,0000*5C  228 64 0 0 64 0
160 161 162 163 164 165 166 167
----------------------------------------------------------------------------

.Clockstats
[cols="10%,20%,70%",options="header"]
|=============================================================================
|Column|Sample          |Meaning
|1     |56299           |MJD
|2     |76876.691       |Time of day in seconds
168
|3     |NMEA(0)         |Driver type and unit.
169 170 171 172 173 174 175 176 177 178 179
|4     |$GPGGA,...0*5C  |NMEA Sentence
|5     |228             |Number of sentences received
|6     |64              |Number of sentences accepted and used for timekeeping
|7     |0               |Number of sentences rejected
                         because they were marked invalid (poor signal)
|8     |0               |Number of sentences rejected because of bad
                         checksum or invalid date/time
|9     |64              |Number of sentences filtered by mode bits or same second
|10    |0               |Number of PPS pulses used, overrides NMEA sentences
|=============================================================================

180
The clock identification in field 3 is normally the driver type and
181
unit, but if your ntpd was built in strict Classic compatibility
182 183 184
mode it will be a magic clock address expressing the same information
in a more opaque way.

185 186 187
Sentences like $GPGSV that don't contain the time will get counted in
the total but otherwise ignored.

188
http://support.ntp.org/bin/view/Support/ConfiguringNMEARefclocks[Configuring
189
NMEA Refclocks] might give further useful hints for specific hardware
190 191
devices that exhibit strange or curious behaviour. Note that it
describes NTP Classic and the old refclock configuration syntax, and
192
assumes the old default speed of 4800 bps.
193 194 195 196 197

To make a specific setting, select the corresponding decimal values from
the mode byte table, add them all together and enter the resulting
decimal value into the clock configuration line.

James Browning's avatar
James Browning committed
198
== Setting up the Garmin GPS-25XL
199

200
Switch off all output by sending it the following string.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218

-------------------
"$PGRMO,,2<cr><lf>"
-------------------

Now switch only $GPRMC on by sending it the following string.

------------------------
"$PGRMO,GPRMC,1<cr><lf>"
------------------------

On some systems the PPS signal isn't switched on by default. It can be
switched on by sending the following string.

-----------------------------
"$PGRMC,,,,,,,,,,,,2<cr><lf>"
-----------------------------

James Browning's avatar
James Browning committed
219
== Driver Options
220

221 222
+unit+ 'number'::
  The driver unit number, defaulting to 0. Used as a distinguishing
223
  suffix in the driver device name.
224
+time1+ 'time'::
225 226
  Specifies the PPS time offset calibration factor, in seconds and
  fraction, with default 0.0.
227
+time2+ 'time'::
228 229
  Specifies the serial end of line time offset calibration factor, in
  seconds and fraction, with default 0.0.
230
+stratum+ 'number'::
231
  Specifies the driver stratum, in decimal from 0 to 15, with default 0.
232
+refid+ 'string'::
233
  Specifies the driver reference identifier, an ASCII string from one to
234 235
  four characters, with default +GPS+.
+flag1 {0 | 1}+::
236 237
  Disable PPS signal processing if 0 (default); enable PPS signal
  processing if 1.
238
+flag2 {0 | 1}+::
239 240
  If PPS signal processing is enabled, capture the pulse on the rising
  edge if 0 (default); capture on the falling edge if 1.
241
+flag3 {0 | 1}+::
242
  If PPS signal processing is enabled, use the +ntpd+ clock discipline
243
  if 0 (default); use the kernel discipline if 1.
244
+flag4 {0 | 1}+::
245
  Obscures location in timecode: 0 for disable (default), 1 for enable.
246 247
+subtype+::
   Not used by this driver.
248
+mode+::
249
   Used to control GPS sentence selection and logging.
250 251 252 253 254
+path+ 'filename'::
  Overrides the default device path.
+ppspath+ 'filename'::
  Overrides the default PPS-device path.
+baud+ 'number'::
255
  Overrides the default baud/bps rate.
256

James Browning's avatar
James Browning committed
257
== Configuration Example
258

259
------------------------------------------------------------------------------
260 261
refclock nmea baud 19200	# All sentences from /dev/gps0 at 19200 bps
refclock nmea path /dev/ttyUSB0	# All sentences from /dev/ttyUSB0 at 9600 bps
262
------------------------------------------------------------------------------
263 264 265 266 267

link:refclock.html[Reference Clock Drivers]

'''''

James Browning's avatar
James Browning committed
268
== Known bugs
269 270

If your GPS has firmware made more than 1024 weeks (19 years and 36
271 272 273 274 275
weeks) in the past, its internal date counter will almost certainly
wrap around and generate spurious timestamps.  Beginning in January
2018, newer GPSes may have a longer wraparound (8192 weeks, or 157
years and 28 weeks) but it is not safe to bet that any given receiver
will have firmware updated to take advantage of this.
276 277 278 279 280 281 282 283

This problem is fundamental and cannot be compensated for in code
without relying on the accuracy of the local system clock, which
is exactly what an NTP implementation may not do without risking
perverse failure modes (especially at startup time). The only
remedy is not to use ancient GPS hardware.

'''''
284
include::includes/footer.adoc[]