/src/gpsd/gpsd-3.26.2~dev/drivers/driver_nmea0183.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Driver for NMEA 0183 protocol, aka IEC 61162-1 |
3 | | * There are many versions of NMEA 0183. |
4 | | * |
5 | | * IEC 61162-1:1995 |
6 | | * IEC 61162-1:2000 |
7 | | * IEC 61162-1:2007 |
8 | | * NMEA 4.00 aligns with IEC 61162-1:2010 |
9 | | * NMEA 4.10 aligns with IEC 61162-1:2016 |
10 | | * |
11 | | * Sadly, the protocol is proprietary and not documented publicly. |
12 | | * So every firmware seems to have a different opinion on how |
13 | | * to implement the messages. |
14 | | * |
15 | | * This file is Copyright 2010 by the GPSD project |
16 | | * SPDX-License-Identifier: BSD-2-clause |
17 | | */ |
18 | | |
19 | | #include "../include/gpsd_config.h" // must be before all includes |
20 | | |
21 | | #include <ctype.h> // for isdigit() |
22 | | #include <float.h> // for FLT_EVAL_METHOD |
23 | | #include <stdio.h> |
24 | | #include <stdlib.h> |
25 | | #include <stdbool.h> |
26 | | #include <math.h> |
27 | | #include <string.h> |
28 | | #include <stdarg.h> |
29 | | #include <time.h> |
30 | | |
31 | | #include "../include/gpsd.h" |
32 | | #include "../include/strfuncs.h" |
33 | | |
34 | | #include "../include/timespec.h" |
35 | | |
36 | | // $SNRSTAAT insstatus |
37 | | static const struct vlist_t vsnrstat_insstatus[] = { |
38 | | {-1, "Failure"}, |
39 | | {0, "Disabled"}, |
40 | | {1, "Init started"}, |
41 | | {2, "Known inst angle"}, |
42 | | {3, "Init OK"}, |
43 | | {0, NULL}, |
44 | | }; |
45 | | |
46 | | // $SNRSTAAT odostatus |
47 | | static const struct vlist_t vsnrstat_odostatus[] = { |
48 | | {-1, "Failure"}, |
49 | | {0, "Disabled"}, |
50 | | {1, "Init started"}, |
51 | | {2, "Known scale"}, |
52 | | {3, "Init OK"}, |
53 | | {0, NULL}, |
54 | | }; |
55 | | |
56 | | // $SNRSTAAT InstallState |
57 | | static const struct vlist_t vsnrstat_InstallState[] = { |
58 | | {-1, "Failure"}, |
59 | | {0, "In progress"}, |
60 | | {1, "Weak Sats"}, |
61 | | {2, "Need Acc"}, |
62 | | {3, "Low Speed"}, |
63 | | {0, NULL}, |
64 | | }; |
65 | | |
66 | | // $SNRSTAAT mapstat |
67 | | static const struct vlist_t vsnrstat_mapstat[] = { |
68 | | {-2, "Abnormal"}, |
69 | | {-1, "Unconfigured"}, |
70 | | {0, "No info"}, |
71 | | {1, "Unapplied"}, |
72 | | {1, "OK"}, |
73 | | {0, NULL}, |
74 | | }; |
75 | | |
76 | | /************************************************************************** |
77 | | * |
78 | | * Parser helpers begin here |
79 | | * |
80 | | **************************************************************************/ |
81 | | |
82 | | /* Allow avoiding long double intermediate values. |
83 | | * |
84 | | * On platforms with 0 != FLT_EVAL_METHOD intermediate values may be kept |
85 | | * as long doubles. Some 32-bit OpenBSD and 32-bit Debian have |
86 | | * FLT_EVAL_METHOD == 2. FreeBSD 13,0 has FLT_EVAL_METHOD == -1. Various |
87 | | * cc options (-mfpmath=387, -mno-sse, etc.) can also change FLT_EVAL_METHOD |
88 | | * from 0. |
89 | | * |
90 | | * Although (long double) may in principle more accurate then (double), it |
91 | | * can cause slight differences that lead to regression failures. In |
92 | | * other cases (long double) and (double) are the same, thus no effect. |
93 | | * Storing values in volatile variables forces the exact size requested. |
94 | | * Where the volatile declaration is unnecessary (and absent), such extra |
95 | | * intermediate variables are normally optimized out. |
96 | | */ |
97 | | |
98 | | #if !defined(FLT_EVAL_METHOD) || 0 != FLT_EVAL_METHOD |
99 | | #define FLT_VOLATILE volatile |
100 | | #else |
101 | | #define FLT_VOLATILE |
102 | | #endif // FLT_EVAL_METHOD |
103 | | |
104 | | /* Common lat/lon decoding for do_lat_lon |
105 | | * |
106 | | * This version avoids the use of modf(), which can be slow and also suffers |
107 | | * from exactness problems. The integer minutes are first extracted and |
108 | | * corrected for the improper degree scaling, using integer arithmetic. |
109 | | * Then the fractional minutes are added as a double, and the result is scaled |
110 | | * to degrees, using multiply which is faster than divide. |
111 | | * |
112 | | * Forcing the intermediate minutes value to a double is sufficient to |
113 | | * avoid regression problems with FLT_EVAL_METHOD>=2. |
114 | | */ |
115 | | static inline double decode_lat_or_lon(const char *field) |
116 | 0 | { |
117 | 0 | long degrees, minutes; |
118 | 0 | FLT_VOLATILE double full_minutes; |
119 | 0 | char *cp; |
120 | | |
121 | | // Get integer "minutes" |
122 | 0 | minutes = strtol(field, &cp, 10); |
123 | | // Must have decimal point |
124 | 0 | if ('.' != *cp) { |
125 | 0 | return NAN; |
126 | 0 | } |
127 | | // Extract degrees (scaled by 100) |
128 | 0 | degrees = minutes / 100; |
129 | | // Rescale degrees to normal factor of 60 |
130 | 0 | minutes -= degrees * (100 - 60); |
131 | | // Add fractional minutes |
132 | 0 | full_minutes = minutes + safe_atof(cp); |
133 | | // Scale to degrees & return |
134 | 0 | return full_minutes * (1.0 / 60.0); |
135 | 0 | } |
136 | | |
137 | | /* process a pair of latitude/longitude fields starting at field index BEGIN |
138 | | * The input fields look like this: |
139 | | * field[0]: 4404.1237962 |
140 | | * field[1]: N |
141 | | * field[2]: 12118.8472460 |
142 | | * field[3]: W |
143 | | * input format of lat/lon is NMEA style DDDMM.mmmmmmm |
144 | | * yes, 7 digits of precision past the decimal point from survey grade GPS |
145 | | * |
146 | | * Ignoring the complications ellipsoids add: |
147 | | * 1 minute latitude = 1853 m |
148 | | * 0.001 minute latitude = 1.853 m |
149 | | * 0.000001 minute latitude = 0.001853 m = 1.853 mm |
150 | | * 0.0000001 minute latitude = 0.0001853 m = 0.1853 mm |
151 | | * |
152 | | * return: 0 == OK, non zero is failure. |
153 | | */ |
154 | | static int do_lat_lon(char *field[], struct gps_fix_t *out) |
155 | 0 | { |
156 | 0 | double lon; |
157 | 0 | double lat; |
158 | |
|
159 | 0 | if ('\0' == field[0][0] || |
160 | 0 | '\0' == field[1][0] || |
161 | 0 | '\0' == field[2][0] || |
162 | 0 | '\0' == field[3][0]) { |
163 | 0 | return 1; |
164 | 0 | } |
165 | | |
166 | 0 | lat = decode_lat_or_lon(field[0]); |
167 | 0 | if ('S' == field[1][0]) |
168 | 0 | lat = -lat; |
169 | |
|
170 | 0 | lon = decode_lat_or_lon(field[2]); |
171 | 0 | if ('W' == field[3][0]) |
172 | 0 | lon = -lon; |
173 | |
|
174 | 0 | if (0 == isfinite(lat) || |
175 | 0 | 0 == isfinite(lon)) { |
176 | 0 | return 2; |
177 | 0 | } |
178 | | |
179 | 0 | out->latitude = lat; |
180 | 0 | out->longitude = lon; |
181 | 0 | return 0; |
182 | 0 | } |
183 | | |
184 | | // decode for FAA Mode indicator. NMEA 4+ |
185 | | static const struct clist_t c_faa_mode[] = { |
186 | | {'A', "Autonomous"}, |
187 | | {'C', "Caution"}, // Quectel Querk |
188 | | {'D', "Differential"}, |
189 | | {'E', "Estimated"}, // dead reckoning) |
190 | | {'F', "Float RTK"}, |
191 | | {'M', "Manual Input."}, // surveyed) |
192 | | {'N', "Data Not Valid"}, |
193 | | {'0', "Unk"}, // Skytraq?? |
194 | | {'P', "Precise"}, // (NMEA 4+) |
195 | | {'R', "Integer RTK"}, |
196 | | {'S', "Simulated"}, |
197 | | {'U', "Unsafe"}, // Quectel querk |
198 | | {'V', "Invalid"}, // ?? |
199 | | {'\0', NULL} |
200 | | }; |
201 | | |
202 | | /* process an FAA mode character |
203 | | * As used in $GPRMC (field 13) and similar. |
204 | | * return status as in session->newdata.status |
205 | | */ |
206 | | static int faa_mode(char mode) |
207 | 0 | { |
208 | 0 | int newstatus = STATUS_GPS; |
209 | |
|
210 | 0 | switch (mode) { |
211 | 0 | case '\0': // missing |
212 | 0 | FALLTHROUGH |
213 | 0 | case 'O': // Skytraq ?? |
214 | 0 | FALLTHROUGH |
215 | 0 | case 'V': // Invalid |
216 | 0 | newstatus = STATUS_UNK; |
217 | 0 | break; |
218 | 0 | case 'A': // Autonomous |
219 | 0 | FALLTHROUGH |
220 | 0 | default: |
221 | 0 | newstatus = STATUS_GPS; |
222 | 0 | break; |
223 | 0 | case 'D': // Differential |
224 | 0 | newstatus = STATUS_DGPS; |
225 | 0 | break; |
226 | 0 | case 'E': // Estimated dead reckoning |
227 | 0 | newstatus = STATUS_DR; |
228 | 0 | break; |
229 | 0 | case 'F': // Float RTK |
230 | 0 | newstatus = STATUS_RTK_FLT; |
231 | 0 | break; |
232 | 0 | case 'M': // manual input. Interpret as surveyed to better match GGA |
233 | 0 | newstatus = STATUS_TIME; |
234 | 0 | break; |
235 | 0 | case 'N': // Data Not Valid |
236 | | // already handled, for paranoia sake also here |
237 | 0 | newstatus = STATUS_UNK; |
238 | 0 | break; |
239 | 0 | case 'P': // Precise (NMEA 4+) |
240 | 0 | newstatus = STATUS_DGPS; // sort of DGPS |
241 | 0 | break; |
242 | 0 | case 'R': // fixed RTK |
243 | 0 | newstatus = STATUS_RTK_FIX; |
244 | 0 | break; |
245 | 0 | case 'S': // simulator |
246 | 0 | newstatus = STATUS_SIM; |
247 | 0 | break; |
248 | 0 | } |
249 | 0 | return newstatus; |
250 | 0 | } |
251 | | |
252 | | /************************************************************************** |
253 | | * |
254 | | * Scary timestamp fudging begins here |
255 | | * |
256 | | * Four sentences, GGA and GLL and RMC and ZDA, contain timestamps. |
257 | | * GGA/GLL/RMC timestamps look like hhmmss.ss, with the trailing .ss, |
258 | | * or .sss, part optional. |
259 | | * RMC has a date field, in the format ddmmyy. ZDA has separate fields |
260 | | * for day/month/year, with a 4-digit year. This means that for RMC we |
261 | | * must supply a century and for GGA and GLL we must supply a century, |
262 | | * year, and day. We get the missing data from a previous RMC or ZDA; |
263 | | * century in RMC is supplied from the daemon's context (initialized at |
264 | | * startup time) if there has been no previous ZDA. |
265 | | * |
266 | | **************************************************************************/ |
267 | | |
268 | 0 | #define DD(s) ((int)((s)[0]-'0')*10+(int)((s)[1]-'0')) |
269 | | |
270 | | /* decode supplied ddmmyy, but no century part, into *date |
271 | | * |
272 | | * return: 0 == OK, greater than zero on failure |
273 | | */ |
274 | | static int decode_ddmmyy(struct tm *date, const char *ddmmyy, |
275 | | struct gps_device_t *session) |
276 | 0 | { |
277 | 0 | int mon; |
278 | 0 | int mday; |
279 | 0 | int year; |
280 | 0 | unsigned i; // NetBSD complains about signed array index |
281 | |
|
282 | 0 | if (NULL == ddmmyy || |
283 | 0 | '\0' == ddmmyy[0]) { |
284 | 0 | return 1; |
285 | 0 | } |
286 | 0 | for (i = 0; i < 6; i++) { |
287 | | // NetBSD 6 wants the cast |
288 | 0 | if (0 == isdigit((int)ddmmyy[i])) { |
289 | | // catches NUL and non-digits |
290 | | // Telit HE910 can set year to "-1" (1999 - 2000) |
291 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
292 | 0 | "NMEA0183: merge_ddmmyy(%s), malformed date\n", ddmmyy); |
293 | 0 | return 2; |
294 | 0 | } |
295 | 0 | } |
296 | | // check for termination |
297 | 0 | if ('\0' != ddmmyy[6]) { |
298 | | // missing NUL |
299 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
300 | 0 | "NMEA0183: merge_ddmmyy(%s), malformed date\n", ddmmyy); |
301 | 0 | return 3; |
302 | 0 | } |
303 | | |
304 | | // should be no defects left to segfault DD() |
305 | 0 | mday = DD(ddmmyy); |
306 | 0 | mon = DD(ddmmyy + 2); |
307 | 0 | year = DD(ddmmyy + 4); |
308 | | |
309 | | // check for century wrap, so 1968 < year < 2069 |
310 | 0 | if (69 > year) { |
311 | 0 | year += 100; |
312 | 0 | } |
313 | |
|
314 | 0 | if (!IN(1, mon, 12)) { |
315 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
316 | 0 | "NMEA0183: merge_ddmmyy(%s), malformed month\n", ddmmyy); |
317 | 0 | return 4; |
318 | 0 | } // else |
319 | 0 | if (!IN(1, mday, 31)) { |
320 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
321 | 0 | "NMEA0183: merge_ddmmyy(%s), malformed day\n", ddmmyy); |
322 | 0 | return 5; |
323 | 0 | } // else |
324 | | |
325 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
326 | 0 | "NMEA0183: merge_ddmmyy(%s) sets year %d\n", |
327 | 0 | ddmmyy, year); |
328 | 0 | date->tm_year = year; |
329 | 0 | date->tm_mon = mon - 1; |
330 | 0 | date->tm_mday = mday; |
331 | | // FIXME: check fractional time! |
332 | |
|
333 | 0 | GPSD_LOG(LOG_RAW, &session->context->errout, |
334 | 0 | "NMEA0183: merge_ddmmyy(%s) %d %d %d\n", |
335 | 0 | ddmmyy, date->tm_mon, date->tm_mday, date->tm_year); |
336 | 0 | return 0; |
337 | 0 | } |
338 | | |
339 | | /* sentence supplied ddmmyy, but no century part |
340 | | * iff valid, merge into session_>nmea.date |
341 | | * |
342 | | * return: 0 == OK, greater than zero on failure |
343 | | */ |
344 | | static int merge_ddmmyy(const char *ddmmyy, struct gps_device_t *session) |
345 | 0 | { |
346 | 0 | struct tm date = {0}; |
347 | 0 | int retcode; |
348 | |
|
349 | 0 | retcode = decode_ddmmyy(&date, ddmmyy, session); |
350 | 0 | if (0 != retcode) { |
351 | | // leave session->nmea untouched. |
352 | 0 | return retcode; |
353 | 0 | } |
354 | | // check for century wrap ?? |
355 | | // Good time, merge it. |
356 | 0 | session->nmea.date.tm_mday = date.tm_mday; |
357 | 0 | session->nmea.date.tm_mon = date.tm_mon; |
358 | 0 | session->nmea.date.tm_year = date.tm_year; |
359 | 0 | return 0; |
360 | 0 | } |
361 | | |
362 | | /* decode an hhmmss.ss string into struct tm data and nsecs |
363 | | * |
364 | | * return: 0 == OK, otherwise failure |
365 | | */ |
366 | | static int decode_hhmmss(struct tm *date, long *nsec, const char *hhmmss, |
367 | | struct gps_device_t *session) |
368 | 0 | { |
369 | 0 | int old_hour = date->tm_hour; |
370 | 0 | int i; |
371 | |
|
372 | 0 | if (NULL == hhmmss || |
373 | 0 | '\0' == hhmmss[0]) { |
374 | 0 | return 1; |
375 | 0 | } |
376 | 0 | for (i = 0; i < 6; i++) { |
377 | | // NetBSD 6 wants the cast |
378 | 0 | if (0 == isdigit((int)hhmmss[i])) { |
379 | | // catches NUL and non-digits |
380 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
381 | 0 | "NMEA0183: decode_hhmmss(%s), malformed time\n", hhmmss); |
382 | 0 | return 2; |
383 | 0 | } |
384 | 0 | } |
385 | | // don't check for termination, might have fractional seconds |
386 | | |
387 | 0 | date->tm_hour = DD(hhmmss); |
388 | 0 | if (date->tm_hour < old_hour) { // midnight wrap |
389 | | // really?? |
390 | 0 | date->tm_mday++; |
391 | 0 | } |
392 | 0 | date->tm_min = DD(hhmmss + 2); |
393 | 0 | date->tm_sec = DD(hhmmss + 4); |
394 | |
|
395 | 0 | if ('.' == hhmmss[6] && |
396 | | // NetBSD 6 wants the cast |
397 | 0 | 0 != isdigit((int)hhmmss[7])) { |
398 | | // codacy hates strlen() |
399 | 0 | int sublen = strnlen(hhmmss + 7, 20); |
400 | 0 | i = atoi(hhmmss + 7); |
401 | 0 | *nsec = (long)i * (long)pow(10.0, 9 - sublen); |
402 | 0 | } else { |
403 | 0 | *nsec = 0; |
404 | 0 | } |
405 | 0 | GPSD_LOG(LOG_RAW, &session->context->errout, |
406 | 0 | "NMEA0183: decode_hhmmss(%s) %d %d %d %09ld\n", |
407 | 0 | hhmmss, |
408 | 0 | date->tm_hour, date->tm_min, date->tm_sec, *nsec); |
409 | |
|
410 | 0 | return 0; |
411 | 0 | } |
412 | | |
413 | | /* decode an hhmmss UTC time |
414 | | * if valid, merge into: |
415 | | * session->nmea.date |
416 | | * session->nmea.subseconds |
417 | | * |
418 | | * return: 0 == OK, greater than zero on failure |
419 | | */ |
420 | | static int merge_hhmmss(const char *hhmmss, struct gps_device_t *session) |
421 | 0 | { |
422 | 0 | struct tm date = {0}; |
423 | 0 | timespec_t ts = {0}; |
424 | 0 | int retcode; |
425 | |
|
426 | 0 | retcode = decode_hhmmss(&date, &ts.tv_nsec, hhmmss, session); |
427 | 0 | if (0 != retcode) { |
428 | | // leave session->nmea untouched. |
429 | 0 | return retcode; |
430 | 0 | } |
431 | | // Good time, merge it. |
432 | 0 | session->nmea.date.tm_hour = date.tm_hour; |
433 | 0 | session->nmea.date.tm_min = date.tm_min; |
434 | 0 | session->nmea.date.tm_sec = date.tm_sec; |
435 | 0 | session->nmea.subseconds.tv_sec = 0; |
436 | 0 | session->nmea.subseconds.tv_nsec = ts.tv_nsec; |
437 | |
|
438 | 0 | return 0; |
439 | 0 | } |
440 | | |
441 | | /* register_fractional_time() |
442 | | * "fractional time" is a struct timespec of seconds since midnight |
443 | | * used to try to detect epoch changes as NMEA comes in. |
444 | | * tag is field[0] |
445 | | * *fld is "hhmmss.ss" |
446 | | */ |
447 | | static void register_fractional_time(const char *tag, const char *fld, |
448 | | struct gps_device_t *session) |
449 | 0 | { |
450 | 0 | struct tm date = {0}; |
451 | 0 | struct timespec ts = {0}; |
452 | 0 | char ts_buf[TIMESPEC_LEN]; |
453 | |
|
454 | 0 | if (0 != decode_hhmmss(&date, &ts.tv_nsec, fld, session)) { |
455 | | // invalid time |
456 | 0 | return; |
457 | 0 | } |
458 | | |
459 | 0 | ts.tv_sec = date.tm_hour * 3600 + date.tm_min * 60 + date.tm_sec; |
460 | |
|
461 | 0 | session->nmea.last_frac_time = session->nmea.this_frac_time; |
462 | 0 | session->nmea.this_frac_time = ts; |
463 | 0 | session->nmea.latch_frac_time = true; |
464 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
465 | 0 | "NMEA0183: %s: registers fractional time %s\n", |
466 | 0 | tag, |
467 | 0 | timespec_str(&session->nmea.this_frac_time, ts_buf, |
468 | 0 | sizeof(ts_buf))); |
469 | 0 | } |
470 | | |
471 | | // convert NMEA sigid to ublox sigid |
472 | | static unsigned char nmea_sigid_to_ubx(struct gps_device_t *session, |
473 | | unsigned char nmea_sigid) |
474 | 0 | { |
475 | 0 | unsigned char ubx_sigid = 0; |
476 | | |
477 | | // FIXME: need to know gnssid to guess sigid |
478 | 0 | switch (nmea_sigid) { |
479 | 0 | default: |
480 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
481 | 0 | "NMEA0183: Unknown nmea_sigid %u\n", nmea_sigid); |
482 | 0 | FALLTHROUGH |
483 | 0 | case 0: |
484 | | // missing, assume GPS L1 |
485 | | // ALLYSTAR, "all signal" |
486 | 0 | ubx_sigid = 0; |
487 | 0 | break; |
488 | 0 | case 1: |
489 | | // L1 |
490 | | // ALLYSTAR, GLO G1CA |
491 | | // ALLYSTAR, GAL E5A |
492 | | // ALLYSTAR, BDS B1I |
493 | 0 | ubx_sigid = 0; |
494 | 0 | break; |
495 | 0 | case 2: |
496 | | // E5, could be 5 or 6. |
497 | | // ALLYSTAR, GAL E5B |
498 | | // ALLYSTAR, BDS B2I |
499 | 0 | ubx_sigid = 5; |
500 | 0 | break; |
501 | 0 | case 3: |
502 | | // B2 or L2, could be 2 or 3. |
503 | | // ALLYSTAR, GLO G2CA |
504 | | // ALLYSTAR, BDS B3I |
505 | 0 | ubx_sigid = 2; |
506 | 0 | break; |
507 | 0 | case 4: |
508 | | // ALLYSTAR, BDS B2A |
509 | 0 | ubx_sigid = 7; // This is for NMEA digid 5, but we have 4! Close. |
510 | 0 | break; |
511 | 0 | case 5: |
512 | | // L2 |
513 | | // ALLYSTAR, BDS B2A |
514 | 0 | ubx_sigid = 4; |
515 | 0 | break; |
516 | 0 | case 6: |
517 | | // L2CL |
518 | | // ALLYSTAR, GAL L1A |
519 | 0 | ubx_sigid = 3; |
520 | 0 | break; |
521 | 0 | case 7: |
522 | | // E1, could be 0 or 1. |
523 | | // ALLYSTAR, GAL LBC |
524 | 0 | ubx_sigid = 0; |
525 | 0 | break; |
526 | 0 | case 8: |
527 | | // ALLYSTAR, GPS L5Q |
528 | 0 | ubx_sigid = 7; |
529 | 0 | break; |
530 | 0 | case 9: |
531 | | // ALLYSTAR, Quectel, GPS L1C |
532 | | // ALLYSTAR, BDS B1C |
533 | 0 | ubx_sigid = 0; |
534 | 0 | break; |
535 | 0 | case 11: |
536 | | // ALLYSTAR, GPS L6 |
537 | 0 | ubx_sigid = 0; |
538 | 0 | break; |
539 | 0 | } |
540 | | |
541 | 0 | return ubx_sigid; |
542 | 0 | } |
543 | | |
544 | | /* Deal with range-mapping attempts to use IDs 1-32 by Beidou, etc. |
545 | | * |
546 | | * See struct satellite_t in gps.h for ubx and nmea gnssid and svid mappings |
547 | | * |
548 | | * char *talker -- NMEA talker string |
549 | | * int nmea_satnum -- NMEA (All ver) satellite number (kinda the PRN) |
550 | | * int nmea_gnssid -- NMEA 4.10 gnssid, if known, otherwise zero |
551 | | * unsigned char *ubx_gnssid -- returned u-blox gnssid |
552 | | * unsigned char *ubx_svid -- returned u-blox gnssid |
553 | | * |
554 | | * Return the NMEA 2.x to 4.0 extended PRN |
555 | | */ |
556 | | static int nmeaid_to_prn(char *talker, int nmea_satnum, |
557 | | int nmea_gnssid, |
558 | | unsigned char *ubx_gnssid, |
559 | | unsigned char *ubx_svid) |
560 | 0 | { |
561 | | /* |
562 | | * According to https://github.com/mvglasow/satstat/wiki/NMEA-IDs |
563 | | * and u-blox documentation. |
564 | | * NMEA IDs can be roughly divided into the following ranges: |
565 | | * |
566 | | * 1..32: GPS |
567 | | * 33..64: Various SBAS systems (EGNOS, WAAS, SDCM, GAGAN, MSAS) |
568 | | * 65..96: GLONASS |
569 | | * 101..136: Quectel Querk, (not NMEA), seems to be Galileo |
570 | | * 152..158: Various SBAS systems (EGNOS, WAAS, SDCM, GAGAN, MSAS) |
571 | | * 173..182: IMES |
572 | | * 193..202: QZSS (u-blox extended 4.10) |
573 | | * 201..264: BeiDou (not NMEA, not u-blox?) Quectel Querk. |
574 | | * 301..336: Galileo |
575 | | * 401..437: BeiDou |
576 | | * null: GLONASS unused |
577 | | * 500-509: NavIC (IRNSS) NOT STANDARD! |
578 | | * 901..918: NavIC (IRNSS), ALLYSTAR |
579 | | * |
580 | | * The issue is what to do when GPSes from these different systems |
581 | | * fight for IDs in the 1-32 range, as in this pair of Beidou sentences |
582 | | * |
583 | | * $BDGSV,2,1,07,01,00,000,45,02,13,089,35,03,00,000,37,04,00,000,42*6E |
584 | | * $BDGSV,2,2,07,05,27,090,,13,19,016,,11,07,147,*5E |
585 | | * |
586 | | * Because the PRNs are only used for generating a satellite |
587 | | * chart, mistakes here aren't dangerous. The code will record |
588 | | * and use multiple sats with the same ID in one skyview; in |
589 | | * effect, they're recorded by the order in which they occur |
590 | | * rather than by PRN. |
591 | | */ |
592 | 0 | int nmea2_prn = nmea_satnum; |
593 | |
|
594 | 0 | *ubx_gnssid = 0; // default to ubx_gnssid is GPS |
595 | 0 | *ubx_svid = 0; // default to unknown ubx_svid |
596 | |
|
597 | 0 | if (1 > nmea_satnum) { |
598 | | // uh, oh... |
599 | 0 | nmea2_prn = 0; |
600 | 0 | } else if (0 < nmea_gnssid) { |
601 | | // this switch handles case where nmea_gnssid is known |
602 | 0 | switch (nmea_gnssid) { |
603 | 0 | case 1: |
604 | 0 | if (33 > nmea_satnum) { |
605 | | // 1 = GPS 1-32 |
606 | 0 | *ubx_gnssid = 0; |
607 | 0 | *ubx_svid = nmea_satnum; |
608 | 0 | } else if (65 > nmea_satnum) { |
609 | | // 1 = SBAS 33-64 |
610 | 0 | *ubx_gnssid = 1; |
611 | 0 | *ubx_svid = nmea_satnum + 87; |
612 | 0 | } else if (137 > nmea_satnum) { |
613 | | // 3 = Galileo, 101-136, NOT NMEA. Quectel Querk |
614 | 0 | *ubx_gnssid = 3; |
615 | 0 | *ubx_svid = nmea_satnum - 100; |
616 | 0 | } else if (152 > nmea_satnum) { |
617 | | // Huh? |
618 | 0 | *ubx_gnssid = 0; |
619 | 0 | *ubx_svid = 0; |
620 | 0 | nmea2_prn = 0; |
621 | 0 | } else if (158 > nmea_satnum) { |
622 | | // 1 = SBAS 152-158 |
623 | 0 | *ubx_gnssid = 1; |
624 | 0 | *ubx_svid = nmea_satnum; |
625 | 0 | } else if (193 > nmea_satnum) { |
626 | | // Huh? |
627 | 0 | *ubx_gnssid = 0; |
628 | 0 | *ubx_svid = 0; |
629 | 0 | nmea2_prn = 0; |
630 | 0 | } else if (200 > nmea_satnum) { |
631 | | // 1 = QZSS 193-197 |
632 | | // undocumented u-blox goes to 199 |
633 | 0 | *ubx_gnssid = 3; |
634 | 0 | *ubx_svid = nmea_satnum - 192; |
635 | 0 | } else if (265 > nmea_satnum) { |
636 | | // 3 = BeiDor, 201-264, NOT NMEA. Quectel Querk |
637 | 0 | *ubx_gnssid = 3; |
638 | 0 | *ubx_svid = nmea_satnum - 200; |
639 | 0 | } else { |
640 | | // Huh? |
641 | 0 | *ubx_gnssid = 0; |
642 | 0 | *ubx_svid = 0; |
643 | 0 | nmea2_prn = 0; |
644 | 0 | } |
645 | 0 | break; |
646 | 0 | case 2: |
647 | | // 2 = GLONASS 65-96, nul |
648 | 0 | *ubx_gnssid = 6; |
649 | 0 | if (64 > nmea_satnum) { |
650 | | // NMEA svid 1 - 64 |
651 | 0 | *ubx_svid = nmea_satnum; |
652 | 0 | } else { |
653 | | /* Jackson Labs Micro JLT, Quectel Querk, SiRF, Skytrak, |
654 | | * u-blox quirk: GLONASS are 65 to 96 */ |
655 | 0 | *ubx_svid = nmea_satnum - 64; |
656 | 0 | } |
657 | 0 | nmea2_prn = 64 + *ubx_svid; |
658 | 0 | break; |
659 | 0 | case 3: |
660 | | // 3 = Galileo 1-36 |
661 | 0 | *ubx_gnssid = 2; |
662 | 0 | if (100 > nmea_satnum) { |
663 | | // NMEA |
664 | 0 | *ubx_svid = nmea_satnum; |
665 | 0 | } else if (100 < nmea_satnum && |
666 | 0 | 200 > nmea_satnum) { |
667 | | // Quectel Querk, NOT NMEA, 101 - 199 |
668 | 0 | *ubx_svid = nmea_satnum - 100; |
669 | 0 | } else if (300 < nmea_satnum && |
670 | 0 | 400 > nmea_satnum) { |
671 | | // Jackson Labs quirk, NOT NMEA, 301 - 399 |
672 | 0 | *ubx_svid = nmea_satnum - 300; |
673 | 0 | } |
674 | 0 | nmea2_prn = 300 + *ubx_svid; // 301 - 399 |
675 | 0 | break; |
676 | 0 | case 4: |
677 | | // 4 - BeiDou 1-37 |
678 | 0 | *ubx_gnssid = 3; |
679 | 0 | if (100 > nmea_satnum) { |
680 | | // NMEA 1 - 99 |
681 | 0 | *ubx_svid = nmea_satnum; |
682 | 0 | } else if (200 < nmea_satnum && |
683 | 0 | 300 > nmea_satnum) { |
684 | | // Quectel Querk, NOT NMEA, 201 - 299 |
685 | 0 | *ubx_svid = nmea_satnum - 200; |
686 | 0 | } else if (400 < nmea_satnum && |
687 | 0 | 500 > nmea_satnum) { |
688 | | // Jackson Labs quirk, NOT NMEA, 401 - 499 |
689 | 0 | *ubx_svid = nmea_satnum - 400; |
690 | 0 | } |
691 | | // put it at 400+ where NMEA 4.11 wants it |
692 | 0 | nmea2_prn = 400 + *ubx_svid; |
693 | 0 | break; |
694 | 0 | case 5: |
695 | | // 5 - QZSS, 1 - 10, NMEA 4.11 |
696 | 0 | *ubx_gnssid = 5; |
697 | 0 | if (100 > nmea_satnum) { |
698 | | // NMEA 1 - 99 |
699 | 0 | *ubx_svid = nmea_satnum; |
700 | 0 | } else { |
701 | | // Telit quirk, not NMEA 193 - 199 |
702 | 0 | *ubx_svid = nmea_satnum - 192; |
703 | 0 | } |
704 | | |
705 | | // put it at 193 to 199 where NMEA 4.11 wants it |
706 | | // huh? space for only 7? |
707 | 0 | nmea2_prn = 192 + *ubx_svid; |
708 | 0 | break; |
709 | 0 | case 6: |
710 | | // 6 - NavIC (IRNSS) 1-15 |
711 | 0 | *ubx_gnssid = 7; |
712 | 0 | *ubx_svid = nmea_satnum; |
713 | 0 | nmea2_prn = nmea_satnum + 500; // This is wrong... |
714 | 0 | break; |
715 | 0 | default: |
716 | | // unknown |
717 | | // x = IMES Not defined by NMEA 4.10 |
718 | 0 | nmea2_prn = 0; |
719 | 0 | break; |
720 | 0 | } |
721 | | |
722 | | /* left with NMEA 2.x to NMEA 4.0 satnums |
723 | | * use talker ID to disambiguate */ |
724 | 0 | } else if (32 >= nmea_satnum) { |
725 | 0 | *ubx_svid = nmea_satnum; |
726 | 0 | switch (talker[0]) { |
727 | 0 | case 'G': |
728 | 0 | switch (talker[1]) { |
729 | 0 | case 'A': |
730 | | // Galileo |
731 | 0 | nmea2_prn = 300 + nmea_satnum; |
732 | 0 | *ubx_gnssid = 2; |
733 | 0 | break; |
734 | 0 | case 'B': |
735 | | // map Beidou IDs 1..37 to 401..437 |
736 | 0 | *ubx_gnssid = 3; |
737 | 0 | nmea2_prn = 400 + nmea_satnum; |
738 | 0 | break; |
739 | 0 | case 'I': |
740 | | // map NavIC (IRNSS) IDs 1..10 to 500 - 509, not NMEA |
741 | 0 | *ubx_gnssid = 7; |
742 | 0 | nmea2_prn = 500 + nmea_satnum; |
743 | 0 | break; |
744 | 0 | case 'L': |
745 | | // GLONASS GL doesn't seem to do this, better safe than sorry |
746 | 0 | nmea2_prn = 64 + nmea_satnum; |
747 | 0 | *ubx_gnssid = 6; |
748 | 0 | break; |
749 | 0 | case 'Q': |
750 | | // GQ, QZSS, 1 - 10 |
751 | 0 | nmea2_prn = 192 + nmea_satnum; |
752 | 0 | *ubx_gnssid = 5; |
753 | 0 | break; |
754 | 0 | case 'N': |
755 | | // all of them, but only GPS is 0 < PRN < 33 |
756 | 0 | FALLTHROUGH |
757 | 0 | case 'P': |
758 | | // GPS,SBAS,QZSS, but only GPS is 0 < PRN < 33 |
759 | 0 | FALLTHROUGH |
760 | 0 | default: |
761 | | // WTF? |
762 | 0 | break; |
763 | 0 | } // else ?? |
764 | 0 | break; |
765 | 0 | case 'B': |
766 | 0 | if ('D' == talker[1]) { |
767 | | // map Beidou IDs |
768 | 0 | nmea2_prn = 400 + nmea_satnum; |
769 | 0 | *ubx_gnssid = 3; |
770 | 0 | } // else ?? |
771 | 0 | break; |
772 | 0 | case 'P': |
773 | | // Quectel EC25 & EC21 use PQxxx for BeiDou |
774 | 0 | if ('Q' == talker[1]) { |
775 | | // map Beidou IDs |
776 | 0 | nmea2_prn = 400 + nmea_satnum; |
777 | 0 | *ubx_gnssid = 3; |
778 | 0 | } // else ?? |
779 | 0 | break; |
780 | 0 | case 'Q': |
781 | 0 | if ('Z' == talker[1]) { |
782 | | // QZSS |
783 | 0 | nmea2_prn = 192 + nmea_satnum; |
784 | 0 | *ubx_gnssid = 5; |
785 | 0 | } // else ? |
786 | 0 | break; |
787 | 0 | default: |
788 | | // huh? |
789 | 0 | break; |
790 | 0 | } |
791 | 0 | } else if (64 >= nmea_satnum) { |
792 | | // NMEA-ID (33..64) to SBAS PRN 120-151. |
793 | | // SBAS |
794 | 0 | *ubx_gnssid = 1; |
795 | 0 | *ubx_svid = 87 + nmea_satnum; |
796 | 0 | } else if (96 >= nmea_satnum) { |
797 | | // GLONASS 65..96 |
798 | 0 | *ubx_gnssid = 6; |
799 | 0 | *ubx_svid = nmea_satnum - 64; |
800 | 0 | } else if (120 > nmea_satnum) { |
801 | | // Huh? |
802 | 0 | *ubx_gnssid = 0; |
803 | 0 | *ubx_svid = 0; |
804 | 0 | nmea2_prn = 0; |
805 | 0 | } else if (158 >= nmea_satnum) { |
806 | | // SBAS 120..158 |
807 | 0 | *ubx_gnssid = 1; |
808 | 0 | *ubx_svid = nmea_satnum; |
809 | 0 | } else if (173 > nmea_satnum) { |
810 | | // Huh? |
811 | 0 | *ubx_gnssid = 0; |
812 | 0 | *ubx_svid = 0; |
813 | 0 | nmea2_prn = 0; |
814 | 0 | } else if (182 >= nmea_satnum) { |
815 | | // IMES 173..182 |
816 | 0 | *ubx_gnssid = 4; |
817 | 0 | *ubx_svid = nmea_satnum - 172; |
818 | 0 | } else if (193 > nmea_satnum) { |
819 | | // Huh? |
820 | 0 | *ubx_gnssid = 0; |
821 | 0 | *ubx_svid = 0; |
822 | 0 | nmea2_prn = 0; |
823 | 0 | } else if (197 >= nmea_satnum) { |
824 | | // QZSS 193..197 |
825 | | // undocumented u-blox goes to 199 |
826 | 0 | *ubx_gnssid = 5; |
827 | 0 | *ubx_svid = nmea_satnum - 192; |
828 | 0 | } else if (201 > nmea_satnum) { |
829 | | // Huh? |
830 | 0 | *ubx_gnssid = 0; |
831 | 0 | *ubx_svid = 0; |
832 | 0 | nmea2_prn = 0; |
833 | 0 | } else if (237 >= nmea_satnum) { |
834 | | // BeiDou, non-standard, some SiRF put BeiDou 201-237 |
835 | | // $GBGSV,2,2,05,209,07,033,*62 |
836 | 0 | *ubx_gnssid = 3; |
837 | 0 | *ubx_svid = nmea_satnum - 200; |
838 | 0 | nmea2_prn += 200; // move up to 400 where NMEA 2.x wants it. |
839 | 0 | } else if (301 > nmea_satnum) { |
840 | | // Huh? |
841 | 0 | *ubx_gnssid = 0; |
842 | 0 | *ubx_svid = 0; |
843 | 0 | nmea2_prn = 0; |
844 | 0 | } else if (356 >= nmea_satnum) { |
845 | | // Galileo 301..356 |
846 | 0 | *ubx_gnssid = 2; |
847 | 0 | *ubx_svid = nmea_satnum - 300; |
848 | 0 | } else if (401 > nmea_satnum) { |
849 | | // Huh? |
850 | 0 | *ubx_gnssid = 0; |
851 | 0 | *ubx_svid = 0; |
852 | 0 | nmea2_prn = 0; |
853 | 0 | } else if (437 >= nmea_satnum) { |
854 | | // BeiDou |
855 | 0 | *ubx_gnssid = 3; |
856 | 0 | *ubx_svid = nmea_satnum - 400; |
857 | 0 | } else if (499 >= nmea_satnum) { |
858 | | // 438 to 500?? |
859 | 0 | *ubx_gnssid = 0; |
860 | 0 | *ubx_svid = 0; |
861 | 0 | nmea2_prn = 0; |
862 | 0 | } else if (518 >= nmea_satnum) { |
863 | | // NavIC (IRNSS) IDs 1..18 to 510 - 509, not NMEA |
864 | 0 | *ubx_gnssid = 7; |
865 | 0 | *ubx_svid = nmea_satnum - 500; |
866 | 0 | } else if (900 >= nmea_satnum) { |
867 | | // 438 to 900?? |
868 | 0 | *ubx_gnssid = 0; |
869 | 0 | *ubx_svid = 0; |
870 | 0 | nmea2_prn = 0; |
871 | 0 | } else if (918 >= nmea_satnum) { |
872 | | // 900 to 918 NavIC (IRNSS), per ALLYSTAR (NMEA?) |
873 | 0 | *ubx_gnssid = 7; |
874 | 0 | *ubx_svid = nmea_satnum - 900; |
875 | 0 | } else { |
876 | | // greater than 437 Huh? |
877 | 0 | *ubx_gnssid = 0; |
878 | 0 | *ubx_svid = 0; |
879 | 0 | nmea2_prn = 0; |
880 | 0 | } |
881 | | |
882 | 0 | return nmea2_prn; |
883 | 0 | } |
884 | | |
885 | | /************************************************************************** |
886 | | * |
887 | | * NMEA sentence handling begins here |
888 | | * |
889 | | **************************************************************************/ |
890 | | |
891 | | static gps_mask_t processACCURACY(int c UNUSED, char *field[], |
892 | | struct gps_device_t *session) |
893 | 0 | { |
894 | | /* |
895 | | * $GPACCURACY,961.2*04 |
896 | | * |
897 | | * ACCURACY,x.x*hh<cr><lf> |
898 | | * |
899 | | * The only data field is "accuracy". |
900 | | * The MT3333 manual just says "The smaller the number is, the be better" |
901 | | */ |
902 | 0 | gps_mask_t mask = ONLINE_SET; |
903 | |
|
904 | 0 | if ('\0' == field[1][0]) { |
905 | | // no data |
906 | 0 | return mask; |
907 | 0 | } |
908 | | |
909 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
910 | 0 | "NMEA0183: $GPACCURACY: %10s.\n", field[1]); |
911 | 0 | return mask; |
912 | 0 | } |
913 | | |
914 | | // BWC - Bearing and Distance to Waypoint - Great Circle |
915 | | static gps_mask_t processBWC(int count, char *field[], |
916 | | struct gps_device_t *session) |
917 | 0 | { |
918 | | /* |
919 | | * GPBWC,220516,5130.02,N,00046.34,W,213.8,T,218.0,M,0004.6,N,EGLM*11 |
920 | | * |
921 | | * 1. UTC Time, hh is hours, mm is minutes, ss.ss is seconds |
922 | | * 2. Waypoint Latitude |
923 | | * 3. N = North, S = South |
924 | | * 4. Waypoint Longitude |
925 | | * 5. E = East, W = West |
926 | | * 6. Bearing, degrees True |
927 | | * 7. T = True |
928 | | * 8. Bearing, degrees Magnetic |
929 | | * 9. M = Magnetic |
930 | | * 10. Distance, Nautical Miles |
931 | | * 11. N = Nautical Miles |
932 | | * 12. Waypoint ID |
933 | | * 13. FAA mode indicator (NMEA 2.3 and later, optional) |
934 | | * 14. Checksum |
935 | | * |
936 | | * Parse this just to get the time, to help the cycle ender |
937 | | */ |
938 | 0 | gps_mask_t mask = ONLINE_SET; |
939 | |
|
940 | 0 | if ('\0' != field[1][0]) { |
941 | 0 | if (0 == merge_hhmmss(field[1], session)) { |
942 | 0 | if (0 == session->nmea.date.tm_year) { |
943 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
944 | 0 | "NMEA0183: can't use BWC time until after ZDA or RMC" |
945 | 0 | " has supplied a year.\n"); |
946 | 0 | } else { |
947 | 0 | mask = TIME_SET; |
948 | 0 | } |
949 | 0 | } |
950 | 0 | } |
951 | 0 | if (14 <= count) { |
952 | | // NMEA 2.3 and later |
953 | 0 | session->newdata.status = faa_mode(field[13][0]); |
954 | 0 | } |
955 | |
|
956 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
957 | 0 | "NMEA0183: BWC: hhmmss=%s status %d faa mode %s(%s)\n", |
958 | 0 | field[1], session->newdata.status, |
959 | 0 | field[13], char2str(field[13][0], c_faa_mode)); |
960 | 0 | return mask; |
961 | 0 | } |
962 | | |
963 | | static gps_mask_t processDBT(int c UNUSED, char *field[], |
964 | | struct gps_device_t *session) |
965 | 0 | { |
966 | | /* |
967 | | * $SDDBT,7.7,f,2.3,M,1.3,F*05 |
968 | | * 1) Depth below sounder in feet |
969 | | * 2) Fixed value 'f' indicating feet |
970 | | * 3) Depth below sounder in meters |
971 | | * 4) Fixed value 'M' indicating meters |
972 | | * 5) Depth below sounder in fathoms |
973 | | * 6) Fixed value 'F' indicating fathoms |
974 | | * 7) Checksum. |
975 | | * |
976 | | * In real-world sensors, sometimes not all three conversions are reported. |
977 | | */ |
978 | 0 | gps_mask_t mask = ONLINE_SET; |
979 | |
|
980 | 0 | if ('\0' != field[3][0]) { |
981 | 0 | session->newdata.depth = safe_atof(field[3]); |
982 | 0 | mask |= (ALTITUDE_SET); |
983 | 0 | } else if ('\0' != field[1][0]) { |
984 | 0 | session->newdata.depth = safe_atof(field[1]) * FEET_TO_METERS; |
985 | 0 | mask |= (ALTITUDE_SET); |
986 | 0 | } else if ('\0' != field[5][0]) { |
987 | 0 | session->newdata.depth = safe_atof(field[5]) * FATHOMS_TO_METERS; |
988 | 0 | mask |= (ALTITUDE_SET); |
989 | 0 | } |
990 | |
|
991 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
992 | 0 | "NMEA0183: %s mode %d, depth %lf.\n", |
993 | 0 | field[0], |
994 | 0 | session->newdata.mode, |
995 | 0 | session->newdata.depth); |
996 | 0 | return mask; |
997 | 0 | } |
998 | | |
999 | | static gps_mask_t processDPT(int c UNUSED, char *field[], |
1000 | | struct gps_device_t *session) |
1001 | 0 | { |
1002 | | /* |
1003 | | * $--DPT,x.x,x.x,x.x*hh<CR><LF> |
1004 | | * 1) Depth below sounder in meters |
1005 | | * 2) (+) Offset between sounder and waterline in meters |
1006 | | * (-) Offset between sounder and keel in meters |
1007 | | * 3) Maximum range scale |
1008 | | * 4) Checksum. |
1009 | | * |
1010 | | * $SDDBT and $SDDPT should agree, but often don't. |
1011 | | * |
1012 | | */ |
1013 | 0 | double offset; |
1014 | 0 | gps_mask_t mask = ONLINE_SET; |
1015 | |
|
1016 | 0 | if ('\0' == field[1][0]) { |
1017 | | // no depth |
1018 | 0 | return mask; |
1019 | 0 | } |
1020 | 0 | session->newdata.depth = safe_atof(field[1]); |
1021 | 0 | offset = safe_atof(field[2]); |
1022 | 0 | if (0.0 > offset) { |
1023 | | // adjust to get depth from keel |
1024 | 0 | session->newdata.depth -= offset; |
1025 | 0 | } |
1026 | 0 | mask |= ALTITUDE_SET; |
1027 | |
|
1028 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1029 | 0 | "NMEA0183: %s depth %.1f offset %s max %s\n", |
1030 | 0 | field[0], |
1031 | 0 | session->newdata.depth, field[2], field[3]); |
1032 | 0 | return mask; |
1033 | 0 | } |
1034 | | |
1035 | | /* NMEA Map Datum |
1036 | | * |
1037 | | * FIXME: seems to happen after cycle ender, so nothing happens... |
1038 | | */ |
1039 | | static gps_mask_t processDTM(int c UNUSED, char *field[], |
1040 | | struct gps_device_t *session) |
1041 | 0 | { |
1042 | | /* |
1043 | | * $GPDTM,W84,C*52 |
1044 | | * $GPDTM,xxx,x,xx.xxxx,x,xx.xxxx,x,,xxx*hh<CR><LF> |
1045 | | * 1 = Local datum code (xxx): |
1046 | | * W84 – WGS84 |
1047 | | * W72 – WGS72 |
1048 | | * S85 – SGS85 |
1049 | | * P90 – PE90 |
1050 | | * 999 – User defined |
1051 | | * IHO datum code |
1052 | | * 2 = Local datum sub code (x) |
1053 | | * 3 = Latitude offset in minutes (xx.xxxx) |
1054 | | * 4 = Latitude offset mark (N: +, S: -) (x) |
1055 | | * 5 = Longitude offset in minutes (xx.xxxx) |
1056 | | * 6 = Longitude offset mark (E: +, W: -) (x) |
1057 | | * 7 = Altitude offset in meters. Always null |
1058 | | * 8 = Datum (xxx): |
1059 | | * W84 – WGS84 |
1060 | | * W72 – WGS72 |
1061 | | * S85 – SGS85 |
1062 | | * P90 – PE90 |
1063 | | * 999 – User defined |
1064 | | * IHO datum code |
1065 | | * 9 = checksum |
1066 | | */ |
1067 | 0 | int i; |
1068 | 0 | static struct |
1069 | 0 | { |
1070 | 0 | char *code; |
1071 | 0 | char *name; |
1072 | 0 | } codes[] = { |
1073 | 0 | {"W84", "WGS84"}, |
1074 | 0 | {"W72", "WGS72"}, |
1075 | 0 | {"S85", "SGS85"}, |
1076 | 0 | {"P90", "PE90"}, |
1077 | 0 | {"999", "User Defined"}, |
1078 | 0 | {"", ""}, |
1079 | 0 | }; |
1080 | |
|
1081 | 0 | gps_mask_t mask = ONLINE_SET; |
1082 | |
|
1083 | 0 | if ('\0' == field[1][0]) { |
1084 | 0 | return mask; |
1085 | 0 | } |
1086 | | |
1087 | 0 | for (i = 0; ; i++) { |
1088 | 0 | if ('\0' == codes[i].code[0]) { |
1089 | | // not found |
1090 | 0 | strlcpy(session->newdata.datum, field[1], |
1091 | 0 | sizeof(session->newdata.datum)); |
1092 | 0 | break; |
1093 | 0 | } |
1094 | 0 | if (0 ==strcmp(codes[i].code, field[1])) { |
1095 | 0 | strlcpy(session->newdata.datum, codes[i].name, |
1096 | 0 | sizeof(session->newdata.datum)); |
1097 | 0 | break; |
1098 | 0 | } |
1099 | 0 | } |
1100 | |
|
1101 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
1102 | 0 | "NMEA0183: xxDTM: datum=%.40s\n", |
1103 | 0 | session->newdata.datum); |
1104 | 0 | return mask; |
1105 | 0 | } |
1106 | | |
1107 | | // NMEA 3.0 Estimated Position Error |
1108 | | static gps_mask_t processGBS(int c UNUSED, char *field[], |
1109 | | struct gps_device_t *session) |
1110 | 0 | { |
1111 | | /* |
1112 | | * $GPGBS,082941.00,2.4,1.5,3.9,25,,-43.7,27.5*65 |
1113 | | * 1) UTC time of the fix associated with this sentence (hhmmss.ss) |
1114 | | * 2) Expected error in latitude (meters) |
1115 | | * 3) Expected error in longitude (meters) |
1116 | | * 4) Expected error in altitude (meters) |
1117 | | * 5) PRN of most likely failed satellite |
1118 | | * 6) Probability of missed detection for most likely failed satellite |
1119 | | * 7) Estimate of bias in meters on most likely failed satellite |
1120 | | * 8) Standard deviation of bias estimate |
1121 | | * 9) NMEA 4.1 GNSS ID |
1122 | | * 10) NMEA 4.1 Signal ID |
1123 | | * Checksum |
1124 | | * |
1125 | | * Fields 2, 3 and 4 are one standard deviation. |
1126 | | */ |
1127 | 0 | gps_mask_t mask = ONLINE_SET; |
1128 | | |
1129 | | // register fractional time for end-of-cycle detection |
1130 | 0 | register_fractional_time(field[0], field[1], session); |
1131 | | |
1132 | | // check that we're associated with the current fix |
1133 | 0 | if (session->nmea.date.tm_hour == DD(field[1]) && |
1134 | 0 | session->nmea.date.tm_min == DD(field[1] + 2) && |
1135 | 0 | session->nmea.date.tm_sec == DD(field[1] + 4)) { |
1136 | | // FIXME: check fractional time! |
1137 | 0 | session->newdata.epy = safe_atof(field[2]); |
1138 | 0 | session->newdata.epx = safe_atof(field[3]); |
1139 | 0 | session->newdata.epv = safe_atof(field[4]); |
1140 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
1141 | 0 | "NMEA0183: GBS: epx=%.2f epy=%.2f epv=%.2f\n", |
1142 | 0 | session->newdata.epx, |
1143 | 0 | session->newdata.epy, |
1144 | 0 | session->newdata.epv); |
1145 | 0 | mask = HERR_SET | VERR_SET; |
1146 | 0 | } else { |
1147 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1148 | 0 | "NMEA0183: second in $GPGBS error estimates doesn't match.\n"); |
1149 | 0 | } |
1150 | 0 | return mask; |
1151 | 0 | } |
1152 | | |
1153 | | // Global Positioning System Fix Data |
1154 | | static gps_mask_t processGGA(int c UNUSED, char *field[], |
1155 | | struct gps_device_t *session) |
1156 | 0 | { |
1157 | | /* |
1158 | | * GGA,123519,4807.038,N,01131.324,E,1,08,0.9,545.4,M,46.9,M, , *42 |
1159 | | * 1 123519 Fix taken at 12:35:19 UTC |
1160 | | * 2,3 4807.038,N Latitude 48 deg 07.038' N |
1161 | | * 4,5 01131.324,E Longitude 11 deg 31.324' E |
1162 | | * 6 1 Fix quality: |
1163 | | * 0 = invalid, |
1164 | | * 1 = GPS, |
1165 | | * u-blox may use 1 for Estimated |
1166 | | * 2 = DGPS, |
1167 | | * 3 = PPS (Precise Position Service), |
1168 | | * 4 = RTK (Real Time Kinematic) with fixed integers, |
1169 | | * 5 = Float RTK, |
1170 | | * 6 = Estimated, |
1171 | | * 7 = Manual, |
1172 | | * 8 = Simulator |
1173 | | * 7 08 Number of satellites in use |
1174 | | * 8 0.9 Horizontal dilution of position |
1175 | | * 9,10 545.4,M Altitude, Meters MSL |
1176 | | * 11,12 46.9,M Height of geoid (mean sea level) above WGS84 |
1177 | | * ellipsoid, in Meters |
1178 | | * 13 33 time in seconds since last DGPS update |
1179 | | * usually empty |
1180 | | * 14 1023 DGPS station ID number (0000-1023) |
1181 | | * usually empty |
1182 | | * |
1183 | | * Some GPS, like the SiRFstarV in NMEA mode, send both GPGSA and |
1184 | | * GLGPSA with identical data. |
1185 | | */ |
1186 | 0 | gps_mask_t mask = ONLINE_SET; |
1187 | 0 | int newstatus; |
1188 | 0 | char last_last_gga_talker = session->nmea.last_gga_talker; |
1189 | 0 | int fix; // a.k.a Quality flag |
1190 | 0 | session->nmea.last_gga_talker = field[0][1]; |
1191 | |
|
1192 | 0 | if ('\0' == field[6][0]) { |
1193 | | /* no data is no data, assume no fix |
1194 | | * the test/daemon/myguide-3100.log shows lat/lon/alt but |
1195 | | * no status, and related RMC shows no fix. */ |
1196 | 0 | fix = -1; |
1197 | 0 | } else { |
1198 | 0 | fix = atoi(field[6]); |
1199 | 0 | } |
1200 | | // Jackson Labs Micro JLT uses nonstadard fix flag, not handled |
1201 | 0 | switch (fix) { |
1202 | 0 | case 0: // no fix |
1203 | 0 | newstatus = STATUS_UNK; |
1204 | 0 | if ('\0' == field[1][0]) { |
1205 | | /* No time available. That breaks cycle end detector |
1206 | | * Force report to bypass cycle detector and get report out. |
1207 | | * To handle Querks (Quectel) like this: |
1208 | | * $GPGGA,,,,,,0,,,,,,,,*66 |
1209 | | */ |
1210 | 0 | memset(&session->nmea.date, 0, sizeof(session->nmea.date)); |
1211 | 0 | session->cycle_end_reliable = false; |
1212 | 0 | mask |= REPORT_IS | TIME_SET; |
1213 | 0 | } |
1214 | 0 | break; |
1215 | 0 | case 1: |
1216 | | // could be 2D, 3D, GNSSDR |
1217 | 0 | newstatus = STATUS_GPS; |
1218 | 0 | break; |
1219 | 0 | case 2: // differential |
1220 | 0 | newstatus = STATUS_DGPS; |
1221 | 0 | break; |
1222 | 0 | case 3: |
1223 | | // GPS PPS, fix valid, could be 2D, 3D, GNSSDR |
1224 | 0 | newstatus = STATUS_PPS_FIX; |
1225 | 0 | break; |
1226 | 0 | case 4: // RTK integer |
1227 | 0 | newstatus = STATUS_RTK_FIX; |
1228 | 0 | break; |
1229 | 0 | case 5: // RTK float |
1230 | 0 | newstatus = STATUS_RTK_FLT; |
1231 | 0 | break; |
1232 | 0 | case 6: |
1233 | | // dead reckoning, could be valid or invalid |
1234 | 0 | newstatus = STATUS_DR; |
1235 | 0 | break; |
1236 | 0 | case 7: |
1237 | | // manual input, surveyed |
1238 | 0 | newstatus = STATUS_TIME; |
1239 | 0 | break; |
1240 | 0 | case 8: |
1241 | | /* simulated mode |
1242 | | * Garmin GPSMAP and Gecko sends an 8, but undocumented why */ |
1243 | 0 | newstatus = STATUS_SIM; |
1244 | 0 | break; |
1245 | 0 | case -1: |
1246 | 0 | FALLTHROUGH |
1247 | 0 | default: |
1248 | 0 | newstatus = -1; |
1249 | 0 | break; |
1250 | 0 | } |
1251 | 0 | if (0 <= newstatus) { |
1252 | 0 | session->newdata.status = newstatus; |
1253 | 0 | mask = STATUS_SET; |
1254 | 0 | } |
1255 | | /* |
1256 | | * There are some receivers (the Trimble Placer 450 is an example) that |
1257 | | * don't ship a GSA with mode 1 when they lose satellite lock. Instead |
1258 | | * they just keep reporting GGA and GSA on subsequent cycles with the |
1259 | | * timestamp not advancing and a bogus mode. |
1260 | | * |
1261 | | * On the assumption that GGA is only issued once per cycle we can |
1262 | | * detect this here (it would be nicer to do it on GSA but GSA has |
1263 | | * no timestamp). |
1264 | | * |
1265 | | * SiRFstarV breaks this assumption, sending GGA with different |
1266 | | * talker IDs. |
1267 | | */ |
1268 | 0 | if ('\0' != last_last_gga_talker && |
1269 | 0 | last_last_gga_talker != session->nmea.last_gga_talker) { |
1270 | | // skip the time check |
1271 | 0 | session->nmea.latch_mode = 0; |
1272 | 0 | } else { |
1273 | 0 | session->nmea.latch_mode = strncmp(field[1], |
1274 | 0 | session->nmea.last_gga_timestamp, |
1275 | 0 | sizeof(session->nmea.last_gga_timestamp))==0; |
1276 | 0 | } |
1277 | |
|
1278 | 0 | if (session->nmea.latch_mode) { |
1279 | 0 | session->newdata.status = STATUS_UNK; |
1280 | 0 | session->newdata.mode = MODE_NO_FIX; |
1281 | 0 | mask |= MODE_SET | STATUS_SET; |
1282 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1283 | 0 | "NMEA0183: xxGGA: latch mode\n"); |
1284 | 0 | } else { |
1285 | 0 | (void)strlcpy(session->nmea.last_gga_timestamp, field[1], |
1286 | 0 | sizeof(session->nmea.last_gga_timestamp)); |
1287 | 0 | } |
1288 | | |
1289 | | /* satellites_visible is used as an accumulator in xxGSV |
1290 | | * so if we set it here we break xxGSV |
1291 | | * Some GPS, like SiRFstarV NMEA, report per GNSS used |
1292 | | * counts in GPGGA and GLGGA. |
1293 | | */ |
1294 | 0 | session->nmea.gga_sats_used = atoi(field[7]); |
1295 | |
|
1296 | 0 | if ('\0' == field[1][0]) { |
1297 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
1298 | 0 | "NMEA0183: GGA time missing.\n"); |
1299 | 0 | } else if (0 == merge_hhmmss(field[1], session)) { |
1300 | 0 | register_fractional_time(field[0], field[1], session); |
1301 | 0 | if (0 == session->nmea.date.tm_year) { |
1302 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
1303 | 0 | "NMEA0183: can't use GGA time until after ZDA or RMC" |
1304 | 0 | " has supplied a year.\n"); |
1305 | 0 | } else { |
1306 | 0 | mask |= TIME_SET; |
1307 | 0 | } |
1308 | 0 | } |
1309 | |
|
1310 | 0 | if (0 == do_lat_lon(&field[2], &session->newdata)) { |
1311 | 0 | session->newdata.mode = MODE_2D; |
1312 | 0 | mask |= LATLON_SET; |
1313 | 0 | if ('\0' != field[11][0]) { |
1314 | 0 | session->newdata.geoid_sep = safe_atof(field[11]); |
1315 | 0 | } else { |
1316 | 0 | session->newdata.geoid_sep = wgs84_separation( |
1317 | 0 | session->newdata.latitude, session->newdata.longitude); |
1318 | 0 | } |
1319 | | /* |
1320 | | * SiRF chipsets up to version 2.2 report a null altitude field. |
1321 | | * See <http://www.sirf.com/Downloads/Technical/apnt0033.pdf>. |
1322 | | * If we see this, force mode to 2D at most. |
1323 | | */ |
1324 | 0 | if ('\0' != field[9][0]) { |
1325 | | // altitude is MSL |
1326 | 0 | session->newdata.altMSL = safe_atof(field[9]); |
1327 | | // Let gpsd_error_model() deal with altHAE |
1328 | 0 | mask |= ALTITUDE_SET; |
1329 | | /* |
1330 | | * This is a bit dodgy. Technically we shouldn't set the mode |
1331 | | * bit until we see GSA. But it may be later in the cycle, |
1332 | | * some devices like the FV-18 don't send it by default, and |
1333 | | * elsewhere in the code we want to be able to test for the |
1334 | | * presence of a valid fix with mode > MODE_NO_FIX. |
1335 | | * |
1336 | | * Use gga_sats_used; as double check on MODE_3D |
1337 | | */ |
1338 | 0 | if (4 <= session->nmea.gga_sats_used) { |
1339 | 0 | session->newdata.mode = MODE_3D; |
1340 | 0 | } |
1341 | 0 | } |
1342 | 0 | if (3 > session->nmea.gga_sats_used) { |
1343 | 0 | session->newdata.mode = MODE_NO_FIX; |
1344 | 0 | } |
1345 | 0 | } else { |
1346 | 0 | session->newdata.mode = MODE_NO_FIX; |
1347 | 0 | } |
1348 | 0 | mask |= MODE_SET; |
1349 | | |
1350 | | // BT-451 sends 99.99 for invalid DOPs |
1351 | | // Jackson Labs send 99.00 for invalid DOPs |
1352 | | // Skytraq send 0.00 for invalid DOPs |
1353 | 0 | if ('\0' != field[8][0]) { |
1354 | 0 | double hdop; |
1355 | 0 | hdop = safe_atof(field[8]); |
1356 | 0 | if (IN(0.01, hdop, 89.99)) { |
1357 | | // why not to newdata? |
1358 | 0 | session->gpsdata.dop.hdop = hdop; |
1359 | 0 | mask |= DOP_SET; |
1360 | 0 | } |
1361 | 0 | } |
1362 | | |
1363 | | // get DGPS stuff |
1364 | 0 | if ('\0' != field[13][0] && |
1365 | 0 | '\0' != field[14][0]) { |
1366 | | // both, or neither |
1367 | 0 | double age; |
1368 | 0 | int station; |
1369 | |
|
1370 | 0 | age = safe_atof(field[13]); |
1371 | 0 | station = atoi(field[14]); |
1372 | 0 | if (0.09 < age || |
1373 | 0 | 0 < station) { |
1374 | | // ignore both zeros |
1375 | 0 | session->newdata.dgps_age = age; |
1376 | 0 | session->newdata.dgps_station = station; |
1377 | 0 | } |
1378 | 0 | } |
1379 | |
|
1380 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1381 | 0 | "NMEA0183: GGA: hhmmss=%s lat=%.2f lon=%.2f altMSL=%.2f " |
1382 | 0 | "mode=%d status=%d\n", |
1383 | 0 | field[1], |
1384 | 0 | session->newdata.latitude, |
1385 | 0 | session->newdata.longitude, |
1386 | 0 | session->newdata.altMSL, |
1387 | 0 | session->newdata.mode, |
1388 | 0 | session->newdata.status); |
1389 | 0 | return mask; |
1390 | 0 | } |
1391 | | |
1392 | | // Geographic position - Latitude, Longitude |
1393 | | static gps_mask_t processGLL(int count, char *field[], |
1394 | | struct gps_device_t *session) |
1395 | 0 | { |
1396 | | /* Introduced in NMEA 3.0. |
1397 | | * |
1398 | | * $GPGLL,4916.45,N,12311.12,W,225444,A,A*5C |
1399 | | * |
1400 | | * 1,2: 4916.46,N Latitude 49 deg. 16.45 min. North |
1401 | | * 3,4: 12311.12,W Longitude 123 deg. 11.12 min. West |
1402 | | * 5: 225444 Fix taken at 22:54:44 UTC |
1403 | | * 6: A Data valid |
1404 | | * 7: A Autonomous mode |
1405 | | * 8: *5C Mandatory NMEA checksum |
1406 | | * |
1407 | | * 1,2 Latitude, N (North) or S (South) |
1408 | | * 3,4 Longitude, E (East) or W (West) |
1409 | | * 5 UTC of position |
1410 | | * 6 A = Active, V = Invalid data |
1411 | | * 7 Mode Indicator |
1412 | | * See faa_mode() for possible mode values. |
1413 | | * |
1414 | | * I found a note at <http://www.secoh.ru/windows/gps/nmfqexep.txt> |
1415 | | * indicating that the Garmin 65 does not return time and status. |
1416 | | * SiRF chipsets don't return the Mode Indicator. |
1417 | | * This code copes gracefully with both quirks. |
1418 | | * |
1419 | | * Unless you care about the FAA indicator, this sentence supplies nothing |
1420 | | * that GPRMC doesn't already. But at least two (Garmin GPS 48 and |
1421 | | * Magellan Triton 400) actually ship updates in GLL that aren't redundant. |
1422 | | * |
1423 | | */ |
1424 | 0 | char *status = field[7]; |
1425 | 0 | gps_mask_t mask = ONLINE_SET; |
1426 | |
|
1427 | 0 | if (field[5][0] != '\0') { |
1428 | 0 | if (0 == merge_hhmmss(field[5], session)) { |
1429 | 0 | register_fractional_time(field[0], field[5], session); |
1430 | 0 | if (0 == session->nmea.date.tm_year) { |
1431 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
1432 | 0 | "NMEA0183: can't use GLL time until after ZDA or RMC" |
1433 | 0 | " has supplied a year.\n"); |
1434 | 0 | } else { |
1435 | 0 | mask = TIME_SET; |
1436 | 0 | } |
1437 | 0 | } |
1438 | 0 | } |
1439 | 0 | if ('\0' == field[6][0] || |
1440 | 0 | 'V' == field[6][0]) { |
1441 | | // Invalid |
1442 | 0 | session->newdata.status = STATUS_UNK; |
1443 | 0 | session->newdata.mode = MODE_NO_FIX; |
1444 | 0 | } else if ('A' == field[6][0] && |
1445 | 0 | (count < 8 || *status != 'N') && |
1446 | 0 | 0 == do_lat_lon(&field[1], &session->newdata)) { |
1447 | 0 | int newstatus; |
1448 | |
|
1449 | 0 | mask |= LATLON_SET; |
1450 | |
|
1451 | 0 | newstatus = STATUS_GPS; |
1452 | 0 | if (8 <= count) { |
1453 | 0 | newstatus = faa_mode(*status); |
1454 | 0 | } |
1455 | | /* |
1456 | | * This is a bit dodgy. Technically we shouldn't set the mode |
1457 | | * bit until we see GSA, or similar. But it may be later in the |
1458 | | * cycle, some devices like the FV-18 don't send it by default, |
1459 | | * and elsewhere in the code we want to be able to test for the |
1460 | | * presence of a valid fix with mode > MODE_NO_FIX. |
1461 | | */ |
1462 | 0 | if (0 != isfinite(session->gpsdata.fix.altHAE) || |
1463 | 0 | 0 != isfinite(session->gpsdata.fix.altMSL)) { |
1464 | 0 | session->newdata.mode = MODE_3D; |
1465 | 0 | } else if (3 < session->gpsdata.satellites_used) { |
1466 | | // 4 sats used means 3D |
1467 | 0 | session->newdata.mode = MODE_3D; |
1468 | 0 | } else if (MODE_2D > session->gpsdata.fix.mode || |
1469 | 0 | (0 == isfinite(session->oldfix.altHAE) && |
1470 | 0 | 0 == isfinite(session->oldfix.altMSL))) { |
1471 | 0 | session->newdata.mode = MODE_2D; |
1472 | 0 | } |
1473 | 0 | session->newdata.status = newstatus; |
1474 | 0 | } else { |
1475 | 0 | session->newdata.status = STATUS_UNK; |
1476 | 0 | session->newdata.mode = MODE_NO_FIX; |
1477 | 0 | } |
1478 | 0 | mask |= STATUS_SET | MODE_SET; |
1479 | |
|
1480 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1481 | 0 | "NMEA0183: GLL: hhmmss=%s lat=%.2f lon=%.2f mode=%d status=%d " |
1482 | 0 | "faa mode %s(%s)\n", |
1483 | 0 | field[5], |
1484 | 0 | session->newdata.latitude, |
1485 | 0 | session->newdata.longitude, |
1486 | 0 | session->newdata.mode, |
1487 | 0 | session->newdata.status, |
1488 | 0 | field[7], char2str(field[7][0], c_faa_mode)); |
1489 | 0 | return mask; |
1490 | 0 | } |
1491 | | |
1492 | | // Geographic position - Latitude, Longitude, and more |
1493 | | static gps_mask_t processGNS(int count UNUSED, char *field[], |
1494 | | struct gps_device_t *session) |
1495 | 0 | { |
1496 | | /* Introduced in NMEA 4.0? |
1497 | | * |
1498 | | * This mostly duplicates RMC, except for the multi GNSS mode |
1499 | | * indicator. |
1500 | | * |
1501 | | * Example. Ignore the line break. |
1502 | | * $GPGNS,224749.00,3333.4268304,N,11153.3538273,W,D,19,0.6,406.110, |
1503 | | * -26.294,6.0,0138,S,*6A |
1504 | | * |
1505 | | * 1: 224749.00 UTC HHMMSS.SS. 22:47:49.00 |
1506 | | * 2: 3333.4268304 Latitude DDMM.MMMMM. 33 deg. 33.4268304 min |
1507 | | * 3: N Latitude North |
1508 | | * 4: 12311.12 Longitude 111 deg. 53.3538273 min |
1509 | | * 5: W Longitude West |
1510 | | * 6: D FAA mode indicator |
1511 | | * see faa_mode() for possible mode values |
1512 | | * May be one to six characters. |
1513 | | * Char 1 = GPS |
1514 | | * Char 2 = GLONASS |
1515 | | * Char 3 = Galileo |
1516 | | * Char 4 = BDS |
1517 | | * Char 5 = QZSS |
1518 | | * Char 6 = NavIC (IRNSS) |
1519 | | * 7: 19 Number of Satellites used in solution |
1520 | | * 8: 0.6 HDOP |
1521 | | * 9: 406110 MSL Altitude in meters |
1522 | | * 10: -26.294 Geoid separation in meters |
1523 | | * 11: 6.0 Age of differential corrections, in seconds |
1524 | | * 12: 0138 Differential reference station ID |
1525 | | * 13: S NMEA 4.1+ Navigation status |
1526 | | * S = Safe |
1527 | | * C = Caution |
1528 | | * U = Unsafe |
1529 | | * V = Not valid for navigation |
1530 | | * 8: *6A Mandatory NMEA checksum |
1531 | | * |
1532 | | */ |
1533 | 0 | int newstatus; |
1534 | 0 | gps_mask_t mask = ONLINE_SET; |
1535 | |
|
1536 | 0 | if ('\0' != field[1][0]) { |
1537 | 0 | if (0 == merge_hhmmss(field[1], session)) { |
1538 | 0 | register_fractional_time(field[0], field[1], session); |
1539 | 0 | if (0 == session->nmea.date.tm_year) { |
1540 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
1541 | 0 | "NMEA0183: can't use GNS time until after ZDA or RMC" |
1542 | 0 | " has supplied a year.\n"); |
1543 | 0 | } else { |
1544 | 0 | mask = TIME_SET; |
1545 | 0 | } |
1546 | 0 | } |
1547 | 0 | } |
1548 | | |
1549 | | /* FAA mode: not valid, ignore |
1550 | | * Yes, in 2019 a GLONASS only fix may be valid, but not worth |
1551 | | * the confusion */ |
1552 | 0 | if ('\0' == field[6][0] || // FAA mode: missing |
1553 | 0 | 'N' == field[6][0]) { // FAA mode: not valid |
1554 | 0 | session->newdata.mode = MODE_NO_FIX; |
1555 | 0 | mask |= MODE_SET; |
1556 | 0 | return mask; |
1557 | 0 | } |
1558 | | /* navigation status, assume S=safe and C=caution are OK |
1559 | | * can be missing on valid fix */ |
1560 | 0 | if ('U' == field[13][0] || // Unsafe |
1561 | 0 | 'V' == field[13][0]) { // not valid |
1562 | 0 | return mask; |
1563 | 0 | } |
1564 | | |
1565 | 0 | session->nmea.gga_sats_used = atoi(field[7]); |
1566 | |
|
1567 | 0 | if (0 == do_lat_lon(&field[2], &session->newdata)) { |
1568 | 0 | mask |= LATLON_SET; |
1569 | 0 | session->newdata.mode = MODE_2D; |
1570 | |
|
1571 | 0 | if ('\0' != field[9][0]) { |
1572 | | // altitude is MSL |
1573 | 0 | session->newdata.altMSL = safe_atof(field[9]); |
1574 | 0 | if (0 != isfinite(session->newdata.altMSL)) { |
1575 | 0 | mask |= ALTITUDE_SET; |
1576 | 0 | if (3 < session->nmea.gga_sats_used) { |
1577 | | // more than 3 sats used means 3D |
1578 | 0 | session->newdata.mode = MODE_3D; |
1579 | 0 | } |
1580 | 0 | } |
1581 | | // only need geoid_sep if in 3D mode |
1582 | 0 | if ('\0' != field[10][0]) { |
1583 | 0 | session->newdata.geoid_sep = safe_atof(field[10]); |
1584 | 0 | } |
1585 | | // Let gpsd_error_model() deal with geoid_sep and altHAE |
1586 | 0 | } |
1587 | 0 | } else { |
1588 | 0 | session->newdata.mode = MODE_NO_FIX; |
1589 | 0 | mask |= MODE_SET; |
1590 | 0 | } |
1591 | |
|
1592 | 0 | if ('\0' != field[8][0]) { |
1593 | 0 | session->gpsdata.dop.hdop = safe_atof(field[8]); |
1594 | 0 | mask |= DOP_SET; |
1595 | 0 | } |
1596 | | |
1597 | | // we ignore all but the leading mode indicator. |
1598 | 0 | newstatus = faa_mode(field[6][0]); |
1599 | |
|
1600 | 0 | session->newdata.status = newstatus; |
1601 | 0 | mask |= MODE_SET | STATUS_SET; |
1602 | | |
1603 | | // get DGPS stuff |
1604 | 0 | if ('\0' != field[11][0] && |
1605 | 0 | '\0' != field[12][0]) { |
1606 | | // both, or neither |
1607 | 0 | session->newdata.dgps_age = safe_atof(field[11]); |
1608 | 0 | session->newdata.dgps_station = atoi(field[12]); |
1609 | 0 | } |
1610 | |
|
1611 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1612 | 0 | "NMEA0183: GNS: hhmmss=%s lat=%.2f lon=%.2f mode=%d status=%d " |
1613 | 0 | "faa mode %s(%s)\n", |
1614 | 0 | field[1], |
1615 | 0 | session->newdata.latitude, |
1616 | 0 | session->newdata.longitude, |
1617 | 0 | session->newdata.mode, |
1618 | 0 | session->newdata.status, |
1619 | 0 | field[6], char2str(field[6][0], c_faa_mode)); |
1620 | 0 | return mask; |
1621 | 0 | } |
1622 | | |
1623 | | // GNSS Range residuals |
1624 | | static gps_mask_t processGRS(int count UNUSED, char *field[], |
1625 | | struct gps_device_t *session) |
1626 | 0 | { |
1627 | | /* In NMEA 3.01 |
1628 | | * |
1629 | | * Example: |
1630 | | * $GPGRS,150119.000,1,-0.33,-2.59,3.03,-0.09,-2.98,7.12,-15.6,17.0,,,,*5A |
1631 | | * |
1632 | | * 1: 150119.000 UTC HHMMSS.SS |
1633 | | * 2: 1 Mode: 0 == original, 1 == recomputed |
1634 | | * 3: -0.33 range residual in meters sat 1 |
1635 | | * 4: -2.59 range residual sat 2 |
1636 | | * [...] |
1637 | | * n: *5A Mandatory NMEA checksum |
1638 | | * |
1639 | | */ |
1640 | 0 | int mode; |
1641 | 0 | gps_mask_t mask = ONLINE_SET; |
1642 | |
|
1643 | 0 | if ('\0' == field[1][0] || |
1644 | 0 | 0 != merge_hhmmss(field[1], session)) { |
1645 | | // bad time |
1646 | 0 | return mask; |
1647 | 0 | } |
1648 | | |
1649 | 0 | mode = atoi(field[2]); |
1650 | 0 | if (1 != mode && |
1651 | 0 | 2 != mode) { |
1652 | | // bad mode |
1653 | 0 | return mask; |
1654 | 0 | } |
1655 | | |
1656 | | // FIXME: partial decode. How to match sat numbers up with GSA? |
1657 | | |
1658 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
1659 | 0 | "NMEA0183: %s: mode %d count %d\n", |
1660 | 0 | field[0], mode, count); |
1661 | 0 | return mask; |
1662 | 0 | } |
1663 | | |
1664 | | // GPS DOP and Active Satellites |
1665 | | static gps_mask_t processGSA(int count, char *field[], |
1666 | | struct gps_device_t *session) |
1667 | 0 | { |
1668 | 0 | #define GSA_TALKER field[0][1] |
1669 | | /* |
1670 | | * eg1. $GPGSA,A,3,,,,,,16,18,,22,24,,,3.6,2.1,2.2*3C |
1671 | | * eg2. $GPGSA,A,3,19,28,14,18,27,22,31,39,,,,,1.7,1.0,1.3*35 |
1672 | | * NMEA 4.10: $GNGSA,A,3,13,12,22,19,08,21,,,,,,,1.05,0.64,0.83,4*0B |
1673 | | * 1 = Mode: |
1674 | | * M=Manual, forced to operate in 2D or 3D |
1675 | | * A=Automatic, 3D/2D |
1676 | | * 2 = Mode: |
1677 | | * 1=Fix not available, |
1678 | | * 2=2D, |
1679 | | * 3=3D |
1680 | | * E=Dead Reckonig (Antaris) |
1681 | | * 3-14 (or 24!) = satellite PRNs used in position fix (null unused) |
1682 | | * 15 = PDOP |
1683 | | * 16 = HDOP |
1684 | | * 17 = VDOP |
1685 | | * -- -- -- |
1686 | | * 18 - NMEA 4.10+ GNSS System ID, u-blox extended, Quectel $PQ |
1687 | | * 0 = QZSS (Trimble only) |
1688 | | * 1 = GPS |
1689 | | * 2 = GLONASS |
1690 | | * 3 = Galileo |
1691 | | * 4 = BeiDou |
1692 | | * 5 = QZSS |
1693 | | * 6 - NavIC (IRNSS) |
1694 | | * -- OR -- |
1695 | | * 18 SiRF TriG puts a floating point number here. |
1696 | | * -- -- -- |
1697 | | * |
1698 | | * Not all documentation specifies the number of PRN fields, it |
1699 | | * may be variable. Most doc that specifies says 12 PRNs. |
1700 | | * |
1701 | | * The Navior-24 CH-4701 outputs 30 fields, 24 PRNs! |
1702 | | * GPGSA,A,3,27,23,13,07,25,,,,,,,,,,,,,,,,,,,,07.9,06.0,05.2 |
1703 | | * |
1704 | | * The Skytraq S2525F8-BD-RTK output both GPGSA and BDGSA in the |
1705 | | * same cycle: |
1706 | | * $GPGSA,A,3,23,31,22,16,03,07,,,,,,,1.8,1.1,1.4*3E |
1707 | | * $BDGSA,A,3,214,,,,,,,,,,,,1.8,1.1,1.4*18 |
1708 | | * These need to be combined like GPGSV and BDGSV |
1709 | | * |
1710 | | * The SiRF-TriG, found in their Atlas VI SoC, uses field 18 for |
1711 | | * something other than the NMEA gnss ID: |
1712 | | * $GPGSA,A,3,25,32,12,14,,,,,,,,,2.1,1.1,1.8,1.2*39 |
1713 | | * $BDGSA,A,3,02,03,04,,,,,,,,,,2.1,1.1,1.8,1.2*2D |
1714 | | * |
1715 | | * Some GPS emit GNGSA. So far we have not seen a GPS emit GNGSA |
1716 | | * and then another flavor of xxGSA |
1717 | | * |
1718 | | * Some Skytraq will emit all GPS in one GNGSA, Then follow with |
1719 | | * another GNGSA with the BeiDou birds. |
1720 | | * |
1721 | | * SEANEXX, SiRFstarIV, and others also do it twice in one cycle: |
1722 | | * $GNGSA,A,3,31,26,21,,,,,,,,,,3.77,2.55,2.77*1A |
1723 | | * $GNGSA,A,3,75,86,87,,,,,,,,,,3.77,2.55,2.77*1C |
1724 | | * seems like the first is GNSS and the second GLONASS |
1725 | | * |
1726 | | * u-blox 9 outputs one per GNSS on each cycle. Note the |
1727 | | * extra last parameter which is NMEA gnssid: |
1728 | | * $GNGSA,A,3,13,16,21,15,10,29,27,20,,,,,1.05,0.64,0.83,1*03 |
1729 | | * $GNGSA,A,3,82,66,81,,,,,,,,,,1.05,0.64,0.83,2*0C |
1730 | | * $GNGSA,A,3,07,12,33,,,,,,,,,,1.05,0.64,0.83,3*0A |
1731 | | * $GNGSA,A,3,13,12,22,19,08,21,,,,,,,1.05,0.64,0.83,4*0B |
1732 | | * Also note the NMEA 4.0 GLONASS PRN (82) in an NMEA 4.1 |
1733 | | * sentence. |
1734 | | * |
1735 | | * Another Quectel Querk. Note the extra field on the end. |
1736 | | * System ID, 4 = BeiDou, 5 = QZSS |
1737 | | * |
1738 | | * $PQGSA,A,3,12,,,,,,,,,,,,1.2,0.9,0.9,4*3C |
1739 | | * $PQGSA,A,3,,,,,,,,,,,,,1.2,0.9,0.9,5*3E |
1740 | | * NMEA 4.11 says they should use $BDGSA and $GQGSA |
1741 | | */ |
1742 | 0 | gps_mask_t mask = ONLINE_SET; |
1743 | 0 | char last_last_gsa_talker = session->nmea.last_gsa_talker; |
1744 | 0 | int nmea_gnssid = 0; |
1745 | | |
1746 | | /* |
1747 | | * One chipset called the i.Trek M3 issues GPGSA lines that look like |
1748 | | * this: "$GPGSA,A,1,,,,*32" when it has no fix. This is broken |
1749 | | * in at least two ways: it's got the wrong number of fields, and |
1750 | | * it claims to be a valid sentence (A flag) when it isn't. |
1751 | | * Alarmingly, it's possible this error may be generic to SiRFstarIII. |
1752 | | */ |
1753 | 0 | if (session->nmea.latch_mode) { |
1754 | | // last GGA had a non-advancing timestamp; don't trust this GSA |
1755 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1756 | 0 | "NMEA0183: %s: non-advancing timestamp\n", field[0]); |
1757 | | // FIXME: return here? |
1758 | 0 | } else { |
1759 | 0 | int i; |
1760 | |
|
1761 | 0 | i = atoi(field[2]); |
1762 | | /* |
1763 | | * The first arm of this conditional ignores dead-reckoning |
1764 | | * fixes from an Antaris chipset. which returns E in field 2 |
1765 | | * for a dead-reckoning estimate. Fix by Andreas Stricker. |
1766 | | */ |
1767 | 0 | if (1 <= i && |
1768 | 0 | 3 >= i) { |
1769 | 0 | session->newdata.mode = i; |
1770 | 0 | mask = MODE_SET; |
1771 | |
|
1772 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1773 | 0 | "NMEA0183: %s sets mode %d\n", |
1774 | 0 | field[0], session->newdata.mode); |
1775 | 0 | } |
1776 | |
|
1777 | | #if 0 // debug |
1778 | | GPSD_LOG(LOG_SHOUT, &session->context->errout, |
1779 | | "NMEA0183: %s: count %d \n", field[0], count); |
1780 | | #endif // debug |
1781 | 0 | if (19 < count) { |
1782 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
1783 | 0 | "NMEA0183: %s: count %d too long!\n", field[0], count); |
1784 | 0 | } else { |
1785 | 0 | double dop; |
1786 | | |
1787 | | // Just ignore the last fields of the Navior CH-4701 |
1788 | | |
1789 | | // BT-451 sends 99.99 for invalid DOPs |
1790 | | // Jackson Labs send 99.00 for invalid DOPs |
1791 | | // Skytraq send 0.00 for invalid DOPs |
1792 | 0 | if ('\0' != field[15][0]) { |
1793 | 0 | dop = safe_atof(field[15]); |
1794 | 0 | if (IN(0.01, dop, 89.99)) { |
1795 | 0 | session->gpsdata.dop.pdop = dop; |
1796 | 0 | mask |= DOP_SET; |
1797 | 0 | } |
1798 | 0 | } |
1799 | 0 | if ('\0' != field[16][0]) { |
1800 | 0 | dop = safe_atof(field[16]); |
1801 | 0 | if (IN(0.01, dop, 89.99)) { |
1802 | 0 | session->gpsdata.dop.hdop = dop; |
1803 | 0 | mask |= DOP_SET; |
1804 | 0 | } |
1805 | 0 | } |
1806 | 0 | if ('\0' != field[17][0]) { |
1807 | 0 | dop = safe_atof(field[17]); |
1808 | 0 | if (IN(0.01, dop, 89.99)) { |
1809 | 0 | session->gpsdata.dop.vdop = dop; |
1810 | 0 | mask |= DOP_SET; |
1811 | 0 | } |
1812 | 0 | } |
1813 | 0 | if (19 == count && |
1814 | 0 | '\0' != field[18][0]) { |
1815 | 0 | if (NULL != strchr(field[18], '.')) { |
1816 | | // SiRF TriG puts a floating point in field 18 |
1817 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
1818 | 0 | "NMEA0183: %s: illegal field 18 (%s)!\n", |
1819 | 0 | field[0], field[18]); |
1820 | 0 | } else { |
1821 | | // get the NMEA 4.10, or $PQGSA, system ID |
1822 | 0 | nmea_gnssid = atoi(field[18]); |
1823 | 0 | } |
1824 | 0 | } |
1825 | 0 | } |
1826 | | /* |
1827 | | * might have gone from GPGSA to GLGSA/BDGSA |
1828 | | * or GNGSA to GNGSA |
1829 | | * or GNGSA to PQGSA |
1830 | | * in which case accumulate |
1831 | | */ |
1832 | | // FIXME: maybe on clear on first GPGSA? |
1833 | 0 | if ('\0' == session->nmea.last_gsa_talker || |
1834 | 0 | (GSA_TALKER == session->nmea.last_gsa_talker && |
1835 | 0 | 'N' != GSA_TALKER && |
1836 | 0 | 'Q' != GSA_TALKER) ) { |
1837 | 0 | session->gpsdata.satellites_used = 0; |
1838 | 0 | memset(session->nmea.sats_used, 0, sizeof(session->nmea.sats_used)); |
1839 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1840 | 0 | "NMEA0183: %s: clear sats_used\n", field[0]); |
1841 | 0 | } |
1842 | 0 | session->nmea.last_gsa_talker = GSA_TALKER; |
1843 | | |
1844 | | /* figure out which constellation(s) this GSA is for by looking |
1845 | | * at the talker ID. */ |
1846 | 0 | switch (session->nmea.last_gsa_talker) { |
1847 | 0 | case 'A': |
1848 | | // GA Galileo |
1849 | 0 | nmea_gnssid = 3; |
1850 | 0 | session->nmea.seen_gagsa = true; |
1851 | 0 | break; |
1852 | 0 | case 'B': |
1853 | | // GB BeiDou |
1854 | 0 | FALLTHROUGH |
1855 | 0 | case 'D': |
1856 | | // BD BeiDou |
1857 | 0 | nmea_gnssid = 4; |
1858 | 0 | session->nmea.seen_bdgsa = true; |
1859 | 0 | break; |
1860 | 0 | case 'I': |
1861 | | // GI IRNSS |
1862 | 0 | nmea_gnssid = 6; |
1863 | 0 | session->nmea.seen_gigsa = true; |
1864 | 0 | break; |
1865 | 0 | case 'L': |
1866 | | // GL GLONASS |
1867 | 0 | nmea_gnssid = 2; |
1868 | 0 | session->nmea.seen_glgsa = true; |
1869 | 0 | break; |
1870 | 0 | case 'N': |
1871 | | // GN GNSS |
1872 | 0 | session->nmea.seen_gngsa = true; |
1873 | | // field 18 is the NMEA gnssid in 4.10 and up. |
1874 | | // nmea_gnssid set above |
1875 | 0 | break; |
1876 | 0 | case 'P': |
1877 | | // GP GPS |
1878 | 0 | session->nmea.seen_gpgsa = true; |
1879 | 0 | nmea_gnssid = 1; |
1880 | 0 | break; |
1881 | 0 | case 'Q': |
1882 | | // Quectel EC25 & EC21 use PQGSA for QZSS and GLONASS |
1883 | 0 | if ('P' == field[0][0] && |
1884 | 0 | 0 != nmea_gnssid) { |
1885 | | /* Quectel EC25 & EC21 use PQGSV for BeiDou or QZSS |
1886 | | * nmea_gnssid set above. What about seen? |
1887 | | */ |
1888 | 0 | break; |
1889 | 0 | } |
1890 | 0 | FALLTHROUGH |
1891 | 0 | case 'Z': // QZ QZSS |
1892 | | // NMEA 4.11 GQGSA for QZSS |
1893 | 0 | nmea_gnssid = 5; |
1894 | 0 | session->nmea.seen_qzgsa = true; |
1895 | 0 | break; |
1896 | 0 | } |
1897 | | |
1898 | | /* The magic 6 here is the tag, two mode fields, and three DOP fields. |
1899 | | * Maybe 7, NMEA 4.10+, also has gnssid field. */ |
1900 | 0 | for (i = 0; i < count - 6; i++) { |
1901 | 0 | int prn; |
1902 | 0 | int n; |
1903 | 0 | int nmea_satnum; // almost svid... |
1904 | 0 | unsigned char ubx_gnssid; // UNUSED |
1905 | 0 | unsigned char ubx_svid; // UNUSED |
1906 | | |
1907 | | // skip empty fields, otherwise empty becomes prn=200 |
1908 | 0 | if ('\0' == field[i + 3][0]) { |
1909 | 0 | continue; |
1910 | 0 | } |
1911 | 0 | if (NULL != strchr(field[i + 3], '.')) { |
1912 | | // found a float, must be PDOP, done. |
1913 | 0 | break; |
1914 | 0 | } |
1915 | 0 | nmea_satnum = atoi(field[i + 3]); |
1916 | 0 | if (1 > nmea_satnum || |
1917 | 0 | 600 < nmea_satnum) { |
1918 | 0 | continue; |
1919 | 0 | } |
1920 | 0 | prn = nmeaid_to_prn(field[0], nmea_satnum, nmea_gnssid, |
1921 | 0 | &ubx_gnssid, &ubx_svid); |
1922 | |
|
1923 | | #if 0 // debug |
1924 | | GPSD_LOG(LOG_SHOUT, &session->context->errout, |
1925 | | "NMEA0183: %s PRN %d nmea_gnssid %d " |
1926 | | "nmea_satnum %d ubx_gnssid %d ubx_svid %d count %d \n", |
1927 | | field[0], prn, nmea_gnssid, nmea_satnum, ubx_gnssid, |
1928 | | ubx_svid, count); |
1929 | | #endif // debug |
1930 | |
|
1931 | 0 | if (0 >= prn) { |
1932 | | // huh? |
1933 | 0 | continue; |
1934 | 0 | } |
1935 | | // check first BEFORE over-writing memory |
1936 | 0 | if (MAXCHANNELS <= session->gpsdata.satellites_used) { |
1937 | | /* This should never happen as xxGSA is limited to 12, |
1938 | | * except for the Navior-24 CH-4701. |
1939 | | * But it could happen with multiple GSA per cycle */ |
1940 | 0 | GPSD_LOG(LOG_ERROR, &session->context->errout, |
1941 | 0 | "NMEA0183: %s used >= MAXCHANNELS!\n", field[0]); |
1942 | 0 | break; |
1943 | 0 | } |
1944 | | /* check for duplicate. |
1945 | | * Often GPS in both $GPGSA and $GNGSA, for example Quectel. */ |
1946 | 0 | for (n = 0; n < MAXCHANNELS; n++) { |
1947 | 0 | if ( 0 == session->nmea.sats_used[n]) { |
1948 | | // unused slot, use it. |
1949 | 0 | session->nmea.sats_used[n] = (unsigned short)prn; |
1950 | 0 | session->gpsdata.satellites_used = n + 1; |
1951 | 0 | break; |
1952 | 0 | } |
1953 | 0 | if (session->nmea.sats_used[n] == (unsigned short)prn) { |
1954 | | // Duplicate! |
1955 | 0 | break; |
1956 | 0 | } |
1957 | 0 | } |
1958 | 0 | } |
1959 | 0 | mask |= USED_IS; |
1960 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1961 | 0 | "NMEA0183: %s: mode=%d used=%d pdop=%.2f hdop=%.2f " |
1962 | 0 | "vdop=%.2f nmea_gnssid %d\n", |
1963 | 0 | field[0], session->newdata.mode, |
1964 | 0 | session->gpsdata.satellites_used, |
1965 | 0 | session->gpsdata.dop.pdop, |
1966 | 0 | session->gpsdata.dop.hdop, |
1967 | 0 | session->gpsdata.dop.vdop, nmea_gnssid); |
1968 | 0 | } |
1969 | | // assumes GLGSA or BDGSA, if present, is emitted directly after the GPGSA |
1970 | 0 | if ((session->nmea.seen_bdgsa || |
1971 | 0 | session->nmea.seen_gagsa || |
1972 | 0 | session->nmea.seen_gigsa || |
1973 | 0 | session->nmea.seen_glgsa || |
1974 | 0 | session->nmea.seen_gngsa || |
1975 | 0 | session->nmea.seen_qzgsa) && |
1976 | 0 | GSA_TALKER == 'P') { |
1977 | 0 | mask = ONLINE_SET; |
1978 | 0 | } else if ('N' != last_last_gsa_talker && |
1979 | 0 | 'N' == GSA_TALKER) { |
1980 | | /* first of two GNGSA |
1981 | | * if mode == 1 some GPS only output 1 GNGSA, so ship mode always */ |
1982 | 0 | mask = ONLINE_SET | MODE_SET; |
1983 | 0 | } |
1984 | | |
1985 | | // cast for 32/64 compatibility |
1986 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
1987 | 0 | "NMEA0183: %s: count %d visible %d used %d mask %#llx\n", |
1988 | 0 | field[0], count, session->gpsdata.satellites_used, |
1989 | 0 | session->gpsdata.satellites_used, |
1990 | 0 | (long long unsigned)mask); |
1991 | 0 | return mask; |
1992 | 0 | #undef GSA_TALKER |
1993 | 0 | } |
1994 | | |
1995 | | // GST - GPS Pseudorange Noise Statistics |
1996 | | static gps_mask_t processGST(int count, char *field[], |
1997 | | struct gps_device_t *session) |
1998 | 0 | { |
1999 | | /* |
2000 | | * GST,hhmmss.ss,x,x,x,x,x,x,x,*hh |
2001 | | * 1 UTC time of associated GGA fix |
2002 | | * 2 Total RMS standard deviation of ranges inputs to the nav solution |
2003 | | * 3 Standard deviation (meters) of semi-major axis of error ellipse |
2004 | | * 4 Standard deviation (meters) of semi-minor axis of error ellipse |
2005 | | * 5 Orientation of semi-major axis of error ellipse (true north degrees) |
2006 | | * 6 Standard deviation (meters) of latitude error |
2007 | | * 7 Standard deviation (meters) of longitude error |
2008 | | * 8 Standard deviation (meters) of altitude error |
2009 | | * 9 Checksum |
2010 | | */ |
2011 | 0 | struct tm date = {0}; |
2012 | 0 | timespec_t ts; |
2013 | 0 | int ret; |
2014 | 0 | char ts_buf[TIMESPEC_LEN]; |
2015 | 0 | gps_mask_t mask = ONLINE_SET; |
2016 | |
|
2017 | 0 | if (0 > count) { |
2018 | 0 | return mask; |
2019 | 0 | } |
2020 | | |
2021 | | // since it is NOT current time, do not register_fractional_time() |
2022 | | // compute start of today |
2023 | 0 | if (0 < session->nmea.date.tm_year) { |
2024 | | // Do not bother if no current year |
2025 | 0 | memset(&date, 0, sizeof(date)); |
2026 | 0 | date.tm_year = session->nmea.date.tm_year; |
2027 | 0 | date.tm_mon = session->nmea.date.tm_mon; |
2028 | 0 | date.tm_mday = session->nmea.date.tm_mday; |
2029 | | |
2030 | | /* note this is not full UTC, just HHMMSS.ss |
2031 | | * this is not the current time, |
2032 | | * it references another GPA of the same stamp. So do not set |
2033 | | * any time stamps with it */ |
2034 | 0 | ret = decode_hhmmss(&date, &ts.tv_nsec, field[1], session); |
2035 | 0 | } else { |
2036 | 0 | ret = 1; |
2037 | 0 | } |
2038 | 0 | if (0 == ret) { |
2039 | | // convert to timespec_t , tv_nsec already set |
2040 | 0 | session->gpsdata.gst.utctime.tv_sec = mkgmtime(&date); |
2041 | 0 | session->gpsdata.gst.utctime.tv_nsec = ts.tv_nsec; |
2042 | 0 | } else { |
2043 | | // no idea of UTC time now |
2044 | 0 | session->gpsdata.gst.utctime.tv_sec = 0; |
2045 | 0 | session->gpsdata.gst.utctime.tv_nsec = 0; |
2046 | 0 | } |
2047 | 0 | session->gpsdata.gst.rms_deviation = safe_atof(field[2]); |
2048 | 0 | session->gpsdata.gst.smajor_deviation = safe_atof(field[3]); |
2049 | 0 | session->gpsdata.gst.sminor_deviation = safe_atof(field[4]); |
2050 | 0 | session->gpsdata.gst.smajor_orientation = safe_atof(field[5]); |
2051 | 0 | session->gpsdata.gst.lat_err_deviation = safe_atof(field[6]); |
2052 | 0 | session->gpsdata.gst.lon_err_deviation = safe_atof(field[7]); |
2053 | 0 | session->gpsdata.gst.alt_err_deviation = safe_atof(field[8]); |
2054 | |
|
2055 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
2056 | 0 | "NMEA0183: GST: utc = %s, rms = %.2f, maj = %.2f, min = %.2f," |
2057 | 0 | " ori = %.2f, lat = %.2f, lon = %.2f, alt = %.2f\n", |
2058 | 0 | timespec_str(&session->gpsdata.gst.utctime, ts_buf, |
2059 | 0 | sizeof(ts_buf)), |
2060 | 0 | session->gpsdata.gst.rms_deviation, |
2061 | 0 | session->gpsdata.gst.smajor_deviation, |
2062 | 0 | session->gpsdata.gst.sminor_deviation, |
2063 | 0 | session->gpsdata.gst.smajor_orientation, |
2064 | 0 | session->gpsdata.gst.lat_err_deviation, |
2065 | 0 | session->gpsdata.gst.lon_err_deviation, |
2066 | 0 | session->gpsdata.gst.alt_err_deviation); |
2067 | |
|
2068 | 0 | mask = GST_SET | ONLINE_SET; |
2069 | 0 | return mask; |
2070 | 0 | } |
2071 | | |
2072 | | // xxGSV - GPS Satellites in View |
2073 | | static gps_mask_t processGSV(int count, char *field[], |
2074 | | struct gps_device_t *session) |
2075 | 0 | { |
2076 | 0 | #define GSV_TALKER field[0][1] |
2077 | | /* |
2078 | | * GSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75 |
2079 | | * 1) 2 Number of sentences for full data |
2080 | | * 2) 1 Sentence 1 of 2 |
2081 | | * 3) 08 Total number of satellites in view |
2082 | | * 4) 01 Satellite PRN number |
2083 | | * 5) 40 Elevation, degrees |
2084 | | * 6) 083 Azimuth, degrees |
2085 | | * 7) 46 Signal-to-noise ratio in decibels |
2086 | | * <repeat for up to 4 satellites per sentence> |
2087 | | * m - 1) NMEA 4.10 Signal Id (optional) |
2088 | | * Quecktel Querk: 0 for "All Signa;s". |
2089 | | * m=n-1) Quectel Querk: System ID (optional) |
2090 | | * 4 = BeiDou, 5 = QZSS |
2091 | | * n) checksum |
2092 | | * |
2093 | | * NMEA 4.1+: |
2094 | | * $GAGSV,3,1,09,02,00,179,,04,09,321,,07,11,134,11,11,10,227,,7*7F |
2095 | | * after the satellite block, before the checksum, new field: |
2096 | | * NMEA Signal ID, depends on constellation. |
2097 | | & see include/gps.h |
2098 | | * |
2099 | | * Quectel Querk: |
2100 | | * $PQGSV,4,2,15,09,16,120,,10,26,049,,16,07,123,,19,34,212,,0,4*62 |
2101 | | * after the Signal ID, before the checksum, new field: |
2102 | | * System ID |
2103 | | * 4 = BeiDou |
2104 | | * 5 = QZSS |
2105 | | * |
2106 | | * Can occur with talker IDs: |
2107 | | * BD (Beidou), |
2108 | | * GA (Galileo), |
2109 | | * GB (Beidou), |
2110 | | * GI (IRNSS), |
2111 | | * GL (GLONASS), |
2112 | | * GN (GLONASS, any combination GNSS), |
2113 | | * GP (GPS, SBAS, QZSS), |
2114 | | * GQ (QZSS). |
2115 | | * PQ (QZSS). Quectel Querk. BeiDou or QZSS |
2116 | | * QZ (QZSS). |
2117 | | * |
2118 | | * As of April 2019: |
2119 | | * no gpsd regressions have GNGSV |
2120 | | * every xxGSV cycle starts with GPGSV |
2121 | | * xxGSV cycles may be spread over several xxRMC cycles |
2122 | | * |
2123 | | * GL may be (incorrectly) used when GSVs are mixed containing |
2124 | | * GLONASS, GN may be (incorrectly) used when GSVs contain GLONASS |
2125 | | * only. Usage is inconsistent. |
2126 | | * |
2127 | | * In the GLONASS version sat IDs run from 65-96 (NMEA0183 |
2128 | | * standardizes this). At least two GPSes, the BU-353 GLONASS and |
2129 | | * the u-blox NEO-M8N, emit a GPGSV set followed by a GLGSV set. |
2130 | | * We have also seen two GPSes, the Skytraq S2525F8-BD-RTK and a |
2131 | | * SiRF-IV variant, that emit GPGSV followed by BDGSV. We need to |
2132 | | * combine these. |
2133 | | * |
2134 | | * The following shows how the Skytraq S2525F8-BD-RTK output both |
2135 | | * GPGSV and BDGSV in the same cycle: |
2136 | | * $GPGSV,4,1,13,23,66,310,29,03,65,186,33,26,43,081,27,16,41,124,38*78 |
2137 | | * $GPGSV,4,2,13,51,37,160,38,04,37,066,25,09,34,291,07,22,26,156,37*77 |
2138 | | * $GPGSV,4,3,13,06,19,301,,31,17,052,20,193,11,307,,07,11,232,27*4F |
2139 | | * $GPGSV,4,4,13,01,03,202,30*4A |
2140 | | * $BDGSV,1,1,02,214,55,153,40,208,01,299,*67 |
2141 | | * |
2142 | | * The driver automatically adapts to either case, but it takes until the |
2143 | | * second cycle (usually 10 seconds from device connect) for it to |
2144 | | * learn to expect BDGSV or GLGSV. |
2145 | | * |
2146 | | * Some GPS (Garmin 17N) spread the xxGSV over several cycles. So |
2147 | | * cycles, or cycle time, can not be used to determine start of |
2148 | | * xxGSV cycle. |
2149 | | * |
2150 | | * NMEA 4.1 adds a signal-ID field just before the checksum. First |
2151 | | * seen in May 2015 on a u-blox M8. It can output 2 sets of GPGSV |
2152 | | * in one cycle, one for L1C and the other for L2C. |
2153 | | * |
2154 | | * Once again, Quectel is Querky. They added the $PQGSV sentence |
2155 | | * to handle what NMEA 4.11 says should be in the $BDGSV and $GQGSV |
2156 | | * sentences. $PQGSV adds a new field just before the checksum for the |
2157 | | * System ID. This field is set to 4 for BeiDou, or 5 for QZSS. The EG25 |
2158 | | * output can look like this: |
2159 | | * |
2160 | | * $GLGSV,2,1,08,78,37,039,22,79,53,317,21,69,56,275,20,88,23,077,18,1*7A |
2161 | | * $GLGSV,2,2,08,87,11,030,17,68,37,195,21,70,11,331,,81,13,129,,1*79 |
2162 | | * $PQGSV,4,1,15,02,20,116,,03,,,,05,34,137,,07,05,046,,0,4*58 |
2163 | | * $PQGSV,4,2,15,09,16,120,,10,26,049,,16,07,123,,19,34,212,,0,4*62 |
2164 | | * $PQGSV,4,3,15,20,03,174,,21,05,324,,22,37,281,,27,28,085,,0,4*65 |
2165 | | * $PQGSV,4,4,15,28,07,039,,29,,,,30,23,143,,0,4*67 |
2166 | | * $GAGSV,1,1,02,04,53,296,,09,05,322,,7*71 |
2167 | | * $GPGSV,3,1,10,13,80,247,17,14,47,043,19,15,48,295,20,17,48,108,17,1*62 |
2168 | | * $GPGSV,3,2,10,19,36,151,18,30,32,087,18,05,14,230,,07,03,098,,1*65 |
2169 | | * $GPGSV,3,3,10,12,00,234,,24,13,295,,1*69 |
2170 | | * |
2171 | | * Skytraq PX1172RH_DS can output GPGSV, GLGSV, GAGSV and GBGSV all in |
2172 | | * same epoch. And each of those repeated for different signals |
2173 | | * (L1C/L2C/etc.) |
2174 | | */ |
2175 | |
|
2176 | 0 | int n, fldnum; |
2177 | 0 | unsigned char nmea_sigid = 0; |
2178 | 0 | int nmea_gnssid = 0; |
2179 | 0 | unsigned char ubx_sigid = 0; |
2180 | |
|
2181 | 0 | if (3 >= count) { |
2182 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2183 | 0 | "NMEA0183: %s, malformed - fieldcount %d <= 3\n", |
2184 | 0 | field[0], count); |
2185 | 0 | gpsd_zero_satellites(&session->gpsdata); |
2186 | 0 | return ONLINE_SET; |
2187 | 0 | } |
2188 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2189 | 0 | "NMEA0183: %s: part %s of %s, last_gsv_talker '%#x' " |
2190 | 0 | " last_gsv_sigid %u\n", |
2191 | 0 | field[0], field[2], field[1], |
2192 | 0 | session->nmea.last_gsv_talker, |
2193 | 0 | session->nmea.last_gsv_sigid); |
2194 | | |
2195 | | /* |
2196 | | * This check used to be !=0, but we have loosen it a little to let by |
2197 | | * NMEA 4.1 GSVs with an extra signal-ID field at the end. Then loosen |
2198 | | * some more for Quectel Querky $PQGSV. |
2199 | | */ |
2200 | 0 | switch (count % 4) { |
2201 | 0 | case 0: |
2202 | | // normal, pre-NMEA 4.10 |
2203 | 0 | break; |
2204 | 0 | case 1: |
2205 | | // NMEA 4.10, get the signal ID |
2206 | 0 | nmea_sigid = atoi(field[count - 1]); |
2207 | 0 | ubx_sigid = nmea_sigid_to_ubx(session, nmea_sigid); |
2208 | 0 | break; |
2209 | 0 | case 2: |
2210 | | // Quectel Querk. $PQGSV, get the signal ID, and system ID |
2211 | 0 | nmea_sigid = atoi(field[count - 2]); |
2212 | 0 | ubx_sigid = nmea_sigid_to_ubx(session, nmea_sigid); |
2213 | 0 | nmea_gnssid = atoi(field[count - 1]); |
2214 | 0 | if (4 > nmea_gnssid || |
2215 | 0 | 5 < nmea_gnssid) { |
2216 | | // Quectel says only 4 or 5 |
2217 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2218 | 0 | "NMEA0183: %sm invalid nmea_gnssid %d\n", |
2219 | 0 | field[0], nmea_gnssid); |
2220 | 0 | return ONLINE_SET; |
2221 | 0 | } |
2222 | 0 | break; |
2223 | 0 | default: |
2224 | | // bad count |
2225 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2226 | 0 | "NMEA0183: malformed %s - fieldcount(%d)\n", |
2227 | 0 | field[0], count); |
2228 | 0 | gpsd_zero_satellites(&session->gpsdata); |
2229 | 0 | return ONLINE_SET; |
2230 | 0 | } |
2231 | | |
2232 | 0 | session->nmea.await = atoi(field[1]); |
2233 | 0 | session->nmea.part = atoi(field[2]); |
2234 | 0 | if (1 > session->nmea.part) { |
2235 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2236 | 0 | "NMEA0183: %s: malformed - bad part %d\n", |
2237 | 0 | field[0], session->nmea.part); |
2238 | 0 | gpsd_zero_satellites(&session->gpsdata); |
2239 | 0 | return ONLINE_SET; |
2240 | 0 | } |
2241 | | |
2242 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2243 | 0 | "NMEA0183: %s: part %d of %d nmea_gnssid %d nmea_sigid %d " |
2244 | 0 | "ubx_sigid %d\n", |
2245 | 0 | field[0], session->nmea.part, session->nmea.await, |
2246 | 0 | nmea_gnssid, nmea_sigid, ubx_sigid); |
2247 | |
|
2248 | 0 | if (1 == session->nmea.part) { |
2249 | | /* |
2250 | | * might have gone from GPGSV to GLGSV/BDGSV/QZGSV, |
2251 | | * in which case accumulate |
2252 | | * |
2253 | | * NMEA 4.1 might have gone from GPGVS,sigid=x to GPGSV,sigid=y |
2254 | | * |
2255 | | * Quectel EG25 can go GLGSV, PQGSV, GAGSV, GPGSV, in one cycle. |
2256 | | * |
2257 | | * session->nmea.last_gsv_talker is zero at cycle start |
2258 | | */ |
2259 | 0 | if ('\0' == session->nmea.last_gsv_talker) { |
2260 | | // Assume all xxGSV in same epoch. Clear at 1st in eopoch. |
2261 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2262 | 0 | "NMEA0183: %s: new part %d, last_gsv_talker '%#x', " |
2263 | 0 | "zeroing\n", |
2264 | 0 | field[0], |
2265 | 0 | session->nmea.part, |
2266 | 0 | session->nmea.last_gsv_talker); |
2267 | 0 | gpsd_zero_satellites(&session->gpsdata); |
2268 | 0 | } |
2269 | 0 | } |
2270 | |
|
2271 | 0 | session->nmea.last_gsv_talker = GSV_TALKER; |
2272 | 0 | session->nmea.last_gsv_sigid = ubx_sigid; // UNUSED |
2273 | 0 | switch (GSV_TALKER) { |
2274 | 0 | case 'A': // GA Galileo |
2275 | 0 | nmea_gnssid = 3; |
2276 | | // Quectel LC79D can have sigid 6 (L1-A) and 1 (E5a) |
2277 | 0 | session->nmea.seen_gagsv = true; |
2278 | 0 | break; |
2279 | 0 | case 'B': // GB BeiDou |
2280 | 0 | FALLTHROUGH |
2281 | 0 | case 'D': // BD BeiDou |
2282 | 0 | nmea_gnssid = 4; |
2283 | 0 | session->nmea.seen_bdgsv = true; |
2284 | 0 | break; |
2285 | 0 | case 'I': // GI IRNSS |
2286 | 0 | nmea_gnssid = 6; |
2287 | 0 | session->nmea.seen_gigsv = true; |
2288 | 0 | break; |
2289 | 0 | case 'L': // GL GLONASS |
2290 | 0 | nmea_gnssid = 2; |
2291 | 0 | session->nmea.seen_glgsv = true; |
2292 | 0 | break; |
2293 | 0 | case 'N': // GN GNSS |
2294 | 0 | session->nmea.seen_gngsv = true; |
2295 | 0 | break; |
2296 | 0 | case 'P': // GP GPS |
2297 | 0 | session->nmea.seen_gpgsv = true; |
2298 | 0 | break; |
2299 | 0 | case 'Q': // $GQ, and $PQ (Quectel Querk) QZSS |
2300 | 0 | if ('P' == field[0][0] && |
2301 | 0 | 0 != nmea_gnssid) { |
2302 | | /* Quectel EC25 & EC21 use PQGSV for BeiDou or QZSS |
2303 | | * 4 = BeiDou, 5 = QZSS |
2304 | | * nmea_gnssid set above, what about seen? |
2305 | | */ |
2306 | 0 | if (4 == nmea_gnssid) { |
2307 | 0 | session->nmea.seen_bdgsv = true; |
2308 | 0 | } else if (5 == nmea_gnssid) { |
2309 | 0 | session->nmea.seen_qzgsv = true; |
2310 | 0 | } else { |
2311 | 0 | GPSD_LOG(LOG_ERROR, &session->context->errout, |
2312 | 0 | "NMEA0183: %s: invalid nmea_gnssid %d\n", |
2313 | 0 | field[0], nmea_gnssid); |
2314 | 0 | return ONLINE_SET; |
2315 | 0 | } |
2316 | 0 | break; |
2317 | 0 | } |
2318 | | // else $GQ |
2319 | 0 | FALLTHROUGH |
2320 | 0 | case 'Z': // QZ QZSS |
2321 | 0 | nmea_gnssid = 5; |
2322 | 0 | session->nmea.seen_qzgsv = true; |
2323 | 0 | break; |
2324 | 0 | default: |
2325 | | // uh, what? |
2326 | 0 | break; |
2327 | 0 | } |
2328 | | |
2329 | 0 | for (fldnum = 4; fldnum < count / 4 * 4;) { |
2330 | 0 | struct satellite_t *sp; |
2331 | 0 | int nmea_svid; |
2332 | |
|
2333 | 0 | if (MAXCHANNELS <= session->gpsdata.satellites_visible) { |
2334 | 0 | GPSD_LOG(LOG_ERROR, &session->context->errout, |
2335 | 0 | "NMEA0183: %s: internal error - too many " |
2336 | 0 | "satellites [%d]!\n", |
2337 | 0 | field[0], session->gpsdata.satellites_visible); |
2338 | 0 | gpsd_zero_satellites(&session->gpsdata); |
2339 | 0 | break; |
2340 | 0 | } |
2341 | 0 | sp = &session->gpsdata.skyview[session->gpsdata.satellites_visible]; |
2342 | 0 | nmea_svid = atoi(field[fldnum++]); |
2343 | 0 | if (0 == nmea_svid) { |
2344 | | // skip bogus fields |
2345 | 0 | continue; |
2346 | 0 | } |
2347 | 0 | sp->PRN = (short)nmeaid_to_prn(field[0], nmea_svid, nmea_gnssid, |
2348 | 0 | &sp->gnssid, &sp->svid); |
2349 | |
|
2350 | 0 | sp->elevation = (double)atoi(field[fldnum++]); |
2351 | 0 | sp->azimuth = (double)atoi(field[fldnum++]); |
2352 | 0 | sp->ss = (double)atoi(field[fldnum++]); |
2353 | 0 | sp->used = false; |
2354 | 0 | sp->sigid = ubx_sigid; |
2355 | | |
2356 | | /* sadly NMEA 4.1 does not tell us which sigid (L1, L2) is |
2357 | | * used. So if the ss is zero, do not mark used */ |
2358 | 0 | if (0 < sp->PRN && |
2359 | 0 | 0 < sp->ss) { |
2360 | 0 | for (n = 0; n < MAXCHANNELS; n++) { |
2361 | 0 | if (session->nmea.sats_used[n] == (unsigned short)sp->PRN) { |
2362 | 0 | sp->used = true; |
2363 | 0 | break; |
2364 | 0 | } |
2365 | 0 | } |
2366 | 0 | } |
2367 | | #if 0 // debug |
2368 | | GPSD_LOG(LOG_SHOUT, &session->context->errout, |
2369 | | "NMEA0183: %s nmea_gnssid %d nmea_satnum %d ubx_gnssid %d " |
2370 | | "ubx_svid %d nmea2_prn %d az %.1f el %.1f used %d\n", |
2371 | | field[0], nmea_gnssid, nmea_svid, sp->gnssid, sp->svid, |
2372 | | sp->PRN, sp->elevation, sp->azimuth, sp->used); |
2373 | | #endif // debug |
2374 | | |
2375 | | /* |
2376 | | * Incrementing this unconditionally falls afoul of chipsets like |
2377 | | * the Motorola Oncore GT+ that emit empty fields at the end of the |
2378 | | * last sentence in a GPGSV set if the number of satellites is not |
2379 | | * a multiple of 4. |
2380 | | */ |
2381 | 0 | session->gpsdata.satellites_visible++; |
2382 | 0 | } |
2383 | |
|
2384 | | #if 0 // debug code |
2385 | | GPSD_LOG(LOG_SHOUT, &session->context->errout, |
2386 | | "NMEA0183: %s: vis %d bdgsv %d gagsv %d gigsv %d glgsv %d " |
2387 | | "gngsv %d qpgsv %d qzgsv %d\n", |
2388 | | field[0], |
2389 | | session->gpsdata.satellites_visible, |
2390 | | session->nmea.seen_bdgsv, |
2391 | | session->nmea.seen_gagsv, |
2392 | | session->nmea.seen_gigsv, |
2393 | | session->nmea.seen_glgsv, |
2394 | | session->nmea.seen_gngsv, |
2395 | | session->nmea.seen_gpgsv, |
2396 | | session->nmea.seen_qzgsv); |
2397 | | #endif // debug |
2398 | | |
2399 | | /* |
2400 | | * Alas, we can't sanity check field counts when there are multiple sat |
2401 | | * pictures, because the visible member counts *all* satellites - you |
2402 | | * get a bad result on the second and later SV spans. Note, this code |
2403 | | * assumes that if any of the special sat pics occur they come right |
2404 | | * after a stock GPGSV one. |
2405 | | * |
2406 | | * FIXME: Add per-talker totals so we can do this check properly. |
2407 | | */ |
2408 | 0 | if (!(session->nmea.seen_bdgsv || |
2409 | 0 | session->nmea.seen_gagsv || |
2410 | 0 | session->nmea.seen_gigsv || |
2411 | 0 | session->nmea.seen_glgsv || |
2412 | 0 | session->nmea.seen_gngsv || |
2413 | 0 | session->nmea.seen_qzgsv)) { |
2414 | 0 | if (session->nmea.part == session->nmea.await |
2415 | 0 | && atoi(field[3]) != session->gpsdata.satellites_visible) { |
2416 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2417 | 0 | "NMEA0183: %s field 3 value of %d != actual count %d\n", |
2418 | 0 | field[0], atoi(field[3]), |
2419 | 0 | session->gpsdata.satellites_visible); |
2420 | 0 | } |
2421 | 0 | } |
2422 | | |
2423 | | // not valid data until we've seen a complete set of parts |
2424 | 0 | if (session->nmea.part < session->nmea.await) { |
2425 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2426 | 0 | "NMEA0183: %s: Partial satellite data (%d of %d).\n", |
2427 | 0 | field[0], session->nmea.part, session->nmea.await); |
2428 | 0 | session->nmea.gsx_more = true; |
2429 | 0 | return ONLINE_SET; |
2430 | 0 | } |
2431 | 0 | session->nmea.gsx_more = false; |
2432 | | /* |
2433 | | * This sanity check catches an odd behavior of SiRFstarII receivers. |
2434 | | * When they can't see any satellites at all (like, inside a |
2435 | | * building) they sometimes cough up a hairball in the form of a |
2436 | | * GSV packet with all the azimuth entries 0 (but nonzero |
2437 | | * elevations). This behavior was observed under SiRF firmware |
2438 | | * revision 231.000.000_A2. |
2439 | | */ |
2440 | 0 | for (n = 0; n < session->gpsdata.satellites_visible; n++) { |
2441 | 0 | if (0 != session->gpsdata.skyview[n].azimuth) { |
2442 | | // odd? |
2443 | 0 | goto sane; |
2444 | 0 | } |
2445 | 0 | } |
2446 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2447 | 0 | "NMEA0183: %s: Satellite data no good (%d of %d).\n", |
2448 | 0 | field[0], session->nmea.part, session->nmea.await); |
2449 | 0 | gpsd_zero_satellites(&session->gpsdata); |
2450 | 0 | return ONLINE_SET; |
2451 | 0 | sane: |
2452 | 0 | session->gpsdata.skyview_time.tv_sec = 0; |
2453 | 0 | session->gpsdata.skyview_time.tv_nsec = 0; |
2454 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2455 | 0 | "NMEA0183: %s: Satellite data OK (%d of %d).\n", |
2456 | 0 | field[0], session->nmea.part, session->nmea.await); |
2457 | | |
2458 | | /* assumes GLGSV or BDGSV group, if present, is emitted after the GPGSV |
2459 | | * An assumption that Quectel breaks; The EG25 can send in one epoch: |
2460 | | * $GLGSV, $PQGSV, $GAGSV, then $GPGSV! */ |
2461 | 0 | if ((session->nmea.seen_bdgsv || |
2462 | 0 | session->nmea.seen_gagsv || |
2463 | 0 | session->nmea.seen_gigsv || |
2464 | 0 | session->nmea.seen_glgsv || |
2465 | 0 | session->nmea.seen_gngsv || |
2466 | 0 | session->nmea.seen_qzgsv) && |
2467 | 0 | ('P' == GSV_TALKER && |
2468 | 0 | 'P' != session->nmea.end_gsv_talker)) { |
2469 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2470 | 0 | "NMEA0183: %s: not end talker %d\n", |
2471 | 0 | field[0], session->nmea.end_gsv_talker); |
2472 | 0 | return ONLINE_SET; |
2473 | 0 | } |
2474 | | |
2475 | | #if 0 // debug code |
2476 | | { |
2477 | | char ts_buf[TIMESPEC_LEN]; |
2478 | | char ts_buf1[TIMESPEC_LEN]; |
2479 | | GPSD_LOG(LOG_SHOUT, &session->context->errout, |
2480 | | "NMEA0183: %s: set skyview_time %s frac_time %s\n", |
2481 | | field[0], |
2482 | | timespec_str(&session->gpsdata.skyview_time, ts_buf, |
2483 | | sizeof(ts_buf)), |
2484 | | timespec_str(&session->nmea.this_frac_time, ts_buf1, |
2485 | | sizeof(ts_buf1))); |
2486 | | } |
2487 | | #endif // debug |
2488 | | |
2489 | 0 | return SATELLITE_SET; |
2490 | 0 | #undef GSV_TALKER |
2491 | 0 | } |
2492 | | |
2493 | | /* |
2494 | | * Unicore $GYOACC MEMS Sensor DAta |
2495 | | * Note: Invalid sender: $GY |
2496 | | */ |
2497 | | static gps_mask_t processGYOACC(int c UNUSED, char *field[], |
2498 | | struct gps_device_t *session) |
2499 | 0 | { |
2500 | | /* |
2501 | | * $GYOACC,050624,002133.10,0.004634,0.000273,0.004348,100,-4.666065, |
2502 | | * -3.466573,7.960348,100,31,0,100,0*02 |
2503 | | */ |
2504 | 0 | gps_mask_t mask = ONLINE_SET; |
2505 | 0 | double gyroX = safe_atof(field[3]); // deg/s |
2506 | 0 | double gyroY = safe_atof(field[4]); // deg/s |
2507 | 0 | double gyroZ = safe_atof(field[5]); // deg/s |
2508 | 0 | unsigned gyroPeriod = atoi(field[6]); // period in ms |
2509 | 0 | double accX = safe_atof(field[7]); // m/s^2 |
2510 | 0 | double accY = safe_atof(field[8]); // m/s^2 |
2511 | 0 | double accZ = safe_atof(field[9]); // m/s^2 |
2512 | 0 | unsigned accPeriod = atoi(field[10]); // period in ms |
2513 | 0 | int temp = atoi(field[11]); // temperature C |
2514 | 0 | unsigned speed = atoi(field[12]); // pulses |
2515 | 0 | unsigned pulsePeriod = atoi(field[13]); // period in ms |
2516 | 0 | unsigned fwd = atoi(field[14]); // 0 == forward, 1 == reverse |
2517 | 0 | struct tm date = {0}; |
2518 | 0 | timespec_t ts = {0}; |
2519 | | |
2520 | | // Not at the same rate at the GNSS epoch. So do not use session->nmea |
2521 | 0 | if (0 == decode_hhmmss(&date, &ts.tv_nsec, field[2], session) && |
2522 | 0 | 0 == decode_ddmmyy(&date, field[1], session)) { |
2523 | |
|
2524 | 0 | session->gpsdata.attitude.mtime.tv_sec = mkgmtime(&date); |
2525 | 0 | session->gpsdata.attitude.mtime.tv_nsec = ts.tv_nsec; |
2526 | 0 | } else { |
2527 | 0 | session->gpsdata.attitude.mtime.tv_sec = 0; |
2528 | 0 | session->gpsdata.attitude.mtime.tv_nsec = 0; |
2529 | 0 | } |
2530 | |
|
2531 | 0 | session->gpsdata.attitude.gyro_x = gyroX; |
2532 | 0 | session->gpsdata.attitude.gyro_y = gyroY; |
2533 | 0 | session->gpsdata.attitude.gyro_z = gyroZ; |
2534 | 0 | session->gpsdata.attitude.acc_x = accX; |
2535 | 0 | session->gpsdata.attitude.acc_y = accY; |
2536 | 0 | session->gpsdata.attitude.acc_z = accZ; |
2537 | 0 | mask |= ATTITUDE_SET; |
2538 | |
|
2539 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
2540 | 0 | "NMEA0183: $GYOACC time %lld.%09lld " |
2541 | 0 | "gyro X %.6f Y %.6f Z %.6f per %u " |
2542 | 0 | "acc X %.6f Y %.6f Z %.6f per %u " |
2543 | 0 | "temp %d speed %u per %u fwd %u\n", |
2544 | 0 | (long long)session->gpsdata.attitude.mtime.tv_sec, |
2545 | 0 | (long long)session->gpsdata.attitude.mtime.tv_nsec, |
2546 | 0 | gyroX, gyroY, gyroZ, gyroPeriod, |
2547 | 0 | accX, accY, accZ, accPeriod, |
2548 | 0 | temp, speed, pulsePeriod, fwd); |
2549 | 0 | return mask; |
2550 | 0 | } |
2551 | | |
2552 | | static gps_mask_t processHDG(int c UNUSED, char *field[], |
2553 | | struct gps_device_t *session) |
2554 | 0 | { |
2555 | | /* |
2556 | | * $SDHDG,234.6,,,1.3,E*34 |
2557 | | * |
2558 | | * $--HDG,h.h,d.d,a,v.v,a*hh<CR><LF> |
2559 | | * Magnetic sensor heading, degrees |
2560 | | * Magnetic deviation, degrees E/W |
2561 | | * Magnetic variation, degrees, E/W |
2562 | | * |
2563 | | * 1. To obtain Magnetic Heading: |
2564 | | * Add Easterly deviation (E) to Magnetic Sensor Reading |
2565 | | * Subtract Westerly deviation (W) from Magnetic Sensor Reading |
2566 | | * 2. To obtain True Heading: |
2567 | | * Add Easterly variation (E) to Magnetic Heading |
2568 | | * Subtract Westerly variation (W) from Magnetic Heading |
2569 | | * 3. Variation and deviation fields shall be null fields if unknown. |
2570 | | */ |
2571 | |
|
2572 | 0 | gps_mask_t mask = ONLINE_SET; |
2573 | 0 | double sensor_heading; |
2574 | 0 | double magnetic_deviation; |
2575 | |
|
2576 | 0 | if ('\0' == field[1][0]) { |
2577 | | // no data |
2578 | 0 | return mask; |
2579 | 0 | } |
2580 | 0 | sensor_heading = safe_atof(field[1]); |
2581 | 0 | if ((0.0 > sensor_heading) || |
2582 | 0 | (360.0 < sensor_heading)) { |
2583 | | // bad data */ |
2584 | 0 | return mask; |
2585 | 0 | } |
2586 | 0 | magnetic_deviation = safe_atof(field[2]); |
2587 | 0 | if ((0.0 > magnetic_deviation) || |
2588 | 0 | (360.0 < magnetic_deviation)) { |
2589 | | // bad data |
2590 | 0 | return mask; |
2591 | 0 | } |
2592 | 0 | switch (field[2][0]) { |
2593 | 0 | case 'E': |
2594 | 0 | sensor_heading += magnetic_deviation; |
2595 | 0 | break; |
2596 | 0 | case 'W': |
2597 | 0 | sensor_heading += magnetic_deviation; |
2598 | 0 | break; |
2599 | 0 | default: |
2600 | | // ignore |
2601 | 0 | break; |
2602 | 0 | } |
2603 | | |
2604 | | // good data |
2605 | 0 | session->newdata.magnetic_track = sensor_heading; |
2606 | 0 | mask |= MAGNETIC_TRACK_SET; |
2607 | | |
2608 | | // get magnetic variation |
2609 | 0 | if ('\0' != field[3][0] && |
2610 | 0 | '\0' != field[4][0]) { |
2611 | 0 | session->newdata.magnetic_var = safe_atof(field[3]); |
2612 | |
|
2613 | 0 | switch (field[4][0]) { |
2614 | 0 | case 'E': |
2615 | | // no change |
2616 | 0 | mask |= MAGNETIC_TRACK_SET; |
2617 | 0 | break; |
2618 | 0 | case 'W': |
2619 | 0 | session->newdata.magnetic_var = -session->newdata.magnetic_var; |
2620 | 0 | mask |= MAGNETIC_TRACK_SET; |
2621 | 0 | break; |
2622 | 0 | default: |
2623 | | // huh? |
2624 | 0 | session->newdata.magnetic_var = NAN; |
2625 | 0 | break; |
2626 | 0 | } |
2627 | 0 | } |
2628 | | |
2629 | | |
2630 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
2631 | 0 | "NMEA0183: $SDHDG heading %lf var %.1f\n", |
2632 | 0 | session->newdata.magnetic_track, |
2633 | 0 | session->newdata.magnetic_var); |
2634 | 0 | return mask; |
2635 | 0 | } |
2636 | | |
2637 | | /* precessHDM() - process magnetic headingxxHDM messages |
2638 | | * |
2639 | | * Deprecated by NMEA in 2008 |
2640 | | */ |
2641 | | static gps_mask_t processHDM(int c UNUSED, char *field[], |
2642 | | struct gps_device_t *session) |
2643 | 0 | { |
2644 | | /* |
2645 | | * $APHDM,218.634,M*39 |
2646 | | * |
2647 | | * 1) Magnetic heading |
2648 | | * 2) M == Magnetic |
2649 | | * ) checksum |
2650 | | * |
2651 | | */ |
2652 | 0 | gps_mask_t mask = ONLINE_SET; |
2653 | |
|
2654 | 0 | if ('\0' == field[1][0]) { |
2655 | | // no data |
2656 | 0 | return mask; |
2657 | 0 | } |
2658 | | |
2659 | | // assume good data |
2660 | 0 | session->gpsdata.attitude.mheading = safe_atof(field[1]); |
2661 | 0 | mask |= ATTITUDE_SET; |
2662 | |
|
2663 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2664 | 0 | "NMEA0183: $xxHDM: Magnetic heading %f\n", |
2665 | 0 | session->gpsdata.attitude.mheading); |
2666 | 0 | return mask; |
2667 | 0 | } |
2668 | | |
2669 | | static gps_mask_t processHDT(int c UNUSED, char *field[], |
2670 | | struct gps_device_t *session) |
2671 | 0 | { |
2672 | | /* |
2673 | | * $HEHDT,341.8,T*21 |
2674 | | * |
2675 | | * $xxHDT,x.x*hh<cr><lf> |
2676 | | * |
2677 | | * The only data field is true heading in degrees. |
2678 | | * The following field is required to be 'T' indicating a true heading. |
2679 | | * It is followed by a mandatory nmea_checksum. |
2680 | | */ |
2681 | 0 | gps_mask_t mask = ONLINE_SET; |
2682 | 0 | double heading; |
2683 | |
|
2684 | 0 | if ('\0' == field[1][0]) { |
2685 | | // no data |
2686 | 0 | return mask; |
2687 | 0 | } |
2688 | 0 | heading = safe_atof(field[1]); |
2689 | 0 | if (0.0 > heading || |
2690 | 0 | 360.0 < heading) { |
2691 | | // bad data |
2692 | 0 | return mask; |
2693 | 0 | } |
2694 | | // True heading |
2695 | 0 | session->gpsdata.attitude.heading = heading; |
2696 | |
|
2697 | 0 | mask |= ATTITUDE_SET; |
2698 | |
|
2699 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2700 | 0 | "NMEA0183: $xxHDT heading %lf.\n", |
2701 | 0 | session->gpsdata.attitude.heading); |
2702 | 0 | return mask; |
2703 | 0 | } |
2704 | | |
2705 | | /* $INFO, Inertial Sense product info |
2706 | | * Not a legal NMEA message name |
2707 | | * https://docs.inertialsense.com/user-manual/com-protocol/nmea/#info |
2708 | | */ |
2709 | | static gps_mask_t processINFO(int c UNUSED, char *field[], |
2710 | | struct gps_device_t *session) |
2711 | 0 | { |
2712 | | /* |
2713 | | * $INFO,928404541,1.0.2.0,2.2.2.0,-377462659,2.0.0.0,-53643429, |
2714 | | * Inertial Sense Inc,2025-01-10,16:06:13.50,GPX -1,4,0, *7D |
2715 | | * |
2716 | | * 1 Serial number Manufacturer serial number |
2717 | | * 2 Hardware version Hardware version |
2718 | | * 3 Firmware version Firmware version |
2719 | | * 4 Build number Firmware build number |
2720 | | * 5 Protocol version Communications protocol version |
2721 | | * 6 Repo revision Repository revision number |
2722 | | * 7 Manufacturer Manufacturer name |
2723 | | * 8 Build date Build date |
2724 | | * 9 Build time Build time |
2725 | | * 10 Add Info Additional information |
2726 | | * 11 Hardware Hardware: 1=uINS, 2=EVB, 3=IMX, 4=GPX |
2727 | | * 12 Reserved Reserved for internal purpose. |
2728 | | * 13 Build type Build type: |
2729 | | * 'a'=ALPHA, 'b'=BETA, 'c'=RELEASE CANDIDATE, 'r'=PRODUCTION RELEASE, |
2730 | | * 'd'=debug, ' '= ???? |
2731 | | */ |
2732 | | |
2733 | | // hardwaare |
2734 | 0 | static struct clist_t hardware[] = { |
2735 | 0 | {'1', "uISN"}, |
2736 | 0 | {'2', "EVB"}, |
2737 | 0 | {'3', "INX"}, |
2738 | 0 | {'4', "GPX"}, |
2739 | 0 | {'\0', NULL}, |
2740 | 0 | }; |
2741 | |
|
2742 | 0 | if ('\0' == session->subtype[0] && |
2743 | 0 | !session->context->passive) { |
2744 | | // first time seen, send init |
2745 | |
|
2746 | 0 | (void)nmea_send(session, "$STPC"); // stop all messages |
2747 | | |
2748 | | /* Enable all possible NMEA messages, at 1Hz |
2749 | | * 1 PIMU, 2 PPIMU, 3 PRIMU, 4 PINS1, 5 PINS2 |
2750 | | * 6 PGPSP, 7 GGA, 8 GLL, 9 GSA, 10 RMC, 11 ZDA, 12 PASHR |
2751 | | * 13 PSTRB, 14 INFO, 15 GSV, 16 VTG |
2752 | | * there are many more... |
2753 | | */ |
2754 | 0 | (void)nmea_send(session, |
2755 | 0 | "$ASCE,0," // Set current port |
2756 | 0 | "1,0," // PIMU |
2757 | 0 | "2,0," // PPIMU |
2758 | 0 | "3,0," // PRIMU |
2759 | 0 | "4,0," // PINS1 |
2760 | 0 | "5,0," // PINS2 |
2761 | 0 | "6,5," // PGPSP |
2762 | 0 | "7,5," // GGA |
2763 | 0 | "8,5," // GLL |
2764 | 0 | "9,5," // GSA |
2765 | 0 | "10,5," // RMC |
2766 | 0 | "11,5," // ZDA |
2767 | 0 | "12,5," // PASHR |
2768 | 0 | "13,5," // PSTRB |
2769 | 0 | "14,0," // INFO |
2770 | 0 | "15,5," // GSV |
2771 | 0 | "16,5," // VTG |
2772 | 0 | "17,5," // ? |
2773 | 0 | "18,5"); // ? |
2774 | 0 | } |
2775 | | |
2776 | | // save serial number |
2777 | 0 | strlcpy(session->gpsdata.dev.sernum, field[1], |
2778 | 0 | sizeof(session->gpsdata.dev.sernum)); |
2779 | | // save HW as subtype |
2780 | 0 | (void)snprintf(session->subtype, sizeof(session->subtype), |
2781 | 0 | "%s-%.11s", |
2782 | 0 | char2str(field[11][0], hardware), field[2]); |
2783 | | // save FW Version as subtype1 |
2784 | 0 | (void)snprintf(session->subtype1, sizeof(session->subtype1), |
2785 | 0 | "FW %.11s", |
2786 | 0 | field[3]); |
2787 | |
|
2788 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2789 | 0 | "NMEA0183: INFO: serial %s subtype %s subtype1 %s\n", |
2790 | 0 | session->gpsdata.dev.sernum, session->subtype, session->subtype1); |
2791 | |
|
2792 | 0 | return ONLINE_SET; |
2793 | 0 | } |
2794 | | |
2795 | | static gps_mask_t processMTW(int c UNUSED, char *field[], |
2796 | | struct gps_device_t *session) |
2797 | 0 | { |
2798 | | /* Water temp in degrees C |
2799 | | * $--MTW,x.x,C*hh<CR><LF> |
2800 | | * |
2801 | | * Fields in order: |
2802 | | * 1. water temp degrees C |
2803 | | * 2. C |
2804 | | * *hh mandatory nmea_checksum |
2805 | | */ |
2806 | 0 | gps_mask_t mask = ONLINE_SET; |
2807 | |
|
2808 | 0 | if ('\0' == field[1][0] || |
2809 | 0 | 'C' != field[2][0]) { |
2810 | | // no temp |
2811 | 0 | return mask; |
2812 | 0 | } |
2813 | 0 | session->newdata.wtemp = safe_atof(field[1]); |
2814 | |
|
2815 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2816 | 0 | "NMEA0183: %s temp %.1f C\n", |
2817 | 0 | field[0], session->newdata.wtemp); |
2818 | 0 | return mask; |
2819 | 0 | } |
2820 | | |
2821 | | static gps_mask_t processMWD(int c UNUSED, char *field[], |
2822 | | struct gps_device_t *session) |
2823 | 0 | { |
2824 | | /* |
2825 | | * xxMWD - Wind direction and speed |
2826 | | * $xxMWD,x.x,T,x.x,M,x.x,N,x.x,M*hh<cr><lf> |
2827 | | * Fields in order: |
2828 | | * 1. wind direction, 0 to 359, True |
2829 | | * 2. T |
2830 | | * 3. wind direction, 0 to 359, Magnetic |
2831 | | * 4. M |
2832 | | * 5. wind speed, knots |
2833 | | * 6. N |
2834 | | * 7. wind speed, meters/sec |
2835 | | * 8. M |
2836 | | * *hh mandatory nmea_checksum |
2837 | | */ |
2838 | 0 | gps_mask_t mask = ONLINE_SET; |
2839 | |
|
2840 | 0 | session->newdata.wanglet = safe_atof(field[1]); |
2841 | 0 | session->newdata.wanglem = safe_atof(field[3]); |
2842 | 0 | session->newdata.wspeedt = safe_atof(field[7]); |
2843 | 0 | mask |= NAVDATA_SET; |
2844 | |
|
2845 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
2846 | 0 | "NMEA0183: xxMWD wanglet %.2f wanglem %.2f wspeedt %.2f\n", |
2847 | 0 | session->newdata.wanglet, |
2848 | 0 | session->newdata.wanglem, |
2849 | 0 | session->newdata.wspeedt); |
2850 | 0 | return mask; |
2851 | 0 | } |
2852 | | |
2853 | | static gps_mask_t processMWV(int c UNUSED, char *field[], |
2854 | | struct gps_device_t *session) |
2855 | 0 | { |
2856 | | /* |
2857 | | * xxMWV - Wind speed and angle |
2858 | | * $xxMWV,x.x,a,x.x,a,A*hh<cr><lf> |
2859 | | * Fields in order: |
2860 | | * 1. wind angle, 0 to 359, True |
2861 | | * 2. R = Relative (apparent), T = Theoretical (calculated) |
2862 | | * Is T magnetic or true?? |
2863 | | * 3. wind speed |
2864 | | * 4. wind speed units K/M/N/S |
2865 | | * 6. A = Valid, V = invalid |
2866 | | * *hh mandatory nmea_checksum |
2867 | | */ |
2868 | 0 | gps_mask_t mask = ONLINE_SET; |
2869 | |
|
2870 | 0 | if (('R' == field[2][0]) && |
2871 | 0 | ('N' == field[4][0]) && |
2872 | 0 | ('A' == field[5][0])) { |
2873 | | // relative, knots, and valid |
2874 | 0 | session->newdata.wangler = safe_atof(field[1]); |
2875 | 0 | session->newdata.wspeedr = safe_atof(field[3]) * KNOTS_TO_MPS; |
2876 | 0 | mask |= NAVDATA_SET; |
2877 | 0 | } |
2878 | |
|
2879 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
2880 | 0 | "NMEA0183: xxMWV wangler %.2f wspeedr %.2f\n", |
2881 | 0 | session->newdata.wangler, |
2882 | 0 | session->newdata.wspeedr); |
2883 | 0 | return mask; |
2884 | 0 | } |
2885 | | |
2886 | | // PAIRxxx is Airoha, spunoff from Mediatek |
2887 | | |
2888 | | // PAIR001 -- ACK/NAK |
2889 | | static gps_mask_t processPAIR001(int c UNUSED, char *field[], |
2890 | | struct gps_device_t *session) |
2891 | 0 | { |
2892 | 0 | int reason; |
2893 | 0 | const char *reasons[] = { |
2894 | 0 | "Success", |
2895 | 0 | "In process, wait", |
2896 | 0 | "Failed", |
2897 | 0 | "Not supported", |
2898 | 0 | "Busy, try again.", |
2899 | 0 | "Unknown", // gpsd only |
2900 | 0 | }; |
2901 | | |
2902 | | // ACK / NACK |
2903 | 0 | reason = atoi(field[2]); |
2904 | 0 | if (4 == reason) { |
2905 | | // ACK |
2906 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
2907 | 0 | "NMEA0183: PAIR001, ACK: %s\n", field[1]); |
2908 | 0 | return ONLINE_SET; |
2909 | 0 | } |
2910 | | |
2911 | | // else, NACK |
2912 | 0 | if (0 > reason || |
2913 | 0 | 4 < reason) { |
2914 | | // WTF? |
2915 | 0 | reason = 5; |
2916 | 0 | } |
2917 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2918 | 0 | "NMEA0183: PAIR NACK: %s, reason: %s\n", |
2919 | 0 | field[1], reasons[reason]); |
2920 | |
|
2921 | 0 | return ONLINE_SET; |
2922 | 0 | } |
2923 | | |
2924 | | // PAIR010 -- Request Aiding |
2925 | | static gps_mask_t processPAIR010(int c UNUSED, char *field[], |
2926 | | struct gps_device_t *session) |
2927 | 0 | { |
2928 | 0 | int type; |
2929 | 0 | const char *types[] = { |
2930 | 0 | "EPO data", |
2931 | 0 | "Time", |
2932 | 0 | "Location", |
2933 | 0 | "Unknown", // gpsd only |
2934 | 0 | }; |
2935 | |
|
2936 | 0 | int system; |
2937 | 0 | const char *systems[] = { |
2938 | 0 | "GPS", |
2939 | 0 | "GLONASS", |
2940 | 0 | "Galileo", |
2941 | 0 | "BDS", |
2942 | 0 | "QZSS", |
2943 | 0 | "Unknown", // gpsd only |
2944 | 0 | }; |
2945 | 0 | int wn; // week number |
2946 | 0 | int tow; // time of week |
2947 | |
|
2948 | 0 | type = atoi(field[1]); |
2949 | 0 | if (0 > type || |
2950 | 0 | 2 < type) { |
2951 | | // WTF? |
2952 | 0 | type = 3; |
2953 | 0 | } |
2954 | 0 | system = atoi(field[2]); |
2955 | 0 | if (0 > system || |
2956 | 0 | 4 < system) { |
2957 | | // WTF? |
2958 | 0 | system = 5; |
2959 | 0 | } |
2960 | 0 | wn = atoi(field[3]); |
2961 | 0 | tow = atoi(field[4]); |
2962 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2963 | 0 | "NMEA0183: PAIR010: Need %s for %s. WN %d TOW %d\n", |
2964 | 0 | types[type], systems[system], wn, tow); |
2965 | |
|
2966 | 0 | return ONLINE_SET; |
2967 | 0 | } |
2968 | | |
2969 | | // PDTINFO Unicore Product Information |
2970 | | static gps_mask_t processPDTINFO(int c UNUSED, char *field[], |
2971 | | struct gps_device_t *session) |
2972 | 0 | { |
2973 | 0 | (void)snprintf(session->subtype, sizeof(session->subtype), |
2974 | 0 | "%s, %s, %s", |
2975 | 0 | field[1], field[2], field[5]); |
2976 | | // save SW and HW Version as subtype1 |
2977 | 0 | (void)snprintf(session->subtype1, sizeof(session->subtype1), |
2978 | 0 | "SW %s,HW %s", |
2979 | 0 | field[4], field[3]); |
2980 | |
|
2981 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
2982 | 0 | "NMEA0183: PDTINFO: subtype %s subtype1 %s\n", |
2983 | 0 | session->subtype, session->subtype1); |
2984 | |
|
2985 | 0 | return ONLINE_SET; |
2986 | 0 | } |
2987 | | |
2988 | | /* Ashtech sentences take this format: |
2989 | | * $PASHDR,type[,val[,val]]*CS |
2990 | | * type is an alphabetic subsentence type |
2991 | | * |
2992 | | * Oxford Technical Solutions (OxTS) also uses the $PASHR sentence, |
2993 | | * but with a very different sentence contents: |
2994 | | * $PASHR,HHMMSS.SSS,HHH.HH,T,RRR.RR,PPP.PP,aaa.aa,r.rrr,p.ppp,h.hhh,Q1,Q2*CS |
2995 | | * |
2996 | | * so field 1 in ASHTECH is always alphabetic and numeric in OXTS |
2997 | | * |
2998 | | */ |
2999 | | static gps_mask_t processPASHR(int c UNUSED, char *field[], |
3000 | | struct gps_device_t *session) |
3001 | 0 | { |
3002 | 0 | gps_mask_t mask = ONLINE_SET; |
3003 | 0 | char ts_buf[TIMESPEC_LEN]; |
3004 | |
|
3005 | 0 | if (0 == strcmp("ACK", field[1])) { |
3006 | | // ACK |
3007 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, "NMEA0183: PASHR,ACK\n"); |
3008 | 0 | return ONLINE_SET; |
3009 | 0 | } else if (0 == strcmp("MCA", field[1])) { |
3010 | | // MCA, raw data |
3011 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, "NMEA0183: PASHR,MCA\n"); |
3012 | 0 | return ONLINE_SET; |
3013 | 0 | } else if (0 == strcmp("NAK", field[1])) { |
3014 | | // NAK |
3015 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, "NMEA0183: PASHR,NAK\n"); |
3016 | 0 | return ONLINE_SET; |
3017 | 0 | } else if (0 == strcmp("PBN", field[1])) { |
3018 | | // PBN, position data |
3019 | | // FIXME: decode this for ECEF |
3020 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, "NMEA0183: PASHR,PBN\n"); |
3021 | 0 | return ONLINE_SET; |
3022 | 0 | } else if (0 == strcmp("POS", field[1])) { // 3D Position |
3023 | | /* $PASHR,POS, |
3024 | | * |
3025 | | * 2: position type: |
3026 | | * 0 = autonomous |
3027 | | * 1 = position differentially corrected with RTCM code |
3028 | | * 2 = position differentially corrected with CPD float solution |
3029 | | * 3 = position is CPD fixed solution |
3030 | | */ |
3031 | 0 | mask |= MODE_SET | STATUS_SET | CLEAR_IS; |
3032 | 0 | if ('\0' == field[2][0]) { |
3033 | | // empty first field means no 3D fix is available |
3034 | 0 | session->newdata.status = STATUS_UNK; |
3035 | 0 | session->newdata.mode = MODE_NO_FIX; |
3036 | 0 | } else { |
3037 | | |
3038 | | // if we make it this far, we at least have a 3D fix |
3039 | 0 | session->newdata.mode = MODE_3D; |
3040 | 0 | if (1 <= atoi(field[2])) |
3041 | 0 | session->newdata.status = STATUS_DGPS; |
3042 | 0 | else |
3043 | 0 | session->newdata.status = STATUS_GPS; |
3044 | |
|
3045 | 0 | session->nmea.gga_sats_used = atoi(field[3]); |
3046 | 0 | if (0 == merge_hhmmss(field[4], session)) { |
3047 | 0 | register_fractional_time(field[0], field[4], session); |
3048 | 0 | mask |= TIME_SET; |
3049 | 0 | } |
3050 | 0 | if (0 == do_lat_lon(&field[5], &session->newdata)) { |
3051 | 0 | mask |= LATLON_SET; |
3052 | 0 | if ('\0' != field[9][0]) { |
3053 | | // altitude is already WGS 84 |
3054 | 0 | session->newdata.altHAE = safe_atof(field[9]); |
3055 | 0 | mask |= ALTITUDE_SET; |
3056 | 0 | } |
3057 | 0 | } |
3058 | 0 | session->newdata.track = safe_atof(field[11]); |
3059 | 0 | session->newdata.speed = safe_atof(field[12]) / MPS_TO_KPH; |
3060 | 0 | session->newdata.climb = safe_atof(field[13]); |
3061 | 0 | if ('\0' != field[14][0]) { |
3062 | 0 | session->gpsdata.dop.pdop = safe_atof(field[14]); |
3063 | 0 | mask |= DOP_SET; |
3064 | 0 | } |
3065 | 0 | if ('\0' != field[15][0]) { |
3066 | 0 | session->gpsdata.dop.hdop = safe_atof(field[15]); |
3067 | 0 | mask |= DOP_SET; |
3068 | 0 | } |
3069 | 0 | if ('\0' != field[16][0]) { |
3070 | 0 | session->gpsdata.dop.vdop = safe_atof(field[16]); |
3071 | 0 | mask |= DOP_SET; |
3072 | 0 | } |
3073 | 0 | if ('\0' != field[17][0]) { |
3074 | 0 | session->gpsdata.dop.tdop = safe_atof(field[17]); |
3075 | 0 | mask |= DOP_SET; |
3076 | 0 | } |
3077 | 0 | mask |= (SPEED_SET | TRACK_SET | CLIMB_SET); |
3078 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3079 | 0 | "NMEA0183: PASHR,POS: hhmmss=%s lat=%.2f lon=%.2f" |
3080 | 0 | " altHAE=%.f" |
3081 | 0 | " speed=%.2f track=%.2f climb=%.2f mode=%d status=%d" |
3082 | 0 | " pdop=%.2f hdop=%.2f vdop=%.2f tdop=%.2f used=%d\n", |
3083 | 0 | field[4], session->newdata.latitude, |
3084 | 0 | session->newdata.longitude, session->newdata.altHAE, |
3085 | 0 | session->newdata.speed, session->newdata.track, |
3086 | 0 | session->newdata.climb, session->newdata.mode, |
3087 | 0 | session->newdata.status, session->gpsdata.dop.pdop, |
3088 | 0 | session->gpsdata.dop.hdop, session->gpsdata.dop.vdop, |
3089 | 0 | session->gpsdata.dop.tdop, session->nmea.gga_sats_used); |
3090 | 0 | } |
3091 | 0 | } else if (0 == strcmp("RID", field[1])) { // Receiver ID |
3092 | 0 | (void)snprintf(session->subtype, sizeof(session->subtype) - 1, |
3093 | 0 | "%s ver %s", field[2], field[3]); |
3094 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3095 | 0 | "NMEA0183: PASHR,RID: subtype=%s mask={}\n", |
3096 | 0 | session->subtype); |
3097 | 0 | return mask; |
3098 | 0 | } else if (0 == strcmp("SAT", field[1])) { // Satellite Status |
3099 | 0 | struct satellite_t *sp; |
3100 | 0 | int i, n = session->gpsdata.satellites_visible = atoi(field[2]); |
3101 | |
|
3102 | 0 | session->gpsdata.satellites_used = 0; |
3103 | 0 | for (i = 0, sp = session->gpsdata.skyview; |
3104 | 0 | sp < session->gpsdata.skyview + n; sp++, i++) { |
3105 | |
|
3106 | 0 | sp->PRN = (short)atoi(field[3 + i * 5 + 0]); |
3107 | 0 | sp->azimuth = (double)atoi(field[3 + i * 5 + 1]); |
3108 | 0 | sp->elevation = (double)atoi(field[3 + i * 5 + 2]); |
3109 | 0 | sp->ss = safe_atof(field[3 + i * 5 + 3]); |
3110 | 0 | sp->used = false; |
3111 | 0 | if ('U' == field[3 + i * 5 + 4][0]) { |
3112 | 0 | sp->used = true; |
3113 | 0 | session->gpsdata.satellites_used++; |
3114 | 0 | } |
3115 | 0 | } |
3116 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3117 | 0 | "NMEA0183: PASHR,SAT: used=%d\n", |
3118 | 0 | session->gpsdata.satellites_used); |
3119 | 0 | session->gpsdata.skyview_time.tv_sec = 0; |
3120 | 0 | session->gpsdata.skyview_time.tv_nsec = 0; |
3121 | 0 | mask |= SATELLITE_SET | USED_IS; |
3122 | |
|
3123 | 0 | } else if (0 == strcmp("T", field[3])) { // Assume OxTS PASHR |
3124 | | // FIXME: decode OxTS $PASHDR, time is wrong, breaks cycle order |
3125 | 0 | if (0 == merge_hhmmss(field[1], session)) { |
3126 | | // register_fractional_time(field[0], field[1], session); |
3127 | | // mask |= TIME_SET; confuses cycle order |
3128 | 0 | } |
3129 | | // Assume true heading |
3130 | 0 | session->gpsdata.attitude.heading = safe_atof(field[2]); |
3131 | 0 | session->gpsdata.attitude.roll = safe_atof(field[4]); |
3132 | 0 | session->gpsdata.attitude.pitch = safe_atof(field[5]); |
3133 | | // mask |= ATTITUDE_SET; * confuses cycle order ?? |
3134 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3135 | 0 | "NMEA0183: PASHR (OxTS) time %s, heading %lf.\n", |
3136 | 0 | timespec_str(&session->newdata.time, ts_buf, sizeof(ts_buf)), |
3137 | 0 | session->gpsdata.attitude.heading); |
3138 | 0 | } |
3139 | 0 | return mask; |
3140 | 0 | } |
3141 | | |
3142 | | /* Android GNSS super message |
3143 | | * A stub. |
3144 | | */ |
3145 | | static gps_mask_t processPGLOR(int c UNUSED, char *field[], |
3146 | | struct gps_device_t *session) |
3147 | 0 | { |
3148 | | /* |
3149 | | * $PGLOR,0,FIX,.... |
3150 | | * 1 = sentence version (may not be present) |
3151 | | * 2 = message subtype |
3152 | | * .... |
3153 | | * |
3154 | | * subtypes: |
3155 | | * $PGLOR,[],AGC - ?? |
3156 | | * $PGLOR,[],CPU - CPU Loading |
3157 | | * $PGLOR,[],FIN - Request completion status |
3158 | | * $PGLOR,0,FIX,seconds - Time To Fix |
3159 | | * $PGLOR,[],FTS - Factory Test Status |
3160 | | * $PGLOR,[],GFC - GeoFence Fix |
3161 | | * $PGLOR,[],GLO - ?? |
3162 | | * $PGLOR,[],HLA - Value of HULA sensors |
3163 | | * $PGLOR,[],IMS - IMES messages |
3164 | | * $PGLOR,1,LSQ,hhmmss.ss - Least squares GNSS fix |
3165 | | * $PGLOR,NET - Report network information |
3166 | | * $PGLOR,[],NEW - Indicate new GPS request |
3167 | | * $PGLOR,[],PFM - Platform Status |
3168 | | * $PGLOR,[],PPS - Indicate PPS time corrections |
3169 | | * $PGLOR,5,PWR i - Power consumption report |
3170 | | * Only have doc for 5, Quectel uses 4 |
3171 | | * $PGLOR,[],RID - Version Information |
3172 | | * $PGLOR,2,SAT - GPS Satellite information |
3173 | | * $PGLOR,[],SIO - Serial I/O status report |
3174 | | * $PGLOR,[],SPA - Spectrum analyzer results |
3175 | | * $PGLOR,0,SPD - Speed, Steps, etc. |
3176 | | * $PGLOR,SPL - ?? |
3177 | | * $PGLOR,[],SPS - ?? |
3178 | | * $PGLOR,10,STA - GLL status |
3179 | | * $PGLOR,[],SVC - ?? |
3180 | | * $PGLOR,[],SVD - SV Dopplers detected in the false alarm test. |
3181 | | * $PGLOR,[],SMx - Report GPS Summary Information |
3182 | | * $PGLOR,[],UNC - ?? |
3183 | | * |
3184 | | * Are NET and SPL really so different? |
3185 | | * |
3186 | | */ |
3187 | 0 | gps_mask_t mask = ONLINE_SET; |
3188 | 0 | int got_one = 0; |
3189 | |
|
3190 | 0 | switch (field[1][0]) { |
3191 | 0 | case '0': |
3192 | 0 | if (0 == strncmp("FIX", field[2], 3)) { |
3193 | 0 | got_one = 1; |
3194 | | // field 3, time to first fix in seconds |
3195 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3196 | 0 | "NMEA0183: PGLOR: FIX, TTFF %s\n", |
3197 | 0 | field[3]); |
3198 | 0 | } else if (0 == strncmp("SPD", field[2], 3)) { |
3199 | 0 | got_one = 1; |
3200 | | // field 4, ddmmy.ss UTC |
3201 | | // field 5, hhmmss.ss UTC |
3202 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3203 | 0 | "NMEA0183: PGLOR: SPD, %s %s UTC\n", |
3204 | 0 | field[4], field[5]); |
3205 | 0 | } |
3206 | 0 | break; |
3207 | 0 | case '1': |
3208 | 0 | if (0 == strncmp("LSQ", field[2], 3)) { |
3209 | 0 | got_one = 1; |
3210 | | // field 3, hhmmss.ss UTC, only field Quectel supplies |
3211 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3212 | 0 | "NMEA0183: PGLOR: LSQ %s UTC\n", |
3213 | 0 | field[3]); |
3214 | 0 | } else if ('0' == field[1][1] && |
3215 | 0 | 0 == strncmp("STA", field[2], 3)) { |
3216 | | // version 10 |
3217 | 0 | got_one = 1; |
3218 | | // field 3, hhmmss.ss UTC |
3219 | | // field 7, Position uncertainty meters |
3220 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3221 | 0 | "NMEA0183: PGLOR: STA, UTC %s PosUncer %s\n", |
3222 | 0 | field[3], field[7]); |
3223 | 0 | } |
3224 | 0 | break; |
3225 | 0 | } |
3226 | 0 | if (0 != got_one) { |
3227 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3228 | 0 | "NMEA0183: PGLOR: seq %s type %s\n", |
3229 | 0 | field[1], field[2]); |
3230 | 0 | } |
3231 | 0 | return mask; |
3232 | 0 | } |
3233 | | |
3234 | | // Inertial Sense GPS nav data, not a legal message name |
3235 | | static gps_mask_t processPGPSP(int count UNUSED, char *field[], |
3236 | | struct gps_device_t *session) |
3237 | 0 | { |
3238 | | /* |
3239 | | * $PGPSP,523970800,2351,778,44.06887670,-121.31410390,1114.07,1134.17, |
3240 | | * 2.55,4.32,11.26,0.13,0.52,0.25,0.10,25.7,0.0000,18*51 |
3241 | | * |
3242 | | */ |
3243 | 0 | gps_mask_t mask = ONLINE_SET; |
3244 | 0 | unsigned long i_tow = strtoul(field[1], NULL, 10); // ms |
3245 | 0 | int weeks = atoi(field[2]); |
3246 | 0 | unsigned long status = strtoul(field[3], NULL, 10); |
3247 | 0 | int used = status & 0x0ff; |
3248 | 0 | int gpsStatus = (status >> 8) & 0x0ff; |
3249 | 0 | int fixType = (status >> 16) & 0x0ff; |
3250 | 0 | double lat = safe_atof(field[4]); |
3251 | 0 | double lon = safe_atof(field[5]); |
3252 | 0 | double altHAE = safe_atof(field[6]); |
3253 | 0 | double altMSL = safe_atof(field[7]); |
3254 | 0 | double pDOP = safe_atof(field[8]); |
3255 | 0 | double hAcc = safe_atof(field[9]); |
3256 | 0 | double vAcc = safe_atof(field[10]); |
3257 | 0 | double vecefX = safe_atof(field[11]); |
3258 | 0 | double vecefY = safe_atof(field[12]); |
3259 | 0 | double vecefZ = safe_atof(field[13]); |
3260 | 0 | double sAcc = safe_atof(field[14]); |
3261 | 0 | double cnoMean = safe_atof(field[15]); |
3262 | 0 | double towOffset = safe_atof(field[16]); |
3263 | 0 | int leapS = atoi(field[17]); |
3264 | 0 | char ts_buf[TIMESPEC_LEN]; |
3265 | 0 | char scr[128]; |
3266 | |
|
3267 | 0 | switch (gpsStatus) { |
3268 | 0 | case 0: |
3269 | | // no fix |
3270 | 0 | session->newdata.status = STATUS_UNK; |
3271 | 0 | session->newdata.mode = MODE_NO_FIX; |
3272 | 0 | break; |
3273 | 0 | case 1: |
3274 | | // DR |
3275 | 0 | session->newdata.status = STATUS_DR; |
3276 | 0 | session->newdata.mode = MODE_3D; |
3277 | 0 | break; |
3278 | 0 | case 2: |
3279 | | // 2D |
3280 | 0 | session->newdata.status = STATUS_GPS; |
3281 | 0 | session->newdata.mode = MODE_2D; |
3282 | 0 | break; |
3283 | 0 | case 3: |
3284 | | // 3D |
3285 | 0 | session->newdata.status = STATUS_GPS; |
3286 | 0 | session->newdata.mode = MODE_3D; |
3287 | 0 | break; |
3288 | 0 | case 4: |
3289 | | // GPSDR |
3290 | 0 | session->newdata.status = STATUS_GNSSDR; |
3291 | 0 | session->newdata.mode = MODE_3D; |
3292 | 0 | break; |
3293 | 0 | case 5: |
3294 | | // surveyed |
3295 | 0 | session->newdata.status = STATUS_TIME; |
3296 | 0 | session->newdata.mode = MODE_3D; |
3297 | 0 | break; |
3298 | 0 | case 8: |
3299 | | // DGPS |
3300 | 0 | session->newdata.status = STATUS_DGPS; |
3301 | 0 | session->newdata.mode = MODE_3D; |
3302 | 0 | break; |
3303 | 0 | case 9: |
3304 | | // SBAS ?? |
3305 | 0 | session->newdata.status = STATUS_GPS; |
3306 | 0 | session->newdata.mode = MODE_3D; |
3307 | 0 | break; |
3308 | 0 | case 10: |
3309 | | // FTK SINGLE ?? |
3310 | 0 | session->newdata.status = STATUS_RTK_FLT; // ?? |
3311 | 0 | session->newdata.mode = MODE_3D; |
3312 | 0 | break; |
3313 | 0 | case 11: |
3314 | | // FTK FLOAT |
3315 | 0 | session->newdata.status = STATUS_RTK_FLT; |
3316 | 0 | session->newdata.mode = MODE_3D; |
3317 | 0 | break; |
3318 | 0 | case 12: |
3319 | | // FTK FIX |
3320 | 0 | session->newdata.status = STATUS_RTK_FIX; |
3321 | 0 | session->newdata.mode = MODE_3D; |
3322 | 0 | break; |
3323 | 0 | default: |
3324 | | // Huh? |
3325 | 0 | session->newdata.status = STATUS_UNK; |
3326 | 0 | session->newdata.mode = MODE_NOT_SEEN; |
3327 | 0 | break; |
3328 | 0 | } |
3329 | 0 | mask |= MODE_SET | STATUS_SET; |
3330 | |
|
3331 | 0 | if (MODE_2D == session->newdata.mode || |
3332 | 0 | MODE_3D == session->newdata.mode) { |
3333 | 0 | timespec_t ts_tow; |
3334 | |
|
3335 | 0 | session->newdata.latitude = lat; |
3336 | 0 | session->newdata.longitude = lon; |
3337 | 0 | mask |= LATLON_SET; |
3338 | 0 | if (MODE_3D == session->newdata.mode) { |
3339 | 0 | session->newdata.altHAE = altHAE; |
3340 | 0 | session->newdata.altMSL = altMSL; |
3341 | 0 | mask |= ALTITUDE_SET; |
3342 | 0 | } |
3343 | | // assume leapS is valid if we are 2D ??? |
3344 | 0 | session->context->leap_seconds = leapS; |
3345 | 0 | session->context->valid |= LEAP_SECOND_VALID; |
3346 | | |
3347 | | // assume time is valid if we are 2D ??? |
3348 | 0 | MSTOTS(&ts_tow, i_tow); |
3349 | 0 | session->newdata.time = gpsd_gpstime_resolv(session, weeks, |
3350 | 0 | ts_tow); |
3351 | |
|
3352 | 0 | mask |= (TIME_SET | NTPTIME_IS); |
3353 | 0 | } |
3354 | |
|
3355 | 0 | GPSD_LOG(LOG_IO, &session->context->errout, |
3356 | 0 | "NMEA0183: PGPSP: %s i_tow=%lu weeks=%d " |
3357 | 0 | "status=x%lx used=%d gpsStatus=%d type=%d " |
3358 | 0 | "lat=%.2f lon=%.2f " |
3359 | 0 | "altHAE=%.2f altMSL=%.2f " |
3360 | 0 | "pdop=%.2f hacc=%.2f vacc=%.2f sacc=%.2f " |
3361 | 0 | "vecef: X=%.2f Y=%.2f Z=%.2f cnoMean=.%1f " |
3362 | 0 | "towOffset=%.4f leapS=%d\n", |
3363 | 0 | timespec_to_iso8601(session->newdata.time, scr, sizeof(scr)), |
3364 | 0 | i_tow, weeks, status, used, gpsStatus, fixType, lat, lon, |
3365 | 0 | altHAE, altMSL, |
3366 | 0 | pDOP, hAcc, vAcc, sAcc, |
3367 | 0 | vecefX, vecefY, vecefZ, cnoMean, |
3368 | 0 | towOffset, leapS); |
3369 | |
|
3370 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
3371 | 0 | "NMEA0183: PGPSP: time=%s lat=%.2f lon=%.2f " |
3372 | 0 | "mode=%d status=%d\n", |
3373 | 0 | timespec_str(&session->newdata.time, ts_buf, sizeof(ts_buf)), |
3374 | 0 | session->newdata.latitude, |
3375 | 0 | session->newdata.longitude, |
3376 | 0 | session->newdata.mode, |
3377 | 0 | session->newdata.status); |
3378 | 0 | return mask; |
3379 | 0 | } |
3380 | | |
3381 | | // Garmin Estimated Position Error |
3382 | | static gps_mask_t processPGRME(int c UNUSED, char *field[], |
3383 | | struct gps_device_t *session) |
3384 | 0 | { |
3385 | | /* |
3386 | | * $PGRME,15.0,M,45.0,M,25.0,M*22 |
3387 | | * 1 = horizontal error estimate |
3388 | | * 2 = units |
3389 | | * 3 = vertical error estimate |
3390 | | * 4 = units |
3391 | | * 5 = spherical error estimate |
3392 | | * 6 = units |
3393 | | * * |
3394 | | * * Garmin won't say, but the general belief is that these are 50% CEP. |
3395 | | * * We follow the advice at <http://gpsinformation.net/main/errors.htm>. |
3396 | | * * If this assumption changes here, it should also change in garmin.c |
3397 | | * * where we scale error estimates from Garmin binary packets, and |
3398 | | * * in libgpsd_core.c where we generate $PGRME. |
3399 | | */ |
3400 | 0 | gps_mask_t mask = ONLINE_SET; |
3401 | |
|
3402 | 0 | if ('M' == field[2][0] && |
3403 | 0 | 'M' == field[4][0] && |
3404 | 0 | 'M' == field[6][0]) { |
3405 | 0 | session->newdata.epx = session->newdata.epy = |
3406 | 0 | safe_atof(field[1]) * (1 / sqrt(2)) |
3407 | 0 | * (GPSD_CONFIDENCE / CEP50_SIGMA); |
3408 | 0 | session->newdata.epv = |
3409 | 0 | safe_atof(field[3]) * (GPSD_CONFIDENCE / CEP50_SIGMA); |
3410 | 0 | session->newdata.sep = |
3411 | 0 | safe_atof(field[5]) * (GPSD_CONFIDENCE / CEP50_SIGMA); |
3412 | 0 | mask = HERR_SET | VERR_SET | PERR_IS; |
3413 | 0 | } |
3414 | |
|
3415 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3416 | 0 | "NMEA0183: PGRME: epx=%.2f epy=%.2f sep=%.2f\n", |
3417 | 0 | session->newdata.epx, |
3418 | 0 | session->newdata.epy, |
3419 | 0 | session->newdata.sep); |
3420 | 0 | return mask; |
3421 | 0 | } |
3422 | | |
3423 | | /* Garmin GPS Fix Data Sentence |
3424 | | * |
3425 | | * FIXME: seems to happen after cycle ender, so little happens... |
3426 | | */ |
3427 | | static gps_mask_t processPGRMF(int c UNUSED, char *field[], |
3428 | | struct gps_device_t *session) |
3429 | 0 | { |
3430 | | /* |
3431 | | * $PGRMF,290,293895,160305,093802,13,5213.1439,N,02100.6511,E,A,2,0,226,2,1*11 |
3432 | | * |
3433 | | * 1 = GPS week |
3434 | | * 2 = GPS seconds |
3435 | | * 3 = UTC Date ddmmyy |
3436 | | * 4 = UTC time hhmmss |
3437 | | * 5 = GPS leap seconds |
3438 | | * 6 = Latitude ddmm.mmmm |
3439 | | * 7 = N or S |
3440 | | * 8 = Longitude dddmm.mmmm |
3441 | | * 9 = E or W |
3442 | | * 10 = Mode, M = Manual, A = Automatic |
3443 | | * 11 = Fix type, 0 = No fix, 2 = 2D fix, 2 = 3D fix |
3444 | | * 12 = Ground Speed, 0 to 1151 km/hr |
3445 | | * 13 = Course over ground, 0 to 359 degrees true |
3446 | | * 14 = pdop, 0 to 9 |
3447 | | * 15 = dop, 0 to 9 |
3448 | | */ |
3449 | 0 | gps_mask_t mask = ONLINE_SET; |
3450 | 0 | timespec_t ts_tow = {0, 0}; |
3451 | | |
3452 | | /* Some garmin fail due to GPS Week Roll Over |
3453 | | * Ignore their UTC date/time, use their GPS week, GPS tow and |
3454 | | * leap seconds to decide the correct time */ |
3455 | 0 | if (isdigit((int)field[5][0])) { |
3456 | 0 | session->context->leap_seconds = atoi(field[5]); |
3457 | 0 | session->context->valid = LEAP_SECOND_VALID; |
3458 | 0 | } |
3459 | 0 | if (isdigit((int)field[1][0]) && |
3460 | 0 | isdigit((int)field[2][0]) && |
3461 | 0 | 0 < session->context->leap_seconds) { |
3462 | | // have GPS week, tow and leap second |
3463 | 0 | unsigned short week = atol(field[1]); |
3464 | 0 | ts_tow.tv_sec = atol(field[2]); |
3465 | 0 | ts_tow.tv_nsec = 0; |
3466 | 0 | session->newdata.time = gpsd_gpstime_resolv(session, week, ts_tow); |
3467 | 0 | mask |= TIME_SET; |
3468 | | // (long long) cast for 32/64 bit compat |
3469 | 0 | GPSD_LOG(LOG_SPIN, &session->context->errout, |
3470 | 0 | "NMEA0183: PGRMF gps time %lld\n", |
3471 | 0 | (long long)session->newdata.time.tv_sec); |
3472 | 0 | } else if (0 == merge_hhmmss(field[4], session) && |
3473 | 0 | 0 == merge_ddmmyy(field[3], session)) { |
3474 | | // fall back to UTC if we need and can |
3475 | | // (long long) cast for 32/64 bit compat |
3476 | 0 | GPSD_LOG(LOG_SPIN, &session->context->errout, |
3477 | 0 | "NMEA0183: PGRMF gps time %lld\n", |
3478 | 0 | (long long)session->newdata.time.tv_sec); |
3479 | 0 | mask |= TIME_SET; |
3480 | 0 | } |
3481 | 0 | if ('A' != field[10][0]) { |
3482 | | // Huh? |
3483 | 0 | return mask; |
3484 | 0 | } |
3485 | 0 | if (0 == do_lat_lon(&field[6], &session->newdata)) { |
3486 | 0 | mask |= LATLON_SET; |
3487 | 0 | } |
3488 | 0 | switch (field[11][0]) { |
3489 | 0 | default: |
3490 | | // Huh? |
3491 | 0 | break; |
3492 | 0 | case '0': |
3493 | 0 | session->newdata.mode = MODE_NO_FIX; |
3494 | 0 | mask |= MODE_SET; |
3495 | 0 | break; |
3496 | 0 | case '1': |
3497 | 0 | session->newdata.mode = MODE_2D; |
3498 | 0 | mask |= MODE_SET; |
3499 | 0 | break; |
3500 | 0 | case '2': |
3501 | 0 | session->newdata.mode = MODE_3D; |
3502 | 0 | mask |= MODE_SET; |
3503 | 0 | break; |
3504 | 0 | } |
3505 | 0 | session->newdata.speed = safe_atof(field[12]) / MPS_TO_KPH; |
3506 | 0 | session->newdata.track = safe_atof(field[13]); |
3507 | 0 | mask |= SPEED_SET | TRACK_SET; |
3508 | 0 | if ('\0' != field[14][0]) { |
3509 | 0 | session->gpsdata.dop.pdop = safe_atof(field[14]); |
3510 | 0 | mask |= DOP_SET; |
3511 | 0 | } |
3512 | 0 | if ('\0' != field[15][0]) { |
3513 | 0 | session->gpsdata.dop.tdop = safe_atof(field[15]); |
3514 | 0 | mask |= DOP_SET; |
3515 | 0 | } |
3516 | |
|
3517 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3518 | 0 | "NMEA0183: PGRMF: pdop %.1f tdop %.1f \n", |
3519 | 0 | session->gpsdata.dop.pdop, |
3520 | 0 | session->gpsdata.dop.tdop); |
3521 | 0 | return mask; |
3522 | 0 | } |
3523 | | |
3524 | | /* Garmin Map Datum |
3525 | | * |
3526 | | * FIXME: seems to happen after cycle ender, so nothing happens... |
3527 | | */ |
3528 | | static gps_mask_t processPGRMM(int c UNUSED, char *field[], |
3529 | | struct gps_device_t *session) |
3530 | 0 | { |
3531 | | /* |
3532 | | * $PGRMM,NAD83*29 |
3533 | | * 1 = Map Datum |
3534 | | */ |
3535 | 0 | gps_mask_t mask = ONLINE_SET; |
3536 | |
|
3537 | 0 | if ('\0' != field[1][0]) { |
3538 | 0 | strlcpy(session->newdata.datum, field[1], |
3539 | 0 | sizeof(session->newdata.datum)); |
3540 | 0 | } |
3541 | |
|
3542 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3543 | 0 | "NMEA0183: PGRMM: datum=%.40s\n", |
3544 | 0 | session->newdata.datum); |
3545 | 0 | return mask; |
3546 | 0 | } |
3547 | | |
3548 | | // Garmin Sensor Status Info |
3549 | | static gps_mask_t processPGRMT(int c UNUSED, char *field[], |
3550 | | struct gps_device_t *session) |
3551 | 0 | { |
3552 | | /* |
3553 | | * $PGRMT,GPS 15x-W software ver. 4.20,,,,,,,,*6A |
3554 | | * 1 = Product, model and software version |
3555 | | * 2 = ROM Checksum test P=pass, F=fail |
3556 | | * 3 = Receiver failure discrete, P=pass, F=fail |
3557 | | * 4 = Stored data lost, R=retained, L=lost |
3558 | | * 5 = Real time clock lost, R=retained, L=lost |
3559 | | * 6 = Oscillator drift discrete, P=pass, F=excessive drift detected |
3560 | | * 7 = Data collection discrete, C=collecting, null if not collecting |
3561 | | * 8 = GPS sensor temperature in degrees C |
3562 | | * 9 = GPS sensor configuration data, R=retained, L=lost |
3563 | | * |
3564 | | * Output once per minuite by default. |
3565 | | * 50 char max. |
3566 | | * |
3567 | | * As of October 2022, only ever seen field 1 populated |
3568 | | */ |
3569 | 0 | gps_mask_t mask = ONLINE_SET; |
3570 | |
|
3571 | 0 | strlcpy(session->subtype, field[1], sizeof(session->subtype)); |
3572 | |
|
3573 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3574 | 0 | "NMEA0183: PGRMT: subtype %s\n", |
3575 | 0 | session->subtype); |
3576 | 0 | return mask; |
3577 | 0 | } |
3578 | | |
3579 | | // Garmin 3D Velocity Information |
3580 | | static gps_mask_t processPGRMV(int c UNUSED, char *field[], |
3581 | | struct gps_device_t *session) |
3582 | 0 | { |
3583 | | /* |
3584 | | * $PGRMV,-2.4,-1.1,0.3*59 |
3585 | | * 1 = true east velocity, m/s |
3586 | | * 2 = true north velocity, m/s |
3587 | | * 3 = true up velocity, m/s |
3588 | | */ |
3589 | 0 | gps_mask_t mask = ONLINE_SET; |
3590 | |
|
3591 | 0 | if ('\0' == field[1][0] || |
3592 | 0 | '\0' == field[2][0] || |
3593 | 0 | '\0' == field[3][0]) { |
3594 | | // nothing to report |
3595 | 0 | return mask; |
3596 | 0 | } |
3597 | | |
3598 | 0 | session->newdata.NED.velE = safe_atof(field[1]); |
3599 | 0 | session->newdata.NED.velN = safe_atof(field[2]); |
3600 | 0 | session->newdata.NED.velD = -safe_atof(field[3]); |
3601 | |
|
3602 | 0 | mask |= VNED_SET; |
3603 | |
|
3604 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3605 | 0 | "NMEA0183: PGRMV: velE %.2f velN %.2f velD %.2f\n", |
3606 | 0 | session->newdata.NED.velE, |
3607 | 0 | session->newdata.NED.velN, |
3608 | 0 | session->newdata.NED.velD); |
3609 | 0 | return mask; |
3610 | 0 | } |
3611 | | |
3612 | | // Garmin Altitude Information |
3613 | | static gps_mask_t processPGRMZ(int c UNUSED, char *field[], |
3614 | | struct gps_device_t *session) |
3615 | 0 | { |
3616 | | /* |
3617 | | * $PGRMZ,246,f,3*1B |
3618 | | * 1 = Altitude (probably MSL) in feet |
3619 | | * 2 = f (feet) |
3620 | | * 3 = Mode |
3621 | | * 1 = No Fix |
3622 | | * 2 = 2D Fix |
3623 | | * 3 = 3D Fix |
3624 | | * |
3625 | | * From: Garmin Proprietary NMEA 0183 Sentences |
3626 | | * technical Specifications |
3627 | | * 190-00684-00, Revision C December 2008 |
3628 | | */ |
3629 | 0 | gps_mask_t mask = ONLINE_SET; |
3630 | | |
3631 | | // codacy does not like strlen() |
3632 | 0 | if ('f' == field[2][0] && |
3633 | 0 | 0 < strnlen(field[1], 20)) { |
3634 | | // have a GPS altitude, must be 3D |
3635 | | // seems to be altMSL. regressions show this matches GPGGA MSL |
3636 | 0 | session->newdata.altMSL = atoi(field[1]) * FEET_TO_METERS; |
3637 | 0 | mask |= (ALTITUDE_SET); |
3638 | 0 | } |
3639 | 0 | switch (field[3][0]) { |
3640 | 0 | default: |
3641 | | // Huh? |
3642 | 0 | break; |
3643 | 0 | case '1': |
3644 | 0 | session->newdata.mode = MODE_NO_FIX; |
3645 | 0 | mask |= MODE_SET; |
3646 | 0 | break; |
3647 | 0 | case '2': |
3648 | 0 | session->newdata.mode = MODE_2D; |
3649 | 0 | mask |= MODE_SET; |
3650 | 0 | break; |
3651 | 0 | case '3': |
3652 | 0 | session->newdata.mode = MODE_3D; |
3653 | 0 | mask |= MODE_SET; |
3654 | 0 | break; |
3655 | 0 | } |
3656 | | |
3657 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
3658 | 0 | "NMEA0183: PGRMZ: altMSL %.2f mode %d\n", |
3659 | 0 | session->newdata.altMSL, |
3660 | 0 | session->newdata.mode); |
3661 | 0 | return mask; |
3662 | 0 | } |
3663 | | |
3664 | | // Magellan Status |
3665 | | static gps_mask_t processPMGNST(int c UNUSED, char *field[], |
3666 | | struct gps_device_t *session) |
3667 | 0 | { |
3668 | | /* |
3669 | | * $PMGNST,01.75,3,T,816,11.1,-00496,00*43 |
3670 | | * 1 = Firmware version number |
3671 | | * 2 = Mode (1 = no fix, 2 = 2D fix, 3 = 3D fix) |
3672 | | * 3 = T if we have a fix |
3673 | | * 4 = battery percentage left in tenths of a percent |
3674 | | * 5 = time left on the GPS battery in hours |
3675 | | * 6 = numbers change (freq. compensation?) |
3676 | | * 7 = PRN number receiving current focus |
3677 | | */ |
3678 | 0 | gps_mask_t mask = ONLINE_SET; |
3679 | 0 | int newmode = atoi(field[3]); |
3680 | |
|
3681 | 0 | if ('T' == field[4][0]) { |
3682 | 0 | switch(newmode) { |
3683 | 0 | default: |
3684 | 0 | session->newdata.mode = MODE_NO_FIX; |
3685 | 0 | break; |
3686 | 0 | case 2: |
3687 | 0 | session->newdata.mode = MODE_2D; |
3688 | 0 | break; |
3689 | 0 | case 3: |
3690 | 0 | session->newdata.mode = MODE_3D; |
3691 | 0 | break; |
3692 | 0 | } |
3693 | 0 | } else { |
3694 | | // Can report 3D fix, but 'F' for no fix |
3695 | 0 | session->newdata.mode = MODE_NO_FIX; |
3696 | 0 | } |
3697 | 0 | mask |= MODE_SET; |
3698 | |
|
3699 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
3700 | 0 | "NMEA0183: PMGNST: mode: %d\n", |
3701 | 0 | session->newdata.mode); |
3702 | 0 | return mask; |
3703 | 0 | } |
3704 | | |
3705 | | static gps_mask_t processPMTK001(int c UNUSED, char *field[], |
3706 | | struct gps_device_t *session) |
3707 | 0 | { |
3708 | 0 | int reason; |
3709 | 0 | const char *mtk_reasons[] = { |
3710 | 0 | "Invalid", |
3711 | 0 | "Unsupported", |
3712 | 0 | "Valid but Failed", |
3713 | 0 | "Valid success", // unused, see above |
3714 | 0 | "Unknown", // gpsd only |
3715 | 0 | }; |
3716 | | |
3717 | | // ACK / NACK |
3718 | 0 | reason = atoi(field[2]); |
3719 | 0 | if (4 == reason) { |
3720 | | // ACK |
3721 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
3722 | 0 | "NMEA0183: MTK ACK: %s\n", field[1]); |
3723 | 0 | return ONLINE_SET; |
3724 | 0 | } |
3725 | | |
3726 | | // else, NACK |
3727 | 0 | if (0 > reason || |
3728 | 0 | 3 < reason) { |
3729 | | // WTF? |
3730 | 0 | reason = 4; |
3731 | 0 | } |
3732 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
3733 | 0 | "NMEA0183: MTK NACK: %s, reason: %s\n", |
3734 | 0 | field[1], mtk_reasons[reason]); |
3735 | 0 | return ONLINE_SET; |
3736 | 0 | } |
3737 | | |
3738 | | static gps_mask_t processPMTK424(int c UNUSED, char *field[], |
3739 | | struct gps_device_t *session) |
3740 | 0 | { |
3741 | | // PPS pulse width response |
3742 | | /* |
3743 | | * Response will look something like: $PMTK424,0,0,1,0,69*12 |
3744 | | * The pulse width is in field 5 (69 in this example). This |
3745 | | * sentence is poorly documented at: |
3746 | | * http://www.trimble.com/embeddedsystems/condor-gps-module.aspx?dtID=documentation |
3747 | | * |
3748 | | * Packet Type: 324 PMTK_API_SET_OUTPUT_CTL |
3749 | | * Packet meaning |
3750 | | * Write the TSIP/antenna/PPS configuration data to the Flash memory. |
3751 | | * DataField [Data0]:TSIP Packet[on/off] |
3752 | | * 0 - Disable TSIP output (Default). |
3753 | | * 1 - Enable TSIP output. |
3754 | | * [Data1]:Antenna Detect[on/off] |
3755 | | * 0 - Disable antenna detect function (Default). |
3756 | | * 1 - Enable antenna detect function. |
3757 | | * [Data2]:PPS on/off |
3758 | | * 0 - Disable PPS function. |
3759 | | * 1 - Enable PPS function (Default). |
3760 | | * [Data3]:PPS output timing |
3761 | | * 0 - Always output PPS (Default). |
3762 | | * 1 - Only output PPS when GPS position is fixed. |
3763 | | * [Data4]:PPS pulse width |
3764 | | * 1~16367999: 61 ns~(61x 16367999) ns (Default = 69) |
3765 | | * |
3766 | | * The documentation does not give the units of the data field. |
3767 | | * Andy Walls <andy@silverblocksystems.net> says: |
3768 | | * |
3769 | | * "The best I can figure using an oscilloscope, is that it is |
3770 | | * in units of 16.368000 MHz clock cycles. It may be |
3771 | | * different for any other unit other than the Trimble |
3772 | | * Condor. 69 cycles / 16368000 cycles/sec = 4.216 microseconds |
3773 | | * [which is the pulse width I have observed]" |
3774 | | * |
3775 | | * Support for this theory comes from the fact that crystal |
3776 | | * TXCOs with a 16.368MHZ period are commonly available from |
3777 | | * multiple vendors. Furthermore, 61*69 = 4209, which is |
3778 | | * close to the observed cycle time and suggests that the |
3779 | | * documentation is trying to indicate 61ns units. |
3780 | | * |
3781 | | * He continues: |
3782 | | * |
3783 | | * "I chose [127875] because to divides 16368000 nicely and the |
3784 | | * pulse width is close to 1/100th of a second. Any number |
3785 | | * the user wants to use would be fine. 127875 cycles / |
3786 | | * 16368000 cycles/second = 1/128 seconds = 7.8125 |
3787 | | * milliseconds" |
3788 | | */ |
3789 | | |
3790 | | // too short? Make it longer |
3791 | 0 | if (127875 > atoi(field[5])) { |
3792 | 0 | (void)nmea_send(session, "$PMTK324,0,0,1,0,127875"); |
3793 | 0 | } |
3794 | 0 | return ONLINE_SET; |
3795 | 0 | } |
3796 | | |
3797 | | static gps_mask_t processPMTK705(int count, char *field[], |
3798 | | struct gps_device_t *session) |
3799 | 0 | { |
3800 | | /* Trimble version: |
3801 | | * $PMTK705,AXN_1.30,0000,20090609,*20<CR><LF> |
3802 | | * |
3803 | | * 0 PMTK705 |
3804 | | * 1 ReleaseStr - Firmware release name and version |
3805 | | * 2 Build_ID - Build ID |
3806 | | * 3 Date code - YYYYMMDD |
3807 | | * 4 Checksum |
3808 | | * |
3809 | | * Quectel Querk. L26. |
3810 | | * $PMTK705,AXN_3.20_3333_13071501,0003,QUECTEL-L26,*1E<CR><LF> |
3811 | | * |
3812 | | * 0 PMTK705 |
3813 | | * 1 ReleaseStr - Firmware release name and version |
3814 | | * 2 Build_ID - Build ID |
3815 | | * 3 Date code - Product Model |
3816 | | * 4 SDK Version (optional) |
3817 | | * * Checksum |
3818 | | */ |
3819 | | |
3820 | | // set device subtype |
3821 | 0 | if (4 == count) { |
3822 | 0 | (void)snprintf(session->subtype, sizeof(session->subtype), |
3823 | 0 | "%s,%s,%s", |
3824 | 0 | field[1], field[2], field[3]); |
3825 | 0 | } else { |
3826 | | // Once again Quectel goes their own way... |
3827 | 0 | (void)snprintf(session->subtype, sizeof(session->subtype), |
3828 | 0 | "%s,%s,%s,%s", |
3829 | 0 | field[1], field[2], field[3], field[4]); |
3830 | 0 | } |
3831 | |
|
3832 | 0 | if ('\0' == session->subtype1[0]) { |
3833 | | /* Query for the Quectel firmware version. |
3834 | | * Quectel GPS receivers containing an MTK chipset use |
3835 | | * this command to return their FW version. |
3836 | | * From |
3837 | | * https://forums.quectel.com/t/determine-nmea-version-of-l76-l/3882/5 |
3838 | | * "$PQVERNO is an internal command and used to query Quectel FW |
3839 | | * version. We haven’t added this internal command in GNSS |
3840 | | * protocol spec." |
3841 | | */ |
3842 | 0 | (void)nmea_send(session, "$PQVERNO,R"); |
3843 | 0 | } |
3844 | |
|
3845 | 0 | return ONLINE_SET; |
3846 | 0 | } |
3847 | | |
3848 | | static gps_mask_t processPQxERR(int c UNUSED, char* field[], |
3849 | | struct gps_device_t* session) |
3850 | 0 | { |
3851 | | /* Quectel generic PQxxxERRROR message handler |
3852 | | * The messages are content free, not very useful. |
3853 | | * |
3854 | | * $PQTMCFGEINSMSGERROR*4A |
3855 | | * $PQTMCFGORIENTATIONERROR*54 |
3856 | | * $PQTMCFGWHEELTICKERROR*44 |
3857 | | * $PQTMQMPTERROR*58 |
3858 | | */ |
3859 | |
|
3860 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
3861 | 0 | "NMEA0183: %s Error\n", field[0]); |
3862 | 0 | return ONLINE_SET; |
3863 | 0 | } |
3864 | | |
3865 | | static gps_mask_t processPQxOK(int c UNUSED, char* field[], |
3866 | | struct gps_device_t* session) |
3867 | 0 | { |
3868 | | /* Quectel generic PQTMxxxOK message handler |
3869 | | * The messages are content free, not very useful. |
3870 | | * |
3871 | | * $PQTMCFGEINSMSGOK*16 |
3872 | | * $PQTMCFGORIENTATIONOK*08 |
3873 | | * $PQTMCFGWHEELTICKOK*18 |
3874 | | */ |
3875 | |
|
3876 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
3877 | 0 | "NMEA0183: %s OK\n", field[0]); |
3878 | 0 | return ONLINE_SET; |
3879 | 0 | } |
3880 | | |
3881 | | // Quectel $PQTMGPS - GNSS position stuff |
3882 | | static gps_mask_t processPQTMGPS(int count UNUSED, char *field[], |
3883 | | struct gps_device_t *session) |
3884 | 0 | { |
3885 | | /* |
3886 | | * $PQTMGPS,671335,463792.000,31.822084600,117.115221100,59.4260,63.0420, |
3887 | | * 0.0270,-171.7101,5.9890,1.3300,2.1100,3,18,*75 |
3888 | | * |
3889 | | * 1 Milliseconds since turn on. 32-bit unsigned integer. |
3890 | | * 2 Time of week. Seconds |
3891 | | * 3 Latitude. Degrees |
3892 | | * 4 Longitude. Degrees |
3893 | | * 5 Height above ellipsoid, Meters |
3894 | | * 6 Altitude above mean-sea-level. Meters |
3895 | | * 7 Ground speed (2D). Meters / sec |
3896 | | * 8 Heading (2D). Degrees. |
3897 | | * 9 Horizontal accuracy estimate. Meters. |
3898 | | * 10 HDOP |
3899 | | * 11 PDOP |
3900 | | * 12 Fix type. 0 = No fix. 2 = 2D fix. 3 = 3D fix. |
3901 | | * 13 Number of navigation satellites (seen? used?) |
3902 | | * |
3903 | | * Note: incomplete time stamp. |
3904 | | */ |
3905 | 0 | gps_mask_t mask = ONLINE_SET; |
3906 | 0 | unsigned ts = atoi(field[1]); |
3907 | 0 | unsigned tow = atoi(field[2]); |
3908 | 0 | double lat = safe_atof(field[3]); |
3909 | 0 | double lon = safe_atof(field[4]); |
3910 | 0 | double hae = safe_atof(field[5]); |
3911 | 0 | double msl = safe_atof(field[6]); |
3912 | 0 | double speed = safe_atof(field[7]); |
3913 | 0 | double heading = safe_atof(field[8]); |
3914 | 0 | double hAcc = safe_atof(field[9]); |
3915 | 0 | double hdop = safe_atof(field[10]); |
3916 | 0 | double pdop = safe_atof(field[11]); |
3917 | 0 | unsigned fix = atoi(field[12]); |
3918 | 0 | unsigned numsat = atoi(field[13]); |
3919 | |
|
3920 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
3921 | 0 | "NMEA0183: PQTMGPS ts %u tow %u lat %.9f lon %.9f HAE %.4f " |
3922 | 0 | "MSL %.4f speed %.4f head %.4f hacc %.4f hdop %.4f pdop %.4f " |
3923 | 0 | "mode %u nsat %u\n", |
3924 | 0 | ts, tow, lat, lon, hae, msl, speed, heading, hAcc, hdop, |
3925 | 0 | pdop, fix, numsat); |
3926 | 0 | return mask; |
3927 | 0 | } |
3928 | | |
3929 | | // Quectel $PQTMIMU - IMU Raw Data |
3930 | | static gps_mask_t processPQTMIMU(int count UNUSED, char *field[], |
3931 | | struct gps_device_t *session) |
3932 | 0 | { |
3933 | | /* |
3934 | | * $PQTMIMU,42634,-0.006832,-0.022814,1.014552,0.315000,-0.402500, |
3935 | | -0.332500,0,0*55 |
3936 | | * |
3937 | | * 1 Milliseconds since turn on. 32-bit unsigned integer. |
3938 | | * 2 Acceleration in X-axis direction. g |
3939 | | * 3 Acceleration in Y-axis direction. g |
3940 | | * 4 Acceleration in A-axis direction. g |
3941 | | * 5 Angular rate in X-axis direction. Degrees / second |
3942 | | * 6 Angular rate in y-axis direction. Degrees / second |
3943 | | * 7 Angular rate in Z-axis direction. Degrees / second |
3944 | | * 8 Cumulative ticks |
3945 | | * 9 Timestamp of last tick |
3946 | | */ |
3947 | 0 | gps_mask_t mask = ONLINE_SET; |
3948 | 0 | unsigned ts = atoi(field[1]); |
3949 | 0 | double accX = safe_atof(field[2]); |
3950 | 0 | double accY = safe_atof(field[3]); |
3951 | 0 | double accZ = safe_atof(field[4]); |
3952 | 0 | double rateX = safe_atof(field[5]); |
3953 | 0 | double rateY = safe_atof(field[6]); |
3954 | 0 | double rateZ = safe_atof(field[7]); |
3955 | 0 | unsigned ticks = atoi(field[8]); |
3956 | 0 | unsigned tick_ts = atoi(field[9]); |
3957 | |
|
3958 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
3959 | 0 | "NMEA0183: PQTMIMU ts %u accX %.6f accY %.6f accZ %.6f " |
3960 | 0 | "rateX %.6f rateY %.6f rateZ %.6f ticks %u tick_ts %u\n", |
3961 | 0 | ts, accX, accY, accZ, rateX, rateY, rateZ, ticks, tick_ts); |
3962 | 0 | return mask; |
3963 | 0 | } |
3964 | | |
3965 | | // Quectel $PQTMINS - DR Nav results |
3966 | | static gps_mask_t processPQTMINS(int count UNUSED, char *field[], |
3967 | | struct gps_device_t *session) |
3968 | 0 | { |
3969 | | /* |
3970 | | * $PQTMINS,42529,1,31.822038000,117.115182800,67.681000,,,,-0.392663, |
3971 | | 1.300793,0.030088*4D |
3972 | | * |
3973 | | * 1 Milliseconds since turn on. 32-bit unsigned integer. |
3974 | | * 2 Solution type, 0 = Pitch and Roll, 1 = GNSS, pitch, roll, heading |
3975 | | * 2 = GNSS + DR, 3 = DR Only |
3976 | | * 3 Latitude. Degrees |
3977 | | * 4 Longitude. Degrees |
3978 | | * 5 Height (HAE?, MSL?) , Meters |
3979 | | * 6 Northward velocity |
3980 | | * 7 Eastward velocity |
3981 | | * 8 Downward velocity |
3982 | | * 9 Roll |
3983 | | * 10 Pitch |
3984 | | * 11 Heading |
3985 | | * |
3986 | | */ |
3987 | 0 | gps_mask_t mask = ONLINE_SET; |
3988 | 0 | unsigned ts = atoi(field[1]); |
3989 | 0 | unsigned sol = atoi(field[2]); |
3990 | 0 | double lat = safe_atof(field[3]); |
3991 | 0 | double lon = safe_atof(field[4]); |
3992 | 0 | double alt = safe_atof(field[5]); |
3993 | 0 | double velN = safe_atof(field[6]); |
3994 | 0 | double velE = safe_atof(field[7]); |
3995 | 0 | double velD = safe_atof(field[8]); |
3996 | 0 | double roll = safe_atof(field[9]); |
3997 | 0 | double pitch = safe_atof(field[10]); |
3998 | 0 | double head = safe_atof(field[11]); |
3999 | |
|
4000 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4001 | 0 | "NMEA0183: PQTMINS ts %u sol %u lat %.9f lon %.9f alt %.6f " |
4002 | 0 | "velN %.6f velE %.6f velD %.6f roll %.6f pitch %.6f head %.6f\n", |
4003 | 0 | ts, sol, lat, lon, alt, velN, velE, velD, roll, pitch, head); |
4004 | 0 | return mask; |
4005 | 0 | } |
4006 | | |
4007 | | // Quectel $PQTMVER - Firmware info |
4008 | | static gps_mask_t processPQTMVER(int count UNUSED, char *field[], |
4009 | | struct gps_device_t *session) |
4010 | 0 | { |
4011 | | /* |
4012 | | * $PQTMVER,MODULE_L89HANR01A06S,2022/07/28,18:27:04*7A |
4013 | | * |
4014 | | * 1 Version |
4015 | | * 2 build date yyyy/mm/dd |
4016 | | * 3 build time hh:mm:ss |
4017 | | * |
4018 | | */ |
4019 | 0 | char obuf[128]; // temp version string buffer |
4020 | 0 | gps_mask_t mask = ONLINE_SET; |
4021 | | |
4022 | | // save as subtype |
4023 | 0 | (void)snprintf(obuf, sizeof(obuf), |
4024 | 0 | "%s %.12s %.10s", |
4025 | 0 | field[1], field[2], field[3]); |
4026 | | |
4027 | | // save what we can |
4028 | 0 | (void)strlcpy(session->subtype, obuf, sizeof(session->subtype) - 1); |
4029 | |
|
4030 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4031 | 0 | "NMEA0183: PQTMVER %s\n", |
4032 | 0 | session->subtype); |
4033 | |
|
4034 | 0 | return mask; |
4035 | 0 | } |
4036 | | |
4037 | | static gps_mask_t processPQVERNO(int c UNUSED, char* field[], |
4038 | | struct gps_device_t* session) |
4039 | 0 | { |
4040 | | /* Example request & response are provided courtesy of Quectel below. |
4041 | | * This command is not publicly documented, but Quectel support |
4042 | | * provided this description via email. This has been tested on |
4043 | | * Quectel version L70-M39, but all recent (2022) versions of Quectel |
4044 | | * support this command is well. |
4045 | | * |
4046 | | * Request: |
4047 | | * $PQVERNO,R*3F |
4048 | | * |
4049 | | * Response: |
4050 | | * $PQVERNO,R,L96NR01A03S,2018/07/30,04:17*6B |
4051 | | * |
4052 | | * Description of the 6 fields are below. |
4053 | | * |
4054 | | * 1. $PQVERNO, Query command |
4055 | | * 2. R, Read |
4056 | | * 3. L96NR01A03S, Quectel firmware version number |
4057 | | * 4. 2018/07/30, Firmware build date |
4058 | | * 5. 04:17* Firmware build time |
4059 | | * 6. 6B Checksum |
4060 | | */ |
4061 | |
|
4062 | 0 | if (0 == strncmp(session->nmea.field[0], "PQVERNO", sizeof("PQVERNO")) && |
4063 | 0 | '\0' != field[2][0]) { |
4064 | 0 | (void)snprintf(session->subtype1, sizeof(session->subtype1), |
4065 | 0 | "%s,%s,%s", |
4066 | 0 | field[2], field[3], field[4]); |
4067 | 0 | } |
4068 | |
|
4069 | 0 | return ONLINE_SET; |
4070 | 0 | } |
4071 | | |
4072 | | /* smart watch sensors |
4073 | | * A stub. |
4074 | | */ |
4075 | | static gps_mask_t processPRHS(int c UNUSED, char *field[], |
4076 | | struct gps_device_t *session) |
4077 | 0 | { |
4078 | | /* |
4079 | | * $PRHS ,type,.... |
4080 | | * type = message type |
4081 | | * |
4082 | | * Yes: $PRHS[space], |
4083 | | * |
4084 | | * types: |
4085 | | * $PRHS ,ACC,9.952756,0.37819514,1.3165021,20150305072428436*44 |
4086 | | * $PRHS ,COM,238.09642,16.275442,82.198425,20150305072428824*43 |
4087 | | * $PRHS ,GYR,0.0,0.0,0.0,20150305072428247*4D |
4088 | | * $PRHS ,LAC,0.23899937,0.009213656,0.02143073,20150305072428437*46 |
4089 | | * $PRHS ,MAG,47.183502,-51.789,-2.7145,20150305072428614*41 |
4090 | | * $PRHS ,ORI,187.86511,-2.1546898,-82.405205,20150305072428614*53 |
4091 | | * $PRHS ,RMC,20150305072427985*55 |
4092 | | * |
4093 | | */ |
4094 | 0 | gps_mask_t mask = ONLINE_SET; |
4095 | |
|
4096 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
4097 | 0 | "NMEA0183: PRHS: type %s\n", |
4098 | 0 | field[1]); |
4099 | 0 | return mask; |
4100 | 0 | } |
4101 | | |
4102 | | static gps_mask_t processPSRFEPE(int c UNUSED, char *field[], |
4103 | | struct gps_device_t *session) |
4104 | 0 | { |
4105 | | /* |
4106 | | * $PSRFEPE,100542.000,A,0.7,6.82,10.69,0.0,180.0*24 |
4107 | | * 1 = UTC Time hhmmss.sss |
4108 | | * 2 = Status. A = Valid, V = Data not valid |
4109 | | * 3 = HDOP |
4110 | | * 4 = EHPE meters (Estimated Horizontal Position Error) |
4111 | | * 5 = EVPE meters (Estimated Vertical Position Error) |
4112 | | * 6 = EHVE meters (Estimated Speed Over Ground/Velocity Error) |
4113 | | * 7 = EHE degrees (Estimated Heading Error) |
4114 | | * |
4115 | | * SiRF won't say if these are 1-sigma or what... |
4116 | | */ |
4117 | 0 | gps_mask_t mask = STATUS_SET; |
4118 | | |
4119 | | // get time/ valid or not |
4120 | 0 | if ('\0' != field[1][0]) { |
4121 | 0 | if (0 == merge_hhmmss(field[1], session)) { |
4122 | 0 | register_fractional_time(field[0], field[1], session); |
4123 | 0 | if (0 == session->nmea.date.tm_year) { |
4124 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
4125 | 0 | "NMEA0183: can't use PSRFEPE time until after ZDA " |
4126 | 0 | "or RMC has supplied a year.\n"); |
4127 | 0 | } else { |
4128 | 0 | mask |= TIME_SET; |
4129 | 0 | } |
4130 | 0 | } |
4131 | 0 | } |
4132 | 0 | if ('A' != field[2][0]) { |
4133 | | // Huh? |
4134 | 0 | return mask; |
4135 | 0 | } |
4136 | | |
4137 | 0 | if ('\0' != field[3][0]) { |
4138 | | /* This adds nothing, it just agrees with the gpsd calculation |
4139 | | * from the skyview. Which is a nice confirmation. */ |
4140 | 0 | session->gpsdata.dop.hdop = safe_atof(field[3]); |
4141 | 0 | mask |= DOP_SET; |
4142 | 0 | } |
4143 | 0 | if ('\0' != field[4][0]) { |
4144 | | // EHPE (Estimated Horizontal Position Error) |
4145 | 0 | session->newdata.eph = safe_atof(field[4]); |
4146 | 0 | mask |= HERR_SET; |
4147 | 0 | } |
4148 | |
|
4149 | 0 | if ('\0' != field[5][0]) { |
4150 | | // Estimated Vertical Position Error (meters, 0.01 resolution) |
4151 | 0 | session->newdata.epv = safe_atof(field[5]); |
4152 | 0 | mask |= VERR_SET; |
4153 | 0 | } |
4154 | |
|
4155 | 0 | if ('\0' != field[6][0]) { |
4156 | | // Estimated Horizontal Speed Error meters/sec |
4157 | 0 | session->newdata.eps = safe_atof(field[6]); |
4158 | 0 | } |
4159 | |
|
4160 | 0 | if ('\0' != field[7][0]) { |
4161 | | // Estimated Heading Error degrees |
4162 | 0 | session->newdata.epd = safe_atof(field[7]); |
4163 | 0 | } |
4164 | |
|
4165 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4166 | 0 | "NMEA0183: PSRFEPE: hdop=%.1f eph=%.1f epv=%.1f eps=%.1f " |
4167 | 0 | "epd=%.1f\n", |
4168 | 0 | session->gpsdata.dop.hdop, |
4169 | 0 | session->newdata.eph, |
4170 | 0 | session->newdata.epv, |
4171 | 0 | session->newdata.eps, |
4172 | 0 | session->newdata.epd); |
4173 | 0 | return mask; |
4174 | 0 | } |
4175 | | |
4176 | | /* Recommended Minimum 3D GNSS Data |
4177 | | * Skytaq |
4178 | | */ |
4179 | | static gps_mask_t processPSTI030(int count UNUSED, char *field[], |
4180 | | struct gps_device_t *session) |
4181 | 0 | { |
4182 | | /* |
4183 | | * $PSTI,030,hhmmss.sss,A,dddmm.mmmmmmm,a,dddmm.mmmmmmm,a,x.x, |
4184 | | x.x,x.x,x.x,ddmmyy,a.x.x,x.x*hh<CR><LF> |
4185 | | * 1 030 Sentence ID |
4186 | | * 2 225446.334 Time of fix 22:54:46 UTC |
4187 | | * 3 A Status of Fix: A = Autonomous, valid; |
4188 | | * V = invalid |
4189 | | * 4,5 4916.45,N Latitude 49 deg. 16.45 min North |
4190 | | * 6,7 12311.12,W Longitude 123 deg. 11.12 min West |
4191 | | * 8 103.323 Mean Sea Level meters |
4192 | | * 9 0.00 East Velocity meters/sec |
4193 | | * 10 0.00 North Velocity meters/sec |
4194 | | * 11 0.00 Up Velocity meters/sec |
4195 | | * 12 181194 Date of fix 18 November 1994 |
4196 | | * 13 A FAA mode indicator |
4197 | | * See faa_mode() for possible mode values. |
4198 | | * 14 1.2 RTK Age |
4199 | | * 15 4.2 RTK Ratio |
4200 | | * 16 *68 mandatory nmea_checksum |
4201 | | * |
4202 | | * In private email, SkyTraq says F mode is 10x more accurate |
4203 | | * than R mode. |
4204 | | */ |
4205 | 0 | gps_mask_t mask = ONLINE_SET; |
4206 | |
|
4207 | 0 | if (0 != strncmp(session->device_type->type_name, "Skytraq", 7)) { |
4208 | | // this is skytraq, but not marked yet, so probe for Skytraq |
4209 | | // Send MID 0x02, to get back MID 0x80 |
4210 | 0 | (void)gpsd_write(session, "\xA0\xA1\x00\x02\x02\x01\x03\x0d\x0a",9); |
4211 | 0 | } |
4212 | |
|
4213 | 0 | if ('V' == field[3][0] || |
4214 | 0 | 'N' == field[13][0]) { |
4215 | | // nav warning, or FAA not valid, ignore the rest of the data |
4216 | 0 | session->newdata.status = STATUS_UNK; |
4217 | 0 | session->newdata.mode = MODE_NO_FIX; |
4218 | 0 | mask |= MODE_SET | STATUS_SET; |
4219 | 0 | } else if ('A' == field[3][0]) { |
4220 | 0 | double east, north, climb, age, ratio; |
4221 | | |
4222 | | // data valid |
4223 | 0 | if ('\0' != field[2][0] && |
4224 | 0 | '\0' != field[12][0]) { |
4225 | | // good date and time |
4226 | 0 | if (0 == merge_hhmmss(field[2], session) && |
4227 | 0 | 0 == merge_ddmmyy(field[12], session)) { |
4228 | 0 | mask |= TIME_SET; |
4229 | 0 | register_fractional_time( "PSTI030", field[2], session); |
4230 | 0 | } |
4231 | 0 | } |
4232 | 0 | if (0 == do_lat_lon(&field[4], &session->newdata)) { |
4233 | 0 | session->newdata.mode = MODE_2D; |
4234 | 0 | mask |= LATLON_SET; |
4235 | 0 | if ('\0' != field[8][0]) { |
4236 | | // altitude is MSL |
4237 | 0 | session->newdata.altMSL = safe_atof(field[8]); |
4238 | 0 | mask |= ALTITUDE_SET; |
4239 | 0 | session->newdata.mode = MODE_3D; |
4240 | | // Let gpsd_error_model() deal with geoid_sep and altHAE |
4241 | 0 | } |
4242 | 0 | mask |= MODE_SET; |
4243 | 0 | } |
4244 | | /* convert ENU to track |
4245 | | * this has more precision than GPVTG, GPVTG comes earlier |
4246 | | * in the cycle */ |
4247 | 0 | east = safe_atof(field[9]); // east velocity m/s |
4248 | 0 | north = safe_atof(field[10]); // north velocity m/s |
4249 | 0 | climb = safe_atof(field[11]); // up velocity m/s |
4250 | 0 | age = safe_atof(field[14]); |
4251 | 0 | ratio = safe_atof(field[15]); |
4252 | |
|
4253 | 0 | session->newdata.NED.velN = north; |
4254 | 0 | session->newdata.NED.velE = east; |
4255 | 0 | session->newdata.NED.velD = -climb; |
4256 | 0 | if (0.05 < (age + ratio)) { |
4257 | | // don't report age == ratio == 0.0 |
4258 | 0 | session->newdata.dgps_age = age; |
4259 | 0 | session->gpsdata.fix.base.ratio = ratio; |
4260 | 0 | } |
4261 | |
|
4262 | 0 | mask |= VNED_SET | STATUS_SET; |
4263 | |
|
4264 | 0 | session->newdata.status = faa_mode(field[13][0]); |
4265 | 0 | if (STATUS_RTK_FIX == session->newdata.status || |
4266 | 0 | STATUS_RTK_FLT == session->newdata.status) { |
4267 | | // RTK_FIX or RTK_FLT |
4268 | 0 | session->gpsdata.fix.base.status = session->newdata.status; |
4269 | 0 | } |
4270 | 0 | } |
4271 | |
|
4272 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4273 | 0 | "NMEA0183: PSTI,030: ddmmyy=%s hhmmss=%s lat=%.2f lon=%.2f " |
4274 | 0 | "status=%d, RTK(Age=%.1f Ratio=%.1f) faa mode %s(%s)\n", |
4275 | 0 | field[12], field[2], |
4276 | 0 | session->newdata.latitude, |
4277 | 0 | session->newdata.longitude, |
4278 | 0 | session->newdata.status, |
4279 | 0 | session->newdata.dgps_age, |
4280 | 0 | session->newdata.base.ratio, |
4281 | 0 | field[13], char2str(field[13][0], c_faa_mode)); |
4282 | 0 | return mask; |
4283 | 0 | } |
4284 | | |
4285 | | /* Skytraq RTK Baseline, fixed base to rover or moving base |
4286 | | * Same as $PSTI.035, except that is moving base to rover |
4287 | | * PX1172RH |
4288 | | */ |
4289 | | static gps_mask_t processPSTI032(int count UNUSED, char *field[], |
4290 | | struct gps_device_t *session) |
4291 | 0 | { |
4292 | | /* |
4293 | | * $PSTI,032,041457.000,170316,A,R,0.603,‐0.837,‐0.089,1.036,144.22,,,,,*1B |
4294 | | * |
4295 | | * 2 UTC time, hhmmss.sss |
4296 | | * 3 UTC Date, ddmmyy |
4297 | | * 4 Status, ‘V’ = Void ‘A’ = Active |
4298 | | * 5 Mode indicator, 'O' = Float RTK, ‘F’ = Float RTK. ‘R’ = Fixed RTK |
4299 | | * 6 East‐projection of baseline, meters |
4300 | | * 7 North‐projection of baseline, meters |
4301 | | * 8 Up‐projection of baseline, meters |
4302 | | * 9 Baseline length, meters |
4303 | | * 10 Baseline course 144.22, true degrees |
4304 | | * 11 Reserved |
4305 | | * 12 Reserved |
4306 | | * 13 Reserved |
4307 | | * 14 Reserved |
4308 | | * 15 Reserved |
4309 | | * 16 Checksum |
4310 | | */ |
4311 | 0 | gps_mask_t mask = ONLINE_SET; |
4312 | 0 | struct baseline_t *base = &session->gpsdata.fix.base; |
4313 | |
|
4314 | 0 | if ('A' != field[4][0]) { |
4315 | | // status not valid |
4316 | 0 | return mask; |
4317 | 0 | } |
4318 | | |
4319 | | // Status Valid |
4320 | 0 | if ('\0' != field[2][0] && |
4321 | 0 | '\0' != field[3][0]) { |
4322 | | // have date and time |
4323 | 0 | if (0 == merge_hhmmss(field[2], session) && |
4324 | 0 | 0 == merge_ddmmyy(field[3], session)) { |
4325 | | // good date and time |
4326 | 0 | mask |= TIME_SET; |
4327 | 0 | register_fractional_time("PSTI032", field[2], session); |
4328 | 0 | } |
4329 | 0 | } |
4330 | |
|
4331 | 0 | if ('F' == field[5][0] || |
4332 | 0 | 'O' == field[5][0]) { |
4333 | | // Floating point RTK |
4334 | | // 'O' is undocuemented, private email says it is just a crappy 'F'. |
4335 | 0 | base->status = STATUS_RTK_FLT; |
4336 | 0 | } else if ('R' == field[5][0]) { |
4337 | | // Fixed point RTK |
4338 | 0 | base->status = STATUS_RTK_FIX; |
4339 | 0 | } else { |
4340 | | // WTF? |
4341 | 0 | return mask; |
4342 | 0 | } |
4343 | | |
4344 | 0 | base->east = safe_atof(field[6]); |
4345 | 0 | base->north = safe_atof(field[7]); |
4346 | 0 | base->up = safe_atof(field[8]); |
4347 | 0 | base->length = safe_atof(field[9]); |
4348 | 0 | base->course = safe_atof(field[10]); |
4349 | |
|
4350 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4351 | 0 | "NMEA0183: PSTI,032: RTK Baseline mode %d E %.3f N %.3f U %.3f " |
4352 | 0 | "length %.3f course %.3f\n", |
4353 | 0 | base->status, base->east, base->north, base->up, |
4354 | 0 | base->length, base->course); |
4355 | 0 | return mask; |
4356 | 0 | } |
4357 | | |
4358 | | /* Skytraq RTK RAW Measurement Monitoring Data |
4359 | | */ |
4360 | | static gps_mask_t processPSTI033(int count UNUSED, char *field[], |
4361 | | struct gps_device_t *session) |
4362 | 0 | { |
4363 | | /* |
4364 | | * $PSTI,033,hhmmss.sss,ddmmyy,x,R,x,G,x,x,,,C,x,x,,,E,x,x,,,R,x,x,,*hh |
4365 | | * $PSTI,033,110431.000,150517,2,R,1,G,1,0,,,C,0,0,,,E,0,0,,,R,0,0,,*72 |
4366 | | * |
4367 | | * 2 UTC time, hhmmss.sss |
4368 | | * 3 UTC Date, ddmmyy |
4369 | | * 4 "2", version |
4370 | | * 5 Receiver, R = Rover, B = Base |
4371 | | * 6 total cycle‐slipped raw measurements |
4372 | | * 7 "G", GPS |
4373 | | * 8 cycle slipped L1 |
4374 | | * 9 cycle slipped L2 |
4375 | | * 10 reserved |
4376 | | * 11 reserved |
4377 | | * 12 "C", BDS |
4378 | | * 12 cycle slipped B1 |
4379 | | * 14 cycle slipped B2 |
4380 | | * 15 reserved |
4381 | | * 16 reserved |
4382 | | * 17 "E", Galileo |
4383 | | * 18 cycle slipped E1 |
4384 | | * 19 cycle slipped E5b |
4385 | | * 20 reserved |
4386 | | * 21 reserved |
4387 | | * 22 "R", GLONASS |
4388 | | * 23 cycle slipped G1 |
4389 | | * 24 cycle slipped G2 |
4390 | | * 25 reserved |
4391 | | * 26 reserved |
4392 | | * 27 Checksum |
4393 | | */ |
4394 | 0 | gps_mask_t mask = ONLINE_SET; |
4395 | 0 | char receiver; |
4396 | 0 | unsigned total, L1, L2, B1, B2, E1, E5b, G1, G2; |
4397 | |
|
4398 | 0 | if ('2' != field[4][0]) { |
4399 | | // we only understand version 2 |
4400 | 0 | return mask; |
4401 | 0 | } |
4402 | 0 | if ('B' != field[5][0] && |
4403 | 0 | 'R' != field[5][0]) { |
4404 | | // Huh? Rover or Base |
4405 | 0 | return mask; |
4406 | 0 | } |
4407 | 0 | receiver = field[5][0]; |
4408 | |
|
4409 | 0 | if ('\0' != field[2][0] && |
4410 | 0 | '\0' != field[3][0]) { |
4411 | | // have date and time |
4412 | 0 | if (0 == merge_hhmmss(field[2], session) && |
4413 | 0 | 0 == merge_ddmmyy(field[3], session)) { |
4414 | | // good date and time |
4415 | 0 | mask |= TIME_SET; |
4416 | 0 | register_fractional_time("PSTI033", field[2], session); |
4417 | 0 | } |
4418 | 0 | } |
4419 | 0 | total = atoi(field[6]); |
4420 | 0 | L1 = atoi(field[7]); |
4421 | 0 | L2 = atoi(field[8]); |
4422 | 0 | B1 = atoi(field[13]); |
4423 | 0 | B2 = atoi(field[14]); |
4424 | 0 | E1 = atoi(field[18]); |
4425 | 0 | E5b = atoi(field[19]); |
4426 | 0 | G1 = atoi(field[23]); |
4427 | 0 | G2 = atoi(field[24]); |
4428 | |
|
4429 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4430 | 0 | "NMEA0183: PSTI,033: RTK RAW receiver %c Slips: total %u L1 %u " |
4431 | 0 | "L2 %u B1 %u B2 %u E1 %u E5b %u G1 %u G2 %u\n", |
4432 | 0 | receiver, total, L1, L2, B1, B2, E1, E5b, G1, G2); |
4433 | 0 | return mask; |
4434 | 0 | } |
4435 | | |
4436 | | // Skytraq RTK Baseline, moving base to moving rover |
4437 | | // PX1172RH |
4438 | | static gps_mask_t processPSTI035(int count UNUSED, char *field[], |
4439 | | struct gps_device_t *session) |
4440 | 0 | { |
4441 | | /* |
4442 | | * $PSTI,035,041457.000,170316,A,R,0.603,‐0.837,‐0.089,1.036,144.22,,,,,*1B |
4443 | | * |
4444 | | * 2 UTC time, hhmmss.sss |
4445 | | * 3 UTC Date, ddmmyy |
4446 | | * 4 Status, ‘V’ = Void ‘A’ = Active |
4447 | | * 5 Mode indicator, ‘F’ = Float RTK. ‘R’ = FIxed RTK |
4448 | | * 6 East‐projection of baseline, meters |
4449 | | * 7 North‐projection of baseline, meters |
4450 | | * 8 Up‐projection of baseline, meters |
4451 | | * 9 Baseline length, meters |
4452 | | * 10 Baseline course 144.22, true degrees |
4453 | | * 11 Reserved |
4454 | | * 12 Reserved |
4455 | | * 13 Reserved |
4456 | | * 14 Reserved |
4457 | | * 15 Reserved |
4458 | | * 16 Checksum |
4459 | | */ |
4460 | |
|
4461 | 0 | gps_mask_t mask = ONLINE_SET; |
4462 | 0 | struct baseline_t *base = &session->gpsdata.attitude.base; |
4463 | | |
4464 | | // RTK Baseline Data of Rover Moving Base Receiver |
4465 | 0 | if ('\0' != field[2][0] && |
4466 | 0 | '\0' != field[3][0]) { |
4467 | | // good date and time |
4468 | 0 | if (0 == merge_hhmmss(field[2], session) && |
4469 | 0 | 0 == merge_ddmmyy(field[3], session)) { |
4470 | 0 | mask |= TIME_SET; |
4471 | 0 | register_fractional_time( "PSTI035", field[2], session); |
4472 | 0 | } |
4473 | 0 | } |
4474 | 0 | if ('A' != field[4][0]) { |
4475 | | // No valid data, except time, sort of |
4476 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4477 | 0 | "NMEA0183: PSTI,035: not valid\n"); |
4478 | 0 | base->status = STATUS_UNK; |
4479 | 0 | return mask; |
4480 | 0 | } |
4481 | 0 | if ('F' == field[5][0]) { |
4482 | | // Float RTX |
4483 | 0 | base->status = STATUS_RTK_FLT; |
4484 | 0 | } else if ('R' == field[5][0]) { |
4485 | | // Fix RTX |
4486 | 0 | base->status = STATUS_RTK_FIX; |
4487 | 0 | } // else ?? |
4488 | |
|
4489 | 0 | base->east = safe_atof(field[6]); |
4490 | 0 | base->north = safe_atof(field[7]); |
4491 | 0 | base->up = safe_atof(field[8]); |
4492 | 0 | base->length = safe_atof(field[9]); |
4493 | 0 | base->course = safe_atof(field[10]); |
4494 | 0 | mask |= ATTITUDE_SET; |
4495 | |
|
4496 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4497 | 0 | "NMEA0183: PSTI,035: RTK Baseline mode %d E %.3f N %.3f U %.3f " |
4498 | 0 | "length %.3f course %.3f\n", |
4499 | 0 | base->status, base->east, base->north, base->up, |
4500 | 0 | base->length, base->course); |
4501 | 0 | return mask; |
4502 | 0 | } |
4503 | | |
4504 | | // Skytraq PSTI,036 – Heading, Pitch and Roll |
4505 | | // PX1172RH |
4506 | | static gps_mask_t processPSTI036(int count UNUSED, char *field[], |
4507 | | struct gps_device_t *session) |
4508 | 0 | { |
4509 | | /* |
4510 | | * $PSTI,036,054314.000,030521,191.69,‐16.35,0.00,R*4D |
4511 | | * |
4512 | | * 2 UTC time, hhmmss.sss |
4513 | | * 3 UTC Date, ddmmyy |
4514 | | * 4 Heading, 0 - 359.9, when mode == R, degrees |
4515 | | * 5 Pitch, -90 - 90, when mode == R, degrees |
4516 | | * 6 Roll, -90 - 90, when mode == R, degrees |
4517 | | * 7 Mode |
4518 | | * 'N’ = Data not valid |
4519 | | * 'A’ = Autonomous mode |
4520 | | * 'D’ = Differential mode |
4521 | | * 'E’ = Estimated (dead reckoning) mode |
4522 | | * 'M’ = Manual input mode |
4523 | | * 'S’ = Simulator mode |
4524 | | * 'F’ = Float RTK |
4525 | | * 'R’ = Fix RTK |
4526 | | * 8 Checksum |
4527 | | */ |
4528 | |
|
4529 | 0 | gps_mask_t mask = ONLINE_SET; |
4530 | 0 | int mode; |
4531 | |
|
4532 | 0 | if ('\0' != field[2][0] && |
4533 | 0 | '\0' != field[3][0]) { |
4534 | | // good date and time |
4535 | 0 | if (0 == merge_hhmmss(field[2], session) && |
4536 | 0 | 0 == merge_ddmmyy(field[3], session)) { |
4537 | 0 | mask |= TIME_SET; |
4538 | 0 | register_fractional_time("PSTI036", field[2], session); |
4539 | 0 | } |
4540 | 0 | } |
4541 | 0 | if ('\0' == field[7][0] || |
4542 | 0 | 'N' == field[7][0]) { |
4543 | | // No valid data, except time, sort of |
4544 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4545 | 0 | "NMEA0183: PSTI,036: not valid\n"); |
4546 | 0 | return mask; |
4547 | 0 | } |
4548 | | // good attitude data to use |
4549 | 0 | session->gpsdata.attitude.mtime = gpsd_utc_resolve(session); |
4550 | 0 | session->gpsdata.attitude.heading = safe_atof(field[4]); |
4551 | 0 | session->gpsdata.attitude.pitch = safe_atof(field[5]); |
4552 | 0 | session->gpsdata.attitude.roll = safe_atof(field[6]); |
4553 | 0 | mode = faa_mode(field[7][0]); |
4554 | |
|
4555 | 0 | mask |= ATTITUDE_SET; |
4556 | |
|
4557 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4558 | 0 | "NMEA0183: PSTI,036: mode %d heading %.2f pitch %.2f roll %.2f " |
4559 | 0 | "faa mode %s(%s)\n", |
4560 | 0 | mode, |
4561 | 0 | session->gpsdata.attitude.heading, |
4562 | 0 | session->gpsdata.attitude.pitch, |
4563 | 0 | session->gpsdata.attitude.roll, |
4564 | 0 | field[7], char2str(field[7][0], c_faa_mode)); |
4565 | 0 | return mask; |
4566 | 0 | } |
4567 | | |
4568 | | /* decoce $PSTMANTENNASTATUS antenna status |
4569 | | * Private STM |
4570 | | * Also used bysome Quectel. |
4571 | | * Present in ST Teseo liv4f |
4572 | | * |
4573 | | */ |
4574 | | static gps_mask_t processPSTMANTENNASTATUS(int c UNUSED, char *field[], |
4575 | | struct gps_device_t *session) |
4576 | 0 | { |
4577 | | /* |
4578 | | * $PSTMANTENNASTATUS,<ant_status>,<op_mode>,<rf_path>,<pwr_switch>*<chk> |
4579 | | * $PSTMANTENNASTATUS,0,0,0,0*51 |
4580 | | * |
4581 | | * ant_status Decimal Current |
4582 | | * 0 = Normal condition |
4583 | | * 1 = Open condition |
4584 | | * 2 = Short condition |
4585 | | * |
4586 | | * op_mode Decimal |
4587 | | * Current antenna detection operating mode |
4588 | | * 0 = Automatic mode |
4589 | | * 1 = Manual mode |
4590 | | * |
4591 | | * rf_path Decimal |
4592 | | * Current RF path |
4593 | | * 0 = External antenna |
4594 | | * 1 = Internal antenna |
4595 | | * |
4596 | | * pwr_switch Decimal |
4597 | | * Current antenna power status |
4598 | | * 0 = Antenna power is on |
4599 | | * 1 = Antenna power is off |
4600 | | */ |
4601 | |
|
4602 | 0 | static const struct vlist_t vop_mode[] = { |
4603 | 0 | {0, "Auto"}, |
4604 | 0 | {1, "Manual"}, |
4605 | 0 | {0, NULL}, |
4606 | 0 | }; |
4607 | |
|
4608 | 0 | static const struct vlist_t vpwr_switch[] = { |
4609 | 0 | {0, "On"}, |
4610 | 0 | {1, "Off"}, |
4611 | 0 | {0, NULL}, |
4612 | 0 | }; |
4613 | |
|
4614 | 0 | static const struct vlist_t vrf_path[] = { |
4615 | 0 | {0, "External"}, |
4616 | 0 | {1, "Internal"}, |
4617 | 0 | {0, NULL}, |
4618 | 0 | }; |
4619 | |
|
4620 | 0 | gps_mask_t mask = ONLINE_SET; |
4621 | 0 | int ant_status = atoi(field[1]); |
4622 | 0 | int op_mode = atoi(field[2]); |
4623 | 0 | int rf_path = atoi(field[3]); |
4624 | 0 | int pwr_switch = atoi(field[4]); |
4625 | |
|
4626 | 0 | switch(ant_status) { |
4627 | 0 | case 0: |
4628 | 0 | session->newdata.ant_stat = ANT_OK; |
4629 | 0 | break; |
4630 | 0 | case 1: |
4631 | 0 | session->newdata.ant_stat = ANT_OPEN; |
4632 | 0 | break; |
4633 | 0 | case 2: |
4634 | 0 | session->newdata.ant_stat = ANT_SHORT; |
4635 | 0 | break; |
4636 | 0 | default: |
4637 | 0 | session->newdata.ant_stat = ANT_UNK; |
4638 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4639 | 0 | "NMEA0183: ant_stat: UNKNOWN(%d)\n", ant_status); |
4640 | 0 | break; |
4641 | 0 | } |
4642 | | |
4643 | 0 | if (ANT_UNK != session->newdata.ant_stat) { |
4644 | 0 | mask |= STATUS_SET; |
4645 | 0 | } |
4646 | |
|
4647 | 0 | if (0 > op_mode || |
4648 | 0 | 1 < op_mode) { |
4649 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
4650 | 0 | "NMEA0183: malformed PSTMANTENNASTATUS op_mode: %s\n", |
4651 | 0 | field[2]); |
4652 | 0 | } |
4653 | |
|
4654 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4655 | 0 | "NMEA0183: PSTMANTENNASTATUS ant_status:%d op_mode:%d " |
4656 | 0 | "rf_path:%d pwr_switch:%d\n", |
4657 | 0 | ant_status, op_mode, rf_path, pwr_switch); |
4658 | 0 | GPSD_LOG(LOG_IO, &session->context->errout, |
4659 | 0 | "NMEA0183: PSTMANTENNASTATUS ant_status:%s(%d) op_mode:%s(%d) " |
4660 | 0 | "rf_path:%s(%d) pwer_switch:%s(%d)\n", |
4661 | 0 | val2str(session->newdata.ant_stat, vant_status), |
4662 | 0 | session->newdata.ant_stat, |
4663 | 0 | val2str(op_mode, vop_mode), op_mode, |
4664 | 0 | val2str(rf_path, vrf_path), rf_path, |
4665 | 0 | val2str(pwr_switch, vpwr_switch), pwr_switch); |
4666 | |
|
4667 | 0 | return mask; |
4668 | 0 | } |
4669 | | |
4670 | | /* decoce $PSTMVER |
4671 | | * Private STM |
4672 | | * Present in ST Teseo liv4f |
4673 | | * |
4674 | | * Response to $PSTMGETVER,255 |
4675 | | * |
4676 | | */ |
4677 | | static gps_mask_t processPSTMVER(int c UNUSED, char *field[], |
4678 | | struct gps_device_t *session) |
4679 | 0 | { |
4680 | | /* |
4681 | | * $PSTMVER,<SW name and version>*<checksum> |
4682 | | * |
4683 | | * $PSTMVER,FreeRTOS_V10.4.3_ARM*57 |
4684 | | * $PSTMVER,BINIMG_STA8041_4.6.6.5.6_ARM*0C |
4685 | | * $PSTMVER,SWCFG_86065331*62 |
4686 | | * $PSTMVER,GNSSLIB_8.4.8.13_ARM*7F |
4687 | | * $PSTMVER,OS20LIB_4.3.0_ARM*47 |
4688 | | * $PSTMVER,GPSAPP_2.2.1_ARM*1D |
4689 | | * $PSTMVER,SWCFG_8102510d*35 |
4690 | | * $PSTMVER,WAASLIB_2.18.0_ARM*61 |
4691 | | * $PSTMVER,STAGPSLIB_5.0.0_ARM*59 |
4692 | | * $PSTMVER,STA8090_622bc043*6F |
4693 | | */ |
4694 | |
|
4695 | 0 | gps_mask_t mask = ONLINE_SET; |
4696 | 0 | size_t m_len = strnlen(field[1], 40) + 2; |
4697 | 0 | size_t st_left = (sizeof(session->subtype) - |
4698 | 0 | strnlen(session->subtype, sizeof(session->subtype))); |
4699 | 0 | size_t st1_left = (sizeof(session->subtype1) - |
4700 | 0 | strnlen(session->subtype1, sizeof(session->subtype1))); |
4701 | |
|
4702 | 0 | if (NULL != strstr(session->subtype, field[1]) || |
4703 | 0 | NULL != strstr(session->subtype1, field[1])) { |
4704 | | // already haev it, ignore. |
4705 | 0 | } else if (m_len < st_left) { |
4706 | | // room in subtype |
4707 | 0 | if ('\0' == session->subtype[0]) { |
4708 | 0 | (void)strncat(session->subtype, "STM,", |
4709 | 0 | sizeof(session->subtype) - 1); |
4710 | 0 | } else { |
4711 | 0 | (void)strncat(session->subtype, ",", |
4712 | 0 | sizeof(session->subtype) - 1); |
4713 | 0 | } |
4714 | 0 | (void)strncat(session->subtype, field[1], |
4715 | 0 | sizeof(session->subtype) - 1); |
4716 | 0 | } else if (m_len < st1_left) { |
4717 | | // room in subtype1 |
4718 | 0 | if ('\0' != session->subtype1[0]) { |
4719 | 0 | (void)strncat(session->subtype1, ",", |
4720 | 0 | sizeof(session->subtype1) - 1); |
4721 | 0 | } |
4722 | 0 | (void)strncat(session->subtype1, field[1], |
4723 | 0 | sizeof(session->subtype1) - 1); |
4724 | 0 | } else { |
4725 | | // else no room. log it |
4726 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
4727 | 0 | "NMEA0183: $PSTMVER: no room for: %s\n", field[1]); |
4728 | 0 | } |
4729 | |
|
4730 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4731 | 0 | "NMEA0183: $PSTMVER: %s, %s\n", |
4732 | 0 | session->subtype, session->subtype1); |
4733 | |
|
4734 | 0 | return mask; |
4735 | 0 | } |
4736 | | |
4737 | | // Recommend Minimum Course Specific GPS/TRANSIT Data |
4738 | | static gps_mask_t processRMC(int count, char *field[], |
4739 | | struct gps_device_t *session) |
4740 | 0 | { |
4741 | | /* |
4742 | | * RMC,225446.33,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E,A*68 |
4743 | | * 1 225446.33 Time of fix 22:54:46 UTC |
4744 | | * 2 A Status of Fix: |
4745 | | * A = Autonomous, valid; |
4746 | | * V = invalid |
4747 | | * 3,4 4916.45,N Latitude 49 deg. 16.45 min North |
4748 | | * 5,6 12311.12,W Longitude 123 deg. 11.12 min West |
4749 | | * 7 000.5 Speed over ground, Knots |
4750 | | * 8 054.7 Course Made Good, True north |
4751 | | * 9 181194 Date of fix ddmmyy. 18 November 1994 |
4752 | | * 10,11 020.3,E Magnetic variation 20.3 deg East |
4753 | | * 12 A FAA mode indicator (NMEA 2.3 and later) |
4754 | | * see faa_mode() for possible mode values |
4755 | | * 13 V Nav Status (NMEA 4.1 and later) |
4756 | | * A = autonomous, |
4757 | | * D = differential, |
4758 | | * E = Estimated (DR), |
4759 | | * F = RTK Float |
4760 | | * M = Manual input mode |
4761 | | * N = No fix. Not valid, |
4762 | | * P = High Precision Mode |
4763 | | * R = RTK Integer |
4764 | | * S = Simulator, |
4765 | | * V = Invalid |
4766 | | * *68 mandatory nmea_checksum |
4767 | | * |
4768 | | * SiRF chipsets don't return either Mode Indicator or magnetic variation. |
4769 | | */ |
4770 | 0 | gps_mask_t mask = ONLINE_SET; |
4771 | 0 | char status = field[2][0]; |
4772 | 0 | int newstatus; |
4773 | | |
4774 | | /* As of Dec 2023, the regressions only have A, or V in field 2. |
4775 | | * NMEA says only A, and V are valid |
4776 | | */ |
4777 | 0 | switch (status) { |
4778 | 0 | default: |
4779 | | // missing, never seen this case. |
4780 | 0 | FALLTHROUGH |
4781 | 0 | case 'V': |
4782 | | // Invalid |
4783 | 0 | session->newdata.mode = MODE_NO_FIX; |
4784 | 0 | if ('\0' == field[1][0] || |
4785 | 0 | '\0' == field[9][0]) { |
4786 | | /* No time available. That breaks cycle end detector |
4787 | | * Force report to bypass cycle detector and get report out. |
4788 | | * To handle Querks (Quectel) like this: |
4789 | | * $GPRMC,,V,,,,,,,,,,N*53 |
4790 | | */ |
4791 | 0 | memset(&session->nmea.date, 0, sizeof(session->nmea.date)); |
4792 | 0 | session->cycle_end_reliable = false; |
4793 | 0 | mask |= REPORT_IS | TIME_SET; |
4794 | 0 | } |
4795 | 0 | mask |= STATUS_SET | MODE_SET; |
4796 | 0 | break; |
4797 | 0 | case 'A': |
4798 | | // Valid Fix |
4799 | | /* |
4800 | | * The MTK3301, Royaltek RGM-3800, and possibly other |
4801 | | * devices deliver bogus time values when the navigation |
4802 | | * warning bit is set. |
4803 | | */ |
4804 | | /* The Meinberg GPS164 only outputs GPRMC. Do set status |
4805 | | * so it can increment fixcnt. |
4806 | | */ |
4807 | 0 | if ('\0' != field[1][0] && |
4808 | 0 | 9 < count && |
4809 | 0 | '\0' != field[9][0]) { |
4810 | 0 | if (0 == merge_hhmmss(field[1], session) && |
4811 | 0 | 0 == merge_ddmmyy(field[9], session)) { |
4812 | | // got a good data/time |
4813 | 0 | mask |= TIME_SET; |
4814 | 0 | register_fractional_time(field[0], field[1], session); |
4815 | 0 | } |
4816 | 0 | } |
4817 | | // else, no point to the time only case, no regressions with that |
4818 | |
|
4819 | 0 | if (0 == do_lat_lon(&field[3], &session->newdata)) { |
4820 | 0 | newstatus = STATUS_GPS; |
4821 | 0 | mask |= LATLON_SET; |
4822 | 0 | if (MODE_2D >= session->lastfix.mode) { |
4823 | | /* we have at least a 2D fix |
4824 | | * might cause blinking */ |
4825 | 0 | session->newdata.mode = MODE_2D; |
4826 | 0 | } else if (MODE_3D == session->lastfix.mode) { |
4827 | | // keep the 3D, this may be cycle starter |
4828 | | // might cause blinking |
4829 | 0 | session->newdata.mode = MODE_3D; |
4830 | 0 | } |
4831 | 0 | } else { |
4832 | 0 | newstatus = STATUS_UNK; |
4833 | 0 | session->newdata.mode = MODE_NO_FIX; |
4834 | 0 | } |
4835 | 0 | mask |= MODE_SET; |
4836 | 0 | if ('\0' != field[7][0]) { |
4837 | 0 | session->newdata.speed = safe_atof(field[7]) * KNOTS_TO_MPS; |
4838 | 0 | mask |= SPEED_SET; |
4839 | 0 | } |
4840 | 0 | if ('\0' != field[8][0]) { |
4841 | 0 | session->newdata.track = safe_atof(field[8]); |
4842 | 0 | mask |= TRACK_SET; |
4843 | 0 | } |
4844 | | |
4845 | | // get magnetic variation |
4846 | 0 | if ('\0' != field[10][0] && |
4847 | 0 | '\0' != field[11][0]) { |
4848 | 0 | session->newdata.magnetic_var = safe_atof(field[10]); |
4849 | |
|
4850 | 0 | switch (field[11][0]) { |
4851 | 0 | case 'E': |
4852 | | // no change |
4853 | 0 | break; |
4854 | 0 | case 'W': |
4855 | 0 | session->newdata.magnetic_var = -session->newdata.magnetic_var; |
4856 | 0 | break; |
4857 | 0 | default: |
4858 | | // huh? |
4859 | 0 | session->newdata.magnetic_var = NAN; |
4860 | 0 | break; |
4861 | 0 | } |
4862 | 0 | if (0 == isfinite(session->newdata.magnetic_var) || |
4863 | 0 | 0.09 >= fabs(session->newdata.magnetic_var)) { |
4864 | | // some GPS set 0.0,E, or 0,w instead of blank |
4865 | 0 | session->newdata.magnetic_var = NAN; |
4866 | 0 | } else { |
4867 | 0 | mask |= MAGNETIC_TRACK_SET; |
4868 | 0 | } |
4869 | 0 | } |
4870 | | |
4871 | 0 | if (12 < count) { |
4872 | 0 | if ('\0' != field[12][0]) { |
4873 | | // Have FAA mode indicator (NMEA 2.3 and later) |
4874 | 0 | newstatus = faa_mode(field[12][0]); |
4875 | 0 | } |
4876 | | /* |
4877 | | * Navigation Status |
4878 | | * If present, can not be NUL: |
4879 | | * S = Safe |
4880 | | * C = Caution |
4881 | | * U = Unsafe |
4882 | | * V = invalid. |
4883 | | * |
4884 | | * In the regressions, as of Dec 2023, field 13 is |
4885 | | * always 'V', and field 2 is always 'A'. That seems |
4886 | | * like an invalid combination.... */ |
4887 | 0 | if (13 < count) { |
4888 | 0 | if ('\0' != field[13][0]) { |
4889 | 0 | ; // skip for now |
4890 | 0 | } |
4891 | 0 | } |
4892 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4893 | 0 | "NMEA0183: RMC: status %s(%d) faa mode %s(%s) " |
4894 | 0 | "faa status %s\n", |
4895 | 0 | field[2], newstatus, field[12], |
4896 | 0 | char2str(field[12][0], c_faa_mode), field[13]); |
4897 | 0 | } |
4898 | | |
4899 | | /* |
4900 | | * This copes with GPSes like the Magellan EC-10X that *only* emit |
4901 | | * GPRMC. In this case we set mode and status here so the client |
4902 | | * code that relies on them won't mistakenly believe it has never |
4903 | | * received a fix. |
4904 | | */ |
4905 | 0 | if (3 < session->gpsdata.satellites_used) { |
4906 | | // 4 sats used means 3D |
4907 | 0 | session->newdata.mode = MODE_3D; |
4908 | 0 | } else if (0 != isfinite(session->gpsdata.fix.altHAE) || |
4909 | 0 | 0 != isfinite(session->gpsdata.fix.altMSL)) { |
4910 | | /* we probably have at least a 3D fix |
4911 | | * this handles old GPS that do not report 3D */ |
4912 | 0 | session->newdata.mode = MODE_3D; |
4913 | 0 | } |
4914 | 0 | session->newdata.status = newstatus; |
4915 | 0 | mask |= STATUS_SET | MODE_SET; |
4916 | 0 | } |
4917 | | |
4918 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4919 | 0 | "NMEA0183: RMC: ddmmyy=%s hhmmss=%s lat=%.2f lon=%.2f " |
4920 | 0 | "speed=%.2f track=%.2f mode=%d var=%.1f status=%d\n", |
4921 | 0 | field[9], field[1], |
4922 | 0 | session->newdata.latitude, |
4923 | 0 | session->newdata.longitude, |
4924 | 0 | session->newdata.speed, |
4925 | 0 | session->newdata.track, |
4926 | 0 | session->newdata.mode, |
4927 | 0 | session->newdata.magnetic_var, |
4928 | 0 | session->newdata.status); |
4929 | 0 | return mask; |
4930 | 0 | } |
4931 | | |
4932 | | /* precessROT() - process Rate Of Turn |
4933 | | * |
4934 | | * Deprecated by NMEA in 2008 |
4935 | | */ |
4936 | | static gps_mask_t processROT(int c UNUSED, char *field[], |
4937 | | struct gps_device_t *session) |
4938 | 0 | { |
4939 | | /* |
4940 | | * $APROT,0.013,A*35 |
4941 | | * |
4942 | | * 1) Rate of Turn deg/min |
4943 | | * 2) A = valid, V = Void |
4944 | | * ) checksum |
4945 | | * |
4946 | | */ |
4947 | 0 | gps_mask_t mask = ONLINE_SET; |
4948 | |
|
4949 | 0 | if ('\0' == field[1][0] || |
4950 | 0 | 'A' != field[2][0]) { |
4951 | | // no data |
4952 | 0 | return mask; |
4953 | 0 | } |
4954 | | |
4955 | | // assume good data |
4956 | 0 | session->gpsdata.attitude.rot = safe_atof(field[1]); |
4957 | 0 | mask |= ATTITUDE_SET; |
4958 | |
|
4959 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4960 | 0 | "NMEA0183: $xxROT:Rate of Turn %f\n", |
4961 | 0 | session->gpsdata.attitude.rot); |
4962 | 0 | return mask; |
4963 | 0 | } |
4964 | | |
4965 | | /* |
4966 | | * Unicore $SNRSTAT Sensor status |
4967 | | * Note: Invalid sender: $SN |
4968 | | */ |
4969 | | static gps_mask_t processSNRSTAT(int count UNUSED, char *field[], |
4970 | | struct gps_device_t *session) |
4971 | 0 | { |
4972 | | /* |
4973 | | * $SNRSTAT,1,1,0,0*5D |
4974 | | */ |
4975 | |
|
4976 | 0 | gps_mask_t mask = ONLINE_SET; |
4977 | 0 | static char probe[] = "$PDTINFO\r\n"; |
4978 | 0 | static char type[] = "Unicore"; |
4979 | 0 | int insstatus = atoi(field[1]); // IMU status |
4980 | 0 | int odostatus = atoi(field[2]); // Odometer Status |
4981 | 0 | int InstallState = atoi(field[3]); // Install State |
4982 | 0 | int mapstat = atoi(field[4]); // PAP status |
4983 | |
|
4984 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
4985 | 0 | "NMEA0183: SNRSTAT insstatus %d obsstatus %d InstallState %d " |
4986 | 0 | "mapstat %d\n", |
4987 | 0 | insstatus, odostatus, InstallState, mapstat); |
4988 | |
|
4989 | 0 | GPSD_LOG(LOG_IO, &session->context->errout, |
4990 | 0 | "NMEA0183: SNRSTAT insstatus %s obsstatus %s InstallState %s " |
4991 | 0 | "mapstat %s\n", |
4992 | 0 | val2str(insstatus, vsnrstat_insstatus), |
4993 | 0 | val2str(odostatus, vsnrstat_odostatus), |
4994 | 0 | val2str(InstallState, vsnrstat_InstallState), |
4995 | 0 | val2str(mapstat, vsnrstat_mapstat)); |
4996 | |
|
4997 | 0 | if ('\0' == session->subtype[0]) { |
4998 | | // this is Unicore |
4999 | | // Send $PDTINFO to get back $PDTINFO,.... |
5000 | 0 | (void)gpsd_write(session, probe, sizeof(probe)); |
5001 | | // mark so we don't ask twice |
5002 | 0 | (void)strlcpy(session->subtype, type, sizeof(session->subtype) - 1); |
5003 | 0 | } |
5004 | 0 | return mask; |
5005 | 0 | } |
5006 | | |
5007 | | |
5008 | | /* |
5009 | | * Skytraq undocumented debug sentences take this format: |
5010 | | * $STI,type,val*CS |
5011 | | * type is a 2 char subsentence type |
5012 | | * Note: NO checksum |
5013 | | */ |
5014 | | static gps_mask_t processSTI(int count, char *field[], |
5015 | | struct gps_device_t *session) |
5016 | 0 | { |
5017 | 0 | gps_mask_t mask = ONLINE_SET; |
5018 | |
|
5019 | 0 | if (0 != strncmp(session->device_type->type_name, "Skytraq", 7)) { |
5020 | | // this is skytraq, but marked yet, so probe for Skytraq |
5021 | | // Send MID 0x02, to get back MID 0x80 |
5022 | 0 | (void)gpsd_write(session, "\xA0\xA1\x00\x02\x02\x01\x03\x0d\x0a",9); |
5023 | 0 | } |
5024 | |
|
5025 | 0 | if ( 0 == strcmp( field[1], "IC") ) { |
5026 | | // $STI,IC,error=XX, this is always very bad, but undocumented |
5027 | 0 | GPSD_LOG(LOG_ERROR, &session->context->errout, |
5028 | 0 | "NMEA0183: Skytraq: $STI,%s,%s\n", field[1], field[2]); |
5029 | 0 | return mask; |
5030 | 0 | } |
5031 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
5032 | 0 | "NMEA0183: STI,%s: Unknown type, Count: %d\n", field[1], count); |
5033 | |
|
5034 | 0 | return mask; |
5035 | 0 | } |
5036 | | |
5037 | | // SiRF Estimated Position Errors |
5038 | | // $xxTHS -- True Heading and Status |
5039 | | static gps_mask_t processTHS(int c UNUSED, char *field[], |
5040 | | struct gps_device_t *session) |
5041 | 0 | { |
5042 | | /* |
5043 | | * $GNTHS,121.15.A*1F<CR><LF> |
5044 | | * 1 - Heading, degrees True |
5045 | | * 2 - Mode indicator |
5046 | | * 'A’ = Autonomous |
5047 | | * 'E’ = Estimated (dead reckoning) |
5048 | | * 'M’ = Manual input |
5049 | | * 'S’ = Simulator |
5050 | | * 'V’ = Data not valid |
5051 | | * 3 - Checksum |
5052 | | */ |
5053 | 0 | gps_mask_t mask = ONLINE_SET; |
5054 | 0 | double heading; |
5055 | |
|
5056 | 0 | if ('\0' == field[1][0] || |
5057 | 0 | '\0' == field[2][0]) { |
5058 | | // no data |
5059 | 0 | return mask; |
5060 | 0 | } |
5061 | 0 | if ('V' == field[2][0]) { |
5062 | | // invalid data |
5063 | | // ignore A, E, M and S for now |
5064 | 0 | return mask; |
5065 | 0 | } |
5066 | 0 | heading = safe_atof(field[1]); |
5067 | 0 | if ((0.0 > heading) || |
5068 | 0 | (360.0 < heading)) { |
5069 | | // bad data |
5070 | 0 | return mask; |
5071 | 0 | } |
5072 | | |
5073 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
5074 | 0 | "NMEA0183: $xxTHS heading %lf mode %s\n", |
5075 | 0 | heading, field[2]); |
5076 | |
|
5077 | 0 | return mask; |
5078 | 0 | } |
5079 | | |
5080 | | static gps_mask_t processTNTA(int c UNUSED, char *field[], |
5081 | | struct gps_device_t *session) |
5082 | 0 | { |
5083 | | /* |
5084 | | * Proprietary sentence for iSync GRClok/LNRClok. |
5085 | | |
5086 | | $PTNTA,20000102173852,1,T4,,,6,1,0*32 |
5087 | | |
5088 | | 1. Date/time in format year, month, day, hour, minute, second |
5089 | | 2. Oscillator quality 0:warming up, 1:freerun, 2:disciplined. |
5090 | | 3. Always T4. Format indicator. |
5091 | | 4. Interval ppsref-ppsout in [ns]. Blank if no ppsref. |
5092 | | 5. Fine phase comparator in approx. [ns]. Always close to -500 or |
5093 | | +500 if not disciplined. Blank if no ppsref. |
5094 | | 6. iSync Status. 0:warming up or no light, 1:tracking set-up, |
5095 | | 2:track to PPSREF, 3:synch to PPSREF, 4:Free Run. Track OFF, |
5096 | | 5:FR. PPSREF unstable, 6:FR. No PPSREF, 7:FREEZE, 8:factory |
5097 | | used, 9:searching Rb line |
5098 | | 7. GPS messages indicator. 0:do not take account, 1:take account, |
5099 | | but no message, 2:take account, partially ok, 3:take account, |
5100 | | totally ok. |
5101 | | 8. Transfer quality of date/time. 0:no, 1:manual, 2:GPS, older |
5102 | | than x hours, 3:GPS, fresh. |
5103 | | |
5104 | | */ |
5105 | 0 | gps_mask_t mask = ONLINE_SET; |
5106 | |
|
5107 | 0 | if (0 == strcmp(field[3], "T4")) { |
5108 | 0 | struct oscillator_t *osc = &session->gpsdata.osc; |
5109 | 0 | unsigned int quality = atoi(field[2]); |
5110 | 0 | unsigned int delta = atoi(field[4]); |
5111 | 0 | unsigned int fine = atoi(field[5]); |
5112 | 0 | unsigned int status = atoi(field[6]); |
5113 | 0 | char deltachar = field[4][0]; |
5114 | |
|
5115 | 0 | osc->running = (0 < quality); |
5116 | 0 | osc->reference = (deltachar && (deltachar != '?')); |
5117 | 0 | if (osc->reference) { |
5118 | 0 | if (500 > delta) { |
5119 | 0 | osc->delta = fine; |
5120 | 0 | } else { |
5121 | 0 | osc->delta = ((delta < 500000000) ? delta : 1000000000 - delta); |
5122 | 0 | } |
5123 | 0 | } else { |
5124 | 0 | osc->delta = 0; |
5125 | 0 | } |
5126 | 0 | osc->disciplined = ((quality == 2) && (status == 3)); |
5127 | 0 | mask |= OSCILLATOR_SET; |
5128 | |
|
5129 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5130 | 0 | "NMEA0183: PTNTA,T4: quality=%s, delta=%s, fine=%s," |
5131 | 0 | "status=%s\n", |
5132 | 0 | field[2], field[4], field[5], field[6]); |
5133 | 0 | } |
5134 | 0 | return mask; |
5135 | 0 | } |
5136 | | |
5137 | | static gps_mask_t processTNTHTM(int c UNUSED, char *field[], |
5138 | | struct gps_device_t *session) |
5139 | 0 | { |
5140 | | /* |
5141 | | * Proprietary sentence for True North Technologies Magnetic Compass. |
5142 | | * This may also apply to some Honeywell units since they may have been |
5143 | | * designed by True North. |
5144 | | |
5145 | | $PTNTHTM,14223,N,169,N,-43,N,13641,2454*15 |
5146 | | |
5147 | | HTM,x.x,a,x.x,a,x.x,a,x.x,x.x*hh<cr><lf> |
5148 | | Fields in order: |
5149 | | 1. True heading (compass measurement + deviation + variation) |
5150 | | 2. magnetometer status character: |
5151 | | C = magnetometer calibration alarm |
5152 | | L = low alarm |
5153 | | M = low warning |
5154 | | N = normal |
5155 | | O = high warning |
5156 | | P = high alarm |
5157 | | V = magnetometer voltage level alarm |
5158 | | 3. pitch angle |
5159 | | 4. pitch status character - see field 2 above |
5160 | | 5. roll angle |
5161 | | 6. roll status character - see field 2 above |
5162 | | 7. dip angle |
5163 | | 8. relative magnitude horizontal component of earth's magnetic field |
5164 | | *hh mandatory nmea_checksum |
5165 | | |
5166 | | By default, angles are reported as 26-bit integers: weirdly, the |
5167 | | technical manual says either 0 to 65535 or -32768 to 32767 can |
5168 | | occur as a range. |
5169 | | */ |
5170 | 0 | gps_mask_t mask = ONLINE_SET; |
5171 | | |
5172 | | // True heading |
5173 | 0 | session->gpsdata.attitude.heading = safe_atof(field[1]); |
5174 | 0 | session->gpsdata.attitude.mag_st = *field[2]; |
5175 | 0 | session->gpsdata.attitude.pitch = safe_atof(field[3]); |
5176 | 0 | session->gpsdata.attitude.pitch_st = *field[4]; |
5177 | 0 | session->gpsdata.attitude.roll = safe_atof(field[5]); |
5178 | 0 | session->gpsdata.attitude.roll_st = *field[6]; |
5179 | 0 | session->gpsdata.attitude.dip = safe_atof(field[7]); |
5180 | 0 | session->gpsdata.attitude.mag_x = safe_atof(field[8]); |
5181 | 0 | mask |= (ATTITUDE_SET); |
5182 | |
|
5183 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5184 | 0 | "NMEA0183: $PTNTHTM heading %lf (%c).\n", |
5185 | 0 | session->gpsdata.attitude.heading, |
5186 | 0 | session->gpsdata.attitude.mag_st); |
5187 | 0 | return mask; |
5188 | 0 | } |
5189 | | |
5190 | | // GPS Text message |
5191 | | static gps_mask_t processTXT(int count, char *field[], |
5192 | | struct gps_device_t *session) |
5193 | 0 | { |
5194 | | /* |
5195 | | * $GNTXT,01,01,01,PGRM inv format*2A |
5196 | | * 1 Number of sentences for full data |
5197 | | * 1 Sentence 1 of 1 |
5198 | | * 01 Message type |
5199 | | * 00 - error |
5200 | | * 01 - warning |
5201 | | * 02 - notice |
5202 | | * 07 - user |
5203 | | * PGRM inv format ASCII text |
5204 | | * |
5205 | | * Can occur with talker IDs: |
5206 | | * BD (Beidou), |
5207 | | * GA (Galileo), |
5208 | | * GB (Beidou), |
5209 | | * GI (IRNSS |
5210 | | * GL (GLONASS), |
5211 | | * GN (GLONASS, any combination GNSS), |
5212 | | * GP (GPS, SBAS, QZSS), |
5213 | | * GQ (QZSS). |
5214 | | * PQ (QZSS). Quectel Quirk |
5215 | | * QZ (QZSS). |
5216 | | * |
5217 | | * Unicore undcumented: |
5218 | | * |
5219 | | * $GNTXT,01,01,01,0,500482,0000,80A0,80A0,-45.277,0*6B |
5220 | | * $GNTXT,01,01,02,0,00,10000,00,01,17,01,0001,0000,0.000*57 |
5221 | | */ |
5222 | 0 | gps_mask_t mask = ONLINE_SET; |
5223 | 0 | int msgType = 0; |
5224 | 0 | char *msgType_txt = "Unknown"; |
5225 | |
|
5226 | 0 | if (5 != count) { |
5227 | 0 | return mask; |
5228 | 0 | } |
5229 | | |
5230 | 0 | msgType = atoi(field[3]); |
5231 | |
|
5232 | 0 | switch ( msgType ) { |
5233 | 0 | case 0: |
5234 | 0 | msgType_txt = "Error"; |
5235 | 0 | break; |
5236 | 0 | case 1: |
5237 | 0 | msgType_txt = "Warning"; |
5238 | 0 | break; |
5239 | 0 | case 2: |
5240 | 0 | msgType_txt = "Notice"; |
5241 | 0 | break; |
5242 | 0 | case 7: |
5243 | 0 | msgType_txt = "User"; |
5244 | 0 | break; |
5245 | 0 | } |
5246 | | |
5247 | | // maximum text length unknown, guess 80 |
5248 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
5249 | 0 | "NMEA0183: TXT: %.10s: %.80s\n", |
5250 | 0 | msgType_txt, field[4]); |
5251 | 0 | return mask; |
5252 | 0 | } |
5253 | | |
5254 | | /* process xxVTG |
5255 | | * $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K |
5256 | | * $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K,A |
5257 | | * |
5258 | | * where: |
5259 | | * 1,2 054.7,T True track made good (degrees) |
5260 | | * 3,4 034.4,M Magnetic track made good |
5261 | | * 5,6 005.5,N Ground speed, knots |
5262 | | * 7,8 010.2,K Ground speed, Kilometers per hour |
5263 | | * 9 A Mode Indicator (optional) |
5264 | | * see faa_mode() for possible mode values |
5265 | | * |
5266 | | * see also: |
5267 | | * https://gpsd.gitlab.io/gpsd/NMEA.html#_vtg_track_made_good_and_ground_speed |
5268 | | */ |
5269 | | static gps_mask_t processVTG(int count, |
5270 | | char *field[], |
5271 | | struct gps_device_t *session) |
5272 | 0 | { |
5273 | 0 | gps_mask_t mask = ONLINE_SET; |
5274 | |
|
5275 | 0 | if( (field[1][0] == '\0') || (field[5][0] == '\0')){ |
5276 | 0 | return mask; |
5277 | 0 | } |
5278 | | |
5279 | | // ignore empty/missing field, fix mode of last resort |
5280 | 0 | if ((9 < count) && |
5281 | 0 | ('\0' != field[9][0])) { |
5282 | |
|
5283 | 0 | switch (field[9][0]) { |
5284 | 0 | case 'A': |
5285 | | // Autonomous, 2D or 3D fix |
5286 | 0 | FALLTHROUGH |
5287 | 0 | case 'D': |
5288 | | // Differential, 2D or 3D fix |
5289 | | // MODE_SET here causes issues |
5290 | | // mask |= MODE_SET; |
5291 | 0 | break; |
5292 | 0 | case 'E': |
5293 | | // Estimated, DR only |
5294 | 0 | FALLTHROUGH |
5295 | 0 | case 'N': |
5296 | | // Not Valid |
5297 | | // MODE_SET here causes issues |
5298 | | // mask |= MODE_SET; |
5299 | | // nothing to use here, leave |
5300 | 0 | return mask; |
5301 | 0 | default: |
5302 | | // Huh? |
5303 | 0 | break; |
5304 | 0 | } |
5305 | 0 | } |
5306 | | |
5307 | | // set true track |
5308 | 0 | session->newdata.track = safe_atof(field[1]); |
5309 | 0 | mask |= TRACK_SET; |
5310 | | |
5311 | | // set magnetic variation |
5312 | 0 | if ('\0' != field[3][0]) { // ignore empty fields |
5313 | 0 | session->newdata.magnetic_track = safe_atof(field[3]); |
5314 | 0 | mask |= MAGNETIC_TRACK_SET; |
5315 | 0 | } |
5316 | |
|
5317 | 0 | session->newdata.speed = safe_atof(field[5]) * KNOTS_TO_MPS; |
5318 | 0 | mask |= SPEED_SET; |
5319 | |
|
5320 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5321 | 0 | "NMEA0183: VTG: course(T)=%.2f, course(M)=%.2f, speed=%.2f", |
5322 | 0 | session->newdata.track, session->newdata.magnetic_track, |
5323 | 0 | session->newdata.speed); |
5324 | 0 | return mask; |
5325 | 0 | } |
5326 | | |
5327 | | /* precessXDR() - process transducer messages |
5328 | | */ |
5329 | | static gps_mask_t processXDR(int count, char *field[], |
5330 | | struct gps_device_t *session) |
5331 | 0 | { |
5332 | | /* |
5333 | | * $APXDR,A,0.135,D,PTCH*7C |
5334 | | * $APXDR,A,3.861,D,ROLL*65 |
5335 | | * |
5336 | | * 1) Transducer type |
5337 | | * A = Angular Displacement |
5338 | | * 2) Measurement data |
5339 | | * 3) Units of measure |
5340 | | * D = degrees |
5341 | | * 4) Transducer ID |
5342 | | * can be repeated... |
5343 | | * ) checksum |
5344 | | * |
5345 | | * TODO: stacked measurements, like the TNT Revolution: |
5346 | | $HCXDR,A,177,D,PITCH,A,-40,D,ROLL,G,358,,MAGX,G,2432,,MAGY,G,-8974,,MAGZ*47 |
5347 | | * the bund_zeus: |
5348 | | $IIXDR,C,,C,AIRTEMP,A,-3.0,D,HEEL,A,3.7,D,TRIM,P,,B,BARO,A,-4.2,D,RUDDER*28 |
5349 | | * |
5350 | | */ |
5351 | 0 | gps_mask_t mask = ONLINE_SET; |
5352 | 0 | unsigned int i; |
5353 | 0 | unsigned int num_meas = count / 4; |
5354 | |
|
5355 | 0 | for (i = 0; i < num_meas; i++) { |
5356 | 0 | double data = 0.0; |
5357 | 0 | unsigned int j = i * 4; |
5358 | |
|
5359 | 0 | if ('\0' == field[j + 2][0]) { |
5360 | | // no data, skip it |
5361 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
5362 | 0 | "NMEA0183: $xxXDR: Type %.10s Data %.10s Units %.10s " |
5363 | 0 | "ID %.10s\n", |
5364 | 0 | field[j + 1], field[j + 2], field[j + 3], field[j + 4]); |
5365 | 0 | continue; |
5366 | 0 | } |
5367 | | |
5368 | 0 | data = safe_atof(field[j + 2]); |
5369 | |
|
5370 | 0 | switch (field[j + 1][0]) { |
5371 | 0 | case 'A': |
5372 | | // angles |
5373 | 0 | if ('D' != field[j + 3][0]) { |
5374 | | // not degrees |
5375 | 0 | continue; |
5376 | 0 | } |
5377 | 0 | if (0 == strncmp( "HEEL", field[j + 4], 10)) { |
5378 | | // session->gpsdata.attitude.roll = data; |
5379 | | // mask |= ATTITUDE_SET; |
5380 | 0 | } else if (0 == strncmp( "PTCH", field[j + 4], 10) || |
5381 | 0 | 0 == strncmp( "PITCH", field[j + 4], 10)) { |
5382 | 0 | session->gpsdata.attitude.pitch = data; |
5383 | 0 | mask |= ATTITUDE_SET; |
5384 | 0 | } else if (0 == strncmp( "ROLL", field[j + 4], 10)) { |
5385 | 0 | session->gpsdata.attitude.roll = data; |
5386 | 0 | mask |= ATTITUDE_SET; |
5387 | 0 | } else if (0 == strncmp( "RUDDER", field[j + 4], 10)) { |
5388 | | // session->gpsdata.attitude.roll = data; |
5389 | | // mask |= ATTITUDE_SET; |
5390 | 0 | } else if (0 == strncmp( "TRIM", field[j + 4], 10)) { |
5391 | | // session->gpsdata.attitude.roll = data; |
5392 | | // mask |= ATTITUDE_SET; |
5393 | 0 | } |
5394 | | // else, unknown |
5395 | 0 | break; |
5396 | 0 | case 'G': |
5397 | | // G: TODO: G,358,,MAGX,G,2432,,MAGY,G,-8974,,MAGZ*47 |
5398 | | // oddly field[j + 3][0] is NUL... |
5399 | |
|
5400 | 0 | if (0 == strncmp( "MAGX", field[j + 4], 10)) { |
5401 | | // unknown scale |
5402 | 0 | session->gpsdata.attitude.mag_x = data; |
5403 | 0 | mask |= ATTITUDE_SET; |
5404 | 0 | } else if (0 == strncmp( "MAGY", field[j + 4], 10)) { |
5405 | | // unknown scale |
5406 | 0 | session->gpsdata.attitude.mag_y = data; |
5407 | 0 | mask |= ATTITUDE_SET; |
5408 | 0 | } else if (0 == strncmp( "MAGZ", field[j + 4], 10)) { |
5409 | | // unknown scale |
5410 | 0 | session->gpsdata.attitude.mag_z = data; |
5411 | 0 | mask |= ATTITUDE_SET; |
5412 | 0 | } |
5413 | 0 | break; |
5414 | 0 | case 'C': |
5415 | | // C,,C,AIRTEMP, |
5416 | 0 | FALLTHROUGH |
5417 | 0 | case 'P': |
5418 | | // Pressure: TODO: P,,B,BARO |
5419 | 0 | FALLTHROUGH |
5420 | 0 | default: |
5421 | 0 | break; |
5422 | 0 | } |
5423 | | |
5424 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
5425 | 0 | "NMEA0183: $xxXDR: Type %.10s Data %f Units %.10s ID %.10s\n", |
5426 | 0 | field[j + 1], data, field[j + 3], field[j + 4]); |
5427 | 0 | } |
5428 | 0 | return mask; |
5429 | 0 | } |
5430 | | |
5431 | | // Time & Date |
5432 | | static gps_mask_t processZDA(int c UNUSED, char *field[], |
5433 | | struct gps_device_t *session) |
5434 | 0 | { |
5435 | | /* |
5436 | | * $GPZDA,160012.71,11,03,2004,-1,00*7D |
5437 | | * 1) UTC time (hours, minutes, seconds, may have fractional subsecond) |
5438 | | * 2) Day, 01 to 31 |
5439 | | * 3) Month, 01 to 12 |
5440 | | * 4) Year (4 digits) |
5441 | | * 5) Local zone description, 00 to +- 13 hours |
5442 | | * 6) Local zone minutes description, apply same sign as local hours |
5443 | | * 7) Checksum |
5444 | | * |
5445 | | * Note: some devices, like the u-blox ANTARIS 4h, are known to ship ZDAs |
5446 | | * with some fields blank under poorly-understood circumstances (probably |
5447 | | * when they don't have satellite lock yet). |
5448 | | */ |
5449 | 0 | gps_mask_t mask = ONLINE_SET; |
5450 | 0 | int year, mon, mday, century; |
5451 | 0 | char ts_buf[TIMESPEC_LEN]; |
5452 | |
|
5453 | 0 | if ('\0' == field[1][0] || |
5454 | 0 | '\0' == field[2][0] || |
5455 | 0 | '\0' == field[3][0] || |
5456 | 0 | '\0' == field[4][0]) { |
5457 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
5458 | 0 | "NMEA0183: ZDA fields are empty\n"); |
5459 | 0 | return mask; |
5460 | 0 | } |
5461 | | |
5462 | 0 | if (0 != merge_hhmmss(field[1], session)) { |
5463 | | // bad time |
5464 | 0 | return mask; |
5465 | 0 | } |
5466 | | |
5467 | | /* |
5468 | | * We didn't register fractional time here because we wanted to leave |
5469 | | * ZDA out of end-of-cycle detection. Some devices sensibly emit it only |
5470 | | * when they have a fix, so watching for it can make them look |
5471 | | * like they have a variable fix reporting cycle. But later thought |
5472 | | * was to not throw out good data because it is inconvenient. |
5473 | | */ |
5474 | 0 | mday = atoi(field[2]); |
5475 | 0 | mon = atoi(field[3]); |
5476 | 0 | year = atoi(field[4]); |
5477 | 0 | century = year - year % 100; |
5478 | 0 | if (1900 > year || |
5479 | 0 | 2200 < year) { |
5480 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
5481 | 0 | "NMEA0183: malformed ZDA year: %s\n", field[4]); |
5482 | 0 | } else if (1 > mon || |
5483 | 0 | 12 < mon) { |
5484 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
5485 | 0 | "NMEA0183: malformed ZDA month: %s\n", field[3]); |
5486 | 0 | } else if (1 > mday || |
5487 | 0 | 31 < mday) { |
5488 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
5489 | 0 | "NMEA0183: malformed ZDA day: %s\n", field[2]); |
5490 | 0 | } else { |
5491 | 0 | gpsd_century_update(session, century); |
5492 | 0 | session->nmea.date.tm_year = year - 1900; |
5493 | 0 | session->nmea.date.tm_mon = mon - 1; |
5494 | 0 | session->nmea.date.tm_mday = mday; |
5495 | 0 | session->newdata.time = gpsd_utc_resolve(session); |
5496 | 0 | register_fractional_time(field[0], field[1], session); |
5497 | 0 | mask = TIME_SET; |
5498 | 0 | } |
5499 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5500 | 0 | "NMEA0183: ZDA time %s\n", |
5501 | 0 | timespec_str(&session->newdata.time, ts_buf, sizeof(ts_buf))); |
5502 | 0 | return mask; |
5503 | 0 | } |
5504 | | |
5505 | | |
5506 | | |
5507 | | /************************************************************************** |
5508 | | * |
5509 | | * Entry points begin here |
5510 | | * |
5511 | | **************************************************************************/ |
5512 | | |
5513 | | // parse an NMEA sentence, unpack it into a session structure |
5514 | | gps_mask_t nmea_parse(char *sentence, struct gps_device_t * session) |
5515 | 0 | { |
5516 | 0 | typedef gps_mask_t(*nmea_decoder) (int count, char *f[], |
5517 | 0 | struct gps_device_t * session); |
5518 | 0 | static struct |
5519 | 0 | { |
5520 | 0 | char *name; |
5521 | 0 | char *name1; // 2nd field to match, as is $PSTI,030 |
5522 | 0 | int nf; // minimum number of fields required to parse |
5523 | 0 | bool cycle_continue; // cycle continuer? |
5524 | 0 | nmea_decoder decoder; |
5525 | 0 | } nmea_phrase[NMEA_NUM] = { |
5526 | 0 | {"PGLOR", NULL, 2, false, processPGLOR}, // Android something... |
5527 | 0 | {"PGRMB", NULL, 0, false, NULL}, // ignore Garmin DGPS Beacon Info |
5528 | 0 | {"PGRMC", NULL, 0, false, NULL}, // ignore Garmin Sensor Config |
5529 | 0 | {"PGRME", NULL, 7, false, processPGRME}, |
5530 | 0 | {"PGRMF", NULL, 15, false, processPGRMF}, // Garmin GPS Fix Data |
5531 | 0 | {"PGRMH", NULL, 0, false, NULL}, // ignore Garmin Aviation Height |
5532 | 0 | {"PGRMI", NULL, 0, false, NULL}, // ignore Garmin Sensor Init |
5533 | 0 | {"PGRMM", NULL, 2, false, processPGRMM}, // Garmin Map Datum |
5534 | 0 | {"PGRMO", NULL, 0, false, NULL}, // ignore Garmin Sentence Enable |
5535 | 0 | {"PGRMT", NULL, 10, false, processPGRMT}, // Garmin Sensor Info |
5536 | 0 | {"PGRMV", NULL, 4, false, processPGRMV}, // Garmin 3D Velocity Info |
5537 | 0 | {"PGRMZ", NULL, 4, false, processPGRMZ}, |
5538 | | /* |
5539 | | * Basic sentences must come after the PG* ones, otherwise |
5540 | | * Garmins can get stuck in a loop that looks like this: |
5541 | | * |
5542 | | * 1. A Garmin GPS in NMEA mode is detected. |
5543 | | * |
5544 | | * 2. PGRMC is sent to reconfigure to Garmin binary mode. |
5545 | | * If successful, the GPS echoes the phrase. |
5546 | | * |
5547 | | * 3. nmea_parse() sees the echo as RMC because the talker |
5548 | | * ID is ignored, and fails to recognize the echo as |
5549 | | * PGRMC and ignore it. |
5550 | | * |
5551 | | * 4. The mode is changed back to NMEA, resulting in an |
5552 | | * infinite loop. |
5553 | | */ |
5554 | 0 | {"AAM", NULL, 0, false, NULL}, // ignore Waypoint Arrival Alarm |
5555 | 0 | {"ACCURACY", NULL, 1, true, processACCURACY}, |
5556 | 0 | {"ACN", NULL, 0, false, NULL}, // Alert Command, 4.10+ |
5557 | 0 | {"ALC", NULL, 0, false, NULL}, // Cyclic Alert List, 4.10+ |
5558 | 0 | {"ALF", NULL, 0, false, NULL}, // Alert Sentence, 4.10+ |
5559 | 0 | {"ALM", NULL, 0, false, NULL}, // GPS Almanac Data |
5560 | 0 | {"APB", NULL, 0, false, NULL}, // Autopilot Sentence B |
5561 | 0 | {"ACF", NULL, 0, false, NULL}, // Alert Command Refused, 4.10+ |
5562 | 0 | {"AVR", NULL, 0, false, NULL}, // Same as $PTNL,AVR |
5563 | 0 | {"BOD", NULL, 0, false, NULL}, // Bearing Origin to Destination |
5564 | | // Bearing & Distance to Waypoint, Great Circle |
5565 | 0 | {"BWC", NULL, 12, false, processBWC}, |
5566 | 0 | {"DBT", NULL, 7, false, processDBT}, // depth |
5567 | 0 | {"DPT", NULL, 4, false, processDPT}, // depth |
5568 | 0 | {"DTM", NULL, 2, false, processDTM}, // datum |
5569 | 0 | {"EPV", NULL, 0, false, NULL}, // Command/report Prop Value, 4.10+ |
5570 | 0 | {"GBS", NULL, 7, false, processGBS}, // GNSS Sat Fault Detection |
5571 | 0 | {"GGA", NULL, 13, false, processGGA}, // GPS fix data |
5572 | 0 | {"GGK", NULL, 0, false, NULL}, // Same as $PTNL,GGK |
5573 | 0 | {"GGQ", NULL, 0, false, NULL}, // Leica Position |
5574 | 0 | {"GLC", NULL, 0, false, NULL}, // Geographic Position, LoranC |
5575 | 0 | {"GLL", NULL, 7, true, processGLL}, // Position, Lat/Lon |
5576 | 0 | {"GMP", NULL, 0, false, NULL}, // Map Projection |
5577 | 0 | {"GNS", NULL, 13, false, processGNS}, // GNSS fix data |
5578 | 0 | {"GRS", NULL, 4, false, processGRS}, // GNSS Range Residuals |
5579 | 0 | {"GSA", NULL, 18, false, processGSA}, // DOP and Active sats |
5580 | 0 | {"GST", NULL, 8, false, processGST}, // Pseudorange error stats |
5581 | 0 | {"GSV", NULL, 4, false, processGSV}, // Sats in view |
5582 | | // UNICORE MEMES sensor data |
5583 | 0 | {"GYOACC", NULL, 14, false, processGYOACC}, |
5584 | | // Inertial Sense info, over long |
5585 | | // INFO,928404541,1.0.2.0,2.2.2.0,-377462659,2.0.0.0,-53643429, |
5586 | | // Inertial Sense Inc,2025-01-10,16:06:13.50,GPX -1,4,0, *7D |
5587 | 0 | {"INFO", NULL, 14, false, processINFO}, |
5588 | 0 | {"HCR", NULL, 0, false, NULL}, // Heading Correction, 4.10+ |
5589 | | // Heading, Deviation and Variation |
5590 | 0 | {"HDG", NULL, 0, false, processHDG}, |
5591 | 0 | {"HDM", NULL, 3, false, processHDM}, // $APHDM, Magnetic Heading |
5592 | 0 | {"HDT", NULL, 1, false, processHDT}, // Heading true |
5593 | | // Hell Andle, Roll Period, Roll Amplitude. NMEA 4.10+ |
5594 | 0 | {"HRM", NULL, 0, false, NULL}, |
5595 | 0 | {"HRP", NULL, 0, false, NULL}, // Serpentrio Headinf, Roll, Pitch |
5596 | 0 | {"HWBIAS", NULL, 0, false, NULL}, // Unknown HuaWei sentence |
5597 | 0 | {"LLK", NULL, 0, false, NULL}, // Leica local pos and GDOP |
5598 | 0 | {"LLQ", NULL, 0, false, NULL}, // Leica local pos and quality |
5599 | 0 | {"MLA", NULL, 0, false, NULL}, // GLONASS Almana Data |
5600 | 0 | {"MOB", NULL, 0, false, NULL}, // Man Overboard, NMEA 4.10+ |
5601 | 0 | {"MSS", NULL, 0, false, NULL}, // beacon receiver status |
5602 | 0 | {"MTW", NULL, 3, false, processMTW}, // Water Temperature |
5603 | 0 | {"MWD", NULL, 0, false, processMWD}, // Wind Direction and Speed |
5604 | 0 | {"MWV", NULL, 0, false, processMWV}, // Wind Speed and Angle |
5605 | 0 | {"OHPR", NULL, 18, false, NULL}, // Oceanserver, not supported |
5606 | 0 | {"OSD", NULL, 0, false, NULL}, // ignore Own Ship Data |
5607 | | // general handler for Ashtech |
5608 | 0 | {"PASHR", NULL, 3, false, processPASHR}, |
5609 | | // Airoha proprietary |
5610 | 0 | {"PAIR001", NULL, 3, false, processPAIR001}, // ACK/NAK |
5611 | 0 | {"PAIR010", NULL, 5, false, processPAIR010}, // Request Aiding |
5612 | | |
5613 | | // Unicore proprietary |
5614 | 0 | {"PDTINFO", NULL, 6, false, processPDTINFO}, // Product ID |
5615 | |
|
5616 | 0 | {"PEMT", NULL, 5, false, NULL}, // Evermore proprietary |
5617 | | // Furuno proprietary |
5618 | 0 | {"PERDACK", NULL, 4, false, NULL}, // ACK |
5619 | | // {"PERDAPI", NULL, 3, false, NULL}, // Config Send |
5620 | 0 | {"PERDCRD", NULL, 15, false, NULL}, // NLOSMASK? |
5621 | 0 | {"PERDCRG", "DCR", 6, false, NULL}, // QZSS DC report |
5622 | 0 | {"PERDCRJ", "FREQ", 9, false, NULL}, // Jamming Status |
5623 | 0 | {"PERDCRP", NULL, 9, false, NULL}, // Position |
5624 | 0 | {"PERDCRQ", NULL, 11, false, NULL}, // Galileo SAR |
5625 | 0 | {"PERDCRW", "TPS1", 8, false, NULL}, // Time |
5626 | 0 | {"PERDCRX", "TPS2", 12, false, NULL}, // PPS |
5627 | 0 | {"PERDCRY", "TPS3", 11, false, NULL}, // Position Mode |
5628 | 0 | {"PERDCRZ", "TPS4", 13, false, NULL}, // GCLK |
5629 | 0 | {"PERDMSG", NULL, 3, false, NULL}, // Message |
5630 | 0 | {"PERDSYS", "ANTSEL", 5, false, NULL}, // Antenna |
5631 | 0 | {"PERDSYS", "FIXSESSION", 5, false, NULL}, // Fix Session |
5632 | 0 | {"PERDSYS", "GPIO", 3, false, NULL}, // GPIO |
5633 | 0 | {"PERDSYS", "VERSION", 6, false, NULL}, // Version |
5634 | | |
5635 | | // Inertial Sense |
5636 | 0 | {"PGPSP", NULL, 18, false, processPGPSP}, // GPS nav data |
5637 | | |
5638 | | // Jackson Labs proprietary |
5639 | 0 | {"PJLTS", NULL, 11, false, NULL}, // GPSDO status |
5640 | 0 | {"PJLTV", NULL, 4, false, NULL}, // Time and 3D velocity |
5641 | | // GPS-320FW -- $PLCS |
5642 | 0 | {"PMGNST", NULL, 8, false, processPMGNST}, // Magellan Status |
5643 | | // MediaTek proprietary, EOL. Replaced by Airoha |
5644 | 0 | {"PMTK001", NULL, 3, false, processPMTK001}, // ACK/NAK |
5645 | 0 | {"PMTK010", NULL, 2, false, NULL}, // System Message |
5646 | 0 | {"PMTK011", NULL, 2, false, NULL}, // Text Message |
5647 | 0 | {"PMTK424", NULL, 3, false, processPMTK424}, |
5648 | 0 | {"PMTK705", NULL, 4, false, processPMTK705}, |
5649 | | // MediaTek/Trimble Satellite Channel Status |
5650 | 0 | {"PMTKCHN", NULL, 0, false, NULL}, |
5651 | | |
5652 | | // MTK-3301 -- $POLYN |
5653 | | |
5654 | | // Quectel proprietary |
5655 | 0 | {"PQTMCFGEINSMSGERROR", NULL, 1, false, processPQxERR}, // Error |
5656 | 0 | {"PQTMCFGEINSMSGOK", NULL, 1, false, processPQxOK}, // OK |
5657 | 0 | {"PQTMCFGORIENTATIONERROR", NULL, 1, false, processPQxERR}, // Error |
5658 | 0 | {"PQTMCFGORIENTATION", NULL, 3, false, NULL}, // Orientation |
5659 | 0 | {"PQTMCFGORIENTATIONOK", NULL, 1, false, processPQxOK}, // OK |
5660 | 0 | {"PQTMCFGWHEELTICKERROR", NULL, 1, false, processPQxERR}, // Error |
5661 | 0 | {"PQTMCFGWHEELTICKOK", NULL, 1, false, processPQxOK}, // OK |
5662 | 0 | {"PQTMGPS", NULL, 14, false, processPQTMGPS}, // GPS Status |
5663 | 0 | {"PQTMIMU", NULL, 10, false, processPQTMIMU}, // IMU Raw Data |
5664 | 0 | {"PQTMINS", NULL, 11, false, processPQTMINS}, // INS Results |
5665 | 0 | {"PQTMQMPTERROR", NULL, 1, false, processPQxERR}, // Error |
5666 | 0 | {"PQTMQMPT", NULL, 2, false, NULL}, // Meters / tick |
5667 | 0 | {"PQTMVEHMSG", NULL, 2, false, NULL}, // Vehicle Info |
5668 | 0 | {"PQTMVER", NULL, 4, false, processPQTMVER}, // Firmware info |
5669 | |
|
5670 | 0 | {"PQVERNO", NULL, 5, false, processPQVERNO}, // Version |
5671 | | // smart watch sensors, Yes: space! |
5672 | 0 | {"PRHS ", NULL, 2, false, processPRHS}, |
5673 | 0 | {"PRWIZCH", NULL, 0, false, NULL}, // Rockwell Channel Status |
5674 | 0 | {"PSRF140", NULL, 0, false, NULL}, // SiRF ephemeris |
5675 | 0 | {"PSRF150", NULL, 0, false, NULL}, // SiRF flow control |
5676 | 0 | {"PSRF151", NULL, 0, false, NULL}, // SiRF Power |
5677 | 0 | {"PSRF152", NULL, 0, false, NULL}, // SiRF ephemeris |
5678 | 0 | {"PSRF155", NULL, 0, false, NULL}, // SiRF proprietary |
5679 | 0 | {"PSRFEPE", NULL, 7, false, processPSRFEPE}, // SiRF Estimated Errors |
5680 | | |
5681 | | /* Serpentrio |
5682 | | * $PSSN,HRP -- Heading Pitch, Roll |
5683 | | * $PSSN,RBD -- Rover-Base Direction |
5684 | | * $PSSN,RBP -- Rover-Base Position |
5685 | | * $PSSN,RBV -- Rover-Base Velocity |
5686 | | * $PSSN,SNC -- NTRIP Client Status |
5687 | | * $PSSN,TFM -- RTCM coordinate transform |
5688 | | */ |
5689 | 0 | {"PSSN", NULL, 0, false, NULL}, // $PSSN |
5690 | | |
5691 | | /* |
5692 | | * Skytraq sentences take this format: |
5693 | | * $PSTI,type[,val[,val]]*CS |
5694 | | * type is a 2 or 3 digit subsentence type |
5695 | | * |
5696 | | * Note: these sentences can be at least 105 chars long. |
5697 | | * That violates the NMEA 3.01 max of 82. |
5698 | | */ |
5699 | | // 1 PPS Timing report ID |
5700 | 0 | {"PSTI", "000", 4, false, NULL}, |
5701 | | // Active Antenna Status Report |
5702 | 0 | {"PSTI", "001", 2, false, NULL}, |
5703 | | // GPIO 10 event-triggered time & position stamp. |
5704 | 0 | {"PSTI", "005", 2, false, NULL}, |
5705 | | // Recommended Minimum 3D GNSS Data |
5706 | 0 | {"PSTI", "030", 16, false, processPSTI030}, |
5707 | | // RTK Baseline |
5708 | 0 | {"PSTI", "032", 16, false, processPSTI032}, |
5709 | | // RTK RAW Measurement Monitoring Data |
5710 | 0 | {"PSTI", "033", 27, false, processPSTI033}, |
5711 | | // RTK Baseline Data of Rover Moving Base Receiver |
5712 | 0 | {"PSTI", "035", 8, false, processPSTI035}, |
5713 | | // Heading, Pitch and Roll Messages of vehicle |
5714 | 0 | {"PSTI", "036", 2, false, processPSTI036}, |
5715 | | // $PSTM ST Micro STA8088xx/STA8089xx/STA8090xx |
5716 | 0 | {"PSTM", NULL, 0, false, NULL}, |
5717 | | // STM messages |
5718 | 0 | {"PSTMANTENNASTATUS", NULL, 4, false, processPSTMANTENNASTATUS}, |
5719 | 0 | {"PSTMVER", NULL, 1, false, processPSTMVER}, |
5720 | | |
5721 | | /* Kongsberg Seatex AS. Seapath 320 |
5722 | | * $PSXN,20,horiz-qual,hgt-qual,head-qual,rp-qual*csum |
5723 | | * $PSXN,21,event*csum |
5724 | | * $PSXN,22,gyro-calib,gyro-offs*csum |
5725 | | * $PSXN,23,roll,pitch,head,heave*csum |
5726 | | * $PSXN,24,roll-rate,pitch-rate,yaw-rate,vertical-vel*csum |
5727 | | */ |
5728 | 0 | {"PSXN", NULL, 0, false, NULL}, |
5729 | 0 | {"PTFTTXT", NULL, 0, false, NULL}, // unknown uptime |
5730 | | |
5731 | | /* Trimble Proprietary |
5732 | | * $PTNL,AVR |
5733 | | * $PTNL,GGK |
5734 | | */ |
5735 | 0 | {"PTNI", NULL, 0, false, NULL}, |
5736 | |
|
5737 | 0 | {"PTKM", NULL, 0, false, NULL}, // Robertson RGC12 Gyro |
5738 | 0 | {"PTNLRHVR", NULL, 0, false, NULL}, // Trimble Software Version |
5739 | 0 | {"PTNLRPT", NULL, 0, false, NULL}, // Trimble Serial Port COnfig |
5740 | 0 | {"PTNLRSVR", NULL, 0, false, NULL}, // Trimble Firmware Version |
5741 | 0 | {"PTNLRZD", NULL, 0, false, NULL}, // Extended Time and Date |
5742 | 0 | {"PTNTA", NULL, 8, false, processTNTA}, |
5743 | 0 | {"PTNTHTM", NULL, 9, false, processTNTHTM}, |
5744 | 0 | {"PUBX", NULL, 0, false, NULL}, // u-blox and Antaris |
5745 | 0 | {"QSM", NULL, 3, false, NULL}, // QZSS DC Report |
5746 | 0 | {"RBD", NULL, 0, false, NULL}, // Serpentrio rover-base direction |
5747 | 0 | {"RBP", NULL, 0, false, NULL}, // Serpentrio rover-base position |
5748 | 0 | {"RBV", NULL, 0, false, NULL}, // Serpentrio rover-base velocity |
5749 | 0 | {"RLM", NULL, 0, false, NULL}, // Return Link Message, NMEA 4.10+ |
5750 | | // ignore Recommended Minimum Navigation Info, waypoint |
5751 | 0 | {"RMB", NULL, 0, false, NULL}, // Recommended Min Nav Info |
5752 | 0 | {"RMC", NULL, 8, false, processRMC}, // Recommended Minimum Data |
5753 | 0 | {"ROT", NULL, 3, false, processROT}, // Rate of Turn |
5754 | 0 | {"RPM", NULL, 0, false, NULL}, // ignore Revolutions |
5755 | 0 | {"RRT", NULL, 0, false, NULL}, // Report Route Transfer, NMEA 4.10+ |
5756 | 0 | {"RSA", NULL, 0, false, NULL}, // Rudder Sensor Angle |
5757 | 0 | {"RTE", NULL, 0, false, NULL}, // ignore Routes |
5758 | | // UNICORE, Sensor Status invalid sender (SN) |
5759 | 0 | {"SNRSTAT", NULL, 5, false, processSNRSTAT}, |
5760 | 0 | {"SM1", NULL, 0, false, NULL}, // SafteyNET, All Ships, NMEA 4.10+ |
5761 | 0 | {"SM2", NULL, 0, false, NULL}, // SafteyNET, Coastal, NMEA 4.10+ |
5762 | 0 | {"SM3", NULL, 0, false, NULL}, // SafteyNET, Circular, NMEA 4.10+ |
5763 | 0 | {"SM4", NULL, 0, false, NULL}, // SafteyNET, Rectangular, NMEA 4.10+ |
5764 | 0 | {"SMB", NULL, 0, false, NULL}, // SafteyNET, Msg Body, NMEA 4.10+ |
5765 | 0 | {"SPW", NULL, 0, false, NULL}, // Security Password, NMEA 4.10+ |
5766 | 0 | {"SNC", NULL, 0, false, NULL}, // Serpentrio NTRIP client status |
5767 | 0 | {"STI", NULL, 2, false, processSTI}, // $STI Skytraq |
5768 | 0 | {"TFM", NULL, 0, false, NULL}, // Serpentrio Coord Transform |
5769 | 0 | {"THS", NULL, 0, false, processTHS}, // True Heading and Status |
5770 | 0 | {"TRL", NULL, 0, false, NULL}, // AIS Xmit offline, NMEA 4.10+ |
5771 | 0 | {"TXT", NULL, 5, false, processTXT}, |
5772 | 0 | {"TXTbase", NULL, 0, false, NULL}, // RTCM 1029 TXT |
5773 | 0 | {"VBW", NULL, 0, false, NULL}, // Dual Ground/Water Speed |
5774 | 0 | {"VDO", NULL, 0, false, NULL}, // Own Vessel's Information |
5775 | 0 | {"VDR", NULL, 0, false, NULL}, // Set and Drift |
5776 | 0 | {"VHW", NULL, 0, false, NULL}, // Water Speed and Heading |
5777 | 0 | {"VLW", NULL, 0, false, NULL}, // Dual ground/water distance |
5778 | 0 | {"VTG", NULL, 5, false, processVTG}, // Course/speed over ground |
5779 | | // $APXDR, $HCXDR, Transducer measurements |
5780 | 0 | {"XDR", NULL, 5, false, processXDR}, |
5781 | 0 | {"XTE", NULL, 0, false, NULL}, // Cross-Track Error |
5782 | 0 | {"ZDA", NULL ,4, false, processZDA}, // Time and Date |
5783 | 0 | {NULL, NULL, 0, false, NULL}, // no more |
5784 | 0 | }; |
5785 | |
|
5786 | 0 | int count; |
5787 | 0 | gps_mask_t mask = 0; |
5788 | 0 | unsigned i, thistag = 0, lasttag; |
5789 | 0 | char *p, *e; |
5790 | 0 | volatile char *t; |
5791 | 0 | char ts_buf1[TIMESPEC_LEN]; |
5792 | 0 | char ts_buf2[TIMESPEC_LEN]; |
5793 | 0 | bool skytraq_sti = false; |
5794 | 0 | size_t mlen; |
5795 | | |
5796 | | /* |
5797 | | * We've had reports that on the Garmin GPS-10 the device sometimes |
5798 | | * (1:1000 or so) sends garbage packets that have a valid checksum |
5799 | | * but are like 2 successive NMEA packets merged together in one |
5800 | | * with some fields lost. Usually these are much longer than the |
5801 | | * legal limit for NMEA, so we can cope by just tossing out overlong |
5802 | | * packets. This may be a generic bug of all Garmin chipsets. |
5803 | | */ |
5804 | | // codacy does not like strlen() |
5805 | 0 | mlen = strnlen(sentence, NMEA_MAX + 1); |
5806 | 0 | if (NMEA_MAX < mlen) { |
5807 | 0 | GPSD_LOG(LOG_WARN, &session->context->errout, |
5808 | 0 | "NMEA0183: Overlong packet of %zd+ chars rejected.\n", |
5809 | 0 | mlen); |
5810 | 0 | return ONLINE_SET; |
5811 | 0 | } |
5812 | | |
5813 | | // make an editable copy of the sentence |
5814 | 0 | (void)strlcpy((char *)session->nmea.fieldcopy, sentence, |
5815 | 0 | sizeof(session->nmea.fieldcopy) - 1); |
5816 | | // discard the checksum part |
5817 | 0 | for (p = (char *)session->nmea.fieldcopy; |
5818 | 0 | ('*' != *p) && (' ' <= *p);) { |
5819 | 0 | ++p; |
5820 | 0 | } |
5821 | 0 | if ('*' == *p) { |
5822 | 0 | *p++ = ','; // otherwise we drop the last field |
5823 | 0 | } |
5824 | | #ifdef SKYTRAQ_ENABLE_UNUSED |
5825 | | // $STI is special, no trailing *, or chacksum |
5826 | | if (0 != strncmp( "STI,", sentence, 4)) { |
5827 | | skytraq_sti = true; |
5828 | | *p++ = ','; // otherwise we drop the last field |
5829 | | } |
5830 | | #endif |
5831 | 0 | *p = '\0'; |
5832 | 0 | e = p; |
5833 | | |
5834 | | // split sentence copy on commas, filling the field array |
5835 | 0 | count = 0; |
5836 | 0 | t = p; // end of sentence |
5837 | 0 | p = (char *)session->nmea.fieldcopy + 1; // beginning of tag, 'G' not '$' |
5838 | | // while there is a search string and we haven't run off the buffer... |
5839 | 0 | while ((NULL != p) && |
5840 | 0 | (p <= t)) { |
5841 | 0 | session->nmea.field[count] = p; // we have a field. record it |
5842 | 0 | if (NULL != (p = strchr(p, ','))) { // search for the next delimiter |
5843 | 0 | *p = '\0'; // replace it with a NUL |
5844 | 0 | count++; // bump the counters and continue |
5845 | 0 | p++; |
5846 | 0 | } |
5847 | 0 | } |
5848 | | |
5849 | | // point remaining fields at empty string, just in case |
5850 | 0 | for (i = (unsigned int)count; i < NMEA_MAX_FLD; i++) { |
5851 | 0 | session->nmea.field[i] = e; |
5852 | 0 | } |
5853 | | |
5854 | | // sentences handlers will tell us when they have fractional time |
5855 | 0 | session->nmea.latch_frac_time = false; |
5856 | | // GSA and GSV will set this if more in that series to come. |
5857 | 0 | session->nmea.gsx_more = false; |
5858 | |
|
5859 | | #ifdef __UNUSED |
5860 | | // debug |
5861 | | GPSD_LOG(0, &session->context->errout, |
5862 | | "NMEA0183: got %s\n", session->nmea.field[0]); |
5863 | | #endif // __UNUSED |
5864 | | |
5865 | | // dispatch on field zero, the sentence tag |
5866 | 0 | for (i = 0; i < NMEA_NUM; ++i) { |
5867 | 0 | char *s = session->nmea.field[0]; |
5868 | | |
5869 | | // CODACY #350416, wants explicit numeric end check |
5870 | 0 | if ((NMEA_NUM - 1) <= i || |
5871 | 0 | NULL == nmea_phrase[i].name) { |
5872 | 0 | mask = ONLINE_SET; |
5873 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5874 | 0 | "NMEA0183: Unknown sentence type %s\n", |
5875 | 0 | session->nmea.field[0]); |
5876 | 0 | break; |
5877 | 0 | } |
5878 | | // strnlen() to shut up codacy |
5879 | 0 | if (3 == strnlen(nmea_phrase[i].name, 4) && |
5880 | 0 | !skytraq_sti) { |
5881 | | // $STI is special |
5882 | 0 | s += 2; // skip talker ID |
5883 | 0 | } |
5884 | 0 | if (0 != strcmp(nmea_phrase[i].name, s)) { |
5885 | | // no match |
5886 | 0 | continue; |
5887 | 0 | } |
5888 | 0 | if (NULL != nmea_phrase[i].name1 && |
5889 | 0 | 0 != strcmp(nmea_phrase[i].name1, session->nmea.field[1])) { |
5890 | | // no match on field 2. As in $PSTI,030, |
5891 | 0 | continue; |
5892 | 0 | } |
5893 | | // got a match |
5894 | 0 | if (NULL == nmea_phrase[i].decoder) { |
5895 | | // no decoder for this sentence |
5896 | 0 | mask = ONLINE_SET; |
5897 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5898 | 0 | "NMEA0183: No decoder for sentence type %s\n", |
5899 | 0 | session->nmea.field[0]); |
5900 | 0 | break; |
5901 | 0 | } |
5902 | 0 | if (count < nmea_phrase[i].nf) { |
5903 | | // sentence to short |
5904 | 0 | mask = ONLINE_SET; |
5905 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5906 | 0 | "NMEA0183: Sentence %s too short\n", |
5907 | 0 | session->nmea.field[0]); |
5908 | 0 | break; |
5909 | 0 | } |
5910 | 0 | mask = (nmea_phrase[i].decoder)(count, session->nmea.field, |
5911 | 0 | session); |
5912 | 0 | session->nmea.cycle_continue = nmea_phrase[i].cycle_continue; |
5913 | | /* |
5914 | | * Must force this to be nz, as we're going to rely on a zero |
5915 | | * value to mean "no previous tag" later. |
5916 | | */ |
5917 | | // FIXME: this fails on Skytrak, $PSTI,xx, many different xx |
5918 | 0 | thistag = i + 1; |
5919 | 0 | break; |
5920 | 0 | } |
5921 | | |
5922 | | // prevent overaccumulation of sat reports |
5923 | 0 | if (!str_starts_with(session->nmea.field[0] + 2, "GSV")) { |
5924 | | // This assumes all $xxGSV are contiguous. |
5925 | 0 | if (0 != session->nmea.last_gsv_talker) { |
5926 | 0 | session->nmea.end_gsv_talker = session->nmea.last_gsv_talker; |
5927 | 0 | } |
5928 | 0 | session->nmea.last_gsv_talker = '\0'; |
5929 | 0 | } |
5930 | 0 | if (!str_starts_with(session->nmea.field[0] + 2, "GSA")) { |
5931 | 0 | session->nmea.last_gsa_talker = '\0'; |
5932 | 0 | } |
5933 | | |
5934 | | // timestamp recording for fixes happens here |
5935 | 0 | if (0 != (mask & TIME_SET)) { |
5936 | 0 | if (0 == session->nmea.date.tm_year && |
5937 | 0 | 0 == session->nmea.date.tm_mday) { |
5938 | | // special case to time zero |
5939 | 0 | session->newdata.time = (timespec_t){0, 0}; |
5940 | 0 | } else { |
5941 | 0 | session->newdata.time = gpsd_utc_resolve(session); |
5942 | 0 | } |
5943 | |
|
5944 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5945 | 0 | "NMEA0183: %s newtime is %s = " |
5946 | 0 | "%d-%02d-%02dT%02d:%02d:%02d.%03ldZ\n", |
5947 | 0 | session->nmea.field[0], |
5948 | 0 | timespec_str(&session->newdata.time, ts_buf1, sizeof(ts_buf1)), |
5949 | 0 | 1900 + session->nmea.date.tm_year, |
5950 | 0 | session->nmea.date.tm_mon + 1, |
5951 | 0 | session->nmea.date.tm_mday, |
5952 | 0 | session->nmea.date.tm_hour, |
5953 | 0 | session->nmea.date.tm_min, |
5954 | 0 | session->nmea.date.tm_sec, |
5955 | 0 | session->nmea.subseconds.tv_nsec / 1000000L); |
5956 | | /* |
5957 | | * If we have time and PPS is available, assume we have good time. |
5958 | | * Because this is a generic driver we don't really have enough |
5959 | | * information for a sharper test, so we'll leave it up to the |
5960 | | * PPS code to do its own sanity filtering. |
5961 | | */ |
5962 | 0 | mask |= NTPTIME_IS; |
5963 | 0 | } |
5964 | | |
5965 | | /* |
5966 | | * The end-of-cycle detector. This code depends on just one |
5967 | | * assumption: if a sentence with a timestamp occurs just before |
5968 | | * start of cycle, then it is always good to trigger a report on |
5969 | | * that sentence in the future. For devices with a fixed cycle |
5970 | | * this should work perfectly, locking in detection after one |
5971 | | * cycle. Most split-cycle devices (Garmin 48, for example) will |
5972 | | * work fine. Problems will only arise if a a sentence that |
5973 | | * occurs just before timestamp increments also occurs in |
5974 | | * mid-cycle, as in the Garmin eXplorist 210; those might jitter. |
5975 | | */ |
5976 | 0 | GPSD_LOG(LOG_DATA, &session->context->errout, |
5977 | 0 | "NMEA0183: %s time %s last %s latch %d cont %d\n", |
5978 | 0 | session->nmea.field[0], |
5979 | 0 | timespec_str(&session->nmea.this_frac_time, ts_buf1, |
5980 | 0 | sizeof(ts_buf1)), |
5981 | 0 | timespec_str(&session->nmea.last_frac_time, ts_buf2, |
5982 | 0 | sizeof(ts_buf2)), |
5983 | 0 | session->nmea.latch_frac_time, |
5984 | 0 | session->nmea.cycle_continue); |
5985 | 0 | lasttag = session->nmea.lasttag; |
5986 | 0 | if (session->nmea.gsx_more) { |
5987 | | // more to come, so ignore for cycle ender |
5988 | | // appears that GSA and GSV never start a cycle. |
5989 | 0 | } else if (session->nmea.latch_frac_time) { |
5990 | 0 | timespec_t ts_delta; |
5991 | 0 | TS_SUB(&ts_delta, &session->nmea.this_frac_time, |
5992 | 0 | &session->nmea.last_frac_time); |
5993 | 0 | if (0.01 < fabs(TSTONS(&ts_delta))) { |
5994 | | // time changed |
5995 | 0 | mask |= CLEAR_IS; |
5996 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
5997 | 0 | "NMEA0183: %s starts a reporting cycle. lasttag %d\n", |
5998 | 0 | session->nmea.field[0], lasttag); |
5999 | | /* |
6000 | | * Have we seen a previously timestamped NMEA tag? |
6001 | | * If so, designate as end-of-cycle marker. |
6002 | | * But not if there are continuation sentences; |
6003 | | * those get sorted after the last timestamped sentence |
6004 | | * |
6005 | | */ |
6006 | 0 | if (0 < lasttag && |
6007 | 0 | false == (session->nmea.cycle_enders[lasttag]) && |
6008 | 0 | !session->nmea.cycle_continue) { |
6009 | 0 | session->nmea.cycle_enders[lasttag] = true; |
6010 | | // we might have a (somewhat) reliable end-of-cycle |
6011 | 0 | session->cycle_end_reliable = true; |
6012 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
6013 | 0 | "NMEA0183: tagged %s as a cycle ender. %u\n", |
6014 | 0 | nmea_phrase[lasttag - 1].name, |
6015 | 0 | lasttag); |
6016 | 0 | } |
6017 | 0 | } |
6018 | 0 | } else { |
6019 | | // ignore multiple sequential, like GSV, GSA |
6020 | | // extend the cycle to an un-timestamped sentence? |
6021 | 0 | if (true == session->nmea.cycle_enders[lasttag]) { |
6022 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
6023 | 0 | "NMEA0183: %s is just after a cycle ender. (%s)\n", |
6024 | 0 | session->nmea.field[0], |
6025 | 0 | gps_maskdump(mask)); |
6026 | 0 | if (0 != (mask & ~ONLINE_SET)) { |
6027 | | // new data... after cycle ender |
6028 | 0 | mask |= REPORT_IS; |
6029 | 0 | } |
6030 | 0 | } |
6031 | 0 | if (session->nmea.cycle_continue) { |
6032 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
6033 | 0 | "NMEA0183: %s extends the reporting cycle.\n", |
6034 | 0 | session->nmea.field[0]); |
6035 | | // change ender |
6036 | 0 | session->nmea.cycle_enders[lasttag] = false; |
6037 | 0 | session->nmea.cycle_enders[thistag] = true; |
6038 | | // have a cycle ender |
6039 | 0 | session->cycle_end_reliable = true; |
6040 | 0 | } |
6041 | 0 | } |
6042 | | |
6043 | | // here's where we check for end-of-cycle |
6044 | 0 | if ((session->nmea.latch_frac_time || |
6045 | 0 | session->nmea.cycle_continue) && |
6046 | 0 | (true == session->nmea.cycle_enders[thistag]) && |
6047 | 0 | !session->nmea.gsx_more) { |
6048 | 0 | if (NULL == nmea_phrase[i].name1) { |
6049 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
6050 | 0 | "NMEA0183: %s ends a reporting cycle.\n", |
6051 | 0 | session->nmea.field[0]); |
6052 | 0 | } else { |
6053 | 0 | GPSD_LOG(LOG_PROG, &session->context->errout, |
6054 | 0 | "NMEA0183: %s,%s ends a reporting cycle.\n", |
6055 | 0 | session->nmea.field[0], |
6056 | 0 | session->nmea.field[1]); |
6057 | 0 | } |
6058 | 0 | mask |= REPORT_IS; |
6059 | 0 | } |
6060 | 0 | if (session->nmea.latch_frac_time) { |
6061 | 0 | session->nmea.lasttag = thistag; |
6062 | 0 | } |
6063 | | |
6064 | | /* don't downgrade mode if holding previous fix |
6065 | | * usually because of xxRMC which does not report 2D/3D */ |
6066 | 0 | if (MODE_SET == (mask & MODE_SET) && |
6067 | 0 | MODE_3D == session->gpsdata.fix.mode && |
6068 | 0 | MODE_NO_FIX != session->newdata.mode && |
6069 | 0 | (0 != isfinite(session->lastfix.altHAE) || |
6070 | 0 | 0 != isfinite(session->oldfix.altHAE) || |
6071 | 0 | 0 != isfinite(session->lastfix.altMSL) || |
6072 | 0 | 0 != isfinite(session->oldfix.altMSL))) { |
6073 | 0 | session->newdata.mode = session->gpsdata.fix.mode; |
6074 | 0 | } |
6075 | 0 | return mask; |
6076 | 0 | } |
6077 | | |
6078 | | |
6079 | | /* add NMEA checksum to a possibly terminated sentence |
6080 | | * if \0 terminated adds exactly 5 chars: "*XX\n\n" |
6081 | | * if *\0 terminated adds exactly 4 chars: "XX\n\n" |
6082 | | */ |
6083 | | void nmea_add_checksum(char *sentence) |
6084 | 0 | { |
6085 | 0 | unsigned char sum = '\0'; |
6086 | 0 | char c, *p = sentence; |
6087 | |
|
6088 | 0 | if ('$' == *p || |
6089 | 0 | '!' == *p) { |
6090 | 0 | p++; |
6091 | 0 | } |
6092 | 0 | while (('*' != (c = *p)) && |
6093 | 0 | ('\0' != c)) { |
6094 | 0 | sum ^= c; |
6095 | 0 | p++; |
6096 | 0 | } |
6097 | 0 | (void)snprintf(p, 6, "*%02X\r\n", (unsigned)sum); |
6098 | 0 | } |
6099 | | |
6100 | | // ship a command to the GPS, adding * and correct checksum |
6101 | | ssize_t nmea_write(struct gps_device_t *session, char *buf, size_t len UNUSED) |
6102 | 0 | { |
6103 | 0 | (void)strlcpy(session->msgbuf, buf, sizeof(session->msgbuf)); |
6104 | 0 | if ('$' == session->msgbuf[0]) { |
6105 | 0 | (void)strlcat(session->msgbuf, "*", sizeof(session->msgbuf)); |
6106 | 0 | nmea_add_checksum(session->msgbuf); |
6107 | 0 | } else { |
6108 | 0 | (void)strlcat(session->msgbuf, "\r\n", sizeof(session->msgbuf)); |
6109 | 0 | } |
6110 | | // codacy hates strlen() |
6111 | 0 | session->msgbuflen = strnlen(session->msgbuf, sizeof(session->msgbuf)); |
6112 | 0 | return gpsd_write(session, session->msgbuf, session->msgbuflen); |
6113 | 0 | } |
6114 | | |
6115 | | ssize_t nmea_send(struct gps_device_t * session, const char *fmt, ...) |
6116 | 0 | { |
6117 | 0 | char buf[BUFSIZ]; |
6118 | 0 | va_list ap; |
6119 | |
|
6120 | 0 | va_start(ap, fmt); |
6121 | 0 | (void)vsnprintf(buf, sizeof(buf) - 5, fmt, ap); |
6122 | 0 | va_end(ap); |
6123 | | // codacy hates strlen() |
6124 | 0 | return nmea_write(session, buf, strnlen(buf, sizeof(buf))); |
6125 | 0 | } |
6126 | | |
6127 | | // vim: set expandtab shiftwidth=4 |