Coverage Report

Created: 2026-12-01 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gpsd/gpsd-3.28.1~dev/drivers/driver_superstar2.c
Line
Count
Source
1
/*
2
 * Driver for NovAtel Superstar2
3
 *
4
 * This file is Copyright by the GPSD project
5
 * SPDX-License-Identifier: BSD-2-clause
6
 */
7
#include "../include/gpsd_config.h"  // must be before all includes
8
9
#include <math.h>
10
#include <stdbool.h>
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <string.h>
14
#include <time.h>
15
16
#include "../include/gpsd.h"
17
18
#if defined(SUPERSTAR2_ENABLE)
19
#include "../include/bits.h"
20
#include "../include/driver_superstar2.h"
21
#include "../include/timespec.h"
22
23
/*
24
 * These routines are specific to this driver
25
 */
26
27
    static gps_mask_t superstar2_parse_input(struct gps_device_t *);
28
    static gps_mask_t superstar2_dispatch(struct gps_device_t *,
29
                                          unsigned char *, size_t);
30
    static gps_mask_t superstar2_msg_ack(struct gps_device_t *,
31
                                         unsigned char *, size_t);
32
    static gps_mask_t superstar2_msg_navsol_lla(struct gps_device_t *,
33
                                                unsigned char *, size_t);
34
    static gps_mask_t superstar2_msg_timing(struct gps_device_t *,
35
                                            unsigned char *, size_t);
36
    static gps_mask_t superstar2_msg_svinfo(struct gps_device_t *,
37
                                            unsigned char *, size_t);
38
    static gps_mask_t superstar2_msg_iono_utc(struct gps_device_t *,
39
                                              unsigned char *, size_t);
40
    static gps_mask_t superstar2_msg_ephemeris(struct gps_device_t *,
41
                                               unsigned char *, size_t);
42
43
/*
44
 * These methods may be called elsewhere in gpsd
45
 */
46
    static ssize_t superstar2_control_send(struct gps_device_t *, char *,
47
                                           size_t);
48
    static void superstar2_event_hook(struct gps_device_t *, event_t);
49
    static ssize_t superstar2_write(struct gps_device_t *, char *, size_t);
50
    static bool superstar2_set_speed(struct gps_device_t *, speed_t, char,
51
                                     int);
52
    static void superstar2_set_mode(struct gps_device_t *, int);
53
54
55
/*
56
 * Decode the message ACK message
57
 */
58
    static gps_mask_t superstar2_msg_ack(struct gps_device_t *session,
59
                                         unsigned char *buf, size_t data_len)
60
0
    {
61
0
        if (data_len == 11) {
62
0
            GPSD_LOG(LOG_PROG, &session->context->errout,
63
0
                     "superstar2 #126 - ACK %d %d %d %d %d\n",
64
0
                     buf[5], buf[6], buf[7], buf[8], buf[9]);
65
0
        }
66
0
        return 0;
67
0
    }
68
69
/*
70
 * Decode the navigation solution message. The ECEF version is intentionally
71
 * unhandled. By suppressing evaluation of it, we gain the desirable feature
72
 * that the fix update is atomic and exactly once per cycle.
73
 */
74
75
76
// Navigation Data (User Coordinates) ID# 20
77
    static gps_mask_t superstar2_msg_navsol_lla(struct gps_device_t *session,
78
                                                unsigned char *buf,
79
                                                size_t data_len)
80
0
    {
81
0
        gps_mask_t mask;
82
0
        unsigned char flags;
83
0
        double d;
84
0
        struct tm tm = {0};
85
0
        double int_part;
86
0
        char ts_buf[TIMESPEC_LEN];
87
88
0
        if (data_len != 77) {
89
0
            return 0;
90
0
        }
91
92
0
        GPSD_LOG(LOG_PROG, &session->context->errout,
93
0
                 "superstar2 #20 - user navigation data\n");
94
0
        mask = 0;
95
96
0
        flags = (unsigned char)getub(buf, 72);
97
0
        if ((flags & 0x0f) != 0x03) { // mode 3 is navigation
98
0
            return mask;
99
0
        }
100
101
        // extract time data
102
0
        (void)memset(&tm, '\0', sizeof(tm));
103
0
        tm.tm_hour = (int)getub(buf, 4) & 0x1f;
104
0
        tm.tm_min = (int)getub(buf, 5);
105
0
        d = getled64((char *)buf, 6);       // seconds as a double
106
0
        session->newdata.time.tv_nsec = (long)(modf(d, &int_part) * 1e9);
107
0
        tm.tm_sec = (int)int_part;
108
0
        tm.tm_mday = (int)getub(buf, 14);
109
0
        tm.tm_mon = (int)getub(buf, 15) - 1;
110
0
        tm.tm_year = (int)getleu16(buf, 16) - 1900;
111
0
        tm.tm_isdst = 0;
112
0
        session->newdata.time.tv_sec = mkgmtime(&tm);
113
0
        mask |= TIME_SET | NTPTIME_IS;
114
115
        // extract the local tangential plane (ENU) solution
116
0
        session->newdata.latitude = getled64((char *)buf, 18) * RAD_2_DEG;
117
0
        session->newdata.longitude = getled64((char *)buf, 26) * RAD_2_DEG;
118
        // unclear if this is MSL or WGS84.  Assume WGS84
119
0
        session->newdata.altHAE = getlef32((char *)buf, 34);
120
0
        session->newdata.speed = getlef32((char *)buf, 38);
121
0
        session->newdata.track = getlef32((char *)buf, 42) * RAD_2_DEG;
122
0
        session->newdata.climb = getlef32((char *)buf, 54);
123
0
        mask |= LATLON_SET | ALTITUDE_SET | SPEED_SET | TRACK_SET | CLIMB_SET;
124
125
0
        session->gpsdata.satellites_used = (int)getub(buf, 71) & 0x0f;
126
0
        session->gpsdata.dop.hdop = getleu16(buf, 66) * 0.1;
127
0
        session->gpsdata.dop.vdop = getleu16(buf, 68) * 0.1;
128
        // other DOP if available
129
0
        mask |= DOP_SET | USED_IS;
130
131
0
        flags = (unsigned char)getub(buf, 70);
132
0
        switch (flags & 0x1f) {
133
0
        case 2:
134
0
            session->newdata.mode = MODE_3D;
135
0
            session->newdata.status = STATUS_GPS;
136
0
            break;
137
0
        case 4:
138
0
            session->newdata.mode = MODE_3D;
139
0
            session->newdata.status = STATUS_DGPS;
140
0
            break;
141
0
        case 5:
142
0
            session->newdata.mode = MODE_2D;
143
0
            session->newdata.status = STATUS_DGPS;
144
0
            break;
145
0
        case 3:
146
0
        case 6:
147
0
            session->newdata.mode = MODE_2D;
148
0
            session->newdata.status = STATUS_GPS;
149
0
            break;
150
0
        default:
151
0
            session->newdata.status = STATUS_UNK;
152
0
            session->newdata.mode = MODE_NO_FIX;
153
0
        }
154
155
0
        mask |= MODE_SET | STATUS_SET;
156
0
        GPSD_LOG(LOG_DATA, &session->context->errout,
157
0
                 "NAVSOL_LLA: time=%s lat=%.2f lon=%.2f altHAE=%.2f "
158
0
                 "track=%.2f speed=%.2f climb=%.2f mode=%d status=%d "
159
0
                 "hdop=%.2f hdop=%.2f used=%d\n",
160
0
                 timespec_str(&session->newdata.time, ts_buf, sizeof(ts_buf)),
161
0
                 session->newdata.latitude,
162
0
                 session->newdata.longitude,
163
0
                 session->newdata.altHAE,
164
0
                 session->newdata.track,
165
0
                 session->newdata.speed,
166
0
                 session->newdata.climb,
167
0
                 session->newdata.mode,
168
0
                 session->newdata.status,
169
0
                 session->gpsdata.dop.hdop,
170
0
                 session->gpsdata.dop.vdop,
171
0
                 session->gpsdata.satellites_used);
172
0
        return mask;
173
0
    }
174
175
/*
176
 * GPS Satellite Info
177
 */
178
    static gps_mask_t
179
    superstar2_msg_svinfo(struct gps_device_t *session,
180
                          unsigned char *buf, size_t data_len)
181
0
    {
182
0
        size_t i;
183
0
        unsigned st, nchan, nsv;
184
185
0
        if (67 != data_len) {
186
0
            return 0;
187
0
        }
188
189
0
        GPSD_LOG(LOG_PROG, &session->context->errout,
190
0
                 "superstar2 #33 - satellite data\n");
191
192
0
        nchan = 12;
193
0
        gpsd_zero_satellites(&session->gpsdata);
194
0
        nsv = 0;                // number of actually used satellites
195
0
        for (i = st = 0; i < nchan; i++) {
196
            // get info for one channel/satellite
197
0
            unsigned off = i * 5 + 5;
198
0
            unsigned porn;
199
0
            bool used = (getub(buf, off) & 0x60) == 0x60;
200
0
            if (ROWS(session->gpsdata.skyview) <= i) {
201
0
                break;
202
0
            }
203
0
            if ((porn = (unsigned int)getub(buf, off) & 0x1f) == 0) {
204
0
                porn = (unsigned int)(getub(buf, off + 3) >> 1) + 87;
205
0
            }
206
207
0
            session->gpsdata.skyview[i].PRN = (short)porn;
208
0
            session->gpsdata.skyview[i].ss = (double)getub(buf, off + 4);
209
0
            session->gpsdata.skyview[i].elevation = (double)getsb(buf, off + 1);
210
0
            session->gpsdata.skyview[i].azimuth = (double)getub(buf, off + 2) +
211
0
                                                  (short)((unsigned short)(getub(buf, off + 3) & 0x1) << 1);
212
0
            session->gpsdata.skyview[i].used = used;
213
0
            if (used) {
214
0
                nsv++;
215
0
            }
216
217
0
            if (session->gpsdata.skyview[i].PRN) {
218
0
                st++;
219
0
            }
220
0
        }
221
0
        session->gpsdata.skyview_time.tv_sec = 0;
222
0
        session->gpsdata.skyview_time.tv_nsec = 0;
223
0
        session->gpsdata.satellites_used = nsv;
224
0
        session->gpsdata.satellites_visible = st;
225
0
        GPSD_LOG(LOG_DATA, &session->context->errout,
226
0
                 "SVINFO: visible=%d used=%d mask={SATELLITE|USED}\n",
227
0
                 session->gpsdata.satellites_visible,
228
0
                 session->gpsdata.satellites_used);
229
0
        return SATELLITE_SET | USED_IS;
230
0
    }
231
232
    static gps_mask_t
233
    superstar2_msg_version(struct gps_device_t *session,
234
                           unsigned char *buf, size_t data_len)
235
0
    {
236
0
#define SZ 16
237
0
        char main_sw[SZ], hw_part[SZ], boot_sw[SZ], ser_num[SZ];
238
239
        // byte 98 is device type, value = 3 means superstar2
240
0
        if ((101 != data_len) ||
241
0
            (3 != (getub(buf, 98) & 0x0f))) {
242
0
            return 0;
243
0
        }
244
245
0
        (void)snprintf(main_sw, 15, "%s", (char *)buf + 4);
246
0
        (void)snprintf(hw_part, 15, "%s", (char *)buf + 18);
247
0
        (void)snprintf(boot_sw, 15, "%s", (char *)buf + 36);
248
0
        (void)snprintf(ser_num, 14, "%s", (char *)buf + 73);
249
250
0
        GPSD_LOG(LOG_PROG, &session->context->errout,
251
0
                 "superstar2 #45 - hw part %s boot sw %s main sw %s "
252
0
                 "ser num %s\n",
253
0
                 hw_part, boot_sw, main_sw, ser_num);
254
0
        (void)strlcpy(session->subtype, main_sw, sizeof(session->subtype));
255
0
        GPSD_LOG(LOG_DATA, &session->context->errout,
256
0
                 "VERSION: subtype='%s' mask={DEVEICEID}\n",
257
0
                 session->subtype);
258
0
        return DEVICEID_SET;
259
0
    }
260
261
/**
262
 * Timing Status ID# 113
263
 *
264
 * Precise Timing models only
265
 */
266
    static gps_mask_t
267
    superstar2_msg_timing(struct gps_device_t *session, unsigned char *buf,
268
                          size_t data_len)
269
0
    {
270
0
        gps_mask_t mask;
271
0
        struct tm tm = {0};
272
273
0
        if (65 != data_len) {
274
0
            return 0;
275
0
        }
276
277
0
        GPSD_LOG(LOG_PROG, &session->context->errout,
278
0
                 "superstar2 #113 - timing status\n");
279
0
        if (0 != (getub(buf, 55) & 0x30)) {
280
0
            mask = 0;
281
0
        } else {
282
0
            double d;
283
            // extract time data
284
0
            (void)memset(&tm, '\0', sizeof(tm));
285
0
            tm.tm_mday = (int)getsb(buf, 37);
286
0
            tm.tm_mon = (int)getsb(buf, 38) - 1;
287
0
            tm.tm_year = (int)getles16(buf, 39) - 1900;
288
289
0
            tm.tm_hour = (int)getsb(buf, 41);
290
0
            tm.tm_min = (int)getsb(buf, 42);
291
0
            d = getled64((char *)buf, 43);
292
0
            tm.tm_sec = (int)d;
293
0
            tm.tm_isdst = 0;
294
0
            session->newdata.time.tv_sec = mkgmtime(&tm);
295
0
            session->newdata.time.tv_nsec = 0;
296
0
            session->context->leap_seconds = (int)getsb(buf, 20);
297
0
            mask = TIME_SET | NTPTIME_IS;
298
0
        }
299
0
        GPSD_LOG(LOG_DATA, &session->context->errout,
300
0
                 "TIMING: time=%lld mask={TIME}\n",
301
0
                 (long long)session->newdata.time.tv_sec);
302
0
        return mask;
303
0
    }
304
305
/**
306
 * Raw Measurements
307
 */
308
    static gps_mask_t
309
    superstar2_msg_measurement(struct gps_device_t *session,
310
                               unsigned char *buf, size_t data_len)
311
0
    {
312
0
        gps_mask_t mask = 0;
313
0
        size_t i;
314
0
        unsigned n;
315
0
        double t;
316
317
0
        GPSD_LOG(LOG_PROG, &session->context->errout,
318
0
                 "superstar2 #23 - measurement block\n");
319
320
0
        n = getub(buf, 6); // number of measurements
321
0
        if ((n < 1) || (n > MAXCHANNELS)) {
322
0
            GPSD_LOG(LOG_INF, &session->context->errout,
323
0
                     "superstar2 #23 - mtoo many measurements\n");
324
0
            return 0;
325
0
        }
326
        // data_len == 15 + 11*N Measurement Block + 2
327
0
        if ((17 + (11 * n)) != data_len) {
328
0
            GPSD_LOG(LOG_INF, &session->context->errout,
329
0
                     "superstar2 #23 - bad len %zu s/b %u\n", data_len,
330
0
                     17 + (11 * n));
331
0
            return 0;
332
0
        }
333
334
0
        t = getled64((char *)buf, 7);           // measurement time
335
0
        DTOTS(&session->gpsdata.raw.mtime, t);
336
337
        // this is so we can tell which never got set
338
0
        for (i = 0; i < ROWS(session->gpsdata.raw.meas); i++) {
339
0
            session->gpsdata.raw.meas[i].svid = 0;
340
0
        }
341
0
        for (i = 0; i < n; i++) {
342
0
            unsigned long ul;
343
0
            unsigned off = 11 * i + 15;
344
345
0
            if (ROWS(session->gpsdata.skyview) <= i) {
346
0
                break;
347
0
            }
348
0
            session->gpsdata.skyview[i].PRN =
349
0
                (short)(getub(buf, off) & 0x1f);
350
0
            session->gpsdata.skyview[i].ss =
351
0
                (double)getub(buf, off + 1) / 4.0;
352
0
            session->gpsdata.raw.meas[i].codephase =
353
0
                (double)getleu32(buf, off + 2);
354
0
            ul = (unsigned long)getleu32(buf, off + 6);
355
356
0
            session->gpsdata.raw.meas[i].satstat = (unsigned int)(ul & 0x03L);
357
0
            session->gpsdata.raw.meas[i].carrierphase =
358
0
                (double)((ul >> 2) & 0x03ffL);
359
0
            session->gpsdata.raw.meas[i].pseudorange = (double)(ul >> 12);
360
0
        }
361
362
        // The above decode does not look correct, do not report
363
        // mask |= RAW_IS;
364
0
        return mask;
365
0
    }
366
367
// request for ionospheric and utc time data #75
368
    static unsigned char iono_utc_msg[] = {
369
        0x01, 0x4b, 0xb4, 0x00, 0x00, 0x01
370
    };
371
372
373
374
/**
375
 * Ionospheric/UTC parameters
376
 */
377
    static gps_mask_t
378
    superstar2_msg_iono_utc(struct gps_device_t *session, unsigned char *buf,
379
                            size_t data_len UNUSED)
380
0
    {
381
0
        unsigned i, u;
382
383
0
        i = getub(buf, 12);
384
0
        u = getub(buf, 21);
385
0
        GPSD_LOG(LOG_PROG, &session->context->errout,
386
0
                 "superstar2 #75 - ionospheric & utc data: iono %s utc %s\n",
387
0
                 i ? "ok" : "bad", u ? "ok" : "bad");
388
0
        session->driver.superstar2.last_iono = time(NULL);
389
390
0
        return 0;
391
0
    }
392
393
394
/**
395
 * Ephemeris
396
 */
397
    static gps_mask_t
398
    superstar2_msg_ephemeris(struct gps_device_t *session, unsigned char *buf,
399
                             size_t data_len UNUSED)
400
0
    {
401
0
        unsigned int prn;
402
0
        prn = (unsigned int)(getub(buf, 4) & 0x1f);
403
0
        GPSD_LOG(LOG_PROG, &session->context->errout,
404
0
                 "superstar2 #22 - ephemeris data - prn %u\n", prn);
405
406
        // ephemeris data updates fairly slowly, but when it does, poll UTC
407
0
        if ((time(NULL) - session->driver.superstar2.last_iono) > 60) {
408
0
            (void)superstar2_write(session, (char *)iono_utc_msg,
409
0
                                   sizeof(iono_utc_msg));
410
0
        }
411
412
0
        return ONLINE_SET;
413
0
    }
414
415
416
    static ssize_t
417
    superstar2_write(struct gps_device_t *session, char *msg, size_t msglen)
418
0
    {
419
0
        unsigned short c = 0;
420
0
        size_t i;
421
422
0
        for (i = 0; i < (msglen - 2); i++) {
423
0
            c += (unsigned short)msg[i];
424
0
        }
425
0
        c += 0x100;
426
0
        msg[(int)msg[3] + 4] = (char)((c >> 8) & 0xff);
427
0
        msg[(int)msg[3] + 5] = (char)(c & 0xff);
428
0
        GPSD_LOG(LOG_PROG, &session->context->errout,
429
0
                 "writing superstar2 control type %d len %zu\n",
430
0
                 (int)msg[1] & 0x7f, msglen);
431
0
        return gpsd_write(session, msg, msglen);
432
0
    }
433
434
/**
435
 * Parse the data from the device
436
 */
437
    gps_mask_t
438
    superstar2_dispatch(struct gps_device_t *session, unsigned char *buf,
439
                        size_t len)
440
0
    {
441
0
        int type;
442
443
0
        if (0 == len) {
444
0
            return 0;
445
0
        }
446
447
0
        type = (int)buf[SUPERSTAR2_TYPE_OFFSET];
448
0
        session->cycle_end_reliable = true;
449
450
0
        switch (type) {
451
0
        case SUPERSTAR2_ACK:         // Message Acknowledgement
452
0
            return superstar2_msg_ack(session, buf, len);
453
0
        case SUPERSTAR2_SVINFO:      // Satellite Visibility Data
454
0
            return superstar2_msg_svinfo(session, buf, len);
455
0
        case SUPERSTAR2_NAVSOL_LLA: // Navigation Data
456
0
            return superstar2_msg_navsol_lla(session, buf,
457
0
                                             len) | (CLEAR_IS | REPORT_IS);
458
0
        case SUPERSTAR2_VERSION:     // Hardware/Software Version
459
0
            return superstar2_msg_version(session, buf, len);
460
0
        case SUPERSTAR2_TIMING:      // Timing Parameters
461
0
            return superstar2_msg_timing(session, buf, len);
462
0
        case SUPERSTAR2_MEASUREMENT: // Timing Parameters
463
0
            return superstar2_msg_measurement(session, buf, len);
464
0
        case SUPERSTAR2_IONO_UTC:
465
0
            return superstar2_msg_iono_utc(session, buf, len);
466
0
        case SUPERSTAR2_EPHEMERIS:
467
0
            return superstar2_msg_ephemeris(session, buf, len);
468
469
0
        default:
470
0
            GPSD_LOG(LOG_WARN, &session->context->errout,
471
0
                     "unknown superstar2 packet id 0x%02x length %zd\n",
472
0
                     type, len);
473
0
            return 0;
474
0
        }
475
0
    }
476
477
/**********************************************************
478
*
479
* Externally called routines below here
480
*
481
**********************************************************/
482
483
    static void superstar2_event_hook(struct gps_device_t *session,
484
                                      event_t event)
485
0
    {
486
0
        if (session->context->readonly ||
487
0
            session->context->passive) {
488
0
            return;
489
0
        }
490
491
0
        if (EVENT_IDENTIFIED == event) {
492
0
            unsigned char version_msg[] =
493
0
            { 0x01, 0x2d, 0xd2, 0x00, 0x00, 0x01 };
494
0
            unsigned char svinfo_msg[] =
495
0
            {   0x01, 0xa1, 0x5e, 0x00, 0x00, 0x01 };
496
0
            unsigned char timing_msg[] =
497
0
            {   0x01, 0xf1, 0x0e, 0x00, 0x00, 0x01 };
498
0
            unsigned char navsol_lla_msg[] =
499
0
            {   0x01, 0x94, 0x6b, 0x00, 0x00, 0x01 };
500
0
            unsigned char ephemeris_msg[] =
501
0
            {   0x01, 0x96, 0x69, 0x00, 0x00, 0x01 };
502
0
            unsigned char measurement_msg[] =
503
0
            { 0x01, 0x97, 0x68, 0x01, 0x00, 0x01, 0x01 };
504
505
0
            (void)superstar2_write(session, (char *)timing_msg,
506
0
                                   sizeof(timing_msg));
507
0
            (void)superstar2_write(session, (char *)measurement_msg,
508
0
                                   sizeof(measurement_msg));
509
0
            (void)superstar2_write(session, (char *)svinfo_msg,
510
0
                                   sizeof(svinfo_msg));
511
0
            (void)superstar2_write(session, (char *)navsol_lla_msg,
512
0
                                   sizeof(navsol_lla_msg));
513
0
            (void)superstar2_write(session, (char *)version_msg,
514
0
                                   sizeof(version_msg));
515
0
            (void)superstar2_write(session, (char *)ephemeris_msg,
516
0
                                   sizeof(ephemeris_msg));
517
0
            (void)superstar2_write(session, (char *)iono_utc_msg,
518
0
                                   sizeof(iono_utc_msg));
519
0
            session->driver.superstar2.last_iono = time(NULL);
520
0
        }
521
0
    }
522
523
/*
524
 * This is the entry point to the driver. When the packet sniffer recognizes
525
 * a packet for this driver, it calls this method which passes the packet to
526
 * the binary processor or the nmea processor, depending on the session type.
527
 */
528
    static gps_mask_t superstar2_parse_input(struct gps_device_t *session)
529
0
    {
530
0
        if (SUPERSTAR2_PACKET == session->lexer.type) {
531
0
            return superstar2_dispatch(session, session->lexer.outbuffer,
532
0
                                       session->lexer.length);
533
0
        }
534
0
        if (NMEA_PACKET == session->lexer.type) {
535
0
            return nmea_parse((char *)session->lexer.outbuffer, session);
536
0
        }
537
0
        return 0;
538
0
    }
539
540
    static ssize_t superstar2_control_send(struct gps_device_t *session,
541
                                           char *msg, size_t msglen)
542
0
    {
543
0
        session->msgbuf[0] = 0x1;  // SOH
544
0
        session->msgbuf[1] = msg[0];
545
0
        session->msgbuf[2] = msg[0] ^ 0xff;
546
0
        session->msgbuf[3] = (char)(msglen + 1);
547
0
        (void)memcpy(session->msgbuf + 4, msg + 1, msglen - 1);
548
0
        session->msgbuflen = (size_t) (msglen + 5);
549
0
        return superstar2_write(session, session->msgbuf, session->msgbuflen);
550
0
    }
551
552
    static bool superstar2_set_speed(struct gps_device_t *session,
553
                                     speed_t speed, char parity, int stopbits)
554
0
    {
555
        // parity and stopbit switching aren't available on this chip
556
0
        if (parity != session->gpsdata.dev.parity ||
557
0
            stopbits != (int)session->gpsdata.dev.stopbits) {
558
0
            return false;
559
0
        } else {
560
0
            unsigned char speed_msg[] =
561
0
            { 0x01, 0x48, 0xB7, 0x01, 0x00, 0x00, 0x00 };
562
563
            // high bit 0 in the mode word means set NMEA mode
564
0
            speed_msg[4] = (unsigned char)(speed / 300);
565
0
            return (superstar2_write(session, (char *)speed_msg, 7) == 7);
566
0
        }
567
0
    }
568
569
    static void superstar2_set_mode(struct gps_device_t *session, int mode)
570
0
    {
571
0
        if (MODE_NMEA == mode) {
572
0
            unsigned char mode_msg[] =
573
0
            { 0x01, 0x48, 0xB7, 0x01, 0x00, 0x00, 0x00 };
574
575
            // high bit 0 in the mode word means set NMEA mode
576
0
            mode_msg[4] = (unsigned char)(session->gpsdata.dev.baudrate / 300);
577
0
            (void)superstar2_write(session, (char *)mode_msg, 7);
578
0
        }
579
0
    }
580
581
// *INDENT-OFF*
582
const struct gps_type_t driver_superstar2 = {
583
    // Full name of type
584
    .type_name          = "SuperStarII",
585
    // Associated lexer packet type
586
    .packet_type        = SUPERSTAR2_PACKET,
587
    // Driver type flags
588
    .flags               = DRIVER_STICKY,
589
    // Response string that identifies device (not active)
590
    .trigger            = NULL,
591
    // Number of satellite channels supported by the device
592
    .channels           = 12,
593
    // Startup-time device detector
594
    .probe_detect       = NULL,
595
    // Packet getter (using default routine)
596
    .get_packet         = packet_get1,
597
    // Parse message packets
598
    .parse_packet       = superstar2_parse_input,
599
    // RTCM handler (using default routine)
600
    .rtcm_writer        = gpsd_write,
601
    // non-perturbing initial query
602
    .init_query         = NULL,
603
    // Fire on various lifetime events
604
    .event_hook         = superstar2_event_hook,
605
    // Speed (baudrate) switch
606
    .speed_switcher     = superstar2_set_speed,
607
    // Switch to NMEA mode
608
    .mode_switcher      = superstar2_set_mode,
609
    // Message delivery rate switcher (not active)
610
    .rate_switcher      = NULL,
611
    // Minimum cycle time (not used)
612
    .min_cycle.tv_sec  = 1,             // not relevant, no rate switch
613
    .min_cycle.tv_nsec = 0,             // not relevant, no rate switch
614
    // Control string sender - should provide checksum and trailer
615
    .control_send       = superstar2_control_send,
616
    .time_offset     = NULL,            // no method for NTP fudge factor
617
};
618
// *INDENT-ON*
619
#endif  // defined(SUPERSTAR2_ENABLE)
620
621
// vim: set expandtab shiftwidth=4