~ubuntu-branches/debian/stretch/gpsd/stretch

« back to all changes in this revision

Viewing changes to libgpsd_core.c

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2010-07-15 14:46:02 UTC
  • mto: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: james.westby@ubuntu.com-20100715144602-v68en708flyrtgcm
Tags: upstream-2.95
ImportĀ upstreamĀ versionĀ 2.95

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#endif
38
38
#endif
39
39
 
40
 
 
41
40
int gpsd_switch_driver(struct gps_device_t *session, char *type_name)
42
41
{
43
42
    const struct gps_type_t **dp;
254
253
                log = "Too long for 5Hz, too short for 1Hz\n";
255
254
            } else if (1001000 > cycle) {
256
255
                /* looks like PPS pulse or square wave */
257
 
                    if (0 == duration) {
 
256
                if (0 == duration) {
258
257
                    ok = 1;
259
258
                    log = "PPS invisible pulse\n";
260
259
                } else if (499000 > duration) {
295
294
        }
296
295
        /*@ -boolint @*/
297
296
        if (NULL != log) {
298
 
            gpsd_report(LOG_RAW, "%s", log);
 
297
            gpsd_report(LOG_RAW, "%s\n", log);
299
298
        }
300
299
        if (0 != ok) {
301
300
            (void)ntpshm_pps(session, &tv);
317
316
    if (netgnss_uri_check(session->gpsdata.dev.path)) {
318
317
        session->gpsdata.gps_fd = netgnss_uri_open(session->context,
319
318
                                                   session->gpsdata.dev.path);
320
 
        session->sourcetype = source_socket;
 
319
        session->sourcetype = source_tcp;
321
320
        gpsd_report(LOG_SPIN,
322
321
                    "netgnss_uri_open(%s) returns socket on fd %d\n",
323
322
                    session->gpsdata.dev.path, session->gpsdata.gps_fd);
324
 
        /* otherwise, could be an AIS data feed */
325
 
    } else if (strncmp(session->gpsdata.dev.path, "ais://", 6) == 0) {
 
323
        /* otherwise, could be an TCP data feed */
 
324
    } else if (strncmp(session->gpsdata.dev.path, "tcp://", 6) == 0) {
326
325
        char server[GPS_PATH_MAX], *port;
327
326
        socket_t dsock;
328
327
        (void)strlcpy(server, session->gpsdata.dev.path + 6, sizeof(server));
329
328
        session->gpsdata.gps_fd = -1;
330
329
        port = strchr(server, ':');
331
330
        if (port == NULL) {
332
 
            gpsd_report(LOG_ERROR, "Missing colon in AIS feed spec.\n");
 
331
            gpsd_report(LOG_ERROR, "Missing colon in TCP feed spec.\n");
333
332
            return -1;
334
333
        }
335
334
        *port++ = '\0';
336
 
        gpsd_report(LOG_INF, "opening AIS feed at %s, port %s.\n", server,
 
335
        gpsd_report(LOG_INF, "opening TCP feed at %s, port %s.\n", server,
337
336
                    port);
338
337
        if ((dsock = netlib_connectsock(AF_UNSPEC, server, port, "tcp")) < 0) {
339
 
            gpsd_report(LOG_ERROR, "AIS device open error %s.\n",
340
 
                        netlib_errstr(dsock));
341
 
            return -1;
342
 
        }
343
 
        session->gpsdata.gps_fd = dsock;
 
338
            gpsd_report(LOG_ERROR, "TCP device open error %s.\n",
 
339
                        netlib_errstr(dsock));
 
340
            return -1;
 
341
        }
 
342
        session->gpsdata.gps_fd = dsock;
 
343
        session->sourcetype = source_tcp;
 
344
    } else if (strncmp(session->gpsdata.dev.path, "udp://", 6) == 0) {
 
345
        char server[GPS_PATH_MAX], *port;
 
346
        socket_t dsock;
 
347
        (void)strlcpy(server, session->gpsdata.dev.path + 6, sizeof(server));
 
348
        session->gpsdata.gps_fd = -1;
 
349
        port = strchr(server, ':');
 
350
        if (port == NULL) {
 
351
            gpsd_report(LOG_ERROR, "Missing colon in UDP feed spec.\n");
 
352
            return -1;
 
353
        }
 
354
        *port++ = '\0';
 
355
        gpsd_report(LOG_INF, "opening UDP feed at %s, port %s.\n", server,
 
356
                    port);
 
357
        if ((dsock = netlib_connectsock(AF_UNSPEC, server, port, "udp")) < 0) {
 
358
            gpsd_report(LOG_ERROR, "UDP device open error %s.\n",
 
359
                        netlib_errstr(dsock));
 
360
            return -1;
 
361
        }
 
362
        session->gpsdata.gps_fd = dsock;
 
363
        session->sourcetype = source_udp;
344
364
    }
345
365
    /* otherwise, ordinary serial device */
346
366
    else
383
403
        session->gpsdata.separation = NAN;
384
404
        session->mag_var = NAN;
385
405
        session->releasetime = 0;
 
406
        session->getcount = 0;
386
407
 
387
408
        /* clear the private data union */
388
409
        memset(&session->driver, '\0', sizeof(session->driver));
451
472
}
452
473
 
453
474
static void gpsd_error_model(struct gps_device_t *session,
454
 
                      struct gps_fix_t *fix, struct gps_fix_t *oldfix)
 
475
                             struct gps_fix_t *fix, struct gps_fix_t *oldfix)
455
476
/* compute errors and derived quantities */
456
477
{
457
478
    /*
486
507
        (session->gpsdata.status ==
487
508
         STATUS_DGPS_FIX ? P_UERE_WITH_DGPS : P_UERE_NO_DGPS);
488
509
 
489
 
 
490
510
    /*
491
 
     * OK, this is not an error computation, but
492
 
     * we're at the right place in the architrcture for it.
493
 
     * Compute climb/sink in the simplest possible way.
494
 
     * FIXME: Someday we should compute speed here too.
 
511
     * OK, this is not an error computation, but we're at the right
 
512
     * place in the architecture for it.  Compute speed over ground
 
513
     * and climb/sink in the simplest possible way.
495
514
     */
 
515
    if (fix->mode >= MODE_2D && oldfix->mode >= MODE_2D
 
516
        && isnan(fix->speed) != 0) {
 
517
        if (fix->time == oldfix->time)
 
518
            fix->speed = 0;
 
519
        else
 
520
            fix->speed =
 
521
                earth_distance(fix->latitude, fix->longitude,
 
522
                               oldfix->latitude, oldfix->longitude)
 
523
                / (fix->time - oldfix->time);
 
524
    }
496
525
    if (fix->mode >= MODE_3D && oldfix->mode >= MODE_3D
497
526
        && isnan(fix->climb) != 0) {
498
527
        if (fix->time == oldfix->time)
627
656
        gpsd_report(LOG_RAW,
628
657
                    "packet sniff on %s finds type %d\n",
629
658
                    session->gpsdata.dev.path, session->packet.type);
630
 
        if (session->packet.type > COMMENT_PACKET) {
 
659
        if (session->packet.type == COMMENT_PACKET) {
 
660
            gpsd_report (LOG_PROG, "comment, sync lock deferred\n");
 
661
        } else if (session->packet.type > COMMENT_PACKET) {
631
662
            first_sync = (session->device_type == NULL);
632
663
            for (dp = gpsd_drivers; *dp; dp++)
633
664
                if (session->packet.type == (*dp)->packet_type) {
634
665
                    (void)gpsd_switch_driver(session, (*dp)->type_name);
635
666
                    break;
636
667
                }
637
 
        } else if (!gpsd_next_hunt_setting(session))
 
668
        } else if (session->getcount++ > 1 && !gpsd_next_hunt_setting(session))
638
669
            return ERROR_IS;
639
670
    }
640
671
 
641
672
    /* update the scoreboard structure from the GPS */
642
673
    gpsd_report(LOG_RAW + 2, "%s sent %zd new characters\n",
643
674
                session->gpsdata.dev.path, newlen);
644
 
    if (newlen <= 0) {          /* read error or EOF */
 
675
    if (newlen < 0) {           /* read error */
 
676
        gpsd_report(LOG_INF, "GPS on %s returned error %zd (%lf sec since data)\n",
 
677
                    session->gpsdata.dev.path, newlen,
 
678
                    timestamp() - session->gpsdata.online);
 
679
        session->gpsdata.online = 0;
 
680
        return ERROR_IS;
 
681
    } else if (newlen == 0) {           /* zero length read, possible EOF */
645
682
        gpsd_report(LOG_INF, "GPS on %s is offline (%lf sec since data)\n",
646
683
                    session->gpsdata.dev.path,
647
684
                    timestamp() - session->gpsdata.online);
648
685
        session->gpsdata.online = 0;
649
 
        return 0;
 
686
        return NODATA_IS;
650
687
    } else if (session->packet.outbuflen == 0) {        /* got new data, but no packet */
651
688
        gpsd_report(LOG_RAW + 3, "New data on %s, not yet a packet\n",
652
689
                    session->gpsdata.dev.path);
687
724
 
688
725
        /*
689
726
         * If this is the first time we've achieved sync on this
690
 
         * device, or the the driver type has changed for any other
 
727
         * device, or the driver type has changed for any other
691
728
         * reason, that's a significant event that the caller needs to
692
 
         * know about.  Using DEVICE_IS this way is a bit shaky but
693
 
         * we're short of bits in the flag mask (client library uses
694
 
         * it differently).
 
729
         * know about.
695
730
         */
696
731
        if (first_sync || session->notify_clients) {
697
732
            session->notify_clients = false;
698
 
            received |= DEVICE_IS;
 
733
            received |= DRIVER_IS;
699
734
        }
700
735
 
701
736
        /* Get data from current packet into the fix structure */
811
846
    (void)memset(out->azimuth, 0, sizeof(out->azimuth));
812
847
    (void)memset(out->ss, 0, sizeof(out->ss));
813
848
    out->satellites_visible = 0;
 
849
    clear_dop(&out->dop);
814
850
}