Lines Matching +full:serial +full:- +full:state

2  * refclock_leitch - clock driver for the Leitch CSD-5300 Master Clock
24 * Driver for Leitch CSD-5300 Master Clock System
40 #define PRECISION (-20) /* 1x10-8 */
49 if ((write(A->leitchio.fd,M,sizeof(M)) < 0)) {\
51 fprintf(stderr, "leitch_send: unit %d send failed\n", A->unit); \
53 msyslog(LOG_ERR, "leitch_send: unit %d send failed %m",A->unit);}
56 if ((write(A->leitchio.fd,M,sizeof(M)) < 0)) {\
57 msyslog(LOG_ERR, "leitch_send: unit %d send failed %m",A->unit);}
80 short state; member
125 * leitch_init - initialize internal leitch driver data
139 * leitch_shutdown - shut down a LEITCH clock
153 if (-1 != leitch->leitchio.fd) in leitch_shutdown()
154 io_closeclock(&leitch->leitchio); in leitch_shutdown()
162 * leitch_poll - called by the transmit procedure
172 /* start the state machine rolling */ in leitch_poll()
185 if (leitch->state != STATE_IDLE) { in leitch_poll()
188 leitch->state = STATE_IDLE; in leitch_poll()
191 leitch->state = STATE_DATE; in leitch_poll()
210 if (in->haveflags & CLK_HAVEVAL1) in leitch_control()
211 stratumtouse[unit] = (u_char)(in->fudgeval1); in leitch_control()
212 if (in->haveflags & CLK_HAVEVAL2) in leitch_control()
213 refid[unit] = in->fudgeval2; in leitch_control()
217 peer = (&leitchunits[unit])->peer; in leitch_control()
218 peer->stratum = stratumtouse[unit]; in leitch_control()
219 peer->refid = refid[unit]; in leitch_control()
225 out->type = REFCLK_ATOM_LEITCH; in leitch_control()
226 out->haveflags = CLK_HAVEVAL1 | CLK_HAVEVAL2; in leitch_control()
227 out->fudgeval1 = (int32)stratumtouse[unit]; in leitch_control()
228 out->fudgeval2 = refid[unit]; in leitch_control()
229 out->p_lastcode = ""; in leitch_control()
230 out->clockdesc = LEITCH_DESCRIPTION; in leitch_control()
235 * leitch_start - open the LEITCH devices and initialize data for processing
261 * Open serial port. in leitch_start()
265 if (fd232 == -1) { in leitch_start()
276 * System V serial line parameters (termio interface) in leitch_start()
299 * POSIX serial line parameters (termios interface) in leitch_start()
309 ttyp->c_iflag = IGNBRK|IGNPAR|ICRNL; in leitch_start()
310 ttyp->c_oflag = 0; in leitch_start()
311 ttyp->c_cflag = SPEED232|CS8|CLOCAL|CREAD; in leitch_start()
312 ttyp->c_lflag = ICANON; in leitch_start()
313 ttyp->c_cc[VERASE] = ttyp->c_cc[VKILL] = '\0'; in leitch_start()
328 * 4.3bsd serial line parameters (sgttyb interface) in leitch_start()
352 leitch->peer = peer; in leitch_start()
353 leitch->unit = unit; in leitch_start()
354 leitch->state = STATE_IDLE; in leitch_start()
355 leitch->fudge1 = 15; /* 15ms */ in leitch_start()
357 leitch->leitchio.clock_recv = leitch_receive; in leitch_start()
358 leitch->leitchio.srcclock = peer; in leitch_start()
359 leitch->leitchio.datalen = 0; in leitch_start()
360 leitch->leitchio.fd = fd232; in leitch_start()
361 if (!io_addclock(&leitch->leitchio)) { in leitch_start()
362 leitch->leitchio.fd = -1; in leitch_start()
370 peer->precision = PRECISION; in leitch_start()
371 peer->stratum = stratumtouse[unit]; in leitch_start()
372 peer->refid = refid[unit]; in leitch_start()
385 * leitch_receive - receive data from the serial interface on a leitch
393 struct leitchunit *leitch = rbufp->recv_peer->procptr->unitptr; in leitch_receive()
398 rbufp->recv_length, rbufp->recv_length, in leitch_receive()
399 rbufp->recv_buffer); in leitch_receive()
401 if (rbufp->recv_length != 7) in leitch_receive()
405 switch (leitch->state) { in leitch_receive()
410 leitch->state = STATE_IDLE; in leitch_receive()
416 fprintf(stderr, "%u\n",leitch->yearday); in leitch_receive()
418 leitch->state = STATE_TIME1; in leitch_receive()
423 if (!clocktime(leitch->yearday,leitch->hour,leitch->minute, in leitch_receive()
424 leitch->second, 1, rbufp->recv_time.l_ui, in leitch_receive()
425 &leitch->yearstart, &leitch->reftime1.l_ui)) { in leitch_receive()
426 leitch->state = STATE_IDLE; in leitch_receive()
429 leitch->reftime1.l_uf = 0; in leitch_receive()
432 fprintf(stderr, "%lu\n", (u_long)leitch->reftime1.l_ui); in leitch_receive()
434 MSUTOTSF(leitch->fudge1, leitch->reftime1.l_uf); in leitch_receive()
435 leitch->codetime1 = rbufp->recv_time; in leitch_receive()
436 leitch->state = STATE_TIME2; in leitch_receive()
441 if (!clocktime(leitch->yearday,leitch->hour,leitch->minute, in leitch_receive()
442 leitch->second, 1, rbufp->recv_time.l_ui, in leitch_receive()
443 &leitch->yearstart, &leitch->reftime2.l_ui)) { in leitch_receive()
444 leitch->state = STATE_IDLE; in leitch_receive()
449 fprintf(stderr, "%lu\n", (u_long)leitch->reftime2.l_ui); in leitch_receive()
451 MSUTOTSF(leitch->fudge1, leitch->reftime2.l_uf); in leitch_receive()
452 leitch->codetime2 = rbufp->recv_time; in leitch_receive()
453 leitch->state = STATE_TIME3; in leitch_receive()
458 if (!clocktime(leitch->yearday,leitch->hour,leitch->minute, in leitch_receive()
459 leitch->second, GMT, rbufp->recv_time.l_ui, in leitch_receive()
460 &leitch->yearstart, &leitch->reftime3.l_ui)) { in leitch_receive()
461 leitch->state = STATE_IDLE; in leitch_receive()
466 fprintf(stderr, "%lu\n", (u_long)leitch->reftime3.l_ui); in leitch_receive()
468 MSUTOTSF(leitch->fudge1, leitch->reftime3.l_uf); in leitch_receive()
469 leitch->codetime3 = rbufp->recv_time; in leitch_receive()
471 leitch->state = STATE_IDLE; in leitch_receive()
475 "leitech_receive: invalid state %d unit %d", in leitch_receive()
476 leitch->state, leitch->unit); in leitch_receive()
481 * leitch_process - process a pile of samples from the clock
483 * This routine uses a three-stage median filter to calculate offset and
485 * of the filter (max - min), unless the quality character (format 2) is
486 * non-blank, in which case the dispersion is calculated on the basis of
488 * +-2e-5 according to the radio specifications.
499 off = leitch->reftime1; in leitch_process()
500 L_SUB(&off,&leitch->codetime1); in leitch_process()
501 tmp_fp = leitch->reftime2; in leitch_process()
502 L_SUB(&tmp_fp,&leitch->codetime2); in leitch_process()
505 tmp_fp = leitch->reftime3; in leitch_process()
506 L_SUB(&tmp_fp,&leitch->codetime3); in leitch_process()
511 refclock_receive(leitch->peer); in leitch_process()
545 if (rbufp->recv_length < 6) in leitch_get_date()
547 #undef BAD /* confict: defined as (-1) in AIX sys/param.h */ in leitch_get_date()
548 #define BAD(A) (rbufp->recv_buffer[A] < '0') || (rbufp->recv_buffer[A] > '9') in leitch_get_date()
551 #define ATOB(A) ((rbufp->recv_buffer[A])-'0') in leitch_get_date()
552 leitch->year = ATOB(0)*10 + ATOB(1); in leitch_get_date()
553 leitch->month = ATOB(2)*10 + ATOB(3); in leitch_get_date()
554 leitch->day = ATOB(4)*10 + ATOB(5); in leitch_get_date()
557 if (leitch->month > 12) in leitch_get_date()
559 if (leitch->day > days_in_month[leitch->month-1]) in leitch_get_date()
564 leitch->yearday = leitch->day; in leitch_get_date()
566 while ( i < (leitch->month-1) ) in leitch_get_date()
567 leitch->yearday += days_in_month[i++]; in leitch_get_date()
569 if ((days_per_year((leitch->year>90?1900:2000)+leitch->year)==365) && in leitch_get_date()
570 leitch->month > 2) in leitch_get_date()
571 leitch->yearday--; in leitch_get_date()
588 leitch->hour = ATOB(0)*10 +ATOB(1); in leitch_get_time()
589 leitch->minute = ATOB(2)*10 +ATOB(3); in leitch_get_time()
590 leitch->second = ATOB(4)*10 +ATOB(5); in leitch_get_time()
592 if ((leitch->hour > 23) || (leitch->minute > 60) || in leitch_get_time()
593 (leitch->second > 60)) in leitch_get_time()