Lines Matching +full:up +full:-

2  * refclock_gpsdjson.c - clock driver as GPSD JSON client
15 * - There is no GPSD for Windows. (There is an unofficial port to
18 * - To work properly, this driver needs PPS and TPV/TOFF sentences
22 * - The device name matching must be done in a different way for
26 * Windows, there's no reason why this should not work there ;-) If this
29 * ---------------------------------------------------------------------
51 * ---------------------------------------------------------------------
98 #define INVALID_TOKEN (-1)
166 * information is gleaned from this record -- it contains the local
192 #define PRECISION (-9) /* precision assumed (about 2 ms) */
193 #define PPS_PRECISION (-20) /* precision assumed (about 1 us) */
197 #define MAX_PDU_LEN 8192 /* multi-GNSS reports can be HUGE */
206 * PPS-augmented samples are fed to the core; when the account drops to
207 * zero we switch to a mode where TPV-only timestamps are fed to the
210 * PPS-augmented time stamps.
268 gpsd_start, /* start up driver */
346 u_int tc_sti_used;/* used --^-- */
348 u_int tc_pps_used;/* used --^-- */
372 static int syslogok(clockprocT * const pp, gpsd_unitT * const up);
385 * fallback alias of it, and we try to connect to them in round-robin
392 * started -- otherwise there might be syslog entries from a driver that
418 gpsd_unitT * const up) in syslogok() argument
420 int res = (0 != (pp->sloppyclockflag & CLK_FLAG3)) in syslogok()
421 || (0 == up->logthrottle ) in syslogok()
422 || (LOGTHROTTLE == up->logthrottle ); in syslogok()
424 up->logthrottle = LOGTHROTTLE; in syslogok()
432 /* ---------------------------------------------------------------------
458 /* ---------------------------------------------------------------------
481 "GPSD_JSON: failed to get socket address, giving up."); in gpsd_init_check()
495 /* ---------------------------------------------------------------------
496 * Start: allocate a unit pointer and set up the runtime data
503 clockprocT * const pp = peer->procptr; in gpsd_start()
504 gpsd_unitT * up; in gpsd_start() local
516 while ((up = *uscan) != NULL && up->unit != (unit & 0x7F)) in gpsd_start()
517 uscan = &up->next_unit; in gpsd_start()
518 if (up == NULL) { in gpsd_start()
520 up = emalloc_zero(sizeof(*up)); in gpsd_start()
521 *uscan = up; in gpsd_start()
522 ++up->refcount; in gpsd_start()
525 up->logname = estrdup(refnumtoa(&peer->srcadr)); in gpsd_start()
526 up->unit = unit & 0x7F; in gpsd_start()
527 up->fdt = -1; in gpsd_start()
528 up->addr = s_gpsd_addr; in gpsd_start()
529 up->tickpres = TICKOVER_LOW; in gpsd_start()
537 tmpName = clockdev_lookup(&peer->srcadr, 0); in gpsd_start()
539 up->device = estrdup(tmpName); in gpsd_start()
540 } else if (-1 == myasprintf(&up->device, "%s%u", s_dev_stem, up->unit)) { in gpsd_start()
542 up->logname); in gpsd_start()
545 devname = up->device; in gpsd_start()
546 up->device = ntp_realpath(devname); in gpsd_start()
547 if (NULL == up->device) { in gpsd_start()
549 up->logname, devname); in gpsd_start()
554 if (-1 == lstat(up->device, &sb)) { in gpsd_start()
556 up->logname, up->device); in gpsd_start()
561 up->logname, up->device); in gpsd_start()
565 /* All set up, just increment use count. */ in gpsd_start()
566 ++up->refcount; in gpsd_start()
570 pp->unitptr = (caddr_t)up; in gpsd_start()
571 pp->io.fd = -1; in gpsd_start()
572 pp->io.clock_recv = gpsd_receive; in gpsd_start()
573 pp->io.srcclock = peer; in gpsd_start()
574 pp->io.datalen = 0; in gpsd_start()
575 pp->a_lastcode[0] = '\0'; in gpsd_start()
576 pp->lencode = 0; in gpsd_start()
577 pp->clockdesc = DESCRIPTION; in gpsd_start()
578 memcpy(&pp->refid, REFID, 4); in gpsd_start()
582 peer->precision = PPS_PRECISION; in gpsd_start()
584 peer->precision = PRECISION; in gpsd_start()
586 /* If the daemon name lookup failed, just give up now. */ in gpsd_start()
587 if (NULL == up->addr) { in gpsd_start()
588 msyslog(LOG_ERR, "%s: no GPSD socket address, giving up", in gpsd_start()
589 up->logname); in gpsd_start()
595 refnumtoa(&peer->srcadr), up->device)); in gpsd_start()
596 up->mode = MODE_OP_MODE(peer->ttl); in gpsd_start()
597 if (up->mode > MODE_OP_MAXVAL) in gpsd_start()
598 up->mode = 0; in gpsd_start()
600 up->pps_peer = peer; in gpsd_start()
602 enter_opmode(peer, up->mode); in gpsd_start()
608 INSIST (up); in gpsd_start()
609 if (!--up->refcount) { in gpsd_start()
610 *uscan = up->next_unit; in gpsd_start()
611 free(up->device); in gpsd_start()
612 free(up); in gpsd_start()
615 pp->unitptr = (caddr_t)NULL; in gpsd_start()
619 /* ------------------------------------------------------------------ */
626 clockprocT * const pp = peer->procptr; in gpsd_shutdown()
627 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_shutdown() local
633 if (up == NULL) in gpsd_shutdown()
637 if (peer != up->pps_peer) { in gpsd_shutdown()
638 if (-1 != pp->io.fd) { in gpsd_shutdown()
640 up->logname, pp->io.fd)); in gpsd_shutdown()
641 io_closeclock(&pp->io); in gpsd_shutdown()
642 pp->io.fd = -1; in gpsd_shutdown()
644 if (up->fdt != -1) in gpsd_shutdown()
645 close(up->fdt); in gpsd_shutdown()
648 if (!--up->refcount) { in gpsd_shutdown()
651 if (*uscan == up) in gpsd_shutdown()
652 *uscan = up->next_unit; in gpsd_shutdown()
654 uscan = &(*uscan)->next_unit; in gpsd_shutdown()
655 free(up->logname); in gpsd_shutdown()
656 free(up->device); in gpsd_shutdown()
657 free(up); in gpsd_shutdown()
659 pp->unitptr = (caddr_t)NULL; in gpsd_shutdown()
661 (LOG_NOTICE, "%s: shutdown", refnumtoa(&peer->srcadr))); in gpsd_shutdown()
664 /* ------------------------------------------------------------------ */
671 peerT * const peer = rbufp->recv_peer; in gpsd_receive()
672 clockprocT * const pp = peer->procptr; in gpsd_receive()
673 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_receive() local
679 log_data(peer, 3, "recv", (const char*)rbufp->recv_buffer, in gpsd_receive()
680 (size_t)rbufp->recv_length); in gpsd_receive()
690 psrc = (const char*)rbufp->recv_buffer; in gpsd_receive()
691 esrc = psrc + rbufp->recv_length; in gpsd_receive()
693 pdst = up->buffer + up->buflen; in gpsd_receive()
694 edst = up->buffer + sizeof(up->buffer) - 1; /* for trailing NUL */ in gpsd_receive()
700 while (pdst != up->buffer && pdst[-1] <= ' ') in gpsd_receive()
701 --pdst; in gpsd_receive()
704 up->buflen = pdst - up->buffer; in gpsd_receive()
705 gpsd_parse(peer, &rbufp->recv_time); in gpsd_receive()
706 pdst = up->buffer; in gpsd_receive()
709 if (ch > ' ' || pdst != up->buffer) in gpsd_receive()
713 up->buflen = pdst - up->buffer; in gpsd_receive()
714 up->tickover = TICKOVER_LOW; in gpsd_receive()
717 /* ------------------------------------------------------------------ */
723 gpsd_unitT * const up ) in poll_primary() argument
725 if (pp->coderecv != pp->codeproc) { in poll_primary()
727 pp->lastref = pp->lastrec; in poll_primary()
736 peer->precision = PRECISION; in poll_primary()
737 if (-1 == pp->io.fd) in poll_primary()
739 else if (0 != up->tc_breply) in poll_primary()
745 if (pp->sloppyclockflag & CLK_FLAG4) in poll_primary()
747 &peer->srcadr,"%u %u %u %u %u %u %u", in poll_primary()
748 up->tc_recv, in poll_primary()
749 up->tc_breply, up->tc_nosync, in poll_primary()
750 up->tc_sti_recv, up->tc_sti_used, in poll_primary()
751 up->tc_pps_recv, up->tc_pps_used); in poll_primary()
754 up->tc_breply = 0; in poll_primary()
755 up->tc_recv = 0; in poll_primary()
756 up->tc_nosync = 0; in poll_primary()
757 up->tc_sti_recv = 0; in poll_primary()
758 up->tc_sti_used = 0; in poll_primary()
759 up->tc_pps_recv = 0; in poll_primary()
760 up->tc_pps_used = 0; in poll_primary()
767 gpsd_unitT * const up ) in poll_secondary() argument
769 if (pp->coderecv != pp->codeproc) { in poll_secondary()
771 pp->lastref = pp->lastrec; in poll_secondary()
775 peer->precision = PPS_PRECISION; in poll_secondary()
776 peer->flags &= ~FLAG_PPS; in poll_secondary()
786 clockprocT * const pp = peer->procptr; in gpsd_poll()
787 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_poll() local
789 ++pp->polls; in gpsd_poll()
790 if (peer == up->pps_peer) in gpsd_poll()
791 poll_secondary(peer, pp, up); in gpsd_poll()
793 poll_primary(peer, pp, up); in gpsd_poll()
796 /* ------------------------------------------------------------------ */
805 clockprocT * const pp = peer->procptr; in gpsd_control()
806 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_control() local
808 if (peer == up->pps_peer) { in gpsd_control()
809 DTOLFP(pp->fudgetime1, &up->pps_fudge2); in gpsd_control()
810 if ( ! (pp->sloppyclockflag & CLK_FLAG1)) in gpsd_control()
811 peer->flags &= ~FLAG_PPS; in gpsd_control()
814 DTOLFP(pp->fudgetime1, &up->pps_fudge); in gpsd_control()
815 DTOLFP(pp->fudgetime2, &up->sti_fudge); in gpsd_control()
817 if (MODE_OP_MODE(up->mode ^ peer->ttl)) { in gpsd_control()
818 leave_opmode(peer, up->mode); in gpsd_control()
819 up->mode = MODE_OP_MODE(peer->ttl); in gpsd_control()
820 enter_opmode(peer, up->mode); in gpsd_control()
825 /* ------------------------------------------------------------------ */
831 gpsd_unitT * const up ) in timer_primary() argument
836 * sub-second precison happens here, so receive/connect/retry in timer_primary()
843 if (up->logthrottle) in timer_primary()
844 --up->logthrottle; in timer_primary()
845 if (up->tickover) in timer_primary()
846 --up->tickover; in timer_primary()
847 switch (up->tickover) { in timer_primary()
853 if (-1 != pp->io.fd) { in timer_primary()
856 up->logname, s_req_version)); in timer_primary()
858 rc = write(pp->io.fd, s_req_version, rlen); in timer_primary()
860 } else if (-1 != up->fdt) { in timer_primary()
866 if (-1 != pp->io.fd) in timer_primary()
868 else if (-1 != up->fdt) in timer_primary()
875 if (-1 == pp->io.fd && -1 != up->fdt) in timer_primary()
884 gpsd_unitT * const up ) in timer_secondary() argument
889 up->ppscount2 = max(0, (up->ppscount2 - 1)); in timer_secondary()
890 if (0 == up->ppscount2) { in timer_secondary()
891 if (pp->coderecv != pp->codeproc) { in timer_secondary()
893 pp->coderecv = pp->codeproc; in timer_secondary()
895 peer->flags &= ~FLAG_PPS; in timer_secondary()
904 clockprocT * const pp = peer->procptr; in gpsd_timer()
905 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_timer() local
907 if (peer == up->pps_peer) in gpsd_timer()
908 timer_secondary(peer, pp, up); in gpsd_timer()
910 timer_primary(peer, pp, up); in gpsd_timer()
922 clockprocT * const pp = peer->procptr; in enter_opmode()
923 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in enter_opmode() local
926 up->logname, MODE_OP_MODE(mode))); in enter_opmode()
929 up->fl_rawsti = 0; in enter_opmode()
930 up->ppscount = PPS_MAXCOUNT / 2; in enter_opmode()
932 up->fl_pps = 0; in enter_opmode()
933 up->fl_sti = 0; in enter_opmode()
936 /* ------------------------------------------------------------------ */
943 clockprocT * const pp = peer->procptr; in leave_opmode()
944 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in leave_opmode() local
947 up->logname, MODE_OP_MODE(mode))); in leave_opmode()
950 up->fl_rawsti = 0; in leave_opmode()
951 up->ppscount = 0; in leave_opmode()
953 up->fl_pps = 0; in leave_opmode()
954 up->fl_sti = 0; in leave_opmode()
968 pp->lastref = stamp; in add_clock_sample()
969 if (pp->coderecv == pp->codeproc) in add_clock_sample()
974 /* ------------------------------------------------------------------ */
980 gpsd_unitT * const up ) in eval_strict() argument
982 if (up->fl_sti && up->fl_pps) { in eval_strict()
984 add_clock_sample(peer, pp, up->sti_stamp, up->pps_recvt); in eval_strict()
985 peer->precision = up->pps_prec; in eval_strict()
987 up->fl_pps = 0; in eval_strict()
988 up->fl_sti = 0; in eval_strict()
989 ++up->tc_sti_used; in eval_strict()
993 /* ------------------------------------------------------------------ */
995 * timing information, so there's no danger of PLL-locking to the wrong
1003 gpsd_unitT * const up ) in eval_pps_secondary() argument
1005 if (up->fl_pps2) { in eval_pps_secondary()
1007 add_clock_sample(peer, pp, up->pps_stamp2, up->pps_recvt2); in eval_pps_secondary()
1008 peer->precision = up->pps_prec; in eval_pps_secondary()
1010 up->ppscount2 = min(PPS2_MAXCOUNT, (up->ppscount2 + 2)); in eval_pps_secondary()
1011 if ((PPS2_MAXCOUNT == up->ppscount2) && in eval_pps_secondary()
1012 (pp->sloppyclockflag & CLK_FLAG1) ) in eval_pps_secondary()
1013 peer->flags |= FLAG_PPS; in eval_pps_secondary()
1015 up->fl_pps2 = 0; in eval_pps_secondary()
1016 ++up->tc_pps_used; in eval_pps_secondary()
1020 /* ------------------------------------------------------------------ */
1026 gpsd_unitT * const up ) in eval_serial() argument
1028 if (up->fl_sti) { in eval_serial()
1029 add_clock_sample(peer, pp, up->sti_stamp, up->sti_recvt); in eval_serial()
1030 peer->precision = up->sti_prec; in eval_serial()
1032 up->fl_sti = 0; in eval_serial()
1033 ++up->tc_sti_used; in eval_serial()
1037 /* ------------------------------------------------------------------ */
1042 gpsd_unitT * const up ) in eval_auto() argument
1045 if (!up->fl_sti) in eval_auto()
1055 if (up->fl_pps) { in eval_auto()
1056 up->ppscount = min(PPS_MAXCOUNT, in eval_auto()
1057 (up->ppscount + PPS_INCCOUNT)); in eval_auto()
1058 if ((PPS_MAXCOUNT == up->ppscount) && up->fl_rawsti) { in eval_auto()
1059 up->fl_rawsti = 0; in eval_auto()
1062 up->logname); in eval_auto()
1065 up->ppscount = max(0, (up->ppscount - PPS_DECCOUNT)); in eval_auto()
1066 if ((0 == up->ppscount) && !up->fl_rawsti) { in eval_auto()
1067 up->fl_rawsti = -1; in eval_auto()
1070 up->logname); in eval_auto()
1075 if (up->fl_rawsti) in eval_auto()
1076 eval_serial(peer, pp, up); in eval_auto()
1078 eval_strict(peer, pp, up); in eval_auto()
1085 /* ------------------------------------------------------------------ */
1102 /* store initial value of 'cp' -- see 'strtol()' */ in strtojint()
1110 if (*cp == '-') { in strtojint()
1113 limit_hi = (json_uint)-(JSON_INT_MIN + 1) + 1; in strtojint()
1126 accu = accu * 10 + (*(const u_char*)cp++ - '0'); in strtojint()
1139 /* If possible, store back the end-of-conversion pointer */ in strtojint()
1146 return -(json_int)(accu - 1) - 1; in strtojint()
1151 /* ------------------------------------------------------------------ */
1158 if (tid >= 0 && tid < ctx->ntok) { in json_token_skip()
1159 int len = ctx->tok[tid].size; in json_token_skip()
1170 switch (ctx->tok[tid].type) { in json_token_skip()
1175 for (++tid; len; --len) in json_token_skip()
1186 if (tid < 0 || tid > ctx->ntok) in json_token_skip()
1187 tid = ctx->ntok; in json_token_skip()
1192 /* ------------------------------------------------------------------ */
1203 if (tid < 0 || tid >= ctx->ntok || in json_object_lookup()
1204 ctx->tok[tid].type != JSMN_OBJECT) in json_object_lookup()
1207 len = ctx->tok[tid].size; in json_object_lookup()
1208 for (++tid; len && tid+1 < ctx->ntok; --len) { in json_object_lookup()
1209 if (ctx->tok[tid].type != JSMN_STRING) { /* Blooper! */ in json_object_lookup()
1212 } else if (strcmp(key, ctx->buf + ctx->tok[tid].start)) { in json_object_lookup()
1214 } else if (what < 0 || (u_int)what == ctx->tok[tid+1].type) { in json_object_lookup()
1226 /* ------------------------------------------------------------------ */
1236 return ctx->buf + ctx->tok[tid].start; in json_object_lookup_primitive()
1240 /* ------------------------------------------------------------------ */
1241 /* look up a boolean value. This essentially returns a tribool:
1242 * 0->false, 1->true, (-1)->error/undefined
1255 default : return -1; in json_object_lookup_bool()
1259 /* ------------------------------------------------------------------ */
1269 return ctx->buf + ctx->tok[tid].start; in json_object_lookup_string()
1282 return ctx->buf + ctx->tok[tid].start; in json_object_lookup_string_default()
1286 /* ------------------------------------------------------------------ */
1329 /* ------------------------------------------------------------------ */
1373 /* ------------------------------------------------------------------ */
1385 rc = jsmn_parse(&jsm, buf, len, ctx->tok, JSMN_MAXTOK); in json_parse_record()
1388 ctx->buf = buf; in json_parse_record()
1389 ctx->ntok = rc; in json_parse_record()
1391 if (JSMN_OBJECT != ctx->tok[0].type) in json_parse_record()
1398 for (idx = 0; idx < ctx->ntok; ++idx) in json_parse_record()
1399 if (ctx->tok[idx].end > ctx->tok[idx].start) in json_parse_record()
1400 ctx->buf[ctx->tok[idx].end] = '\0'; in json_parse_record()
1430 /* ------------------------------------------------------------------ */
1442 clockprocT * const pp = peer->procptr; in process_watch()
1443 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in process_watch() local
1448 if (NULL == path || strcmp(path, up->device)) in process_watch()
1453 up->fl_watch = -1; in process_watch()
1455 up->fl_watch = 0; in process_watch()
1457 up->logname, (up->fl_watch & 1))); in process_watch()
1460 /* ------------------------------------------------------------------ */
1468 clockprocT * const pp = peer->procptr; in process_version()
1469 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in process_version() local
1487 if ( ! up->fl_vers) in process_version()
1490 up->logname, revision, release, in process_version()
1492 up->proto_version = PROTO_VERSION(pvhi, pvlo); in process_version()
1493 up->fl_vers = -1; in process_version()
1495 if (syslogok(pp, up)) in process_version()
1498 up->logname); in process_version()
1504 up->pf_nsec = -(up->proto_version >= PROTO_VERSION(3,9)); in process_version()
1509 up->pf_toff = -(up->proto_version >= PROTO_VERSION(3,10)); in process_version()
1524 if (up->fl_watch) in process_version()
1532 snprintf(up->buffer, sizeof(up->buffer), in process_version()
1534 up->device, (up->pf_toff ? ",\"pps\":true" : "")); in process_version()
1535 buf = up->buffer; in process_version()
1538 if (len != write(pp->io.fd, buf, len) && (syslogok(pp, up))) { in process_version()
1544 up->logname); in process_version()
1548 /* ------------------------------------------------------------------ */
1556 clockprocT * const pp = peer->procptr; in process_tpv()
1557 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in process_tpv() local
1573 if ( ! up->pf_toff) in process_tpv()
1574 ++up->tc_sti_recv; in process_tpv()
1575 ++up->tc_nosync; in process_tpv()
1576 up->fl_sti = 0; in process_tpv()
1577 up->fl_pps = 0; in process_tpv()
1578 up->fl_nosync = -1; in process_tpv()
1581 up->fl_nosync = 0; in process_tpv()
1586 if ( ! up->pf_toff) { in process_tpv()
1587 ++up->tc_sti_recv; in process_tpv()
1591 if (convert_ascii_time(&up->sti_stamp, gps_time)) { in process_tpv()
1594 up->logname, in process_tpv()
1595 gmprettydate(&up->sti_stamp), in process_tpv()
1596 gmprettydate(&up->sti_recvt), in process_tpv()
1603 up->sti_local = *rtime; in process_tpv()
1604 up->sti_recvt = *rtime; in process_tpv()
1605 L_SUB(&up->sti_recvt, &up->sti_fudge); in process_tpv()
1606 up->fl_sti = -1; in process_tpv()
1608 ++up->tc_breply; in process_tpv()
1609 up->fl_sti = 0; in process_tpv()
1620 ept = json_object_lookup_float_default(jctx, 0, "ept", 2.0e-3); in process_tpv()
1626 up->sti_prec = clamped_precision(xlog2); in process_tpv()
1629 /* ------------------------------------------------------------------ */
1637 clockprocT * const pp = peer->procptr; in process_pps()
1638 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in process_pps() local
1642 ++up->tc_pps_recv; in process_pps()
1647 if (up->fl_nosync) in process_pps()
1650 up->pps_local = *rtime; in process_pps()
1655 if (up->pf_nsec) { in process_pps()
1656 if ( ! get_binary_time(&up->pps_recvt2, jctx, in process_pps()
1659 if ( ! get_binary_time(&up->pps_stamp2, jctx, in process_pps()
1663 if ( ! get_binary_time(&up->pps_recvt2, jctx, in process_pps()
1666 if ( ! get_binary_time(&up->pps_stamp2, jctx, in process_pps()
1675 jctx, 0, "precision", up->sti_prec); in process_pps()
1676 up->pps_prec = clamped_precision(xlog2); in process_pps()
1679 up->pps_recvt = up->pps_recvt2; in process_pps()
1680 L_SUB(&up->pps_recvt , &up->pps_fudge ); in process_pps()
1681 L_SUB(&up->pps_recvt2, &up->pps_fudge2); in process_pps()
1682 pp->lastrec = up->pps_recvt; in process_pps()
1687 up->pps_stamp = up->pps_recvt; in process_pps()
1688 L_ADDUF(&up->pps_stamp, 0x80000000u); in process_pps()
1689 up->pps_stamp.l_uf = 0; in process_pps()
1691 if (NULL != up->pps_peer) in process_pps()
1692 save_ltc(up->pps_peer->procptr, in process_pps()
1693 gmprettydate(&up->pps_stamp2)); in process_pps()
1696 up->logname, in process_pps()
1697 gmprettydate(&up->pps_stamp2), in process_pps()
1698 gmprettydate(&up->pps_recvt2))); in process_pps()
1700 up->fl_pps = (0 != (pp->sloppyclockflag & CLK_FLAG2)) - 1; in process_pps()
1701 up->fl_pps2 = -1; in process_pps()
1706 up->logname)); in process_pps()
1707 ++up->tc_breply; in process_pps()
1710 /* ------------------------------------------------------------------ */
1718 clockprocT * const pp = peer->procptr; in process_toff()
1719 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in process_toff() local
1721 ++up->tc_sti_recv; in process_toff()
1724 up->pf_toff = -1; in process_toff()
1727 if (up->fl_nosync) in process_toff()
1730 if ( ! get_binary_time(&up->sti_recvt, jctx, in process_toff()
1733 if ( ! get_binary_time(&up->sti_stamp, jctx, in process_toff()
1736 L_SUB(&up->sti_recvt, &up->sti_fudge); in process_toff()
1737 up->sti_local = *rtime; in process_toff()
1738 up->fl_sti = -1; in process_toff()
1740 save_ltc(pp, gmprettydate(&up->sti_stamp)); in process_toff()
1743 up->logname, in process_toff()
1744 gmprettydate(&up->sti_stamp), in process_toff()
1745 gmprettydate(&up->sti_recvt))); in process_toff()
1750 up->logname)); in process_toff()
1751 ++up->tc_breply; in process_toff()
1754 /* ------------------------------------------------------------------ */
1761 clockprocT * const pp = peer->procptr; in gpsd_parse()
1762 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_parse() local
1767 up->logname, ulfptoa(rtime, 6), in gpsd_parse()
1768 up->buflen, up->buffer)); in gpsd_parse()
1773 if (!json_parse_record(&up->json_parse, up->buffer, up->buflen)) { in gpsd_parse()
1774 ++up->tc_breply; in gpsd_parse()
1779 clsid = json_object_lookup_string(&up->json_parse, 0, "class"); in gpsd_parse()
1781 ++up->tc_breply; in gpsd_parse()
1786 process_tpv(peer, &up->json_parse, rtime); in gpsd_parse()
1788 process_pps(peer, &up->json_parse, rtime); in gpsd_parse()
1790 process_toff(peer, &up->json_parse, rtime); in gpsd_parse()
1792 process_version(peer, &up->json_parse, rtime); in gpsd_parse()
1794 process_watch(peer, &up->json_parse, rtime); in gpsd_parse()
1797 ++up->tc_recv; in gpsd_parse()
1800 if (up->pps_peer) in gpsd_parse()
1802 up->pps_peer, up->pps_peer->procptr, up); in gpsd_parse()
1809 if (up->fl_pps && up->fl_sti) { in gpsd_parse()
1811 diff = up->sti_local; in gpsd_parse()
1812 L_SUB(&diff, &up->pps_local); in gpsd_parse()
1814 up->fl_pps = 0; /* pps too old */ in gpsd_parse()
1816 up->fl_sti = 0; /* serial data too old */ in gpsd_parse()
1819 /* dispatch to the mode-dependent processing functions */ in gpsd_parse()
1820 switch (up->mode) { in gpsd_parse()
1823 eval_serial(peer, pp, up); in gpsd_parse()
1827 eval_strict(peer, pp, up); in gpsd_parse()
1831 eval_auto(peer, pp, up); in gpsd_parse()
1836 /* ------------------------------------------------------------------ */
1842 clockprocT * const pp = peer->procptr; in gpsd_stop_socket()
1843 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_stop_socket() local
1845 if (-1 != pp->io.fd) { in gpsd_stop_socket()
1846 if (syslogok(pp, up)) in gpsd_stop_socket()
1849 up->logname, pp->io.fd); in gpsd_stop_socket()
1852 up->logname, pp->io.fd)); in gpsd_stop_socket()
1853 io_closeclock(&pp->io); in gpsd_stop_socket()
1854 pp->io.fd = -1; in gpsd_stop_socket()
1856 up->tickover = up->tickpres; in gpsd_stop_socket()
1857 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH); in gpsd_stop_socket()
1858 up->fl_vers = 0; in gpsd_stop_socket()
1859 up->fl_sti = 0; in gpsd_stop_socket()
1860 up->fl_pps = 0; in gpsd_stop_socket()
1861 up->fl_watch = 0; in gpsd_stop_socket()
1864 /* ------------------------------------------------------------------ */
1870 clockprocT * const pp = peer->procptr; in gpsd_init_socket()
1871 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_init_socket() local
1877 if (NULL == up->addr) in gpsd_init_socket()
1878 up->addr = s_gpsd_addr; in gpsd_init_socket()
1879 ai = up->addr; in gpsd_init_socket()
1880 up->addr = ai->ai_next; in gpsd_init_socket()
1883 up->fdt = socket( in gpsd_init_socket()
1884 ai->ai_family, ai->ai_socktype, ai->ai_protocol); in gpsd_init_socket()
1885 if (-1 == up->fdt) { in gpsd_init_socket()
1886 if (syslogok(pp, up)) in gpsd_init_socket()
1889 up->logname); in gpsd_init_socket()
1893 /* Make sure the socket is non-blocking. Connect/reconnect and in gpsd_init_socket()
1894 * IO happen in an event-driven environment, and synchronous in gpsd_init_socket()
1897 rc = fcntl(up->fdt, F_SETFL, O_NONBLOCK, 1); in gpsd_init_socket()
1898 if (-1 == rc) { in gpsd_init_socket()
1899 if (syslogok(pp, up)) in gpsd_init_socket()
1901 "%s: cannot set GPSD socket to non-blocking: %m", in gpsd_init_socket()
1902 up->logname); in gpsd_init_socket()
1906 * protocol makes it record-oriented, and in most cases in gpsd_init_socket()
1912 rc = setsockopt(up->fdt, IPPROTO_TCP, TCP_NODELAY, in gpsd_init_socket()
1914 if (-1 == rc) { in gpsd_init_socket()
1915 if (syslogok(pp, up)) in gpsd_init_socket()
1918 up->logname); in gpsd_init_socket()
1921 /* Start a non-blocking connect. There might be a synchronous in gpsd_init_socket()
1924 rc = connect(up->fdt, ai->ai_addr, ai->ai_addrlen); in gpsd_init_socket()
1925 if (-1 == rc) { in gpsd_init_socket()
1928 up->logname, up->fdt)); in gpsd_init_socket()
1932 if (syslogok(pp, up)) in gpsd_init_socket()
1935 up->logname); in gpsd_init_socket()
1945 up->logname, up->fdt)); in gpsd_init_socket()
1947 pp->io.fd = up->fdt; in gpsd_init_socket()
1948 up->fdt = -1; in gpsd_init_socket()
1949 if (0 == io_addclock(&pp->io)) { in gpsd_init_socket()
1950 if (syslogok(pp, up)) in gpsd_init_socket()
1953 up->logname); in gpsd_init_socket()
1960 if (-1 != pp->io.fd) in gpsd_init_socket()
1961 close(pp->io.fd); in gpsd_init_socket()
1962 if (-1 != up->fdt) in gpsd_init_socket()
1963 close(up->fdt); in gpsd_init_socket()
1964 pp->io.fd = -1; in gpsd_init_socket()
1965 up->fdt = -1; in gpsd_init_socket()
1966 up->tickover = up->tickpres; in gpsd_init_socket()
1967 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH); in gpsd_init_socket()
1970 /* ------------------------------------------------------------------ */
1976 clockprocT * const pp = peer->procptr; in gpsd_test_socket()
1977 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in gpsd_test_socket() local
1982 /* Check if the non-blocking connect was finished by testing the in gpsd_test_socket()
1987 up->logname, up->fdt)); in gpsd_test_socket()
1994 pfd.fd = up->fdt; in gpsd_test_socket()
2006 FD_SET(up->fdt, &wset); in gpsd_test_socket()
2007 rc = select(up->fdt+1, NULL, &wset, NULL, &tout); in gpsd_test_socket()
2008 if (0 == rc || !(FD_ISSET(up->fdt, &wset))) in gpsd_test_socket()
2016 up->tickover = TICKOVER_LOW; in gpsd_test_socket()
2021 rc = getsockopt(up->fdt, SOL_SOCKET, SO_ERROR, (void *)&ec, &lc); in gpsd_test_socket()
2022 if (-1 == rc || 0 != ec) { in gpsd_test_socket()
2027 if (syslogok(pp, up)) in gpsd_test_socket()
2031 up->logname, up->fdt, ec, errtxt); in gpsd_test_socket()
2035 up->logname, up->fdt, ec, errtxt)); in gpsd_test_socket()
2039 up->logname, up->fdt)); in gpsd_test_socket()
2043 pp->io.fd = up->fdt; in gpsd_test_socket()
2044 up->fdt = -1; in gpsd_test_socket()
2045 if (0 == io_addclock(&pp->io)) { in gpsd_test_socket()
2046 if (syslogok(pp, up)) in gpsd_test_socket()
2049 up->logname); in gpsd_test_socket()
2055 if (-1 != up->fdt) { in gpsd_test_socket()
2057 up->logname, up->fdt)); in gpsd_test_socket()
2058 close(up->fdt); in gpsd_test_socket()
2060 up->fdt = -1; in gpsd_test_socket()
2061 up->tickover = up->tickpres; in gpsd_test_socket()
2062 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH); in gpsd_test_socket()
2069 /* -------------------------------------------------------------------
2078 if (rawprec < -32) in clamped_precision()
2079 rawprec = -32; in clamped_precision()
2083 /* -------------------------------------------------------------------
2101 ep = strptime(gps_time, "%Y-%m-%dT%H:%M:%S", &gd); in convert_ascii_time()
2107 ts.tv_nsec += (*(u_char*)ep - '0') * dw; in convert_ascii_time()
2118 ts.tv_sec = (ntpcal_tm_to_rd(&gd) - DAY_NTP_STARTS) * SECSPERDAY in convert_ascii_time()
2125 /* -------------------------------------------------------------------
2138 if (len >= sizeof(pp->a_lastcode)) in save_ltc()
2139 len = sizeof(pp->a_lastcode) - 1; in save_ltc()
2140 memcpy(pp->a_lastcode, tc, len); in save_ltc()
2142 pp->lencode = (u_short)len; in save_ltc()
2143 pp->a_lastcode[len] = '\0'; in save_ltc()
2146 /* -------------------------------------------------------------------
2166 return -1; in myasprintf()
2176 /* -------------------------------------------------------------------
2202 clockprocT * const pp = peer->procptr; in log_data()
2203 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; in log_data() local
2209 char *dtop = s_lbuf + sizeof(s_lbuf) - 1; /* for NUL */ in log_data()
2224 mprintf("%s[%s]: '%s'\n", up->logname, what, s_lbuf); in log_data()