Lines Matching refs:up

268 	gpsd_start,		/* start up driver */
372 static int syslogok(clockprocT * const pp, gpsd_unitT * const up);
418 gpsd_unitT * const up)
421 || (0 == up->logthrottle )
422 || (LOGTHROTTLE == up->logthrottle );
424 up->logthrottle = LOGTHROTTLE;
481 "GPSD_JSON: failed to get socket address, giving up.");
496 * Start: allocate a unit pointer and set up the runtime data
504 gpsd_unitT * up;
516 while ((up = *uscan) != NULL && up->unit != (unit & 0x7F))
517 uscan = &up->next_unit;
518 if (up == NULL) {
520 up = emalloc_zero(sizeof(*up));
521 *uscan = up;
522 ++up->refcount;
525 up->logname = estrdup(refnumtoa(&peer->srcadr));
526 up->unit = unit & 0x7F;
527 up->fdt = -1;
528 up->addr = s_gpsd_addr;
529 up->tickpres = TICKOVER_LOW;
539 up->device = estrdup(tmpName);
540 } else if (-1 == myasprintf(&up->device, "%s%u", s_dev_stem, up->unit)) {
542 up->logname);
545 devname = up->device;
546 up->device = ntp_realpath(devname);
547 if (NULL == up->device) {
549 up->logname, devname);
554 if (-1 == lstat(up->device, &sb)) {
556 up->logname, up->device);
561 up->logname, up->device);
565 /* All set up, just increment use count. */
566 ++up->refcount;
570 pp->unitptr = (caddr_t)up;
586 /* If the daemon name lookup failed, just give up now. */
587 if (NULL == up->addr) {
588 msyslog(LOG_ERR, "%s: no GPSD socket address, giving up",
589 up->logname);
595 refnumtoa(&peer->srcadr), up->device));
596 up->mode = MODE_OP_MODE(peer->ttl);
597 if (up->mode > MODE_OP_MAXVAL)
598 up->mode = 0;
600 up->pps_peer = peer;
602 enter_opmode(peer, up->mode);
608 INSIST (up);
609 if (!--up->refcount) {
610 *uscan = up->next_unit;
611 free(up->device);
612 free(up);
627 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
633 if (up == NULL)
637 if (peer != up->pps_peer) {
640 up->logname, pp->io.fd));
644 if (up->fdt != -1)
645 close(up->fdt);
648 if (!--up->refcount) {
651 if (*uscan == up)
652 *uscan = up->next_unit;
655 free(up->logname);
656 free(up->device);
657 free(up);
673 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
693 pdst = up->buffer + up->buflen;
694 edst = up->buffer + sizeof(up->buffer) - 1; /* for trailing NUL */
700 while (pdst != up->buffer && pdst[-1] <= ' ')
704 up->buflen = pdst - up->buffer;
706 pdst = up->buffer;
709 if (ch > ' ' || pdst != up->buffer)
713 up->buflen = pdst - up->buffer;
714 up->tickover = TICKOVER_LOW;
723 gpsd_unitT * const up )
739 else if (0 != up->tc_breply)
748 up->tc_recv,
749 up->tc_breply, up->tc_nosync,
750 up->tc_sti_recv, up->tc_sti_used,
751 up->tc_pps_recv, up->tc_pps_used);
754 up->tc_breply = 0;
755 up->tc_recv = 0;
756 up->tc_nosync = 0;
757 up->tc_sti_recv = 0;
758 up->tc_sti_used = 0;
759 up->tc_pps_recv = 0;
760 up->tc_pps_used = 0;
767 gpsd_unitT * const up )
787 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
790 if (peer == up->pps_peer)
791 poll_secondary(peer, pp, up);
793 poll_primary(peer, pp, up);
806 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
808 if (peer == up->pps_peer) {
809 DTOLFP(pp->fudgetime1, &up->pps_fudge2);
814 DTOLFP(pp->fudgetime1, &up->pps_fudge);
815 DTOLFP(pp->fudgetime2, &up->sti_fudge);
817 if (MODE_OP_MODE(up->mode ^ peer->ttl)) {
818 leave_opmode(peer, up->mode);
819 up->mode = MODE_OP_MODE(peer->ttl);
820 enter_opmode(peer, up->mode);
831 gpsd_unitT * const up )
843 if (up->logthrottle)
844 --up->logthrottle;
845 if (up->tickover)
846 --up->tickover;
847 switch (up->tickover) {
856 up->logname, s_req_version));
860 } else if (-1 != up->fdt) {
868 else if (-1 != up->fdt)
875 if (-1 == pp->io.fd && -1 != up->fdt)
884 gpsd_unitT * const up )
889 up->ppscount2 = max(0, (up->ppscount2 - 1));
890 if (0 == up->ppscount2) {
905 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
907 if (peer == up->pps_peer)
908 timer_secondary(peer, pp, up);
910 timer_primary(peer, pp, up);
923 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
926 up->logname, MODE_OP_MODE(mode)));
929 up->fl_rawsti = 0;
930 up->ppscount = PPS_MAXCOUNT / 2;
932 up->fl_pps = 0;
933 up->fl_sti = 0;
944 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
947 up->logname, MODE_OP_MODE(mode)));
950 up->fl_rawsti = 0;
951 up->ppscount = 0;
953 up->fl_pps = 0;
954 up->fl_sti = 0;
980 gpsd_unitT * const up )
982 if (up->fl_sti && up->fl_pps) {
984 add_clock_sample(peer, pp, up->sti_stamp, up->pps_recvt);
985 peer->precision = up->pps_prec;
987 up->fl_pps = 0;
988 up->fl_sti = 0;
989 ++up->tc_sti_used;
1003 gpsd_unitT * const up )
1005 if (up->fl_pps2) {
1007 add_clock_sample(peer, pp, up->pps_stamp2, up->pps_recvt2);
1008 peer->precision = up->pps_prec;
1010 up->ppscount2 = min(PPS2_MAXCOUNT, (up->ppscount2 + 2));
1011 if ((PPS2_MAXCOUNT == up->ppscount2) &&
1015 up->fl_pps2 = 0;
1016 ++up->tc_pps_used;
1026 gpsd_unitT * const up )
1028 if (up->fl_sti) {
1029 add_clock_sample(peer, pp, up->sti_stamp, up->sti_recvt);
1030 peer->precision = up->sti_prec;
1032 up->fl_sti = 0;
1033 ++up->tc_sti_used;
1042 gpsd_unitT * const up )
1045 if (!up->fl_sti)
1055 if (up->fl_pps) {
1056 up->ppscount = min(PPS_MAXCOUNT,
1057 (up->ppscount + PPS_INCCOUNT));
1058 if ((PPS_MAXCOUNT == up->ppscount) && up->fl_rawsti) {
1059 up->fl_rawsti = 0;
1062 up->logname);
1065 up->ppscount = max(0, (up->ppscount - PPS_DECCOUNT));
1066 if ((0 == up->ppscount) && !up->fl_rawsti) {
1067 up->fl_rawsti = -1;
1070 up->logname);
1075 if (up->fl_rawsti)
1076 eval_serial(peer, pp, up);
1078 eval_strict(peer, pp, up);
1241 /* look up a boolean value. This essentially returns a tribool:
1443 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1448 if (NULL == path || strcmp(path, up->device))
1453 up->fl_watch = -1;
1455 up->fl_watch = 0;
1457 up->logname, (up->fl_watch & 1)));
1469 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1487 if ( ! up->fl_vers)
1490 up->logname, revision, release,
1492 up->proto_version = PROTO_VERSION(pvhi, pvlo);
1493 up->fl_vers = -1;
1495 if (syslogok(pp, up))
1498 up->logname);
1504 up->pf_nsec = -(up->proto_version >= PROTO_VERSION(3,9));
1509 up->pf_toff = -(up->proto_version >= PROTO_VERSION(3,10));
1524 if (up->fl_watch)
1532 snprintf(up->buffer, sizeof(up->buffer),
1534 up->device, (up->pf_toff ? ",\"pps\":true" : ""));
1535 buf = up->buffer;
1538 if (len != write(pp->io.fd, buf, len) && (syslogok(pp, up))) {
1544 up->logname);
1557 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1573 if ( ! up->pf_toff)
1574 ++up->tc_sti_recv;
1575 ++up->tc_nosync;
1576 up->fl_sti = 0;
1577 up->fl_pps = 0;
1578 up->fl_nosync = -1;
1581 up->fl_nosync = 0;
1586 if ( ! up->pf_toff) {
1587 ++up->tc_sti_recv;
1591 if (convert_ascii_time(&up->sti_stamp, gps_time)) {
1594 up->logname,
1595 gmprettydate(&up->sti_stamp),
1596 gmprettydate(&up->sti_recvt),
1603 up->sti_local = *rtime;
1604 up->sti_recvt = *rtime;
1605 L_SUB(&up->sti_recvt, &up->sti_fudge);
1606 up->fl_sti = -1;
1608 ++up->tc_breply;
1609 up->fl_sti = 0;
1626 up->sti_prec = clamped_precision(xlog2);
1638 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1642 ++up->tc_pps_recv;
1647 if (up->fl_nosync)
1650 up->pps_local = *rtime;
1655 if (up->pf_nsec) {
1656 if ( ! get_binary_time(&up->pps_recvt2, jctx,
1659 if ( ! get_binary_time(&up->pps_stamp2, jctx,
1663 if ( ! get_binary_time(&up->pps_recvt2, jctx,
1666 if ( ! get_binary_time(&up->pps_stamp2, jctx,
1675 jctx, 0, "precision", up->sti_prec);
1676 up->pps_prec = clamped_precision(xlog2);
1679 up->pps_recvt = up->pps_recvt2;
1680 L_SUB(&up->pps_recvt , &up->pps_fudge );
1681 L_SUB(&up->pps_recvt2, &up->pps_fudge2);
1682 pp->lastrec = up->pps_recvt;
1687 up->pps_stamp = up->pps_recvt;
1688 L_ADDUF(&up->pps_stamp, 0x80000000u);
1689 up->pps_stamp.l_uf = 0;
1691 if (NULL != up->pps_peer)
1692 save_ltc(up->pps_peer->procptr,
1693 gmprettydate(&up->pps_stamp2));
1696 up->logname,
1697 gmprettydate(&up->pps_stamp2),
1698 gmprettydate(&up->pps_recvt2)));
1700 up->fl_pps = (0 != (pp->sloppyclockflag & CLK_FLAG2)) - 1;
1701 up->fl_pps2 = -1;
1706 up->logname));
1707 ++up->tc_breply;
1719 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1721 ++up->tc_sti_recv;
1724 up->pf_toff = -1;
1727 if (up->fl_nosync)
1730 if ( ! get_binary_time(&up->sti_recvt, jctx,
1733 if ( ! get_binary_time(&up->sti_stamp, jctx,
1736 L_SUB(&up->sti_recvt, &up->sti_fudge);
1737 up->sti_local = *rtime;
1738 up->fl_sti = -1;
1740 save_ltc(pp, gmprettydate(&up->sti_stamp));
1743 up->logname,
1744 gmprettydate(&up->sti_stamp),
1745 gmprettydate(&up->sti_recvt)));
1750 up->logname));
1751 ++up->tc_breply;
1762 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1767 up->logname, ulfptoa(rtime, 6),
1768 up->buflen, up->buffer));
1773 if (!json_parse_record(&up->json_parse, up->buffer, up->buflen)) {
1774 ++up->tc_breply;
1779 clsid = json_object_lookup_string(&up->json_parse, 0, "class");
1781 ++up->tc_breply;
1786 process_tpv(peer, &up->json_parse, rtime);
1788 process_pps(peer, &up->json_parse, rtime);
1790 process_toff(peer, &up->json_parse, rtime);
1792 process_version(peer, &up->json_parse, rtime);
1794 process_watch(peer, &up->json_parse, rtime);
1797 ++up->tc_recv;
1800 if (up->pps_peer)
1802 up->pps_peer, up->pps_peer->procptr, up);
1809 if (up->fl_pps && up->fl_sti) {
1811 diff = up->sti_local;
1812 L_SUB(&diff, &up->pps_local);
1814 up->fl_pps = 0; /* pps too old */
1816 up->fl_sti = 0; /* serial data too old */
1820 switch (up->mode) {
1823 eval_serial(peer, pp, up);
1827 eval_strict(peer, pp, up);
1831 eval_auto(peer, pp, up);
1843 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1846 if (syslogok(pp, up))
1849 up->logname, pp->io.fd);
1852 up->logname, pp->io.fd));
1856 up->tickover = up->tickpres;
1857 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH);
1858 up->fl_vers = 0;
1859 up->fl_sti = 0;
1860 up->fl_pps = 0;
1861 up->fl_watch = 0;
1871 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1877 if (NULL == up->addr)
1878 up->addr = s_gpsd_addr;
1879 ai = up->addr;
1880 up->addr = ai->ai_next;
1883 up->fdt = socket(
1885 if (-1 == up->fdt) {
1886 if (syslogok(pp, up))
1889 up->logname);
1897 rc = fcntl(up->fdt, F_SETFL, O_NONBLOCK, 1);
1899 if (syslogok(pp, up))
1902 up->logname);
1912 rc = setsockopt(up->fdt, IPPROTO_TCP, TCP_NODELAY,
1915 if (syslogok(pp, up))
1918 up->logname);
1924 rc = connect(up->fdt, ai->ai_addr, ai->ai_addrlen);
1928 up->logname, up->fdt));
1932 if (syslogok(pp, up))
1935 up->logname);
1945 up->logname, up->fdt));
1947 pp->io.fd = up->fdt;
1948 up->fdt = -1;
1950 if (syslogok(pp, up))
1953 up->logname);
1962 if (-1 != up->fdt)
1963 close(up->fdt);
1965 up->fdt = -1;
1966 up->tickover = up->tickpres;
1967 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH);
1977 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1987 up->logname, up->fdt));
1994 pfd.fd = up->fdt;
2006 FD_SET(up->fdt, &wset);
2007 rc = select(up->fdt+1, NULL, &wset, NULL, &tout);
2008 if (0 == rc || !(FD_ISSET(up->fdt, &wset)))
2016 up->tickover = TICKOVER_LOW;
2021 rc = getsockopt(up->fdt, SOL_SOCKET, SO_ERROR, (void *)&ec, &lc);
2027 if (syslogok(pp, up))
2031 up->logname, up->fdt, ec, errtxt);
2035 up->logname, up->fdt, ec, errtxt));
2039 up->logname, up->fdt));
2043 pp->io.fd = up->fdt;
2044 up->fdt = -1;
2046 if (syslogok(pp, up))
2049 up->logname);
2055 if (-1 != up->fdt) {
2057 up->logname, up->fdt));
2058 close(up->fdt);
2060 up->fdt = -1;
2061 up->tickover = up->tickpres;
2062 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH);
2203 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
2224 mprintf("%s[%s]: '%s'\n", up->logname, what, s_lbuf);