summaryrefslogtreecommitdiff
path: root/driver_geostar.c
blob: 60d80eb4094789bff192ff0b05a3647cc36119d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/*
 * This is the gpsd driver for GeoStar Navigation receivers
 * operating in binary mode.
 *
 * Tested with GeoS-1M GPS/GLONASS receiver.
 *
 * By Viktar Palstsiuk, viktar.palstsiuk@promwad.com
 *
 * This file is Copyright (c) 2010 by the GPSD project
 * BSD terms apply: see the file COPYING in the distribution root for details.
 */

#include <sys/time.h>		/* for select() */
#include <stdbool.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

#include "gpsd.h"
#include "bits.h"
#include "strfuncs.h"

#include <sys/select.h>

#ifdef GEOSTAR_ENABLE
#define GEOSTAR_CHANNELS	24

#define JAN_2008		0x47798280 /* 1199145600 = 2008 - 1970 in seconds */

#define OFFSET(n)		((n)*4+4)

static int decode_channel_id (uint32_t ch_id) {
	int num = 0;
	num = (int)(ch_id & 0x1F);				/* SV ID */
	if((ch_id & (1<<30)) == 0) num += GLONASS_PRN_OFFSET;	/* GLONASS SV */
	else if (num == 0 ) num = 32;				/* GPS SV */
	return num;
}

static int geostar_write(struct gps_device_t *session,
			 unsigned int id, unsigned char *data, size_t len)
{
    int i;
    unsigned long cs = 0;

    putbyte(session->msgbuf, 0, 'P');
    putbyte(session->msgbuf, 1, 'S');
    putbyte(session->msgbuf, 2, 'G');
    putbyte(session->msgbuf, 3, 'G');

    putbe16(session->msgbuf, 4, id);
    putbe16(session->msgbuf, 6, len);

    /* Copy content */
    memcpy(session->msgbuf + 8, data, len * 4);

    len += 2; /* PSGG + id + len */

    /* Calculate checksum */
    for (i = 0; (size_t)i < len; i++) {
	cs ^= getleu32(session->msgbuf, i * 4);
    }

    putle32(session->msgbuf, len * 4, cs);

    len += 1; /* Checksum */

    session->msgbuflen = len * 4;

    gpsd_log(&session->context->errout, LOG_PROG,
	     "Sent GeoStar packet id 0x%x\n", id);
    if (gpsd_write(session, session->msgbuf, session->msgbuflen) !=
	(ssize_t) session->msgbuflen)
	return -1;

    return 0;
}

/* geostar_detect()
 *
 * see if it looks like a GeoStar device is listening and
 * return 1 if found, 0 if not
 */
static bool geostar_detect(struct gps_device_t *session)
{
    unsigned char buf[1 * 4];
    bool ret = false;
    int myfd;
    fd_set fdset;
    struct timeval to;

    myfd = session->gpsdata.gps_fd;

    /* request firmware revision and look for a valid response */
    putbe32(buf, 0, 0);
    if (geostar_write(session, 0xc1, buf, 1) == 0) {
	unsigned int n;
	for (n = 0; n < 3; n++) {
	    FD_ZERO(&fdset);
	    FD_SET(myfd, &fdset);
	    to.tv_sec = 1;
	    to.tv_usec = 0;
	    if (select(myfd + 1, &fdset, NULL, NULL, &to) != 1)
		break;
	    if (generic_get(session) >= 0) {
		if (session->lexer.type == GEOSTAR_PACKET) {
		    gpsd_log(&session->context->errout, LOG_RAW,
			     "geostar_detect found\n");
		    ret = true;
		    break;
		}
	    }
	}
    }

    return ret;
}

static gps_mask_t geostar_analyze(struct gps_device_t *session)
{
    int i, len;
    gps_mask_t mask = 0;
    unsigned int id;
    uint16_t uw1, uw2;
    uint32_t ul1, ul2, ul3, ul4, ul5;
    double d1, d2, d3, d4, d5;
    char buf[BUFSIZ];
    char buf2[BUFSIZ];

    if (session->lexer.type != GEOSTAR_PACKET) {
	gpsd_log(&session->context->errout, LOG_INF,
		 "geostar_analyze packet type %d\n",
		 session->lexer.type);
	return 0;
    }

    if (session->lexer.outbuflen < 12 || session->lexer.outbuffer[0] != 'P')
	return 0;

    /* put data part of message in buf */

    memset(buf, 0, sizeof(buf));
    /* cppcheck-suppress redundantCopy */
    memcpy(buf, session->lexer.outbuffer, session->lexer.outbuflen);

    buf2[len = 0] = '\0';
    for (i = 0; i < (int)session->lexer.outbuflen; i++) {
	str_appendf(buf2, sizeof(buf2),
		       "%02x", buf[len++] = session->lexer.outbuffer[i]);
    }

    id = (unsigned int)getleu16(session->lexer.outbuffer, OFFSET(0));

    gpsd_log(&session->context->errout, LOG_DATA,
	     "GeoStar packet id 0x%02x length %d: %s\n", id, len, buf2);

    session->cycle_end_reliable = true;

    switch (id) {
    case 0x10:
	gpsd_log(&session->context->errout, LOG_INF, "Raw measurements\n");
	break;
    case 0x11:
	gpsd_log(&session->context->errout, LOG_INF, "GPS sub-frame data\n");
	break;
    case 0x12:
	gpsd_log(&session->context->errout, LOG_INF, "GLONASS sub-frame data\n");
	break;
    case 0x13:
	d1 = getled64(buf, OFFSET(1));
	d2 = getled64(buf, OFFSET(3));
	d3 = getled64(buf, OFFSET(5));
	d4 = getled64(buf, OFFSET(29)); /* GPS time */
	d5 = getled64(buf, OFFSET(31)); /* GLONASS time */
	gpsd_log(&session->context->errout, LOG_INF,
		 "ECEF coordinates %g %g %g %f %f\n", d1, d2, d3, d4, d5);
	break;
    case 0x20:
	d1 = getled64(buf, OFFSET(1)); /* time */

	session->newdata.time = d1 + JAN_2008;
	session->newdata.latitude = getled64(buf, OFFSET(3)) * RAD_2_DEG;
	session->newdata.longitude = getled64(buf, OFFSET(5)) * RAD_2_DEG;
	session->newdata.altitude = getled64(buf, OFFSET(7));
	session->gpsdata.separation = getled64(buf, OFFSET(9));
	session->gpsdata.satellites_used = (int)getles32(buf, OFFSET(11));
	session->gpsdata.dop.gdop = getled64(buf, OFFSET(13));
	session->gpsdata.dop.pdop = getled64(buf, OFFSET(15));
	session->gpsdata.dop.tdop = getled64(buf, OFFSET(17));
	session->gpsdata.dop.hdop = getled64(buf, OFFSET(19));
	session->gpsdata.dop.vdop = getled64(buf, OFFSET(21));
	session->newdata.speed = getled64(buf, OFFSET(31));
	session->newdata.track = getled64(buf, OFFSET(33)) * RAD_2_DEG;

	ul1 = getleu32(buf, OFFSET(29)); /* status */

	if (ul1 != 0) {
	    session->gpsdata.status = STATUS_NO_FIX;
	    mask |= STATUS_SET;
	} else {
	    if (session->gpsdata.status < STATUS_FIX) {
		session->gpsdata.status = STATUS_FIX;
		mask |= STATUS_SET;
	    }
	}
	mask |= TIME_SET | PPSTIME_IS | LATLON_SET | ALTITUDE_SET | SPEED_SET | TRACK_SET | DOP_SET | USED_IS | REPORT_IS;

	gpsd_log(&session->context->errout, LOG_INF,
		 "Geographic coordinates %f %g %g %g %g %g\n",
		 d1,
		 session->newdata.latitude,
		 session->newdata.longitude,
		 session->newdata.altitude,
		 session->newdata.speed,
		 session->newdata.track);
	gpsd_log(&session->context->errout, LOG_INF,
		 "Dilution of precision %g %g %g %g %g\n",
		 session->gpsdata.dop.gdop,
		 session->gpsdata.dop.pdop,
		 session->gpsdata.dop.tdop,
		 session->gpsdata.dop.hdop,
		 session->gpsdata.dop.vdop);
	break;
    case 0x21:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	uw1 = getleu16(buf, OFFSET(3));
	uw2 = getleu16(buf, OFFSET(3) + 2);
	gpsd_log(&session->context->errout, LOG_INF,
		 "Current receiver telemetry %x %d %d %d\n",
		 ul1, ul2, uw1, uw2);
	if(ul1 & (1<<3)) {
	    session->newdata.mode = MODE_2D;
	}
	else {
	    session->newdata.mode = MODE_3D;
	}
	if(ul1 & (1<<2)) {
	    session->gpsdata.status = STATUS_FIX;
	}
	else {
	    session->gpsdata.status = STATUS_NO_FIX;
	    session->newdata.mode = MODE_NO_FIX;
	}

	mask |= MODE_SET | STATUS_SET;
	break;
    case 0x22:
	ul1 = getleu32(buf, OFFSET(1));
	gpsd_log(&session->context->errout, LOG_INF, "SVs in view %d\n", ul1);
	session->gpsdata.satellites_visible = (int)ul1;
	if(ul1 > GEOSTAR_CHANNELS) ul1 = GEOSTAR_CHANNELS;
	for(i = 0; (uint32_t)i < ul1; i++) {
	    int16_t s1, s2, s3;
	    ul2 = getleu32(buf, OFFSET(2) + i * 3 * 4);
	    s1 = getles16(buf, OFFSET(3) + i * 3 * 4);
	    s2 = getles16(buf, OFFSET(3) + 2 + i * 3 * 4);
	    s3 = getles16(buf, OFFSET(4) + 2 + i * 3 * 4);
	    gpsd_log(&session->context->errout, LOG_INF, "ID %d Az %g El %g SNR %g\n",
		     decode_channel_id(ul2), s1*0.001*RAD_2_DEG, s2*0.001*RAD_2_DEG, s3*0.1);
	    session->gpsdata.skyview[i].PRN = (short)decode_channel_id(ul2);
	    session->gpsdata.skyview[i].azimuth = (short)round((double)s1*0.001 * RAD_2_DEG);
	    session->gpsdata.skyview[i].elevation = (short)round((double)s2*0.001 * RAD_2_DEG);
	    session->gpsdata.skyview[i].ss = (double)s3*0.1;
	    session->gpsdata.skyview[i].used = (bool)(ul2 & (1<<27));
	}
	session->gpsdata.skyview_time = NAN;
	mask |= SATELLITE_SET | USED_IS;
	break;
    case 0x3e:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	ul3 = getleu32(buf, OFFSET(3));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Receiver power-up message %d %d %d\n", ul1, ul2, ul3);
	break;
    case 0x3f:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	gpsd_log(&session->context->errout, LOG_WARN,
		 "Negative acknowledge %x %d\n", ul1, ul2);
	break;
    case 0x40:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set initial parameters\n");
	break;
    case 0x41:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set serial ports parameters\n");
	break;
    case 0x42:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	ul3 = getleu32(buf, OFFSET(3));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set receiver operation mode %d %d %d\n",
		 ul1, ul2, ul3);
	break;
    case 0x43:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set navigation task solution parameters\n");
	break;
    case 0x44:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set output data rate\n");
	break;
    case 0x46:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Assign data protocol to communication port\n");
	break;
    case 0x48:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set GPS almanac\n");
	break;
    case 0x49:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set GLONASS almanac\n");
	break;
    case 0x4a:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set GPS ephemeris\n");
	break;
    case 0x4b:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set GLONASS ephemeris\n");
	break;
    case 0x4c:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	ul3 = getleu32(buf, OFFSET(3));
	ul4 = getleu32(buf, OFFSET(4));
	ul5 = getleu32(buf, OFFSET(5));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Set PPS parameters %d %d %d %d %d\n",
		 ul1, ul2, ul3, ul4, ul5);
	break;
    case 0x4d:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Enable/disable SV in position fix\n");
	break;
    case 0x4e:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Enable/disable NMEA messages\n");
	break;
    case 0x4f:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Enable/disable binary messages %x %x\n",
		 ul1, ul2);
	break;
    case 0x80:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query initial parameters\n");
	break;
    case 0x81:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query serial ports parameters\n");
	break;
    case 0x82:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	ul3 = getleu32(buf, OFFSET(3));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query receiver operation mode %d %d %d\n",
		 ul1, ul2, ul3);
	break;
    case 0x83:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query navigation task solution parameters\n");
	break;
    case 0x84:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query output data rate\n");
	break;
    case 0x86:
	session->driver.geostar.physical_port = (unsigned int)getleu32(buf, OFFSET(1));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query data protocol assignment to communication port\n");
	gpsd_log(&session->context->errout, LOG_INF,
		 "Connected to physical port %d\n",
		 session->driver.geostar.physical_port);
	break;
    case 0x88:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query GPS almanac\n");
	break;
    case 0x89:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query GLONASS almanac\n");
	break;
    case 0x8a:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query GPS ephemerides\n");
	break;
    case 0x8b:
	d1 = getled64(buf, OFFSET(23));
	d2 = getled64(buf, OFFSET(25));
	d3 = getled64(buf, OFFSET(27));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query GLONASS ephemerides %g %g %g\n",
		 d1, d2, d3);
	break;
    case 0x8c:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	ul3 = getleu32(buf, OFFSET(3));
	ul4 = getleu32(buf, OFFSET(4));
	ul5 = getleu32(buf, OFFSET(5));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query PPS parameters %d %d %d %d %d\n",
		 ul1, ul2, ul3, ul4, ul5);
	break;
    case 0x8d:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query enable/disable status of the SV in position fix\n");
	break;
    case 0x8e:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query enable NMEA messages\n");
	break;
    case 0x8f:
	ul1 = getleu32(buf, OFFSET(1));
	ul2 = getleu32(buf, OFFSET(2));
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Query enable binary messages %x %x\n",
		 ul1, ul2);
	break;
    case 0xc0:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Change operation mode command\n");
	break;
    case 0xc1:
	ul4 = getleu32(buf, OFFSET(1));
	ul1 = getleu32(buf, OFFSET(2));
	ul2 = getleu32(buf, OFFSET(3));
	ul3 = getleu32(buf, OFFSET(4));
	(void)snprintf(session->subtype, sizeof(session->subtype), "%d.%d %d.%d.%d %x %c-%d\n",
		ul4>>16, ul4&0xFFFF, ul1>>9, (ul1>>5)&0xF, ul1&0x1F, ul2, ul3>>24, ul3&0x00FFFFFF);
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Request FW version command: %s\n",
		 session->subtype);
	mask |= DEVICEID_SET;
	break;
    case 0xc2:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Restart receiver command\n");
	break;
    case 0xc3:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Store parameters to Flash command\n");
	break;
    case 0xd0:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Erase Flash sector command\n");
	break;
    case 0xd1:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Write data to Flash command\n");
	break;
    case 0xd2:
	gpsd_log(&session->context->errout, LOG_INF,
		 "Response to Store Serial Number command\n");
	break;
    default:
	gpsd_log(&session->context->errout, LOG_WARN,
		 "Unhandled GeoStar packet type 0x%02x\n", id);
	break;
    }

    return mask;
}

static gps_mask_t geostar_parse_input(struct gps_device_t *session)
{
    if (session->lexer.type == GEOSTAR_PACKET) {
	return geostar_analyze(session);;
    } else
	return 0;
}

#ifdef CONTROLSEND_ENABLE
static ssize_t geostar_control_send(struct gps_device_t *session,
				 char *buf, size_t buflen)
/* not used by the daemon, it's for gpsctl and friends */
{
    return (ssize_t) geostar_write(session,
				(unsigned int)buf[0],
				(unsigned char *)buf + 1, (buflen - 1)/4);
}
#endif /* CONTROLSEND_ENABLE */


static void geostar_init_query(struct gps_device_t *session)
{
    unsigned char buf[2 * 4];
    /* Poll Software Version */
    (void)geostar_write(session, 0xc1, buf, 1);
}

static void geostar_event_hook(struct gps_device_t *session, event_t event)
{
    unsigned char buf[2 * 4];

    if (session->context->readonly)
	return;

    if (event == event_identified || event == event_reactivate) {
	/* Select binary packets */
	putbe32(buf, 0, 0xffff0000);
	putbe32(buf, 4, 0);
	(void)geostar_write(session, 0x4f, buf, 2);

	/* Poll Ports params */
	putbe32(buf, 0, 1);
	(void)geostar_write(session, 0x81, buf, 1);
	putbe32(buf, 0, 0);
	(void)geostar_write(session, 0x81, buf, 1);
	/* Poll Init params */
	(void)geostar_write(session, 0x80, buf, 1);
	/* Poll Mode */
	(void)geostar_write(session, 0x82, buf, 1);
	/* Poll Solution params */
	(void)geostar_write(session, 0x83, buf, 1);
	/* Poll Output rate */
	(void)geostar_write(session, 0x84, buf, 1);
	/* Poll Protocols assignment */
	(void)geostar_write(session, 0x86, buf, 1);
	/* Poll PPS params */
	(void)geostar_write(session, 0x8c, buf, 1);
	/* Poll NMEA packets selected */
	(void)geostar_write(session, 0x8e, buf, 1);
	/* Poll binary packets selected */
	(void)geostar_write(session, 0x8f, buf, 1);
    }

    if (event == event_deactivate) {
	/* Perform cold restart */
	putbe32(buf, 0, 3);
	(void)geostar_write(session, 0xc2, buf, 1);
    }
}

#ifdef RECONFIGURE_ENABLE
static bool geostar_speed_switch(struct gps_device_t *session,
			      speed_t speed, char parity, int stopbits)
{
    unsigned char buf[4 * 4];

    switch (parity) {
    case 'E':
    case 2:
	parity = (char)2;
	break;
    case 'O':
    case 1:
	parity = (char)1;
	break;
    case 'N':
    case 0:
    default:
	parity = (char)0;
	break;
    }

    putbe32(buf, 0, session->driver.geostar.physical_port);
    putbe32(buf, 4, speed);
    putbe32(buf, 8, stopbits);
    putbe32(buf, 12, parity);
    (void)geostar_write(session, 0x41, buf, 4);

    return true;	/* it would be nice to error-check this */
}

static void geostar_mode(struct gps_device_t *session, int mode)
{
    if (mode == MODE_NMEA) {
	unsigned char buf[1 * 4];
	/* Switch to NMEA mode */
	putbe32(buf, 0, 1);
	(void)geostar_write(session, 0x46, buf, 1);
    } else if (mode == MODE_BINARY) {
	/* Switch to binary mode */
	(void)nmea_send(session, "$GPSGG,SWPROT");
    } else {
	gpsd_log(&session->context->errout, LOG_ERROR,
		 "unknown mode %i requested\n", mode);
    }
}
#endif /* RECONFIGURE_ENABLE */

#ifdef TIMEHINT_ENABLE
static double geostar_time_offset(struct gps_device_t *session UNUSED)
{
    return 0.31;
}
#endif /* TIMEHINT_ENABLE */

/* this is everything we export */
/* *INDENT-OFF* */
const struct gps_type_t driver_geostar =
{
    .type_name      = "GeoStar",	/* full name of type */
    .packet_type    = GEOSTAR_PACKET,	/* associated lexer packet type */
    .flags	    = DRIVER_STICKY,	/* remember this */
    .trigger	    = NULL,		/* no trigger */
    .channels       = GEOSTAR_CHANNELS,	/* consumer-grade GPS/GLONASS */
    .probe_detect   = geostar_detect,	/* probe for device */
    .get_packet     = generic_get,	/* use the generic packet getter */
    .parse_packet   = geostar_parse_input,	/* parse message packets */
    .rtcm_writer    = NULL,		/* doesn't accept DGPS corrections */
    .init_query     = geostar_init_query,	/* non-perturbing initial query */
    .event_hook     = geostar_event_hook,	/* fire on various lifetime events */
#ifdef RECONFIGURE_ENABLE
    .speed_switcher = geostar_speed_switch,/* change baud rate */
    .mode_switcher  = geostar_mode,	/* there is a mode switcher */
    .rate_switcher  = NULL,		/* no rate switcher */
    .min_cycle      = 1,		/* not relevant, no rate switcher */
#endif /* RECONFIGURE_ENABLE */
#ifdef CONTROLSEND_ENABLE
    .control_send   = geostar_control_send,/* how to send commands */
#endif /* CONTROLSEND_ENABLE */
#ifdef TIMEHINT_ENABLE
    .time_offset     = geostar_time_offset,
#endif /* TIMEHINT_ENABLE */
};
/* *INDENT-ON* */

#endif /* GEOSTAR_ENABLE */