Lines Matching +full:up +full:- +full:to

2  * refclock_wwvb - clock driver for Spectracom WWVB and GPS receivers
29 * WWVB clocks have proven vulnerable to high ambient conductive RF
31 * relative to the broadcast signal, while the claimed accuracy of the
36 * The WWVB and GPS clocks should be configured for 24-hour display,
38 * baud rate 9600. If the clock is to used as the source for the IRIG
41 * signature control). The GPS clock can be configured either to respond
42 * to a 'T' poll character or left running continuously.
53 * on-time = first <cr>
65 * on-time = <cr>
80 * but is set to 'L' early in the month of an upcoming UTC leap second
81 * and reset to ' ' on the first day of the following month. The d is
82 * set to 'S' for standard time 'I' on the day preceding a switch to
84 * switch to standard time. The start bit of the first <cr> is
85 * synchronized to the indicated time as returned.
87 * This driver does not need to be told which format is in use - it
89 * makes no attempt to correct for the intrinsic jitter of the radio
99 * reverts to the timecode. If the timecode fails for one or more poll
106 * configuration command is set to 1, the driver will retrieve this
107 * table and write it to the clockstats file when the first timecode
117 #define PRECISION (-13) /* precision assumed (about 100 us) */
118 #define PPS_PRECISION (-13) /* precision assumed (about 100 us) */
164 wwvb_start, /* start up driver */
175 * wwvb_start - open the devices and initialize data for processing
183 register struct wwvbunit *up;
192 fd = refclock_open(&peer->srcadr, device, SPEED232, LDISC_CLK);
199 up = emalloc_zero(sizeof(*up));
200 pp = peer->procptr;
201 pp->io.clock_recv = wwvb_receive;
202 pp->io.srcclock = peer;
203 pp->io.datalen = 0;
204 pp->io.fd = fd;
205 if (!io_addclock(&pp->io)) {
207 pp->io.fd = -1;
208 free(up);
211 pp->unitptr = up;
216 peer->precision = PRECISION;
217 pp->clockdesc = DESCRIPTION;
218 memcpy(&pp->refid, REFID, 4);
224 * wwvb_shutdown - shut down the clock
233 struct wwvbunit * up;
235 pp = peer->procptr;
236 up = pp->unitptr;
237 if (-1 != pp->io.fd)
238 io_closeclock(&pp->io);
239 if (NULL != up)
240 free(up);
245 * wwvb_receive - receive data from the serial interface
252 struct wwvbunit *up;
269 peer = rbufp->recv_peer;
270 pp = peer->procptr;
271 up = pp->unitptr;
272 temp = refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &trtmp);
278 * +-50 us relative to the pps; however, on an unmodified 8170
279 * the start bit can be delayed up to 10 ms. In format 2 the
280 * reading precision is only to the millisecond. Thus, unless
281 * you have a PPS gadget and don't have to have the year, format
283 * Save the timestamp of each <CR> in up->laststamp. Lines with
287 * The preceding <CR> is the on-time character for both formats.
288 * The timestamp provided with non-empty lines corresponds to
294 if (up->prev_eol_cr) {
298 up->laststamp = trtmp;
302 up->prev_eol_cr = !up->prev_eol_cr;
305 pp->lencode = temp;
306 pp->lastrec = up->laststamp;
307 up->laststamp = trtmp;
308 up->prev_eol_cr = TRUE;
311 prettydate(&trtmp), prettydate(&pp->lastrec)));
312 if (L_ISZERO(&pp->lastrec))
316 * We get down to business, check the timecode format and decode
317 * its contents. This code uses the timecode length to determine
323 switch (pp->lencode) {
330 if (sscanf(pp->a_lastcode,
332 &syncchar, &pp->day, &pp->hour, &pp->minute,
333 &pp->second, &tmpchar, &dstchar, &tz) == 8) {
334 pp->nsec = 0;
343 if (sscanf(pp->a_lastcode,
345 &syncchar, &qualchar, &pp->year, &pp->day,
346 &pp->hour, &pp->minute, &pp->second, &pp->nsec,
348 pp->nsec *= 1000000;
357 * WARNING: Undocumented, and the on-time character # is
361 if (sscanf(pp->a_lastcode,
363 &syncchar, &pp->year, &month, &day, &pp->hour,
364 &pp->minute, &pp->second, &dstchar, &leapchar) == 8)
366 pp->day = ymd2yd(pp->year, month, day);
367 pp->nsec = 0;
379 if (up->linect > 0) {
380 up->linect--;
381 record_clock_stats(&peer->srcadr,
382 pp->a_lastcode);
392 * Otherwise, set the leap bits according to the leap character.
399 pp->disp = .001;
400 pp->lastref = pp->lastrec;
404 pp->disp = .01;
408 pp->disp = .1;
412 pp->disp = .5;
416 pp->disp = MAXDISPERSE;
420 pp->disp = MAXDISPERSE;
425 pp->leap = LEAP_NOTINSYNC;
427 pp->leap = LEAP_ADDSECOND;
429 pp->leap = LEAP_NOWARNING;
436 up->tcount++;
437 if (peer->flags & FLAG_PPS)
441 if (!refclock_process_f(pp, pp->fudgetime2))
447 * wwvb_timer - called once per second by the transmit procedure
455 register struct wwvbunit *up;
457 char pollchar; /* character sent to clock */
463 * Time to poll the clock. The Spectracom clock responds to a
469 pp = peer->procptr;
470 up = pp->unitptr;
471 if (up->linect > 0)
475 if (write(pp->io.fd, &pollchar, 1) != 1)
483 if (up->ppsapi_lit &&
484 refclock_pps(peer, &up->atom, pp->sloppyclockflag) > 0) {
485 up->pcount++,
486 peer->flags |= FLAG_PPS;
487 peer->precision = PPS_PRECISION;
494 * wwvb_poll - called by the transmit procedure
502 register struct wwvbunit *up;
506 * Sweep up the samples received since the last poll. If none
509 pp = peer->procptr;
510 up = pp->unitptr;
511 pp->polls++;
517 if (pp->sloppyclockflag & CLK_FLAG4 && pp->hour <
518 (int)up->lasthour)
519 up->linect = MONLIN;
520 up->lasthour = (u_char)pp->hour;
527 if (up->pcount == 0) {
528 peer->flags &= ~FLAG_PPS;
529 peer->precision = PRECISION;
531 if (up->tcount == 0) {
532 pp->coderecv = pp->codeproc;
536 up->pcount = up->tcount = 0;
538 if (pp->coderecv == pp->codeproc) {
544 record_clock_stats(&peer->srcadr, pp->a_lastcode);
547 printf("wwvb: timecode %d %s\n", pp->lencode,
548 pp->a_lastcode);
554 * wwvb_control - fudge parameters have been set or changed
565 register struct wwvbunit *up;
568 pp = peer->procptr;
569 up = pp->unitptr;
571 if (!(pp->sloppyclockflag & CLK_FLAG1)) {
572 if (!up->ppsapi_tried)
574 up->ppsapi_tried = 0;
575 if (!up->ppsapi_lit)
577 peer->flags &= ~FLAG_PPS;
578 peer->precision = PRECISION;
579 time_pps_destroy(up->atom.handle);
580 up->atom.handle = 0;
581 up->ppsapi_lit = 0;
585 if (up->ppsapi_tried)
588 * Light up the PPSAPI interface.
590 up->ppsapi_tried = 1;
591 if (refclock_ppsapi(pp->io.fd, &up->atom)) {
592 up->ppsapi_lit = 1;
597 refnumtoa(&peer->srcadr));