Lines Matching +full:ld +full:- +full:pulse +full:- +full:delay +full:- +full:us

2 …* /src/NTP/REPOSITORY/ntp4-dev/ntpd/refclock_parse.c,v 4.81 2009/05/01 10:15:29 kardel RELEASE_200…
18 * Copyright (c) 1995-2015 by Frank Kardel <kardel <AT> ntp.org>
19 …* Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universitaet Erlangen-Nuernberg, Ge…
57 * - Meinberg receiver DCF77 PZF535 (TCXO version) (DCF)
58 * - Meinberg receiver DCF77 PZF535 (OCXO version) (DCF)
59 * - Meinberg receiver DCF77 PZF509 (DCF)
60 * - Meinberg receiver DCF77 AM receivers (e.g. C51) (DCF)
61 * - IGEL CLOCK (DCF)
62 * - ELV DCF7000 (DCF)
63 * - Schmid clock (DCF)
64 * - Conrad DCF77 receiver module (DCF)
65 * - FAU DCF77 NTP receiver (TimeBrick) (DCF)
66 * - WHARTON 400A Series clock (DCF)
68 * - Meinberg GPS receivers (GPS)
69 * - Trimble (TSIP and TAIP protocol) (GPS)
71 * - RCC8000 MSF Receiver (MSF)
72 * - VARITEXT clock (MSF)
80 * format. The firmware release is Uni-Erlangen.
162 # define BUFFER_SIZE(_BUF, _PTR) ((int)((_BUF) + sizeof(_BUF) - (_PTR)))
163 # define BUFFER_SIZES(_BUF, _PTR, _SZ) ((int)((_BUF) + (_SZ) - (_PTR)))
166 * document type of PPS interfacing - copy of ifdef mechanism in local_input()
189 * then some more parse-specific variables are flagged to be printed with
190 * "ntpq -c cv <assid>". This can be lengthy, so by default COND_DEF
235 #define PARSEDEVICE "/dev/refclock-%d" /* device to open %d is unit number */
236 #define PARSEPPSDEVICE "/dev/refclockpps-%d" /* optional pps device to open %d is unit number */
239 #define ABS(_X_) (((_X_) < 0) ? -(_X_) : (_X_))
265 #define PARSE_END(_X_) (*(_X_)->binding->bd_end)(_X_)
266 #define PARSE_SETCS(_X_, _CS_) (*(_X_)->binding->bd_setcs)(_X_, _CS_)
267 #define PARSE_ENABLE(_X_) (*(_X_)->binding->bd_enable)(_X_)
268 #define PARSE_DISABLE(_X_) (*(_X_)->binding->bd_disable)(_X_)
269 #define PARSE_GETFMT(_X_, _DCT_) (*(_X_)->binding->bd_getfmt)(_X_, _DCT_)
270 #define PARSE_SETFMT(_X_, _DCT_) (*(_X_)->binding->bd_setfmt)(_X_, _DCT_)
271 #define PARSE_GETTIMECODE(_X_, _DCT_) (*(_X_)->binding->bd_timecode)(_X_, _DCT_)
310 u_long err_delay; /* minimum delay between messages */
359 err_internal[] = /* really bad things - basically coding/OS errors */
393 struct peer *peer; /* backlink to peer structure - refclock inactive if 0 */
430 void *localdata; /* optional local, receiver-specific data */
449 u_long rate; /* poll rate - once every "rate" seconds - 0 off */
503 #define DCFUA31_BASEDELAY 0.010 /* 10.7421875ms: 10 ms (+/- 3 ms) */
519 #define DCFPZF535_BASEDELAY 0.001968 /* 1.968ms +- 104us (oscilloscope) - relative to start (end o…
522 * @ 5e-8df/f we have accumulated
538 #define DCFPZF535OCXO_BASEDELAY 0.001968 /* 1.968ms +- 104us (oscilloscope) - relative to start (en…
541 * @ 5e-9df/f we have accumulated
560 #define GPS16X_BASEDELAY 0.001968 /* XXX to be fixed ! 1.968ms +- 104us (oscilloscope) - re…
563 * @ 5e-9df/f we have accumulated
588 * ELV DCF7000 Wallclock-Receiver/Switching Clock (Kit)
590 * This is really not the hottest clock - but before you have nothing ...
595 #define DCF7000_MAXUNSYNC (60*5) /* sorry - but it just was not build as a clock */
613 #define WS_POLLRATE 1 /* every second - watch interdependency with poll routine */
627 #define WSDCF_MAXUNSYNC (60*60) /* assume this beast hold at 1 h better than 2 ms XXX-must verify …
637 * RAW DCF77 - input of DCF marks via RS232 - many variants
643 #define RAWDCF_MAXUNSYNC (0) /* sorry - its a true receiver - no signal - no time */
668 * simplest (cheapest) DCF clock - e. g. DCF77 receiver by Conrad
669 * (~40DM - roughly $30 ) followed by a level converter for RS232
674 /* Gude Analog- und Digitalsystem GmbH 'Expert mouseCLOCK USB v2.0' */
676 #define GUDE_EMC_USB_V20_BASEDELAY 0.425 /* USB serial<->USB converter FTDI232R */
719 #define TRIM_TAIPCMDSIZE (sizeof(TRIM_TAIPPOLLCMD)-1)
1299 /* Must match a format-name in a libparse/clk_xxx.c file */
1310 { /* mode 16 - RAWDCF RTS set, DTR clr */
1426 - RAWDCF RTS set, DTR clr */
1449 { /* mode 22 - like 2 with POWERUP trust */
1472 { /* mode 23 - like 7 with POWERUP trust */
1522 #define CLK_REALTYPE(x) ((int)(((x)->ttl) & 0x7F))
1524 #define CLK_UNIT(x) ((int)REFCLOCKUNIT(&(x)->srcadr))
1525 #define CLK_PPS(x) (((x)->ttl) & 0x80)
1536 …_STATETIME(parse, i) ((parse->generic->currentstatus == i) ? parse->statetime[i] + current_time -
1559 parse->errors[i].err_stage = err_tbl[i]; in clear_err()
1560 parse->errors[i].err_cnt = 0; in clear_err()
1561 parse->errors[i].err_last = 0; in clear_err()
1562 parse->errors[i].err_started = 0; in clear_err()
1563 parse->errors[i].err_suppressed = 0; in clear_err()
1568 parse->errors[lstate].err_stage = err_tbl[lstate]; in clear_err()
1569 parse->errors[lstate].err_cnt = 0; in clear_err()
1570 parse->errors[lstate].err_last = 0; in clear_err()
1571 parse->errors[lstate].err_started = 0; in clear_err()
1572 parse->errors[lstate].err_suppressed = 0; in clear_err()
1583 struct errorinfo *err = &parse->errors[lstate]; in list_err()
1585 if (err->err_started == 0) in list_err()
1587 err->err_started = current_time; in list_err()
1590 do_it = (current_time - err->err_last) >= err->err_stage->err_delay; in list_err()
1593 err->err_cnt++; in list_err()
1595 if (err->err_stage->err_count && in list_err()
1596 (err->err_cnt >= err->err_stage->err_count)) in list_err()
1598 err->err_stage++; in list_err()
1599 err->err_cnt = 0; in list_err()
1602 if (!err->err_cnt && do_it) in list_err()
1604 CLK_UNIT(parse->peer), l_mktime(err->err_stage->err_delay)); in list_err()
1607 err->err_suppressed++; in list_err()
1609 err->err_last = current_time; in list_err()
1611 if (do_it && err->err_suppressed) in list_err()
1613 …msyslog(LOG_INFO, "PARSE receiver #%d: %ld message%s suppressed, error condition class persists fo… in list_err()
1614 CLK_UNIT(parse->peer), err->err_suppressed, (err->err_suppressed == 1) ? " was" : "s where", in list_err()
1615 l_mktime(current_time - err->err_started)); in list_err()
1616 err->err_suppressed = 0; in list_err()
1622 /*--------------------------------------------------
1623 * mkreadable - make a printable ascii string (without
1647 endb = buffer + blen - sizeof(ellipsis); in mkreadable()
1649 blen--; /* account for '\0' */ in mkreadable()
1651 while (blen && srclen--) in mkreadable()
1659 blen--; in mkreadable()
1665 while (blen--) in mkreadable()
1678 blen -= 2; in mkreadable()
1684 blen -= 4; in mkreadable()
1689 if (srclen && !blen && endb) /* overflow - set last chars to ... */ in mkreadable()
1698 /*--------------------------------------------------
1699 * mkascii - make a printable ascii string
1700 * assumes (unless defined better) 7-bit ASCII
1804 /*--------------------------------------------------
1819 if (ioctl(parse->ppsfd, I_PUSH, (caddr_t)m1) == -1 && in ppsclock_init()
1820 ioctl(parse->ppsfd, I_PUSH, (caddr_t)m2) == -1) in ppsclock_init()
1825 CLK_UNIT(parse->peer)); in ppsclock_init()
1831 (void)ioctl(parse->ppsfd, I_POP, (caddr_t)0); in ppsclock_init()
1835 parse->flags |= PARSE_PPSCLOCK; in ppsclock_init()
1839 /*--------------------------------------------------
1850 * to test whether it is there (neat interface 8-( ) in stream_init()
1852 if (ioctl(parse->generic->io.fd, I_PUSH, (caddr_t)m1) == -1) in stream_init()
1854 if (errno != EINVAL) /* accept non-existence */ in stream_init()
1856 …G_ERR, "PARSE receiver #%d: stream_init: ioctl(fd, I_PUSH, \"parse\"): %m", CLK_UNIT(parse->peer)); in stream_init()
1862 while(ioctl(parse->generic->io.fd, I_POP, (caddr_t)0) == 0) in stream_init()
1869 if (ioctl(parse->generic->io.fd, I_PUSH, (caddr_t)m1) == -1) in stream_init()
1871 …G_ERR, "PARSE receiver #%d: stream_init: ioctl(fd, I_PUSH, \"parse\"): %m", CLK_UNIT(parse->peer)); in stream_init()
1881 /*--------------------------------------------------
1889 while(ioctl(parse->generic->io.fd, I_POP, (caddr_t)0) == 0) in stream_end()
1893 /*--------------------------------------------------
1909 if (ioctl(parse->generic->io.fd, I_STR, (caddr_t)&strioc) == -1) in stream_setcs()
1911 …, "PARSE receiver #%d: stream_setcs: ioctl(fd, I_STR, PARSEIOC_SETCS): %m", CLK_UNIT(parse->peer)); in stream_setcs()
1917 /*--------------------------------------------------
1932 if (ioctl(parse->generic->io.fd, I_STR, (caddr_t)&strioc) == -1) in stream_enable()
1934 …"PARSE receiver #%d: stream_enable: ioctl(fd, I_STR, PARSEIOC_ENABLE): %m", CLK_UNIT(parse->peer)); in stream_enable()
1937 parse->generic->io.clock_recv = stream_receive; /* ok - parse input in kernel */ in stream_enable()
1941 /*--------------------------------------------------
1956 if (ioctl(parse->generic->io.fd, I_STR, (caddr_t)&strioc) == -1) in stream_disable()
1958 …ARSE receiver #%d: stream_disable: ioctl(fd, I_STR, PARSEIOC_DISABLE): %m", CLK_UNIT(parse->peer)); in stream_disable()
1961 parse->generic->io.clock_recv = local_receive; /* ok - parse input in daemon */ in stream_disable()
1965 /*--------------------------------------------------
1980 if (ioctl(parse->generic->io.fd, I_STR, (caddr_t)&strioc) == -1) in stream_getfmt()
1982 …msyslog(LOG_ERR, "PARSE receiver #%d: ioctl(fd, I_STR, PARSEIOC_GETFMT): %m", CLK_UNIT(parse->peer… in stream_getfmt()
1988 /*--------------------------------------------------
2004 if (ioctl(parse->generic->io.fd, I_STR, (caddr_t)&strioc) == -1) in stream_setfmt()
2006 …"PARSE receiver #%d: stream_setfmt: ioctl(fd, I_STR, PARSEIOC_SETFMT): %m", CLK_UNIT(parse->peer)); in stream_setfmt()
2013 /*--------------------------------------------------
2029 if (ioctl(parse->generic->io.fd, I_STR, (caddr_t)&strioc) == -1) in stream_timecode()
2032 …SE receiver #%d: stream_timecode: ioctl(fd, I_STR, PARSEIOC_TIMECODE): %m", CLK_UNIT(parse->peer)); in stream_timecode()
2039 /*--------------------------------------------------
2050 parse = (struct parseunit *)rbufp->recv_peer->procptr->unitptr; in stream_receive()
2051 if (!parse->peer) in stream_receive()
2054 if (rbufp->recv_length != sizeof(parsetime_t)) in stream_receive()
2058 CLK_UNIT(parse->peer), rbufp->recv_length, (int)sizeof(parsetime_t)); in stream_receive()
2065 (caddr_t)rbufp->recv_buffer, in stream_receive()
2072 CLK_UNIT(parse->peer), in stream_receive()
2085 * switch time stamp world - be sure to normalize small usec field in stream_receive()
2105 /*--------------------------------------------------
2113 return parse_ioinit(&parse->parseio); in local_init()
2116 /*--------------------------------------------------
2124 parse_ioend(&parse->parseio); in local_end()
2128 /*--------------------------------------------------
2139 /*--------------------------------------------------
2148 return parse_setcs(tcl, &parse->parseio); in local_setcs()
2151 /*--------------------------------------------------
2160 return parse_getfmt(tcl, &parse->parseio); in local_getfmt()
2163 /*--------------------------------------------------
2172 return parse_setfmt(tcl, &parse->parseio); in local_setfmt()
2175 /*--------------------------------------------------
2184 return parse_timecode(tcl, &parse->parseio); in local_timecode()
2188 /*--------------------------------------------------
2202 parse = (struct parseunit *)rbufp->recv_peer->procptr->unitptr; in local_input()
2203 if (!parse->peer) in local_input()
2209 count = rbufp->recv_length; in local_input()
2210 s = (unsigned char *)rbufp->recv_buffer; in local_input()
2211 ts.fp = rbufp->recv_time; in local_input()
2213 while (count--) in local_input()
2215 if (parse_ioread(&parse->parseio, (unsigned int)(*s++), &ts)) in local_input()
2222 if (!PARSE_PPS(parse->parseio.parse_dtime.parse_state)) in local_input()
2225 if (parse->flags & PARSE_PPSCLOCK) in local_input()
2233 if (time_pps_fetch(parse->atom.handle, PPS_TSFMT_TSPEC, &pps_info, in local_input()
2236 if (pps_info.assert_sequence + pps_info.clear_sequence != parse->ppsserial) in local_input()
2245 if (parse->flags & PARSE_CLEAR) in local_input()
2250 parse->parseio.parse_dtime.parse_ptime.fp.l_ui = (uint32_t) (pts.tv_sec + JAN_1970); in local_input()
2255 parse->parseio.parse_dtime.parse_ptime.fp.l_ui--; in local_input()
2258 dtemp -= 1; in local_input()
2259 parse->parseio.parse_dtime.parse_ptime.fp.l_ui++; in local_input()
2261 parse->parseio.parse_dtime.parse_ptime.fp.l_uf = (uint32_t)(dtemp * FRAC); in local_input()
2263 parse->parseio.parse_dtime.parse_state |= PARSEB_PPS|PARSEB_S_PPS; in local_input()
2268 "parse: local_receive: fd %ld PPSAPI seq %ld - PPS %s\n", in local_input()
2269 (long)rbufp->fd, in local_input()
2271 lfptoa(&parse->parseio.parse_dtime.parse_ptime.fp, 6)); in local_input()
2281 "parse: local_receive: fd %ld PPSAPI seq assert %ld, seq clear %ld - NO PPS event\n", in local_input()
2282 (long)rbufp->fd, in local_input()
2287 parse->ppsserial = pps_info.assert_sequence + pps_info.clear_sequence; in local_input()
2295 "parse: local_receive: fd %ld PPSAPI time_pps_fetch errno = %d\n", in local_input()
2296 (long)rbufp->fd, in local_input()
2306 if (ioctl(parse->ppsfd, TIOCDCDTIMESTAMP, &dcd_time) != -1) in local_input()
2320 parse->ppsfd, in local_input()
2326 parse->parseio.parse_dtime.parse_ptime.fp = tstmp; in local_input()
2327 parse->parseio.parse_dtime.parse_state |= PARSEB_PPS|PARSEB_S_PPS; in local_input()
2332 if (parse->flags & PARSE_PPSCLOCK) in local_input()
2338 if (ioctl(parse->ppsfd, CIOGETEV, (caddr_t)&ev) == 0) in local_input()
2341 if (ioctl(parse->ppsfd, TIOCGPPSEV, (caddr_t)&ev) == 0) in local_input()
2344 if (ev.serial != parse->ppsserial) in local_input()
2357 parse->parseio.parse_dtime.parse_ptime.fp = tts; in local_input()
2358 parse->parseio.parse_dtime.parse_state |= PARSEB_PPS|PARSEB_S_PPS; in local_input()
2361 parse->ppsserial = ev.serial; in local_input()
2372 memmove((caddr_t)buf->recv_buffer, in local_input()
2373 (caddr_t)&parse->parseio.parse_dtime, in local_input()
2375 buf->recv_length = sizeof(parsetime_t); in local_input()
2376 buf->recv_time = rbufp->recv_time; in local_input()
2378 buf->srcadr = rbufp->srcadr; in local_input()
2380 buf->dstadr = rbufp->dstadr; in local_input()
2381 buf->receiver = rbufp->receiver; in local_input()
2382 buf->fd = rbufp->fd; in local_input()
2383 buf->X_from_where = rbufp->X_from_where; in local_input()
2384 parse->generic->io.recvcount++; in local_input()
2391 parse_iodone(&parse->parseio); in local_input()
2395 memmove((caddr_t)rbufp->recv_buffer, in local_input()
2396 (caddr_t)&parse->parseio.parse_dtime, in local_input()
2398 parse_iodone(&parse->parseio); in local_input()
2399 rbufp->recv_length = sizeof(parsetime_t); in local_input()
2407 /*--------------------------------------------------
2418 parse = (struct parseunit *)rbufp->recv_peer->procptr->unitptr; in local_receive()
2419 if (!parse->peer) in local_receive()
2422 if (rbufp->recv_length != sizeof(parsetime_t)) in local_receive()
2426 CLK_UNIT(parse->peer), rbufp->recv_length, (int)sizeof(parsetime_t)); in local_receive()
2433 (caddr_t)rbufp->recv_buffer, in local_receive()
2440 CLK_UNIT(parse->peer), in local_receive()
2455 /*--------------------------------------------------
2456 * init_iobinding - find and initialize lower layers
2465 while (b->bd_description != (char *)0) in init_iobinding()
2467 if ((*b->bd_init)(parse)) in init_iobinding()
2485 size_t rem = len - (pos - buffer); in ap()
2494 if (l != -1) { in ap()
2495 rem--; in ap()
2505 /*--------------------------------------------------
2598 /*--------------------------------------------------
2644 /*--------------------------------------------------
2663 { CEVNT_PROP, "PROPAGATION DELAY" }, in clockstatus()
2680 snprintf(buffer, sizeof(buffer), "unknown #%ld", (u_long)lstate); in clockstatus()
2686 /*--------------------------------------------------
2687 * l_mktime - make representation of a relative time
2704 delta -= tmp * 60*60*24; in l_mktime()
2719 /*--------------------------------------------------
2720 * parse_statistics - list summary of clock states
2732 CLK_UNIT(parse->peer), in parse_statistics()
2733 l_mktime(current_time - parse->generic->timestarted)); in parse_statistics()
2736 CLK_UNIT(parse->peer), in parse_statistics()
2737 clockstatus(parse->generic->currentstatus)); in parse_statistics()
2742 u_long percent, d = current_time - parse->generic->timestarted; in parse_statistics()
2758 msyslog(LOG_INFO, "PARSE receiver #%d: state %18s: %13s (%3ld.%02ld%%)", in parse_statistics()
2759 CLK_UNIT(parse->peer), in parse_statistics()
2767 /*--------------------------------------------------
2768 * cparse_statistics - wrapper for statistics call
2775 if (parse->laststatistic + PARSESTATISTICS < current_time) in cparse_statistics()
2777 parse->laststatistic = current_time; in cparse_statistics()
2784 /*--------------------------------------------------
2785 * parse_shutdown - shut down a PARSE clock
2795 if (peer && peer->procptr) in parse_shutdown()
2796 parse = peer->procptr->unitptr; in parse_shutdown()
2804 if (!parse->peer) in parse_shutdown()
2806 …msyslog(LOG_INFO, "PARSE receiver #%d: INTERNAL ERROR - unit already inactive - shutdown ignored",… in parse_shutdown()
2811 if (parse->flags & PARSE_PPSCLOCK) in parse_shutdown()
2813 (void)time_pps_destroy(parse->atom.handle); in parse_shutdown()
2816 if (parse->generic->io.fd != parse->ppsfd && parse->ppsfd != -1) in parse_shutdown()
2817 (void)closeserial(parse->ppsfd); /* close separate PPS source */ in parse_shutdown()
2825 if (parse->parse_type->cl_end) in parse_shutdown()
2827 parse->parse_type->cl_end(parse); in parse_shutdown()
2833 if (parse->binding) in parse_shutdown()
2837 * Tell the I/O module to turn us off. We're history. in parse_shutdown()
2839 io_closeclock(&parse->generic->io); in parse_shutdown()
2841 free_varlist(parse->kv); in parse_shutdown()
2845 CLK_UNIT(parse->peer), parse->parse_type->cl_description); in parse_shutdown()
2847 parse->peer = (struct peer *)0; /* unused now */ in parse_shutdown()
2848 peer->procptr->unitptr = (caddr_t)0; in parse_shutdown()
2853 /*----------------------------------------
2862 if (parse->hardppsstate == mode) in parse_hardpps()
2865 if (CLK_PPS(parse->peer) && (parse->flags & PARSE_PPSKERNEL)) { in parse_hardpps()
2870 if (parse->flags & PARSE_CLEAR) in parse_hardpps()
2876 if (time_pps_kcbind(parse->atom.handle, PPS_KC_HARDPPS, i, in parse_hardpps()
2879 CLK_UNIT(parse->peer)); in parse_hardpps()
2883 CLK_UNIT(parse->peer), (mode == PARSE_HARDPPS_ENABLE) ? "en" : "dis"); in parse_hardpps()
2892 parse->hardppsstate = mode; in parse_hardpps()
2895 /*----------------------------------------
2906 parse->flags &= (u_char) (~PARSE_PPSCLOCK); in parse_ppsapi()
2909 * collect PPSAPI offset capability - should move into generic handling in parse_ppsapi()
2911 if (time_pps_getcap(parse->atom.handle, &cap) < 0) { in parse_ppsapi()
2913 CLK_UNIT(parse->peer)); in parse_ppsapi()
2925 if (!refclock_params(parse->flags & (CLK_FLAG1|CLK_FLAG2|CLK_FLAG4), &parse->atom)) in parse_ppsapi()
2932 if (parse->flags & PARSE_CLEAR) { in parse_ppsapi()
2941 CLK_UNIT(parse->peer), cp); in parse_ppsapi()
2945 CLK_UNIT(parse->peer), cp, cap); in parse_ppsapi()
2950 parse->atom.pps_params.clear_offset.tv_sec = (time_t)(-parse->ppsphaseadjust); in parse_ppsapi()
2951 …parse->atom.pps_params.clear_offset.tv_nsec = (long)(-1e9*(parse->ppsphaseadjust - (double)(long)p… in parse_ppsapi()
2956 parse->atom.pps_params.assert_offset.tv_sec = (time_t)(-parse->ppsphaseadjust); in parse_ppsapi()
2957 …parse->atom.pps_params.assert_offset.tv_nsec = (long)(-1e9*(parse->ppsphaseadjust - (double)(long)… in parse_ppsapi()
2961 parse->atom.pps_params.mode |= mode_ppsoffset; in parse_ppsapi()
2963 if (time_pps_setparams(parse->atom.handle, &parse->atom.pps_params) < 0) { in parse_ppsapi()
2965 CLK_UNIT(parse->peer)); in parse_ppsapi()
2969 parse->flags |= PARSE_PPSCLOCK; in parse_ppsapi()
2976 /*--------------------------------------------------
2977 * parse_start - open the PARSE devices and initialize data for processing
3006 msyslog(LOG_INFO, "NTP PARSE support: Copyright (c) 1989-2015, Frank Kardel"); in parse_start()
3016 unit, CLK_REALTYPE(peer), ncltypes-1); in parse_start()
3025 altdev = clockdev_lookup(&peer->srcadr, 0); in parse_start()
3032 altdev = clockdev_lookup(&peer->srcadr, 1); in parse_start()
3047 if (fd232 == -1) in parse_start()
3055 parse->generic = peer->procptr; /* link up */ in parse_start()
3056 parse->generic->unitptr = (caddr_t)parse; /* link down */ in parse_start()
3061 parse->generic->timestarted = current_time; in parse_start()
3062 parse->lastchange = current_time; in parse_start()
3064 parse->flags = 0; in parse_start()
3065 parse->pollneeddata = 0; in parse_start()
3066 parse->laststatistic = current_time; in parse_start()
3067 parse->lastformat = (unsigned short)~0; /* assume no format known */ in parse_start()
3068 parse->timedata.parse_status = (unsigned short)~0; /* be sure to mark initial status change */ in parse_start()
3069 parse->lastmissed = 0; /* assume got everything */ in parse_start()
3070 parse->ppsserial = 0; in parse_start()
3071 parse->ppsfd = -1; in parse_start()
3072 parse->localdata = (void *)0; in parse_start()
3073 parse->localstate = 0; in parse_start()
3074 parse->kv = (struct ctl_var *)0; in parse_start()
3078 parse->parse_type = &parse_clockinfo[type]; in parse_start()
3080 parse->maxunsync = parse->parse_type->cl_maxunsync; in parse_start()
3082 parse->generic->fudgetime1 = parse->parse_type->cl_basedelay; in parse_start()
3084 parse->generic->fudgetime2 = 0.0; in parse_start()
3085 parse->ppsphaseadjust = parse->generic->fudgetime2; in parse_start()
3086 parse->generic->fudgeminjitter = 0.0; in parse_start()
3088 parse->generic->clockdesc = parse->parse_type->cl_description; in parse_start()
3090 peer->rootdelay = parse->parse_type->cl_rootdelay; in parse_start()
3091 peer->sstclktype = parse->parse_type->cl_type; in parse_start()
3092 peer->precision = sys_precision; in parse_start()
3094 peer->stratum = STRATUM_REFCLOCK; in parse_start()
3096 if (peer->stratum <= 1) in parse_start()
3097 memmove((char *)&parse->generic->refid, parse->parse_type->cl_id, 4); in parse_start()
3099 parse->generic->refid = htonl(PARSEHSREFID); in parse_start()
3101 parse->generic->io.fd = fd232; in parse_start()
3103 parse->peer = peer; /* marks it also as busy */ in parse_start()
3108 if (TTY_GETATTR(fd232, &tio) == -1) in parse_start()
3111 parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ in parse_start()
3120 errno = 0; /* pathconf can deliver -1 without changing errno ! */ in parse_start()
3122 disablec = fpathconf(parse->generic->io.fd, _PC_VDISABLE); in parse_start()
3123 if (disablec == -1 && errno) in parse_start()
3125 …OG_ERR, "PARSE receiver #%d: parse_start: fpathconf(fd, _PC_VDISABLE): %m", CLK_UNIT(parse->peer)); in parse_start()
3129 if (disablec != -1) in parse_start()
3152 if ((cfsetospeed(&tio, (speed_t) parse_clockinfo[type].cl_speed) == -1) || in parse_start()
3153 (cfsetispeed(&tio, (speed_t) parse_clockinfo[type].cl_speed) == -1)) in parse_start()
3156 parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ in parse_start()
3168 parse->ppsfd = tty_open(parseppsdev, O_RDWR | O_NOCTTY | O_NONBLOCK, 0777); in parse_start()
3170 if (parse->ppsfd == -1) in parse_start()
3172 parse->ppsfd = fd232; in parse_start()
3176 * Linux PPS - the old way in parse_start()
3181 if (ioctl(parse->ppsfd, TIOCGSERIAL, &ss) < 0 || in parse_start()
3191 ioctl(parse->ppsfd, TIOCSSERIAL, &ss)) < 0) { in parse_start()
3192 msyslog(LOG_NOTICE, "refclock_parse: TIOCSSERIAL fd %d, %m", parse->ppsfd); in parse_start()
3196 parse->flags |= PARSE_PPSCLOCK; in parse_start()
3210 if (CLK_PPS(parse->peer)) in parse_start()
3214 if (ioctl(parse->ppsfd, TIOCSPPS, (caddr_t)&i) == 0) in parse_start()
3216 parse->flags |= PARSE_PPSCLOCK; in parse_start()
3225 parse->hardppsstate = PARSE_HARDPPS_DISABLE; in parse_start()
3226 if (CLK_PPS(parse->peer)) in parse_start()
3228 if (!refclock_ppsapi(parse->ppsfd, &parse->atom)) in parse_start()
3230 …og(LOG_NOTICE, "PARSE receiver #%d: parse_start: could not set up PPS: %m", CLK_UNIT(parse->peer)); in parse_start()
3239 if (TTY_SETATTR(fd232, &tio) == -1) in parse_start()
3242 parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ in parse_start()
3250 parse->generic->io.srcclock = peer; in parse_start()
3251 parse->generic->io.datalen = 0; in parse_start()
3253 parse->binding = init_iobinding(parse); in parse_start()
3255 if (parse->binding == (bind_t *)0) in parse_start()
3257 …R, "PARSE receiver #%d: parse_start: io sub system initialisation failed.", CLK_UNIT(parse->peer)); in parse_start()
3258 parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ in parse_start()
3259 return 0; /* well, ok - special initialisation broke */ in parse_start()
3262 parse->generic->io.clock_recv = parse->binding->bd_receive; /* pick correct receive routine */ in parse_start()
3263 parse->generic->io.io_input = parse->binding->bd_io_input; /* pick correct input routine */ in parse_start()
3268 * than 8 bit I/O - so we pass that information on. in parse_start()
3295 parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ in parse_start()
3296 return 0; /* well, ok - special initialisation broke */ in parse_start()
3299 …strlcpy(tmp_ctl.parseformat.parse_buffer, parse->parse_type->cl_format, sizeof(tmp_ctl.parseformat… in parse_start()
3305 parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ in parse_start()
3306 return 0; /* well, ok - special initialisation broke */ in parse_start()
3313 (void) tcflush(parse->generic->io.fd, TCIOFLUSH); in parse_start()
3319 (void) ioctl(parse->generic->io.fd, TCFLSH, (caddr_t)&flshcmd); in parse_start()
3327 if (parse->parse_type->cl_init) in parse_start()
3329 if (parse->parse_type->cl_init(parse)) in parse_start()
3331 parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ in parse_start()
3332 return 0; /* well, ok - special initialisation broke */ in parse_start()
3339 if (!io_addclock(&parse->generic->io)) in parse_start()
3342 …receiver #%d: parse_start: addclock %s fails (ABORT - clock type requires async io)", CLK_UNIT(par… in parse_start()
3343 parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ in parse_start()
3354 CLK_UNIT(parse->peer), in parse_start()
3355 parse->parse_type->cl_description, parsedev, in parse_start()
3356 (parse->ppsfd != parse->generic->io.fd) ? parseppsdev : parsedev); in parse_start()
3359 CLK_UNIT(parse->peer), in parse_start()
3360 parse->peer->stratum, in parse_start()
3361 l_mktime(parse->maxunsync), parse->peer->precision); in parse_start()
3364 CLK_UNIT(parse->peer), in parse_start()
3365 parse->parse_type->cl_rootdelay, in parse_start()
3366 parse->generic->fudgetime1, in parse_start()
3367 parse->ppsphaseadjust, in parse_start()
3368 parse->binding->bd_description); in parse_start()
3370 msyslog(LOG_INFO, "PARSE receiver #%d: Format recognition: %s", CLK_UNIT(parse->peer), in parse_start()
3371 parse->parse_type->cl_format); in parse_start()
3372 … msyslog(LOG_INFO, "PARSE receiver #%d: %sPPS support%s", CLK_UNIT(parse->peer), in parse_start()
3373 CLK_PPS(parse->peer) ? "" : "NO ", in parse_start()
3374 CLK_PPS(parse->peer) ? in parse_start()
3387 /*--------------------------------------------------
3388 * parse_ctl - process changes on flags/time values
3398 if (in->haveflags & (CLK_HAVEFLAG1|CLK_HAVEFLAG2|CLK_HAVEFLAG3|CLK_HAVEFLAG4)) in parse_ctl()
3401 parse->flags = (parse->flags & (u_char)(~mask)) | (in->flags & mask); in parse_ctl()
3403 if (CLK_PPS(parse->peer)) in parse_ctl()
3410 if (in->haveflags & CLK_HAVETIME1) in parse_ctl()
3412 parse->generic->fudgetime1 = in->fudgetime1; in parse_ctl()
3414 CLK_UNIT(parse->peer), in parse_ctl()
3415 parse->generic->fudgetime1); in parse_ctl()
3418 if (in->haveflags & CLK_HAVETIME2) in parse_ctl()
3420 parse->generic->fudgetime2 = in->fudgetime2; in parse_ctl()
3421 if (parse->flags & PARSE_TRUSTTIME) in parse_ctl()
3423 parse->maxunsync = (u_long)ABS(in->fudgetime2); in parse_ctl()
3425 CLK_UNIT(parse->peer), in parse_ctl()
3426 l_mktime(parse->maxunsync)); in parse_ctl()
3430 parse->ppsphaseadjust = in->fudgetime2; in parse_ctl()
3432 CLK_UNIT(parse->peer), in parse_ctl()
3433 parse->ppsphaseadjust); in parse_ctl()
3435 if (CLK_PPS(parse->peer)) in parse_ctl()
3443 parse->generic->fudgeminjitter = in->fudgeminjitter; in parse_ctl()
3447 /*--------------------------------------------------
3448 * parse_poll - called by the transmit procedure
3456 struct parseunit *parse = peer->procptr->unitptr; in parse_poll()
3458 if (peer != parse->peer) in parse_poll()
3469 parse->generic->polls++; in parse_poll()
3471 if (parse->pollneeddata && in parse_poll()
3472 …((int)(current_time - parse->pollneeddata) > (1<<(max(min(parse->peer->hpoll, parse->peer->ppoll),… in parse_poll()
3476 * bad news - didn't get a response last time in parse_poll()
3478 parse->lastmissed = current_time; in parse_poll()
3482 …r #%d: no data from device within poll interval (check receiver / wiring)", CLK_UNIT(parse->peer)); in parse_poll()
3488 parse->pollneeddata = current_time; in parse_poll()
3490 if (parse->parse_type->cl_poll) in parse_poll()
3492 parse->parse_type->cl_poll(parse); in parse_poll()
3502 /*--------------------------------------------------
3503 * parse_control - set fudge factors, return statistics
3513 struct parseunit *parse = peer->procptr->unitptr; in parse_control()
3520 out->lencode = 0; in parse_control()
3521 out->p_lastcode = 0; in parse_control()
3522 out->kv_list = (struct ctl_var *)0; in parse_control()
3525 if (!parse || !parse->peer) in parse_control()
3532 unit = CLK_UNIT(parse->peer); in parse_control()
3550 out->type = REFCLK_PARSE; in parse_control()
3555 …parse->generic->fudgetime2 = (parse->flags & PARSE_TRUSTTIME) ? (double)parse->maxunsync : parse->… in parse_control()
3558 * figure out skew between PPS and RS232 - just for informational in parse_control()
3561 if (PARSE_SYNC(parse->timedata.parse_state)) in parse_control()
3563 if (PARSE_PPS(parse->timedata.parse_state) && PARSE_TIMECODE(parse->timedata.parse_state)) in parse_control()
3568 * we have a PPS and RS232 signal - calculate the skew in parse_control()
3569 * WARNING: assumes on TIMECODE == PULSE (timecode after pulse) in parse_control()
3571 off = parse->timedata.parse_stime.fp; in parse_control()
3572 L_SUB(&off, &parse->timedata.parse_ptime.fp); /* true offset */ in parse_control()
3573 tt = add_var(&out->kv_list, 80, RO); in parse_control()
3578 if (PARSE_PPS(parse->timedata.parse_state)) in parse_control()
3580 tt = add_var(&out->kv_list, 80, RO|DEF); in parse_control()
3581 snprintf(tt, 80, "refclock_ppstime=\"%s\"", gmprettydate(&parse->timedata.parse_ptime.fp)); in parse_control()
3584 start = tt = add_var(&out->kv_list, 128, RO|DEF); in parse_control()
3587 if (parse->timedata.parse_time.fp.l_ui == 0) in parse_control()
3594 gmprettydate(&parse->timedata.parse_time.fp)); in parse_control()
3604 start = tt = add_var(&out->kv_list, 512, RO|DEF); in parse_control()
3610 tmpctl.parsegettc.parse_state |= parse->timedata.parse_state & in parse_control()
3620 mkascii(outstatus+strlen(outstatus), (int)(sizeof(outstatus)- strlen(outstatus) - 1), in parse_control()
3636 --count; in parse_control()
3638 start = tt = add_var(&out->kv_list, 80, RO|DEF); in parse_control()
3655 start = tt = add_var(&out->kv_list, LEN_STATES, RO|DEF); in parse_control()
3661 u_long d = current_time - parse->generic->timestarted; in parse_control()
3684 (parse->generic->currentstatus == i) ? "*" : "", in parse_control()
3688 if ((count = (int) strlen(item)) < (LEN_STATES - 40 - (tt - start))) in parse_control()
3699 tt = add_var(&out->kv_list, 32, RO); in parse_control()
3700 snprintf(tt, 32, "refclock_id=\"%s\"", parse->parse_type->cl_id); in parse_control()
3702 tt = add_var(&out->kv_list, 80, RO); in parse_control()
3703 snprintf(tt, 80, "refclock_iomode=\"%s\"", parse->binding->bd_description); in parse_control()
3705 tt = add_var(&out->kv_list, 128, RO); in parse_control()
3711 k = parse->kv; in parse_control()
3712 while (k && !(k->flags & EOV)) in parse_control()
3714 set_var(&out->kv_list, k->text, strlen(k->text)+1, k->flags); in parse_control()
3719 out->lencode = (u_short) strlen(outstatus); in parse_control()
3720 out->p_lastcode = outstatus; in parse_control()
3728 /*--------------------------------------------------
3729 * event handling - note that nominal events will also be posted
3738 if (parse->generic->currentstatus != (u_char) event) in parse_event()
3740 parse->statetime[parse->generic->currentstatus] += current_time - parse->lastchange; in parse_event()
3741 parse->lastchange = current_time; in parse_event()
3743 if (parse->parse_type->cl_event) in parse_event()
3744 parse->parse_type->cl_event(parse, event); in parse_event()
3750 CLK_UNIT(parse->peer)); in parse_event()
3753 refclock_report(parse->peer, event); in parse_event()
3757 /*--------------------------------------------------
3776 if (((parsetime->parse_status & CVT_MASK) != CVT_OK) && in parse_process()
3777 ((parsetime->parse_status & CVT_MASK) != CVT_NONE) && in parse_process()
3778 (parse->timedata.parse_status != parsetime->parse_status)) in parse_process()
3784 CLK_UNIT(parse->peer), parsestatus(parsetime->parse_status, buffer, sizeof(buffer))); in parse_process()
3786 if ((parsetime->parse_status & CVT_MASK) == CVT_FAIL) in parse_process()
3789 * tell more about the story - list time code in parse_process()
3798 …msyslog(LOG_ERR, "PARSE receiver #%d: parse_process: parse_timecode() FAILED", CLK_UNIT(parse->pee… in parse_process()
3804 --count; in parse_process()
3807 CLK_UNIT(parse->peer), in parse_process()
3812 parse->timedata.parse_status = parsetime->parse_status; in parse_process()
3819 if ((parsetime->parse_status & CVT_MASK) != CVT_OK) in parse_process()
3822 * got bad data - tell the rest of the system in parse_process()
3824 switch (parsetime->parse_status & CVT_MASK) in parse_process()
3827 if ((parsetime->parse_status & CVT_ADDITIONAL) && in parse_process()
3828 parse->parse_type->cl_message) in parse_process()
3829 parse->parse_type->cl_message(parse, parsetime); in parse_process()
3833 if (PARSE_PPS(parsetime->parse_state)) in parse_process()
3835 parse->timedata.parse_state |= PARSEB_PPS|PARSEB_S_PPS; in parse_process()
3836 parse->timedata.parse_ptime = parsetime->parse_ptime; in parse_process()
3838 break; /* well, still waiting - timeout is handled at higher levels */ in parse_process()
3841 if (parsetime->parse_status & CVT_BADFMT) in parse_process()
3846 if (parsetime->parse_status & CVT_BADDATE) in parse_process()
3851 if (parsetime->parse_status & CVT_BADTIME) in parse_process()
3860 return; /* skip the rest - useless */ in parse_process()
3865 * (in case somebody has swapped clocks 8-) in parse_process()
3867 if (parse->lastformat != parsetime->parse_format) in parse_process()
3871 tmpctl.parseformat.parse_format = parsetime->parse_format; in parse_process()
3876 msyslog(LOG_ERR, "PARSE receiver #%d: parse_getfmt() FAILED", CLK_UNIT(parse->peer)); in parse_process()
3882 CLK_UNIT(parse->peer), tmpctl.parseformat.parse_buffer); in parse_process()
3884 parse->lastformat = parsetime->parse_format; in parse_process()
3890 if ((parse->timedata.parse_state ^ parsetime->parse_state) & in parse_process()
3896 * something happend - except for PPS events in parse_process()
3899 (void) parsestate(parsetime->parse_state, tmp1, sizeof(tmp1)); in parse_process()
3900 (void) parsestate(parse->timedata.parse_state, tmp2, sizeof(tmp2)); in parse_process()
3903 msyslog(LOG_INFO,"PARSE receiver #%d: STATE CHANGE: %s -> %s", in parse_process()
3904 CLK_UNIT(parse->peer), tmp2, tmp1); in parse_process()
3910 if (PARSE_PPS(parse->timedata.parse_state) && !PARSE_PPS(parsetime->parse_state)) in parse_process()
3912 parsetime->parse_state |= PARSEB_PPS|PARSEB_S_PPS; in parse_process()
3913 parsetime->parse_ptime = parse->timedata.parse_ptime; in parse_process()
3919 parse->timedata = *parsetime; in parse_process()
3925 if (PARSE_POWERUP(parsetime->parse_state)) in parse_process()
3959 CLK_UNIT(parse->peer)); in parse_process()
3970 * this is the best possible state - full trust in parse_process()
3982 if (PARSE_SYNC(parsetime->parse_state)) in parse_process()
3985 * currently completely synchronized - best possible state in parse_process()
3987 parse->lastsync = current_time; in parse_process()
3999 CLK_UNIT(parse->peer)); in parse_process()
4003 fudge = parse->generic->fudgetime1; /* standard RS232 Fudgefactor */ in parse_process()
4005 if (PARSE_TIMECODE(parsetime->parse_state)) in parse_process()
4007 rectime = parsetime->parse_stime.fp; in parse_process()
4008 off = reftime = parsetime->parse_time.fp; in parse_process()
4014 printf("PARSE receiver #%d: Reftime %s, Recvtime %s - initial offset %s\n", in parse_process()
4015 CLK_UNIT(parse->peer), in parse_process()
4022 if (PARSE_PPS(parsetime->parse_state) && CLK_PPS(parse->peer)) in parse_process()
4025 double ppsphaseadjust = parse->ppsphaseadjust; in parse_process()
4031 if (parse->atom.pps_params.mode & (PPS_OFFSETCLEAR|PPS_OFFSETASSERT)) in parse_process()
4038 * we have a PPS signal - much better than the RS232 stuff (we hope) in parse_process()
4040 offset = parsetime->parse_ptime.fp; in parse_process()
4045 CLK_UNIT(parse->peer), in parse_process()
4048 if (PARSE_TIMECODE(parsetime->parse_state)) in parse_process()
4050 if (M_ISGEQ(off.l_i, off.l_uf, -1, 0x80000000) && in parse_process()
4056 * RS232 offsets within [-0.5..0.5[ - take PPS offsets in parse_process()
4059 if (parse->parse_type->cl_flags & PARSE_F_PPSONSECOND) in parse_process()
4070 off.l_uf = ~off.l_uf; /* map [0.5..1[ -> [-0.5..0[ */ in parse_process()
4071 off.l_i = (off.l_uf & 0x80000000) ? -1 : 0; /* sign extend */ in parse_process()
4076 * time code describes pulse in parse_process()
4078 reftime = off = parsetime->parse_time.fp; in parse_process()
4091 * Well, no time code to guide us - assume on second pulse in parse_process()
4092 * and pray, that we are within [-0.5..0.5[ in parse_process()
4102 off.l_uf = ~off.l_uf; /* map [0.5..1[ -> [-0.5..0[ */ in parse_process()
4103 off.l_i = (off.l_uf & 0x80000000) ? -1 : 0; /* sign extend */ in parse_process()
4108 if (!PARSE_TIMECODE(parsetime->parse_state)) in parse_process()
4113 if ((parsetime->parse_status & CVT_ADDITIONAL) && in parse_process()
4114 parse->parse_type->cl_message) in parse_process()
4115 parse->parse_type->cl_message(parse, parsetime); in parse_process()
4122 printf("PARSE receiver #%d: Reftime %s, Recvtime %s - final offset %s\n", in parse_process()
4123 CLK_UNIT(parse->peer), in parse_process()
4136 CLK_UNIT(parse->peer), in parse_process()
4141 if ((parsetime->parse_status & CVT_ADDITIONAL) && in parse_process()
4142 parse->parse_type->cl_message) in parse_process()
4143 parse->parse_type->cl_message(parse, parsetime); in parse_process()
4145 if (PARSE_SYNC(parsetime->parse_state)) in parse_process()
4167 if (((current_time - parse->lastsync) > parse->maxunsync) || in parse_process()
4168 (parse->lastsync < parse->lastmissed) || in parse_process()
4169 ((parse->lastsync == 0) && !PARSE_SYNC(parsetime->parse_state)) || in parse_process()
4170 (((parse->parse_type->cl_flags & PARSE_F_POWERUPTRUST) == 0) && in parse_process()
4171 PARSE_POWERUP(parsetime->parse_state))) in parse_process()
4173 parse->generic->leap = LEAP_NOTINSYNC; in parse_process()
4174 parse->lastsync = 0; /* wait for full sync again */ in parse_process()
4178 if (PARSE_LEAPADD(parsetime->parse_state)) in parse_process()
4185 parse->generic->leap = (parse->flags & PARSE_LEAP_DELETE) ? LEAP_DELSECOND : LEAP_ADDSECOND; in parse_process()
4188 if (PARSE_LEAPDEL(parsetime->parse_state)) in parse_process()
4190 parse->generic->leap = LEAP_DELSECOND; in parse_process()
4194 parse->generic->leap = LEAP_NOWARNING; in parse_process()
4198 if (parse->generic->leap != LEAP_NOTINSYNC) in parse_process()
4207 CLK_UNIT(parse->peer), in parse_process()
4213 parse->generic->lastref = reftime; in parse_process()
4215 refclock_process_offset(parse->generic, reftime, rectime, fudge); in parse_process()
4221 if (PARSE_PPS(parsetime->parse_state) && CLK_PPS(parse->peer)) in parse_process()
4223 parse->peer->flags |= (FLAG_PPS | FLAG_TSTAMP_PPS); in parse_process()
4229 parse->peer->flags &= ~(FLAG_PPS | FLAG_TSTAMP_PPS); in parse_process()
4234 * we are in fast startup mode (peer->dist > MAXDISTANCE) in parse_process()
4236 if (!parse->pollneeddata && parse->peer->disp <= MAXDISTANCE) in parse_process()
4239 parse->pollneeddata = 0; in parse_process()
4241 parse->timedata.parse_state &= ~(unsigned)(PARSEB_PPS|PARSEB_S_PPS); in parse_process()
4243 refclock_receive(parse->peer); in parse_process()
4264 * the current date by more than +/- 128 weeks then conversion to a in mk_utcinfo()
4281 + GPS_SEC_BIAS - 1; in mk_utcinfo()
4297 snprintf( t + nc, size - nc, " at UTC midnight at the end of %s, %04i-%02i-%02i", in mk_utcinfo()
4298 daynames[tm->tm_wday], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday ); in mk_utcinfo()
4312 /*------------------------------------------------------------
4313 * gps16x_message - process messages from Meinberg GPS receiver
4321 if (parse->timedata.parse_msglen && parsetime->parse_msg[0] == SOH) in gps16x_message()
4324 unsigned char *bufp = (unsigned char *)parsetime->parse_msg + 1; in gps16x_message()
4331 …mkreadable(msgbuffer, sizeof(msgbuffer), (char *)parsetime->parse_msg, parsetime->parse_msglen, 1); in gps16x_message()
4333 CLK_UNIT(parse->peer), in gps16x_message()
4334 parsetime->parse_msglen, in gps16x_message()
4339 if (header.hdr_csum == mbg_csum(parsetime->parse_msg + 1, 6) && in gps16x_message()
4341 (header.len < sizeof(parsetime->parse_msg) && in gps16x_message()
4360 set_var(&parse->kv, buffer, strlen(buffer)+1, RO|DEF); in gps16x_message()
4394 while (s->flag) in gps16x_message()
4396 if (status & s->flag) in gps16x_message()
4403 p = ap(buffer, sizeof(buffer), p, "%s", (const char *)s->string); in gps16x_message()
4414 set_var(&parse->kv, buffer, strlen(buffer)+1, RO|DEF); in gps16x_message()
4429 set_var(&parse->kv, buffer, sizeof(buffer), RO|DEF); in gps16x_message()
4445 set_var(&parse->kv, buffer, sizeof(buffer), RO|DEF); in gps16x_message()
4480 CLK_UNIT(parse->peer), p); in gps16x_message()
4492 p, ", clock offset at reconnect %c%ld.%07ld s, disconnect time ", in gps16x_message()
4493 (antinfo.delta_t < 0) ? '-' : '+', in gps16x_message()
4509 set_var(&parse->kv, buffer, sizeof(buffer), RO|DEF); in gps16x_message()
4535 set_var(&parse->kv, buffer, sizeof(buffer), RO|COND_DEF); in gps16x_message()
4543 set_var(&parse->kv, buffer, sizeof(buffer), RO|COND_DEF); in gps16x_message()
4551 set_var(&parse->kv, buffer, sizeof(buffer), RO|COND_DEF); in gps16x_message()
4588 case 0x02: cp = "BLOCK IIR-M"; break; in gps16x_message()
4594 if (tmp_val & 0x08) /* A-S is on, P-code is encrypted */ in gps16x_message()
4595 p = ap( buffer, sizeof(buffer), p, ", A-S on" ); in gps16x_message()
4598 set_var(&parse->kv, buffer, sizeof(buffer), RO|COND_DEF); in gps16x_message()
4631 set_var(&parse->kv, buffer, sizeof(buffer), RO|DEF); in gps16x_message()
4655 set_var(&parse->kv, buffer, sizeof(buffer), RO|DEF); in gps16x_message()
4668 CLK_UNIT(parse->peer), in gps16x_message()
4669 header.hdr_csum, mbg_csum(parsetime->parse_msg + 1, 6), in gps16x_message()
4671 …header.data_csum, mbg_csum(bufp, (unsigned)((header.len < sizeof(parsetime->parse_msg)) ? header.l… in gps16x_message()
4678 /*------------------------------------------------------------
4679 * gps16x_poll - query the reciver peridically
4686 struct parseunit *parse = peer->procptr->unitptr; in gps16x_poll()
4706 if (((poll_info_t *)parse->parse_type->cl_data)->rate) in gps16x_poll()
4708 …parse->peer->procptr->nextaction = current_time + ((poll_info_t *)parse->parse_type->cl_data)->rat… in gps16x_poll()
4711 if (sequence[parse->localstate].cmd == (unsigned short)~0) in gps16x_poll()
4712 parse->localstate = 0; in gps16x_poll()
4714 header = sequence + parse->localstate++; in gps16x_poll()
4721 header->hdr_csum = (short)mbg_csum(outp, 6); in gps16x_poll()
4729 mkreadable(buffer, sizeof(buffer), (char *)cmd_buffer, (unsigned)(outp - cmd_buffer), 1); in gps16x_poll()
4730 printf("PARSE receiver #%d: transmitted message #%ld (%d bytes) >%s<\n", in gps16x_poll()
4731 CLK_UNIT(parse->peer), in gps16x_poll()
4732 parse->localstate - 1, in gps16x_poll()
4733 (int)(outp - cmd_buffer), in gps16x_poll()
4738 rtc = (int) write(parse->generic->io.fd, cmd_buffer, (unsigned long)(outp - cmd_buffer)); in gps16x_poll()
4743 …OG_ERR, "PARSE receiver #%d: gps16x_poll: failed to send cmd to clock: %m", CLK_UNIT(parse->peer)); in gps16x_poll()
4746 if (rtc != outp - cmd_buffer) in gps16x_poll()
4749 …d to send cmd incomplete (%d of %d bytes sent)", CLK_UNIT(parse->peer), rtc, (int)(outp - cmd_buff… in gps16x_poll()
4756 /*--------------------------------------------------
4757 * init routine - setup timer
4764 if (((poll_info_t *)parse->parse_type->cl_data)->rate) in gps16x_poll_init()
4766 parse->peer->procptr->action = gps16x_poll; in gps16x_poll_init()
4767 gps16x_poll(parse->peer); in gps16x_poll_init()
4793 /*--------------------------------------------------
4802 const char *ps = ((poll_info_t *)parse->parse_type->cl_data)->string; in poll_dpoll()
4803 long ct = ((poll_info_t *)parse->parse_type->cl_data)->count; in poll_dpoll()
4805 rtc = write(parse->generic->io.fd, ps, ct); in poll_dpoll()
4809 …LOG_ERR, "PARSE receiver #%d: poll_dpoll: failed to send cmd to clock: %m", CLK_UNIT(parse->peer)); in poll_dpoll()
4815 …eceiver #%d: poll_dpoll: failed to send cmd incomplete (%ld of %ld bytes sent)", CLK_UNIT(parse->p… in poll_dpoll()
4820 /*--------------------------------------------------
4828 struct parseunit *parse = peer->procptr->unitptr; in poll_poll()
4830 if (parse->parse_type->cl_poll) in poll_poll()
4831 parse->parse_type->cl_poll(parse); in poll_poll()
4833 if (((poll_info_t *)parse->parse_type->cl_data)->rate) in poll_poll()
4835 …parse->peer->procptr->nextaction = current_time + ((poll_info_t *)parse->parse_type->cl_data)->rat… in poll_poll()
4839 /*--------------------------------------------------
4840 * init routine - setup timer
4847 if (((poll_info_t *)parse->parse_type->cl_data)->rate) in poll_init()
4849 parse->peer->procptr->action = poll_poll; in poll_init()
4850 poll_poll(parse->peer); in poll_init()
4860 /*-------------------------------------------------------------
4861 * trimble TAIP init routine - setup EOL and then do poll_init.
4877 if (TTY_GETATTR(parse->generic->io.fd, &tio) == -1) in trimbletaip_init()
4879 …msyslog(LOG_ERR, "PARSE receiver #%d: trimbletaip_init: tcgetattr(fd, &tio): %m", CLK_UNIT(parse->… in trimbletaip_init()
4886 if (TTY_SETATTR(parse->generic->io.fd, &tio) == -1) in trimbletaip_init()
4888 …g(LOG_ERR, "PARSE receiver #%d: trimbletaip_init: tcsetattr(fd, &tio): %m", CLK_UNIT(parse->peer)); in trimbletaip_init()
4895 /*--------------------------------------------------
4896 * trimble TAIP event routine - reset receiver upon data format trouble
4921 int rtc = (int) write(parse->generic->io.fd, *iv, strlen(*iv)); in trimbletaip_event()
4924 …, "PARSE receiver #%d: trimbletaip_event: failed to send cmd to clock: %m", CLK_UNIT(parse->peer)); in trimbletaip_event()
4932 CLK_UNIT(parse->peer), rtc, (int)strlen(*iv)); in trimbletaip_event()
4942 CLK_UNIT(parse->peer)); in trimbletaip_event()
4956 * The module has a serial I/O port for command/data and a 1 pulse-per-second
4957 * output, about 1 microsecond wide. The leading edge of the pulse is
4959 * the change of the UTC second +/- ~1 microsecond. Some other clocks
4963 * of the PPS pulse for accurate timing. Where it is determined that
4968 * It can use either option for receiving PPS information - the 'ppsclock'
4972 * Config.local. The other option is to use a pulse-stretcher/level-converter
4973 * to convert the PPS pulse into a RS232 start pulse & feed this into another
4985 * the values of data bytes can be anything. The serial interface is RS-422
5022 /*-------------------------------------------------------------------
5027 * float implementation dependend - these must be converted to portable
5068 buf->txt[0] = DLE; in sendcmd()
5069 buf->txt[1] = (u_char)c; in sendcmd()
5070 buf->idx = 2; in sendcmd()
5086 buf->txt[buf->idx++] = DLE; in sendbyte()
5087 buf->txt[buf->idx++] = (u_char)b; in sendbyte()
5096 buf->txt[buf->idx++] = DLE; in sendetx()
5097 buf->txt[buf->idx++] = ETX; in sendetx()
5099 if (write(parse->generic->io.fd, buf->txt, (unsigned long)buf->idx) != buf->idx) in sendetx()
5102 …msyslog(LOG_ERR, "PARSE receiver #%d: sendetx: failed to send cmd to clock: %m", CLK_UNIT(parse->p… in sendetx()
5111 mkreadable(buffer, sizeof(buffer), (char *)buf->txt, (unsigned)buf->idx, 1); in sendetx()
5113 CLK_UNIT(parse->peer), in sendetx()
5114 buf->idx, buffer); in sendetx()
5145 for (i=3; i>=0; i--) in sendflt()
5153 /*--------------------------------------------------
5164 trimble_t *t = parse->localdata; in trimbletsip_setup()
5166 if (t && t->last_reset && in trimbletsip_setup()
5167 ((t->last_reset + TRIMBLE_RESET_HOLDOFF) > current_time)) { in trimbletsip_setup()
5172 t->last_reset = current_time; in trimbletsip_setup()
5210 …OG_ERR, "PARSE receiver #%d: trimbletsip_setup: RECEIVER RE-INITIALIZED (%s)", CLK_UNIT(parse->pee… in trimbletsip_setup()
5215 /*--------------------------------------------------
5223 struct parseunit *parse = peer->procptr->unitptr; in trimble_check()
5224 trimble_t *t = parse->localdata; in trimble_check()
5231 if (current_time > t->last_msg + TRIMBLETSIP_IDLE_TIME) in trimble_check()
5235 poll_poll(parse->peer); /* emit query string and re-arm timer */ in trimble_check()
5237 if (t && t->qtracking) in trimble_check()
5239 u_long oldsats = t->ltrack & ~t->ctrack; in trimble_check()
5241 t->qtracking = 0; in trimble_check()
5242 t->ltrack = t->ctrack; in trimble_check()
5265 /*--------------------------------------------------
5272 { trimble_t *t = parse->localdata; in trimbletsip_end()
5277 parse->localdata = NULL; in trimbletsip_end()
5279 parse->peer->procptr->nextaction = 0; in trimbletsip_end()
5280 parse->peer->procptr->action = NULL; in trimbletsip_end()
5283 /*--------------------------------------------------
5301 if (!parse->localdata) in trimbletsip_init()
5305 t = (trimble_t *)(parse->localdata = emalloc(sizeof(trimble_t))); in trimbletsip_init()
5310 t->last_msg = current_time; in trimbletsip_init()
5314 parse->peer->procptr->action = trimble_check; in trimbletsip_init()
5315 parse->peer->procptr->nextaction = current_time; in trimbletsip_init()
5320 if (TTY_GETATTR(parse->generic->io.fd, &tio) == -1) in trimbletsip_init()
5322 …ver #%d: trimbletsip_init: tcgetattr(%d, &tio): %m", CLK_UNIT(parse->peer), parse->generic->io.fd); in trimbletsip_init()
5327 if ((parse_clockinfo[CLK_TYPE(parse->peer)].cl_lflag & ICANON)) in trimbletsip_init()
5337 if (TTY_SETATTR(parse->generic->io.fd, &tio) == -1) in trimbletsip_init()
5339 …ver #%d: trimbletsip_init: tcsetattr(%d, &tio): %m", CLK_UNIT(parse->peer), parse->generic->io.fd); in trimbletsip_init()
5347 /*------------------------------------------------------------
5348 * trimbletsip_event - handle Trimble events
5349 * simple evente handler - attempt to re-initialize receiver
5438 /*--------------------------------------------------
5439 * trimbletsip_message - process trimble messages
5450 unsigned char *buffer = parsetime->parse_msg; in trimbletsip_message()
5451 unsigned int size = parsetime->parse_msglen; in trimbletsip_message()
5455 (buffer[size-1] != ETX) || in trimbletsip_message()
5456 (buffer[size-2] != DLE)) in trimbletsip_message()
5475 trimble_t *tr = parse->localdata; in trimbletsip_message()
5495 tr->last_msg = current_time; in trimbletsip_message()
5501 t = ap(pbuffer, sizeof(pbuffer), t, "%s=\"", s->varname); in trimbletsip_message()
5509 var_flag = (u_short) s->varmode; in trimbletsip_message()
5541 t = ap(pbuffer, sizeof(pbuffer), t, "-MANUAL, "); in trimbletsip_message()
5543 t = ap(pbuffer, sizeof(pbuffer), t, "-AUTO, "); in trimbletsip_message()
5617 …mkreadable(t, (int)BUFFER_SIZE(pbuffer, t), (char *)&mb(0), (unsigned)(size - 2 - (&mb(0) - buffer… in trimbletsip_message()
5626 "A-to-D Converter Fault", in trimbletsip_message()
5716 ((lat < 0.0) ? (-lat) : (lat))*RTOD, (lat < 0.0 ? 'S' : 'N'), in trimbletsip_message()
5717 ((lng < 0.0) ? (-lng) : (lng))*RTOD, (lng < 0.0 ? 'W' : 'E'), in trimbletsip_message()
5739 ((lat < 0.0) ? (-lat) : (lat))*RTOD, (lat < 0.0 ? 'S' : 'N'), in trimbletsip_message()
5740 ((lng < 0.0) ? (-lng) : (lng))*RTOD, (lng < 0.0 ? 'W' : 'E'), in trimbletsip_message()
5765 t = ap(pbuffer, sizeof(pbuffer), t, "-MANUAL, "); in trimbletsip_message()
5767 t = ap(pbuffer, sizeof(pbuffer), t, "-AUTO, "); in trimbletsip_message()
5782 tr->ctrack |= (1 << (mb(17+i)-1)); in trimbletsip_message()
5787 tr->qtracking = 1; in trimbletsip_message()
5794 t = ap(pbuffer, sizeof(pbuffer), t-2, "[%02d]=\"", mb(0)); /* add index to var name */ in trimbletsip_message()
5834 set_var(&parse->kv, pbuffer, sizeof(pbuffer), var_flag); in trimbletsip_message()
5843 /*--------------------------------------------------
5844 * rawdcf_init_1 - set up modem lines for RAWDCF receivers
5861 if (ioctl(parse->generic->io.fd, TIOCMGET, (caddr_t)&sl232) == -1) in rawdcf_init_1()
5863 …eiver #%d: rawdcf_init_1: WARNING: ioctl(fd, TIOCMGET, [C|T]IOCM_DTR): %m", CLK_UNIT(parse->peer)); in rawdcf_init_1()
5873 if (ioctl(parse->generic->io.fd, TIOCMSET, (caddr_t)&sl232) == -1) in rawdcf_init_1()
5875 …eiver #%d: rawdcf_init_1: WARNING: ioctl(fd, TIOCMSET, [C|T]IOCM_DTR): %m", CLK_UNIT(parse->peer)); in rawdcf_init_1()
5885 …it_1: WARNING: OS interface incapable of setting DTR to power DCF modules", CLK_UNIT(parse->peer)); in rawdcfdtr_init_1()
5890 /*--------------------------------------------------
5891 * rawdcf_init_2 - set up modem lines for RAWDCF receivers
5908 if (ioctl(parse->generic->io.fd, TIOCMGET, (caddr_t)&sl232) == -1) in rawdcf_init_2()
5910 …eiver #%d: rawdcf_init_2: WARNING: ioctl(fd, TIOCMGET, [C|T]IOCM_RTS): %m", CLK_UNIT(parse->peer)); in rawdcf_init_2()
5920 if (ioctl(parse->generic->io.fd, TIOCMSET, (caddr_t)&sl232) == -1) in rawdcf_init_2()
5922 …eiver #%d: rawdcf_init_2: WARNING: ioctl(fd, TIOCMSET, [C|T]IOCM_RTS): %m", CLK_UNIT(parse->peer)); in rawdcf_init_2()
5932 …it_2: WARNING: OS interface incapable of setting RTS to power DCF modules", CLK_UNIT(parse->peer)); in rawdcf_init_2()
5952 * - terminate io bindings before io_closeclock() will close our file descriptor
5958 * support optionally separate PPS devices via /dev/refclockpps-{0..3}
5977 * delay adding refclock to async refclock io after all initializations
5981 * terminate parse io engine after de-registering
6015 * limit re-set rate of trimble clocks
6044 * en- and dis-able HARDPPS in correlation to receiver sync state
6068 * bk sync 20050415 ntp-dev
6071 * bk sync ntp-dev 20041129
6089 * fixed rawdcfdtr_init() -> rawdcf_init_1
6174 * fixed IO handling for non-STREAM IO
6180 * (trimble_check): added periodic checks to facilitate re-initialization
6181 * (trimbletsip_init): made use of EOL character if in non-kernel operation
6244 * Revision information 3.1 - 3.105 from log deleted 1998/04/10 kardel