Coverage Report

Created: 2025-11-17 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gpsd/gpsd-3.26.2~dev/libgps/gpsutils.c
Line
Count
Source
1
/* gpsutils.c -- code shared between low-level and high-level interfaces
2
 *
3
 * This file is Copyright by the GPSD project
4
 * SPDX-License-Identifier: BSD-2-clause
5
 */
6
7
/* The strptime prototype is not provided unless explicitly requested.
8
 * We also need to set the value high enough to signal inclusion of
9
 * newer features (like clock_gettime).  See the POSIX spec for more info:
10
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_01_02 */
11
12
#include "../include/gpsd_config.h"    // must be before all includes
13
14
#include <ctype.h>
15
#include <errno.h>
16
#include <math.h>
17
#include <stdbool.h>
18
#include <stdio.h>
19
#include <stdlib.h>
20
#include <string.h>
21
#include <sys/select.h>  // for to have a pselect(2) prototype a la POSIX
22
#include <sys/time.h>    // for to have a pselect(2) prototype a la SuS
23
#include <time.h>
24
25
#include "../include/gps.h"
26
#include "../include/libgps.h"
27
#include "../include/os_compat.h"
28
#include "../include/timespec.h"
29
30
#ifdef USE_QT
31
#include <QDateTime>
32
#include <QStringList>
33
#endif
34
35
// decodes for gps_fix_t
36
37
// ant_stat
38
const struct vlist_t vant_status[] = {
39
    {ANT_UNK, "UNK"},     // 0
40
    {ANT_OK, "OK"},     // 1
41
    {ANT_OPEN, "OPEN"},    // 2
42
    {ANT_SHORT, "SHORT"},   // 3
43
    {0, NULL},
44
};
45
46
// gnssId names
47
const struct vlist_t vgnssId[] = {
48
    {0, "GPS"},
49
    {1, "SBAS"},
50
    {2, "GAL"},
51
    {3, "BDS"},
52
    {4, "IMES"},
53
    {5, "QZSS"},
54
    {6, "GLO"},
55
    {7, "NavIC"},
56
    {0, NULL},
57
};
58
59
// mode val to mode string
60
const struct vlist_t vmode_str[] = {
61
    {1, "No Fix"},
62
    {2, "2D Fix"},
63
    {3, "3D Fix"},
64
    {0, NULL},
65
};
66
67
// status val to status string
68
const struct vlist_t vstatus_str[] = {
69
    {0, "UNK"},
70
    {1, "GPS"},
71
    {2, "DGPS"},
72
    {3, "RTK_FIX"},
73
    {4, "RTK_FLT"},
74
    {5, "DR"},
75
    {6, "GNSSDR"},
76
    {7, "TIME"},      // Surveyd
77
    {8, "SIM "},
78
    {0, NULL},
79
};
80
81
/* char2str(ch, vlist) - given a char, return a matching string.
82
 *
83
 * Return: pointer to string
84
 */
85
const char *char2str(unsigned char ch, const struct clist_t *clist)
86
0
{
87
0
    while (NULL != clist->str) {
88
0
        if (clist->ch == ch) {
89
0
            return clist->str;
90
0
        }
91
0
        clist++;
92
0
    }
93
0
    return "Unk";
94
0
}
95
96
/* flags2str(val, vlist) - given flags, return a matching string.
97
 *
98
 * flags the flags to find in vlist
99
 * buffer -  the buffer to return string in
100
 ( buflen - length of buffer
101
 *
102
 * Return: pointer to passed in buffer
103
 *         A string matching the flags.
104
 */
105
const char *flags2str(unsigned long flags, const struct flist_t *flist,
106
                      char *buffer, size_t buflen)
107
0
{
108
0
    buffer[0] = '\0';
109
0
    while (NULL != flist->str) {
110
0
        if (flist->val == (flist->mask & flags)) {
111
0
            if ('\0' != buffer[0]) {
112
0
                strlcat(buffer, ",", buflen);
113
0
            }
114
0
            strlcat(buffer, flist->str, buflen);
115
0
        }
116
0
        flist++;
117
0
    }
118
0
    return buffer;
119
0
}
120
121
/* Translate table from gnmssid/sigid to NMEA sigid, signal name and
122
 * RINEX observation code
123
 */
124
0
#define SIGID_NUM 16
125
struct sig_xlate_t {
126
    const char *name;          // plain name
127
    const char *obs;           // RINEX observation code
128
    uint8_t nmea_sigid;        // NMEA 4.10 signal id.  0 == None
129
} const sig_xlate[GNSSID_CNT][SIGID_NUM] = {
130
    {   // 0 - GPS
131
        {"L1 C/A",   "C1C", 1},
132
        {NULL,       NULL},
133
        {NULL,       NULL},
134
        {"L2 CL",    "C2L", 6},
135
        {"L2 CM",    "C2S", 5},
136
        {NULL,       NULL},        // 5
137
        {"L5 I",     "C5I", 7},
138
        {"L5 Q",     "C5Q", 8},
139
    },
140
    {   // 1- SBAS
141
        {"L1C",      "C1C", 1},
142
        // {1, "L5I", "C5I"},  // ??
143
    },
144
    {   // 2 - Galileo
145
        {"E1 C",     "C1C", 7},
146
        {"E1 B",     "C1B", 7},
147
        {NULL,       NULL},
148
        {"E5 aI",    "C5I", 1},  // 3
149
        {"E5 aQ",    "C5Q", 1},
150
        {"E5 bI",    "C7I", 2},
151
        {"E5 bQ",    "C7Q", 2},
152
        {NULL,       NULL},
153
        {"E6 B",     "C6B", 5},   // 8
154
        {"E6 C",     "C6C", 5},
155
        {"E6 A",     "C6A", 4},
156
    },
157
    {   // 3 - BeiDou
158
        {"B1I D1",   "C2I", 1},
159
        {"B1I D2",   "C2I", 1},
160
        {"B2I D1",   "C7I", 0xb},
161
        {"B2I D2",   "C7I", 0xb},
162
        {"B3I D1",   "C6I", 0xb},
163
        {"B1 Cp",    "C1P", 3},  // 5
164
        {"B1 Cd",    "C1D", 3},
165
        {"B2 ap",    "C5P", 5},
166
        {"B2 ad",    "C5P", 5},
167
        {NULL,       NULL},       // 9
168
        {"B3I D2",   "C6I", 0xb},
169
    },
170
    {   // 4 - IMES
171
        {"L5 A",     NULL, 0},
172
    },
173
    {   // 5 - QZSS
174
        {"L1 C/A",   "C1C", 1},
175
        {"L1 S",     "C1Z", 4},
176
        {NULL,       NULL},
177
        {NULL,       NULL},
178
        {"L2 CM",    "C2S", 5},
179
        {"L2 CL",    "C2L", 6},   // 5
180
        {NULL,       NULL},
181
        {NULL,       NULL},
182
        {"L5 I",     "C5I", 7},
183
        {"L5 Q",     "C5Q", 8},
184
        {NULL,       NULL},    //  10
185
        {NULL,       NULL},
186
        {"L1 C/B",   "C1E", 0},
187
    },
188
    {   // 6 - GLONASS
189
        {"L1 OF",    "C1C", 1},
190
        {NULL,       NULL},
191
        {"L2 OF",    "C2C", 3},
192
    },
193
    {   // 8 - IRNSS (NavIC)
194
        {"L5 A",     "C5A", 1},
195
    },
196
};
197
198
199
/* sigid2str()
200
 *
201
 * given a gpsd gnssid, and gpsd sigid, return a string for the
202
 * sigid.  These are (mostly) UBX compatible.  NOT NMEA compatible.
203
 *
204
 * See sigid in include/gps.h
205
 *
206
 * return: static const string
207
 */
208
const char *sigid2str(unsigned char gnssid, unsigned char sigid)
209
0
{
210
0
    const char *rets = "Unk";
211
212
0
    if (GNSSID_CNT <= gnssid) {
213
0
        rets = "GNSS-Unk";
214
0
    } else if (SIGID_NUM <= sigid) {
215
0
        rets = "SIG-Unk";
216
0
    } else {
217
0
        rets = sig_xlate[gnssid][sigid].name;
218
0
        if (NULL == rets) {
219
0
            rets = "Unk";
220
0
        }
221
0
    }
222
223
0
    return rets;
224
0
}
225
226
/* sigid2obs()
227
 *
228
 * given a gpsd gnssid, and gpsd sigid, return a string for the
229
 * RINEX observation code.  These are (mostly) UBX compatible.
230
 *  NOT NMEA compatible.
231
 *
232
 * return: static const string
233
 */
234
const char *sigid2obs(unsigned char gnssid, unsigned char sigid)
235
0
{
236
0
    const char *rets = "Unk";
237
238
0
    if (GNSSID_CNT <= gnssid) {
239
0
        rets = "GNSS-Unk";
240
0
    } else if (SIGID_NUM <= sigid) {
241
0
        rets = "SIG-Unk";
242
0
    } else {
243
0
        rets = sig_xlate[gnssid][sigid].obs;
244
0
        if (NULL == rets) {
245
0
            rets = "Unk";
246
0
        }
247
0
    }
248
249
0
    return rets;
250
0
}
251
252
/* val2str(val, vlist) - given a value, return a matching string.
253
 *
254
 * val the value to find in vlist
255
 *
256
 * Return: pointer to static string
257
 *         The string matching val, or "Unk".
258
 */
259
const char *val2str(unsigned long val, const struct vlist_t *vlist)
260
0
{
261
0
    while (NULL != vlist->str) {
262
0
        if (vlist->val == val) {
263
0
            return vlist->str;
264
0
        }
265
0
        vlist++;
266
0
    }
267
0
    return "Unk";
268
0
}
269
270
/*
271
 * Berkeley implementation of strtod(), inlined to avoid locale problems
272
 * with the decimal point and stripped down to an atof()-equivalent.
273
 */
274
275
/* Takes a decimal ASCII floating-point number, optionally
276
 * preceded by white space.  Must have form "SI.FE-X",
277
 * S may be ither of the signs may be "+", "-", or omitted.
278
 * I is the integer part of the mantissa,
279
 * F is the fractional part of the mantissa,
280
 * X is the exponent.
281
 * Either I or F may be omitted, or both.
282
 * The decimal point isn't necessary unless F is
283
 * present.  The "E" may actually be an "e".  E and X
284
 * may both be omitted (but not just one).
285
 *
286
 * returns NaN if:
287
 *    *string is zero length,
288
 *    the first non-white space is not negative sign ('-'), positive sign ('_')
289
 *    or a digit
290
 */
291
double safe_atof(const char *string)
292
5.47k
{
293
5.47k
    static int maxExponent = 511;   /* Largest possible base 10 exponent.  Any
294
                                     * exponent larger than this will already
295
                                     * produce underflow or overflow, so there's
296
                                     * no need to worry about additional digits.
297
                                     */
298
    /* Table giving binary powers of 10.  Entry is 10^2^i.
299
     * Used to convert decimal exponents into floating-point numbers. */
300
5.47k
    static double powersOf10[] = {
301
5.47k
        10.,
302
5.47k
        100.,
303
5.47k
        1.0e4,
304
5.47k
        1.0e8,
305
5.47k
        1.0e16,
306
5.47k
        1.0e32,
307
5.47k
        1.0e64,
308
5.47k
        1.0e128,
309
5.47k
        1.0e256
310
5.47k
    };
311
312
5.47k
    bool sign = false, expSign = false;
313
5.47k
    double fraction, dblExp, *d;
314
5.47k
    const char *p;
315
5.47k
    unsigned char c;
316
5.47k
    int exp = 0;                // Exponent read from "EX" field.
317
5.47k
    int fracExp = 0;            /* Exponent that derives from the fractional
318
                                 * part.  Under normal circumstatnces, it is
319
                                 * the negative of the number of digits in F.
320
                                 * However, if I is very long, the last digits
321
                                 * of I get dropped (otherwise a long I with a
322
                                 * large negative exponent could cause an
323
                                 * unnecessary overflow on I alone).  In this
324
                                 * case, fracExp is incremented one for each
325
                                 * dropped digit. */
326
5.47k
    int mantSize;               // Number of digits in mantissa.
327
5.47k
    int decPt;                  /* Number of mantissa digits BEFORE decimal
328
                                 * point. */
329
5.47k
    const char *pExp;           /* Temporarily holds location of exponent
330
                                 * in string. */
331
332
    /*
333
     * Strip off leading blanks and check for a sign.
334
     */
335
336
5.47k
    p = string;
337
5.47k
    while (isspace((int)*p)) {
338
0
        p += 1;
339
0
    }
340
5.47k
    if (isdigit((unsigned char)*p)) {
341
        // ignore
342
2.82k
    } else if ('-' == *p) {
343
520
        sign = true;
344
520
        p += 1;
345
2.30k
    } else if ('+' == *p) {
346
200
        p += 1;
347
2.10k
    } else if ('.' == *p) {
348
        // ignore
349
1.42k
    } else {
350
678
        return NAN;
351
678
    }
352
353
    /*
354
     * Count the number of digits in the mantissa (including the decimal
355
     * point), and also locate the decimal point.
356
     */
357
358
4.80k
    decPt = -1;
359
21.2k
    for (mantSize = 0; ; mantSize += 1) {
360
21.2k
        c = *p;
361
21.2k
        if (!isdigit(c)) {
362
6.45k
            if ((c != '.') || (decPt >= 0)) {
363
4.80k
                break;
364
4.80k
            }
365
1.65k
            decPt = mantSize;
366
1.65k
        }
367
16.4k
        p += 1;
368
16.4k
    }
369
370
    /*
371
     * Now suck up the digits in the mantissa.  Use two integers to
372
     * collect 9 digits each (this is faster than using floating-point).
373
     * If the mantissa has more than 18 digits, ignore the extras, since
374
     * they can't affect the value anyway.
375
     */
376
377
4.80k
    pExp  = p;
378
4.80k
    p -= mantSize;
379
4.80k
    if (decPt < 0) {
380
3.14k
        decPt = mantSize;
381
3.14k
    } else {
382
1.65k
        mantSize -= 1;                  // One of the digits was the point.
383
1.65k
    }
384
4.80k
    if (mantSize > 18) {
385
219
        fracExp = decPt - 18;
386
219
        mantSize = 18;
387
4.58k
    } else {
388
4.58k
        fracExp = decPt - mantSize;
389
4.58k
    }
390
4.80k
    if (mantSize == 0) {
391
1.61k
        fraction = 0.0;
392
        // p = string;
393
1.61k
        goto done;
394
3.18k
    } else {
395
3.18k
        int frac1, frac2;
396
397
3.18k
        frac1 = 0;
398
6.01k
        for ( ; mantSize > 9; mantSize -= 1) {
399
2.82k
            c = *p;
400
2.82k
            p += 1;
401
2.82k
            if ('.' == c) {
402
286
                c = *p;
403
286
                p += 1;
404
286
            }
405
2.82k
            frac1 = 10*frac1 + (c - '0');
406
2.82k
        }
407
3.18k
        frac2 = 0;
408
12.6k
        for (; mantSize > 0; mantSize -= 1) {
409
9.43k
            c = *p;
410
9.43k
            p += 1;
411
9.43k
            if ('.' == c) {
412
253
                c = *p;
413
253
                p += 1;
414
253
            }
415
9.43k
            frac2 = 10*frac2 + (c - '0');
416
9.43k
        }
417
3.18k
        fraction = (1.0e9 * frac1) + frac2;
418
3.18k
    }
419
420
    /*
421
     * Skim off the exponent.
422
     */
423
424
3.18k
    p = pExp;
425
3.18k
    if (('E' == *p) ||
426
2.27k
        ('e' == *p)) {
427
1.71k
        p += 1;
428
1.71k
        if ('-' == *p) {
429
487
            expSign = true;
430
487
            p += 1;
431
1.22k
        } else {
432
1.22k
            if ('+' == *p) {
433
194
                p += 1;
434
194
            }
435
1.22k
            expSign = false;
436
1.22k
        }
437
3.16k
        while (isdigit((unsigned char) *p)) {
438
3.16k
            exp = exp * 10 + (*p - '0');
439
3.16k
            if (1024 < exp) {
440
449
                if (true == expSign) {
441
                    // exponent underflow!
442
194
                    return 0.0;
443
194
                } // else  exponent overflow!
444
255
                return INFINITY;
445
449
            }
446
2.71k
            p += 1;
447
2.71k
        }
448
1.71k
    }
449
2.73k
    if (expSign) {
450
293
        exp = fracExp - exp;
451
2.44k
    } else {
452
2.44k
        exp = fracExp + exp;
453
2.44k
    }
454
455
    /*
456
     * Generate a floating-point number that represents the exponent.
457
     * Do this by processing the exponent one bit at a time to combine
458
     * many powers of 2 of 10. Then combine the exponent with the
459
     * fraction.
460
     */
461
462
2.73k
    if (0 > exp) {
463
635
        expSign = true;
464
635
        exp = -exp;
465
2.10k
    } else {
466
2.10k
        expSign = false;
467
2.10k
    }
468
2.73k
    if (exp > maxExponent) {
469
226
        exp = maxExponent;
470
226
        errno = ERANGE;
471
226
    }
472
2.73k
    dblExp = 1.0;
473
7.77k
    for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
474
5.04k
        if (exp & 01) {
475
3.74k
            dblExp *= *d;
476
3.74k
        }
477
5.04k
    }
478
2.73k
    if (expSign) {
479
635
        fraction /= dblExp;
480
2.10k
    } else {
481
2.10k
        fraction *= dblExp;
482
2.10k
    }
483
484
4.35k
done:
485
4.35k
    if (sign) {
486
520
        return -fraction;
487
520
    }
488
3.83k
    return fraction;
489
4.35k
}
490
491
3.12k
#define MONTHSPERYEAR   12      // months per calendar year
492
493
// clear a baseline_t
494
static void gps_clear_base(struct baseline_t *base)
495
0
{
496
0
    base->status = STATUS_UNK;
497
0
    base->east = NAN;
498
0
    base->north = NAN;
499
0
    base->up = NAN;
500
0
    base->length = NAN;
501
0
    base->course = NAN;
502
0
    base->ratio = NAN;
503
0
}
504
505
// stuff a fix structure with recognizable out-of-band values
506
void gps_clear_fix(struct gps_fix_t *fixp)
507
0
{
508
0
    memset(fixp, 0, sizeof(struct gps_fix_t));
509
0
    fixp->altitude = NAN;        // DEPRECATED, undefined
510
0
    fixp->altHAE = NAN;
511
0
    fixp->altMSL = NAN;
512
0
    fixp->climb = NAN;
513
0
    fixp->depth = NAN;
514
0
    fixp->epc = NAN;
515
0
    fixp->epd = NAN;
516
0
    fixp->eph = NAN;
517
0
    fixp->eps = NAN;
518
0
    fixp->ept = NAN;
519
0
    fixp->epv = NAN;
520
0
    fixp->epx = NAN;
521
0
    fixp->epy = NAN;
522
0
    fixp->latitude = NAN;
523
0
    fixp->longitude = NAN;
524
0
    fixp->magnetic_track = NAN;
525
0
    fixp->magnetic_var = NAN;
526
0
    fixp->mode = MODE_NOT_SEEN;
527
0
    fixp->sep = NAN;
528
0
    fixp->speed = NAN;
529
0
    fixp->track = NAN;
530
    // clear ECEF too
531
0
    fixp->ecef.x = NAN;
532
0
    fixp->ecef.y = NAN;
533
0
    fixp->ecef.z = NAN;
534
0
    fixp->ecef.vx = NAN;
535
0
    fixp->ecef.vy = NAN;
536
0
    fixp->ecef.vz = NAN;
537
0
    fixp->ecef.pAcc = NAN;
538
0
    fixp->ecef.vAcc = NAN;
539
0
    fixp->errEllipseOrient = NAN;
540
0
    fixp->errEllipseMajor = NAN;
541
0
    fixp->errEllipseMinor = NAN;
542
0
    fixp->NED.relPosN = NAN;
543
0
    fixp->NED.relPosE = NAN;
544
0
    fixp->NED.relPosD = NAN;
545
0
    fixp->NED.velN = NAN;
546
0
    fixp->NED.velE = NAN;
547
0
    fixp->NED.velD = NAN;
548
0
    fixp->geoid_sep = NAN;
549
0
    fixp->dgps_age = NAN;
550
0
    fixp->dgps_station = -1;
551
0
    fixp->temp = NAN;
552
0
    fixp->wanglem = NAN;
553
0
    fixp->wangler = NAN;
554
0
    fixp->wanglet = NAN;
555
0
    fixp->wspeedr = NAN;
556
0
    fixp->wspeedt = NAN;
557
0
    fixp->wtemp = NAN;
558
0
    gps_clear_base(&fixp->base);
559
0
}
560
561
// stuff an attitude structure with recognizable out-of-band values
562
void gps_clear_att(struct attitude_t *attp)
563
0
{
564
0
    memset(attp, 0, sizeof(struct attitude_t));
565
0
    attp->acc_len = NAN;
566
0
    attp->acc_x = NAN;
567
0
    attp->acc_y = NAN;
568
0
    attp->acc_z = NAN;
569
0
    attp->depth = NAN;
570
0
    attp->dip = NAN;
571
0
    attp->gyro_temp = NAN;
572
0
    attp->gyro_x = NAN;
573
0
    attp->gyro_y = NAN;
574
0
    attp->gyro_z = NAN;
575
0
    attp->heading = NAN;
576
0
    attp->mheading = NAN;
577
0
    attp->mag_len = NAN;
578
0
    attp->mag_x = NAN;
579
0
    attp->mag_y = NAN;
580
0
    attp->mag_z = NAN;
581
0
    attp->pitch = NAN;
582
0
    attp->roll = NAN;
583
0
    attp->rot = NAN;
584
0
    attp->temp = NAN;
585
0
    attp->yaw = NAN;
586
0
    gps_clear_base(&attp->base);
587
0
}
588
589
// Clear a dop_t structure
590
void gps_clear_dop( struct dop_t *dop)
591
0
{
592
0
    dop->xdop = dop->ydop = dop->vdop = dop->tdop = dop->hdop = dop->pdop =
593
0
        dop->gdop = NAN;
594
0
}
595
596
// Clear a gst structure
597
void gps_clear_gst( struct gst_t *gst)
598
0
{
599
0
    memset(&gst->utctime, 0, sizeof(gst->utctime));
600
0
    gst-> rms_deviation =  NAN;
601
0
    gst-> smajor_deviation =  NAN;
602
0
    gst-> sminor_deviation =  NAN;
603
0
    gst-> smajor_orientation =  NAN;
604
0
    gst-> lat_err_deviation =  NAN;
605
0
    gst-> lon_err_deviation =  NAN;
606
0
    gst-> alt_err_deviation =  NAN;
607
0
    gst-> ve_err_deviation =  NAN;
608
0
    gst-> vn_err_deviation =  NAN;
609
0
    gst-> vu_err_deviation =  NAN;
610
0
}
611
612
// stuff a log structure with recognizable out-of-band values
613
void gps_clear_log(struct gps_log_t *logp)
614
0
{
615
0
    memset(logp, 0, sizeof(struct gps_log_t));
616
0
    logp->lon = NAN;
617
0
    logp->lat = NAN;
618
0
    logp->altHAE = NAN;
619
0
    logp->altMSL = NAN;
620
0
    logp->gSpeed = NAN;
621
0
    logp->heading = NAN;
622
0
    logp->tAcc = NAN;
623
0
    logp->hAcc = NAN;
624
0
    logp->vAcc = NAN;
625
0
    logp->sAcc = NAN;
626
0
    logp->headAcc = NAN;
627
0
    logp->velN = NAN;
628
0
    logp->velE = NAN;
629
0
    logp->velD = NAN;
630
0
    logp->pDOP = NAN;
631
0
    logp->distance = NAN;
632
0
    logp->totalDistance = NAN;
633
0
    logp->distanceStd = NAN;
634
0
    logp->fixType = -1;
635
0
}
636
637
/* merge new data (from) into current fix (to)
638
 * Being careful not to lose information */
639
void gps_merge_fix(struct gps_fix_t *to,
640
                   gps_mask_t transfer,
641
                   struct gps_fix_t *from)
642
0
{
643
0
    if ((NULL == to) ||
644
0
        (NULL == from)) {
645
0
        return;
646
0
    }
647
0
    if (0 != (transfer & TIME_SET)) {
648
0
        to->time = from->time;
649
0
    }
650
0
    if (0 != (transfer & LATLON_SET)) {
651
0
        to->latitude = from->latitude;
652
0
        to->longitude = from->longitude;
653
0
    }
654
0
    if (0 != (transfer & MODE_SET)) {
655
        // FIXME?  Maybe only upgrade mode, not downgrade it
656
0
        to->mode = from->mode;
657
0
    }
658
    /* Some messages only report mode, some mode and status, some only status.
659
     * Only upgrade status, not downgrade it */
660
0
    if (0 != (transfer & STATUS_SET)) {
661
0
        if (to->status < from->status) {
662
0
            to->status = from->status;
663
0
        }
664
0
    }
665
0
    if ((transfer & ALTITUDE_SET) != 0) {
666
0
        if (0 != isfinite(from->altHAE)) {
667
0
            to->altHAE = from->altHAE;
668
0
        }
669
0
        if (0 != isfinite(from->altMSL)) {
670
0
            to->altMSL = from->altMSL;
671
0
        }
672
0
        if (0 != isfinite(from->depth)) {
673
0
            to->depth = from->depth;
674
0
        }
675
0
    }
676
0
    if (0 != (transfer & TRACK_SET)) {
677
0
        to->track = from->track;
678
0
    }
679
0
    if (0 != (transfer & MAGNETIC_TRACK_SET)) {
680
0
        if (0 != isfinite(from->magnetic_track)) {
681
0
            to->magnetic_track = from->magnetic_track;
682
0
        }
683
0
        if (0 != isfinite(from->magnetic_var)) {
684
0
            to->magnetic_var = from->magnetic_var;
685
0
        }
686
0
    }
687
0
    if (0 != (transfer & SPEED_SET)) {
688
0
        to->speed = from->speed;
689
0
    }
690
0
    if (0 != (transfer & CLIMB_SET)) {
691
0
        to->climb = from->climb;
692
0
    }
693
0
    if (0 != (transfer & TIMERR_SET)) {
694
0
        to->ept = from->ept;
695
0
    }
696
0
    if (0 != isfinite(from->epx) &&
697
0
        0 != isfinite(from->epy)) {
698
0
        to->epx = from->epx;
699
0
        to->epy = from->epy;
700
0
    }
701
0
    if (0 != isfinite(from->epd)) {
702
0
        to->epd = from->epd;
703
0
    }
704
0
    if (0 != isfinite(from->eph)) {
705
0
        to->eph = from->eph;
706
0
    }
707
0
    if (0 != isfinite(from->eps)) {
708
0
        to->eps = from->eps;
709
0
    }
710
    // spherical error probability, not geoid separation
711
0
    if (0 != isfinite(from->sep)) {
712
0
        to->sep = from->sep;
713
0
    }
714
    // geoid separation, not spherical error probability
715
0
    if (0 != isfinite(from->geoid_sep)) {
716
0
        to->geoid_sep = from->geoid_sep;
717
0
    }
718
0
    if (0 != isfinite(from->epv)) {
719
0
        to->epv = from->epv;
720
0
    }
721
0
    if (0 != (transfer & SPEEDERR_SET)) {
722
0
        to->eps = from->eps;
723
0
    }
724
0
    if (0 != (transfer & ECEF_SET)) {
725
0
        to->ecef.x = from->ecef.x;
726
0
        to->ecef.y = from->ecef.y;
727
0
        to->ecef.z = from->ecef.z;
728
0
        to->ecef.pAcc = from->ecef.pAcc;
729
0
    }
730
0
    if (0 != (transfer & VECEF_SET)) {
731
0
        to->ecef.vx = from->ecef.vx;
732
0
        to->ecef.vy = from->ecef.vy;
733
0
        to->ecef.vz = from->ecef.vz;
734
0
        to->ecef.vAcc = from->ecef.vAcc;
735
0
    }
736
0
    if (0 != isfinite(from->errEllipseOrient) &&
737
0
        0 != isfinite(from->errEllipseMajor) &&
738
0
        0 != isfinite(from->errEllipseMinor)) {
739
0
        to->errEllipseOrient = from->errEllipseOrient;
740
0
        to->errEllipseMajor = from->errEllipseMajor;
741
0
        to->errEllipseMinor = from->errEllipseMinor;
742
0
    }
743
0
    if (0 != (transfer & NED_SET)) {
744
0
        to->NED.relPosN = from->NED.relPosN;
745
0
        to->NED.relPosE = from->NED.relPosE;
746
0
        to->NED.relPosD = from->NED.relPosD;
747
0
        if ((0 != isfinite(from->NED.relPosH)) &&
748
0
            (0 != isfinite(from->NED.relPosL))) {
749
0
            to->NED.relPosH = from->NED.relPosH;
750
0
            to->NED.relPosL = from->NED.relPosL;
751
0
        }
752
0
    }
753
0
    if (0 != (transfer & VNED_SET)) {
754
0
        to->NED.velN = from->NED.velN;
755
0
        to->NED.velE = from->NED.velE;
756
0
        to->NED.velD = from->NED.velD;
757
0
    }
758
0
    if ('\0' != from->datum[0]) {
759
0
        strlcpy(to->datum, from->datum, sizeof(to->datum));
760
0
    }
761
0
    if (0 != isfinite(from->dgps_age) &&
762
0
        0 <= from->dgps_station) {
763
        // both, or neither
764
0
        to->dgps_age = from->dgps_age;
765
0
        to->dgps_station = from->dgps_station;
766
0
    }
767
768
0
    if (ANT_UNK != from->ant_stat) {
769
0
        to->ant_stat = from->ant_stat;
770
0
    }
771
0
    if (0 < from->jam) {
772
0
        to->jam = from->jam;
773
0
    }
774
0
    if (ANT_PWR_UNK != from->ant_power) {
775
0
        to->ant_power = from->ant_power;
776
0
    }
777
    // navdata stuff.  just wind angle and angle for now
778
0
    if (0 != (transfer & NAVDATA_SET)) {
779
0
        if (0 != isfinite(from->wanglem)) {
780
0
            to->wanglem = from->wanglem;
781
0
        }
782
0
        if (0 != isfinite(from->wangler)) {
783
0
            to->wangler = from->wangler;
784
0
        }
785
0
        if (0 != isfinite(from->wanglet)) {
786
0
            to->wanglet = from->wanglet;
787
0
        }
788
0
        if (0 != isfinite(from->wspeedr)) {
789
0
            to->wspeedr = from->wspeedr;
790
0
        }
791
0
        if (0 != isfinite(from->wspeedt)) {
792
0
            to->wspeedt = from->wspeedt;
793
0
        }
794
0
    }
795
0
    if (0 != isfinite(from->temp)) {
796
0
        to->temp = from->temp;
797
0
    }
798
0
    if (0 != isfinite(from->wtemp)) {
799
0
        to->wtemp = from->wtemp;
800
0
    }
801
0
}
802
803
/* mkgmtime(tm)
804
 * convert struct tm, as UTC, to seconds since Unix epoch
805
 * This differs from mktime() from libc.
806
 * mktime() takes struct tm as localtime.
807
 *
808
 * The inverse of gmtime(time_t)
809
 *
810
 * Return: -1 on error, set errno to EOVERFLOW
811
 */
812
time_t mkgmtime(struct tm * t)
813
2.30k
{
814
2.30k
    int year;
815
2.30k
    time_t result;
816
2.30k
    static const int cumdays[MONTHSPERYEAR] =
817
2.30k
        { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
818
819
    // check ranges, ignore tm_isdst and max tm_year
820
2.30k
    if (0 > t->tm_sec ||
821
2.30k
        0 > t->tm_min ||
822
2.30k
        0 > t->tm_hour ||
823
2.30k
        1 > t->tm_mday ||
824
1.86k
        0 > t->tm_mon ||
825
1.86k
        0 > t->tm_year ||
826
1.28k
        0 > t->tm_wday ||
827
1.28k
        0 > t->tm_yday ||
828
1.28k
        61 < t->tm_sec ||
829
1.28k
        59 < t->tm_min ||
830
1.28k
        23 < t->tm_hour ||
831
1.28k
        31 < t->tm_mday ||
832
1.28k
        11 < t->tm_mon ||
833
1.28k
        6 < t->tm_wday ||
834
1.28k
        365 < t->tm_yday) {
835
1.02k
        errno = EOVERFLOW;
836
1.02k
        return -1;
837
1.02k
    }
838
2.30k
    errno = 0;
839
1.28k
    year = 1900 + t->tm_year + t->tm_mon / MONTHSPERYEAR;
840
1.28k
    result = (year - 1970) * 365 + cumdays[t->tm_mon % MONTHSPERYEAR];
841
1.28k
    result += (year - 1968) / 4;
842
1.28k
    result -= (year - 1900) / 100;
843
1.28k
    result += (year - 1600) / 400;
844
1.28k
    if (0 == (year % 4) &&
845
757
        (0 != (year % 100) ||
846
518
         0 == (year % 400)) &&
847
560
        (2 > (t->tm_mon % MONTHSPERYEAR))) {
848
340
        result--;
849
340
    }
850
1.28k
    result += t->tm_mday - 1;
851
1.28k
    result *= 24;
852
1.28k
    result += t->tm_hour;
853
1.28k
    result *= 60;
854
1.28k
    result += t->tm_min;
855
1.28k
    result *= 60;
856
1.28k
    result += t->tm_sec;
857
    /* this is UTC, no DST
858
     * if (t->tm_isdst == 1)
859
     * result -= 3600;
860
     */
861
1.28k
    return result;
862
2.30k
}
863
864
// ISO8601 UTC to Unix timespec, no leapsecond correction.
865
timespec_t iso8601_to_timespec(const char *isotime)
866
2.30k
{
867
2.30k
    timespec_t ret;
868
869
2.30k
#ifndef __clang_analyzer__
870
#ifdef USE_QT
871
    double usec = 0;
872
873
    QString t(isotime);
874
    QDateTime d = QDateTime::fromString(isotime, Qt::ISODate);
875
    QStringList sl = t.split(".");
876
    if (1 < sl.size()) {
877
        usec = sl[1].toInt() / pow(10., (double)sl[1].size());
878
    }
879
    ret.tv_sec = d.toSecsSinceEpoch();
880
    ret.tv_nsec = usec * 1e9;
881
#else  // USE_QT
882
2.30k
    double usec = 0;
883
2.30k
    struct tm tm = {0};
884
885
2.30k
    {
886
2.30k
        char *dp = NULL;
887
2.30k
        dp = strptime(isotime, "%Y-%m-%dT%H:%M:%S", &tm);
888
2.30k
        if (NULL != dp &&
889
633
            '.' == *dp) {
890
194
            usec = strtod(dp, NULL);
891
194
        }
892
2.30k
    }
893
894
    /*
895
     * It would be nice if we could say mktime(&tm) - timezone + usec instead,
896
     * but timezone is not available at all on some BSDs. Besides, when working
897
     * with historical dates the value of timezone after an ordinary tzset(3)
898
     * can be wrong; you have to do a redirect through the IANA historical
899
     * timezone database to get it right.
900
     */
901
2.30k
    ret.tv_sec = mkgmtime(&tm);
902
2.30k
    ret.tv_nsec = usec * 1e9;
903
2.30k
#endif  // USE_QT
904
2.30k
#endif  // __clang_analyzer__
905
906
2.30k
#if 4 < SIZEOF_TIME_T
907
2.30k
    if (253402300799LL < ret.tv_sec) {
908
        // enforce max "9999-12-31T23:59:59.999Z"
909
194
        ret.tv_sec = 253402300799LL;
910
194
    }
911
2.30k
#endif
912
2.30k
    return ret;
913
2.30k
}
914
915
/* Convert POSIX timespec to ISO8601 UTC, put result in isotime.
916
 * no timezone adjustment
917
 * Return: pointer to isotime.
918
 * example: 2007-12-11T23:38:51.033Z */
919
char *timespec_to_iso8601(timespec_t fixtime, char isotime[], size_t len)
920
0
{
921
0
    struct tm when;
922
0
    char timestr[30];
923
0
    long fracsec;
924
925
0
    if (0 > fixtime.tv_sec) {
926
        // Allow 0 for testing of 1970-01-01T00:00:00.000Z
927
0
        strlcpy(isotime, "NaN", len);
928
0
        return isotime;
929
0
    }
930
0
    if (999499999 < fixtime.tv_nsec) {
931
        // round up
932
0
        fixtime.tv_sec++;
933
0
        fixtime.tv_nsec = 0;
934
0
    }
935
936
0
#if 4 < SIZEOF_TIME_T
937
0
    if (253402300799LL < fixtime.tv_sec) {
938
        // enforce max "9999-12-31T23:59:59.999Z"
939
0
        fixtime.tv_sec = 253402300799LL;
940
0
    }
941
0
#endif
942
943
0
    (void)gmtime_r(&fixtime.tv_sec, &when);
944
945
    /*
946
     * Do not mess casually with the number of decimal digits in the
947
     * format!  Most GPSes report over serial links at 0.01s or 0.001s
948
     * precision.  Round to 0.001s
949
     */
950
0
    fracsec = (fixtime.tv_nsec + 500000) / 1000000;
951
952
0
    (void)strftime(timestr, sizeof(timestr), "%Y-%m-%dT%H:%M:%S", &when);
953
0
    (void)snprintf(isotime, len, "%s.%03ldZ",timestr, fracsec);
954
955
0
    return isotime;
956
0
}
957
958
/* return time now as ISO8601, no timezone adjustment
959
 * example: 2007-12-11T23:38:51.033Z */
960
char *now_to_iso8601(char *tbuf, size_t tbuf_sz)
961
0
{
962
0
    timespec_t ts_now;
963
964
0
    (void)clock_gettime(CLOCK_REALTIME, &ts_now);
965
0
    return timespec_to_iso8601(ts_now, tbuf, tbuf_sz);
966
0
}
967
968
0
#define Deg2Rad(n)      ((n) * DEG_2_RAD)
969
970
/* Distance in meters between two points specified in degrees, optionally
971
 * with initial and final bearings. */
972
double earth_distance_and_bearings(double lat1, double lon1,
973
                                   double lat2, double lon2,
974
                                   double *ib, double *fb)
975
0
{
976
    /*
977
     * this is a translation of the javascript implementation of the
978
     * Vincenty distance formula by Chris Veness. See
979
     * http://www.movable-type.co.uk/scripts/latlong-vincenty.html
980
     */
981
0
    double a, b, f;             // WGS-84 ellipsoid params
982
0
    double L, L_P, U1, U2, s_U1, c_U1, s_U2, c_U2;
983
0
    double uSq, A, B, d_S, lambda;
984
    // cppcheck-suppress variableScope
985
0
    double s_L, c_L, s_A, C;
986
0
    double c_S, S, s_S, c_SqA, c_2SM;
987
0
    int i = 100;
988
989
0
    a = WGS84A;
990
0
    b = WGS84B;
991
0
    f = 1 / WGS84F;
992
0
    L = Deg2Rad(lon2 - lon1);
993
0
    U1 = atan((1 - f) * tan(Deg2Rad(lat1)));
994
0
    U2 = atan((1 - f) * tan(Deg2Rad(lat2)));
995
0
    s_U1 = sin(U1);
996
0
    c_U1 = cos(U1);
997
0
    s_U2 = sin(U2);
998
0
    c_U2 = cos(U2);
999
0
    lambda = L;
1000
1001
0
    do {
1002
0
        s_L = sin(lambda);
1003
0
        c_L = cos(lambda);
1004
0
        s_S = sqrt((c_U2 * s_L) * (c_U2 * s_L) +
1005
0
                   (c_U1 * s_U2 - s_U1 * c_U2 * c_L) *
1006
0
                   (c_U1 * s_U2 - s_U1 * c_U2 * c_L));
1007
1008
0
        if (0 == s_S) {
1009
0
            return 0;
1010
0
        }
1011
1012
0
        c_S = s_U1 * s_U2 + c_U1 * c_U2 * c_L;
1013
0
        S = atan2(s_S, c_S);
1014
0
        s_A = c_U1 * c_U2 * s_L / s_S;
1015
0
        c_SqA = 1 - s_A * s_A;
1016
0
        c_2SM = c_S - 2 * s_U1 * s_U2 / c_SqA;
1017
1018
0
        if (0 == isfinite(c_2SM)) {
1019
0
            c_2SM = 0;
1020
0
        }
1021
1022
0
        C = f / 16 * c_SqA * (4 + f * (4 - 3 * c_SqA));
1023
0
        L_P = lambda;
1024
0
        lambda = L + (1 - C) * f * s_A *
1025
0
            (S + C * s_S * (c_2SM + C * c_S * (2 * c_2SM * c_2SM - 1)));
1026
0
    } while ((fabs(lambda - L_P) > 1.0e-12) &&
1027
0
             (0 < --i));
1028
1029
0
    if (0 == i) {
1030
0
        return NAN;             // formula failed to converge
1031
0
    }
1032
1033
0
    uSq = c_SqA * ((a * a) - (b * b)) / (b * b);
1034
0
    A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
1035
0
    B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
1036
0
    d_S = B * s_S * (c_2SM + B / 4 *
1037
0
                     (c_S * (-1 + 2 * c_2SM * c_2SM) - B / 6 * c_2SM *
1038
0
                      (-3 + 4 * s_S * s_S) * (-3 + 4 * c_2SM * c_2SM)));
1039
1040
0
    if (NULL != ib) {
1041
0
        *ib = atan2(c_U2 * sin(lambda),
1042
0
                    c_U1 * s_U2 - s_U1 * c_U2 * cos(lambda));
1043
0
    }
1044
0
    if (NULL != fb) {
1045
0
        *fb = atan2(c_U1 * sin(lambda),
1046
0
                    c_U1 * s_U2 * cos(lambda) - s_U1 * c_U2);
1047
0
    }
1048
1049
0
    return (WGS84B * A * (S - d_S));
1050
0
}
1051
1052
// Distance in meters between two points specified in degrees.
1053
double earth_distance(double lat1, double lon1, double lat2, double lon2)
1054
0
{
1055
0
    return earth_distance_and_bearings(lat1, lon1, lat2, lon2, NULL, NULL);
1056
0
}
1057
1058
/* Wait for data until timeout, ignoring signals.
1059
 *
1060
 * pselect() may set errno on error
1061
 */
1062
bool nanowait(int fd, struct timespec *to)
1063
0
{
1064
0
    fd_set fdset;
1065
1066
0
    FD_ZERO(&fdset);
1067
0
    FD_SET(fd, &fdset);
1068
0
    TS_NORM(to);         // just in case
1069
0
    errno = 0;
1070
    // sigmask is NULL, so equivalent to select()
1071
0
    return pselect(fd + 1, &fdset, NULL, NULL, to, NULL) == 1;
1072
0
}
1073
1074
/* Accept a datum code, return matching string
1075
 *
1076
 * There are a ton of these, only a few are here
1077
 *
1078
 */
1079
void datum_code_string(int code, char *buffer, size_t len)
1080
0
{
1081
0
    const char *datum_str;
1082
1083
0
    switch (code) {
1084
0
    case 0:
1085
0
        datum_str = "WGS84";
1086
0
        break;
1087
0
    case 21:
1088
0
        datum_str = "WGS84";
1089
0
        break;
1090
0
    case 178:
1091
0
        datum_str = "Tokyo Mean";
1092
0
        break;
1093
0
    case 179:
1094
0
        datum_str = "Tokyo-Japan";
1095
0
        break;
1096
0
    case 180:
1097
0
        datum_str = "Tokyo-Korea";
1098
0
        break;
1099
0
    case 181:
1100
0
        datum_str = "Tokyo-Okinawa";
1101
0
        break;
1102
0
    case 182:
1103
0
        datum_str = "PZ90.11";
1104
0
        break;
1105
0
    case 999:
1106
0
        datum_str = "User Defined";
1107
0
        break;
1108
0
    default:
1109
0
        datum_str = NULL;
1110
0
        break;
1111
0
    }
1112
1113
0
    if (NULL == datum_str) {
1114
        // Fake it
1115
0
        snprintf(buffer, len, "%d", code);
1116
0
    } else {
1117
0
        strlcpy(buffer, datum_str, len);
1118
0
    }
1119
0
}
1120
1121
/* make up an NMEA 4.0 (extended) PRN based on gnssId:svId,
1122
 * This does NOT match NMEA 4.10 and 4.11 where all PRN are 1-99,
1123
 * except IMES, QZSS, and some SBAS.
1124
 *
1125
 * Ref Appendix A from u-blox ZED-F9P Interface Description
1126
 * and
1127
 * Section 1.5.3  M10-FW500_InterfaceDescription_UBX-20053845.pdf
1128
 *
1129
 * Using ST Teseo PRN fors for those not defined by UBX.
1130
 * um3407-teseo-vi-and-teseo-app2nmea-specifications-and-commands-stmicroelectronics.pdf
1131
 * Section 3.5
1132
 * But we do not use the per sigId PRNs from ST.
1133
 *
1134
 * Return PRN, less than one for error
1135
 *        -1 for GLONASS svid 255
1136
 */
1137
short ubx2_to_prn(int gnssId, int svId)
1138
0
{
1139
0
    short nmea_PRN = 0;
1140
1141
0
    if (1 > svId) {
1142
        // skip 0 svId
1143
0
        return 0;
1144
0
    }
1145
1146
0
    switch (gnssId) {
1147
0
    case 0:
1148
        // GPS, 1-32 maps to 1-32
1149
0
        if (32 >= svId) {
1150
0
            nmea_PRN = svId;
1151
0
        }
1152
0
        break;
1153
0
    case 1:
1154
        // SBAS, 120..151, 152..158 maps to 33..64, 152..158
1155
0
        if (120 <= svId &&
1156
0
            151 >= svId) {
1157
0
            nmea_PRN = svId - 87;
1158
0
        } else if (158 >= svId) {
1159
0
            nmea_PRN = svId;
1160
0
        }
1161
0
        break;
1162
0
    case 2:
1163
        // Galileo, ubx gnssid:svid 1..36 ->  301-336
1164
        // Galileo, ubx PRN         211..246 ->  301-336
1165
0
        if (36 >= svId) {
1166
0
            nmea_PRN = svId + 300;
1167
0
        } else if (211 > svId) {
1168
            // skip bad svId
1169
0
            return 0;
1170
0
        } else if (246 >= svId) {
1171
0
            nmea_PRN = svId + 90;
1172
0
        }
1173
0
        break;
1174
0
    case 3:
1175
        /* BeiDou, ubx gnssid:svid    1..37 -> to 401-437
1176
         * have seen 1-63 on F10 ProtVer 40.0, March 2025
1177
         *   ubx gnssid:svid    1..63 -> to 401-463
1178
         * BeiDou, ubx "single svid"  159..163,33..64 -> to 401-437 ?? */
1179
0
        if (63 >= svId) {
1180
0
            nmea_PRN = svId + 400;
1181
0
        } else if (159 > svId) {
1182
            // skip bad svId
1183
0
            return 0;
1184
0
        } else if (163 >= svId) {
1185
0
            nmea_PRN = svId + 242;
1186
0
        }
1187
0
        break;
1188
0
    case 4:
1189
        // IMES, ubx gnssid:svid 1-10 -> to 173-182
1190
        // IMES, ubx PRN         173-182 to 173-182
1191
0
        if (10 >= svId) {
1192
0
            nmea_PRN = svId + 172;
1193
0
        } else if (173 > svId) {
1194
            // skip bad svId
1195
0
            return 0;
1196
0
        } else if (182 >= svId) {
1197
0
            nmea_PRN = svId;
1198
0
        }
1199
0
        break;
1200
0
    case 5:
1201
        // QZSS, ubx gnssid:svid 1-10 to 193-202
1202
        // QZSS, ubx PRN         193-202 to 193-202
1203
0
        if (10 >= svId) {
1204
0
            nmea_PRN = svId + 192;
1205
0
        } else if (193 > svId) {
1206
            // skip bad svId
1207
0
            return 0;
1208
0
        } else if (202 >= svId) {
1209
0
            nmea_PRN = svId;
1210
0
        }
1211
0
        break;
1212
0
    case 6:
1213
        // GLONASS, 1-32 maps to 65-96
1214
0
        if (32 >= svId) {
1215
0
            nmea_PRN = svId + 64;
1216
0
        } else if (65 > svId) {
1217
            // skip bad svId
1218
0
            return 0;
1219
0
        } else if (96 >= svId) {
1220
0
            nmea_PRN = svId;
1221
0
        } else if (255 == svId) {
1222
            // skip bad svId, 255 == tracked, but unidentified, skip
1223
0
            nmea_PRN = -1;
1224
0
        }
1225
0
        break;
1226
0
    case 7:
1227
        // NavIC (IRNSS), 1 - 14 -> 801 - 814
1228
0
        if (14 >= svId) {
1229
0
            nmea_PRN = svId + 800;;
1230
0
        }
1231
0
        break;
1232
0
    default:
1233
        // Huh?
1234
0
        nmea_PRN = 0;
1235
0
    }
1236
1237
0
    return nmea_PRN;
1238
0
}
1239
1240
// vim: set expandtab shiftwidth=4