/* * refclock_process - process a sample from the clock * * This routine converts the timecode in the form days, hours, minutes, * seconds and milliseconds/microseconds to internal timestamp format, * then constructs a new entry in the median filter circular buffer. * Return success (1) if the data are correct and consistent with the * converntional calendar. */ int refclock_process( struct refclockproc *pp ) { l_fp offset; /* * Compute the timecode timestamp from the days, hours, minutes, * seconds and milliseconds/microseconds of the timecode. Use * clocktime() for the aggregate seconds and the msec/usec for * the fraction, when present. Note that this code relies on the * filesystem time for the years and does not use the years of * the timecode. */ if (!clocktime(pp->day, pp->hour, pp->minute, pp->second, GMT, pp->lastrec.l_ui, &pp->yearstart, &offset.l_ui)) return (0); if (pp->usec) { TVUTOTSF(pp->usec, offset.l_uf); } else { MSUTOTSF(pp->msec, offset.l_uf); } refclock_process_offset(pp, offset, pp->lastrec, pp->fudgetime1); return (1); }
/* * leitch_receive - receive data from the serial interface on a leitch * clock */ static void leitch_receive( struct recvbuf *rbufp ) { struct leitchunit *leitch = rbufp->recv_peer->procptr->unitptr; #ifdef DEBUG if (debug) fprintf(stderr, "leitch_recieve(%*.*s)\n", rbufp->recv_length, rbufp->recv_length, rbufp->recv_buffer); #endif if (rbufp->recv_length != 7) return; /* The date is return with a trailing newline, discard it. */ switch (leitch->state) { case STATE_IDLE: /* unexpected, discard and resync */ return; case STATE_DATE: if (!leitch_get_date(rbufp,leitch)) { leitch->state = STATE_IDLE; break; } leitch_send(leitch,"T\r"); #ifdef DEBUG if (debug) fprintf(stderr, "%u\n",leitch->yearday); #endif leitch->state = STATE_TIME1; break; case STATE_TIME1: if (!leitch_get_time(rbufp,leitch,1)) { } if (!clocktime(leitch->yearday,leitch->hour,leitch->minute, leitch->second, 1, rbufp->recv_time.l_ui, &leitch->yearstart, &leitch->reftime1.l_ui)) { leitch->state = STATE_IDLE; break; } leitch->reftime1.l_uf = 0; #ifdef DEBUG if (debug) fprintf(stderr, "%lu\n", (u_long)leitch->reftime1.l_ui); #endif MSUTOTSF(leitch->fudge1, leitch->reftime1.l_uf); leitch->codetime1 = rbufp->recv_time; leitch->state = STATE_TIME2; break; case STATE_TIME2: if (!leitch_get_time(rbufp,leitch,2)) { } if (!clocktime(leitch->yearday,leitch->hour,leitch->minute, leitch->second, 1, rbufp->recv_time.l_ui, &leitch->yearstart, &leitch->reftime2.l_ui)) { leitch->state = STATE_IDLE; break; } #ifdef DEBUG if (debug) fprintf(stderr, "%lu\n", (u_long)leitch->reftime2.l_ui); #endif MSUTOTSF(leitch->fudge1, leitch->reftime2.l_uf); leitch->codetime2 = rbufp->recv_time; leitch->state = STATE_TIME3; break; case STATE_TIME3: if (!leitch_get_time(rbufp,leitch,3)) { } if (!clocktime(leitch->yearday,leitch->hour,leitch->minute, leitch->second, GMT, rbufp->recv_time.l_ui, &leitch->yearstart, &leitch->reftime3.l_ui)) { leitch->state = STATE_IDLE; break; } #ifdef DEBUG if (debug) fprintf(stderr, "%lu\n", (u_long)leitch->reftime3.l_ui); #endif MSUTOTSF(leitch->fudge1, leitch->reftime3.l_uf); leitch->codetime3 = rbufp->recv_time; leitch_process(leitch); leitch->state = STATE_IDLE; break; default: msyslog(LOG_ERR, "leitech_receive: invalid state %d unit %d", leitch->state, leitch->unit); } }