Lines Matching refs:ees

55 	if (flags & CLK_FLAG2 && unitinuse) ees->leaphold = 0;
56 ees->dump_vals = flags & CLK_FLAG3;
57 ees->usealldata = flags & CLK_FLAG4;
60 bug->values[0] = (ees->lasttime) ? current_time - ees->lasttime : 0;
61 bug->values[1] = (ees->clocklastgood)?current_time-ees->clocklastgood:0;
62 bug->values[2] = (u_long)ees->status;
63 bug->values[3] = (u_long)ees->lastevent;
64 bug->values[4] = (u_long)ees->reason;
65 bug->values[5] = (u_long)ees->nsamples;
66 bug->values[6] = (u_long)ees->codestate;
67 bug->values[7] = (u_long)ees->day;
68 bug->values[8] = (u_long)ees->hour;
69 bug->values[9] = (u_long)ees->minute;
70 bug->values[10] = (u_long)ees->second;
71 bug->values[11] = (u_long)ees->tz;
72 bug->values[12] = ees->yearstart;
73 bug->values[13] = (ees->leaphold > current_time) ?
74 ees->leaphold - current_time : 0;
78 bug->times[0] = ees->reftime;
79 bug->times[1] = ees->arrvtime;
80 bug->times[2] = ees->lastsampletime;
81 bug->times[3] = ees->offset;
82 bug->times[4] = ees->lowoffset;
83 bug->times[5] = ees->highoffset;
88 bug->times[10]= ees->yearstart, 0;
124 #define EES232 "/dev/ees%d" /* Device to open to read the data */
166 * give offsets into ees->lastcode.
289 #define this_uisec ((ees->arrvtime).l_ui)
290 #define this_sfsec ((ees->arrvtime).l_f)
292 #define LAST_STEPS (sizeof ees->last_steps / sizeof ees->last_steps[0])
329 #define ees_reset(ees) (ees)->nsamples = 0; \
330 (ees)->codestate = EESCS_WAIT
333 #define ees_event(ees, evcode) if ((ees)->status != (u_char)(evcode)) \
334 ees_report_event((ees), (evcode))
350 static void ees_report_event P((struct eesunit *ees, int code));
352 static void ees_process P((struct eesunit *ees));
395 /* msfees_init - initialize internal ees driver data */
434 register struct eesunit *ees;
443 msyslog(LOG_ERR, "ees clock: unit number %d invalid (max %d)",
448 msyslog(LOG_ERR, "ees clock: unit number %d in use", unit);
458 msyslog(LOG_ERR, "ees clock: open of %s failed: %m", eesdev);
465 msyslog(LOG_ERR, "ees clock: ioctl(%s, TIOCEXCL): %m", eesdev);
514 ees = eesunits[unit];
523 ees = eesunits[i];
526 else ees = (struct eesunit *) emalloc(sizeof(struct eesunit));
528 memset((char *)ees, 0, sizeof(struct eesunit));
529 eesunits[unit] = ees;
532 ees->peer = peer;
533 ees->unit = (u_char)unit;
534 ees->timestarted= current_time;
535 ees->ttytype = 0;
536 ees->io.clock_recv= ees_receive;
537 ees->io.srcclock= peer;
538 ees->io.datalen = 0;
539 ees->io.fd = fd232;
556 "ees clock: Push of `%s' and `%s' to %s failed %m",
562 msyslog(LOG_INFO, "I: ees clock: PUSHed %s on %s",
564 ees->ttytype |= T_PPS;
570 if (!io_addclock(&ees->io)) {
572 msyslog(LOG_ERR, "ees clock: io_addclock(%s): %m", eesdev);
591 msyslog(LOG_ERR, "ees clock: %s OK on %d", eesdev, unit);
608 register struct eesunit *ees;
612 "ees clock: INTERNAL ERROR, unit number %d invalid (max %d)",
618 "ees clock: INTERNAL ERROR, unit number %d not in use", unit);
623 ees = eesunits[unit];
624 io_closeclock(&ees->io);
632 struct eesunit *ees,
636 if (ees->status != (u_char)code) {
637 ees->status = (u_char)code;
639 ees->lastevent = (u_char)code;
655 register struct eesunit *ees;
677 ees = (struct eesunit *)rbufp->recv_peer->procptr->unitptr;
684 switch (ees->codestate) {
691 ees->arrvtime = rbufp->recv_time;
692 ees->codestate = EESCS_GOTSOME;
693 ees->lencode = 0;
697 cp = &(ees->lastcode[ees->lencode]);
702 ees->lencode++;
704 if (ees->lencode > LENEESPRT) {
707 "I: ees clock: %d + %d > %d [%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x]",
708 ees->lencode, dpend - dpt, LENEESPRT,
709 #define D(x) (ees->lastcode[x])
713 ees->badformat++;
714 ees->reason = CODEREASON + 1;
715 ees_event(ees, CEVNT_BADREPLY);
716 ees_reset(ees);
725 "I: ees clock %d: %p == %p: await more",
726 ees->unit, dpt, dpend);
732 msyslog(LOG_INFO, "I: ees clock: %0x & 0x7f != 0x7f", *dpt);
733 ees->badformat++;
734 ees->reason = CODEREASON + 2;
735 ees_event(ees, CEVNT_BADREPLY);
736 ees_reset(ees);
745 cp = ees->lastcode;
749 msyslog(LOG_ERR, "ees clock: INTERNAL ERROR: %d state %d",
750 ees->unit, ees->codestate);
751 ees->reason = CODEREASON + 5;
752 ees_event(ees, CEVNT_FAULT);
753 ees_reset(ees);
761 ees->codestate = EESCS_WAIT;
762 ees->lasttime = current_time;
763 if (ees->lencode != LENEESPRT) {
764 ees->badformat++;
765 ees->reason = CODEREASON + 6;
766 ees_event(ees, CEVNT_BADREPLY);
767 ees_reset(ees);
771 cp = ees->lastcode;
775 ees->baddata++;
776 ees->reason = CODEREASON + 7;
777 ees_event(ees, CEVNT_BADREPLY);
778 ees_reset(ees);
784 ees->badformat++;
785 ees->reason = CODEREASON + 8;
786 ees_event(ees, CEVNT_BADREPLY);
787 ees_reset(ees);
792 ees->badformat++;
793 ees->reason = CODEREASON + 9;
794 ees_event(ees, CEVNT_BADREPLY);
795 ees_reset(ees);
800 ees->badformat++;
801 ees->reason = CODEREASON + 10;
802 ees_event(ees, CEVNT_BADREPLY);
803 ees_reset(ees);
814 ees->second = bcdunpack(cp[EESM_SEC]); /* second */
815 ees->minute = bcdunpack(cp[EESM_MIN]); /* minute */
816 ees->hour = bcdunpack(cp[EESM_HOUR]); /* hour */
838 default: ees->baddata++;
839 ees->reason = CODEREASON + 11;
840 ees_event(ees, CEVNT_BADDATE);
841 ees_reset(ees);
845 ees->day = day;
853 ees->tz = istrue(cp[EESM_BST]) ? -1 : 0;
855 if (ees->day > 366 || ees->day < 1 ||
856 ees->hour > 23 || ees->minute > 59 || ees->second > 59) {
857 ees->baddata++;
858 ees->reason = CODEREASON + 12;
859 ees_event(ees, CEVNT_BADDATE);
860 ees_reset(ees);
864 n_sample = ees->nsamples;
867 if (!clocktime(ees->day, ees->hour, ees->minute, ees->second,
868 ees->tz, rbufp->recv_time.l_ui, &ees->yearstart,
870 ees->baddata++;
871 ees->reason = CODEREASON + 13;
872 ees_event(ees, CEVNT_BADDATE);
873 ees_reset(ees);
878 /* DON'T use ees->arrvtime -- it may be < reftime */
879 ees->lastsampletime = tmp;
885 ees->reftime = tmp;
886 ees->clocklastgood = current_time;
893 ees->codeoffsets[n_sample].l_ui = tmp.l_ui;
894 ees->codeoffsets[n_sample].l_uf = 0;
897 sincelast = this_uisec - ees->last_step;
901 rc = ioctl(ees->io.fd, request, (char *) &ppsclockev);
904 DB_PRINT_EV, ees->unit, ees->io.fd, request, is_pps(ees),
910 pps_step = ppsclockev.serial - ees->last_pps_no;
913 if (pps_step == 2) msyslog(LOG_ERR, "pps step = 2 @ %02d", ees->second);
914 if (pps_step == 2 && ees->second == 1) suspect_4ms_step |= 1;
915 if (pps_step == 2 && ees->second == 2) suspect_4ms_step |= 4;
920 ppsclockev.serial, ees->last_pps_no, pps_step);
929 L_SUB(&diff, &ees->arrvtime);
932 DB_PRINT_CDT, (long)ees->arrvtime.l_ui, (long)ees->arrvtime.l_uf,
939 ees->arrvtime = pps_arrvstamp;
944 else if (ees->second == 1) {
947 L_SUB(&diff, &ees->arrvtime);
951 pps_arrvstamp.l_ui - ees->arrvtime.l_ui,
953 ees->arrvtime.l_uf,
959 ees->arrvtime = pps_arrvstamp;
960 L_ADD(&ees->arrvtime, &onesec);
966 ees->last_pps_no = ppsclockev.serial;
971 (long)pps_arrvstamp.l_uf, conv, ees->unit,
982 delta.l_i = ees->arrvtime.l_i;
983 delta.l_f = ees->arrvtime.l_f;
985 L_SUB(&delta, &ees->last_l);
992 if (/*0 <= ees->second && */
993 ees->second < COUNTOF(deltas))
994 deltas[ees->second] = delta_sfsec;
996 if (ees->second == 1) {
1017 (ees->second == 0 || ees->second == 1 || ees->second == 2) &&
1024 if (ees->last_step == 0) sincelast = 0;
1027 /* First time in, just set "ees->last_step" */
1028 if(ees->last_step) {
1032 int p_step = ees->this_step;
1034 ees->last_steps[p_step] = this_step;
1038 ees->this_step = p_step;
1041 int this = ees->last_steps[p];
1072 msyslog(LOG_ERR, "MSF%d: %d: This=%d (%d), other=%d/%d, sum=%d, count=%d, pps_step=%d, suspect=%x", ees->unit, p, ees->last_steps[p], this_step, other_step, third_step, sum, count, pps_step, suspect_4ms_step);
1074 #define SV(x) (ees->last_steps[(x + p_step) % LAST_STEPS])
1076 ees->unit, suspect_4ms_step, p_step, SV(0), SV(1), SV(2), SV(3), SV(4), SV(5), SV(6),
1079 ees->unit, p_step, SV(0), SV(1), SV(2), SV(3), SV(4), SV(5), SV(6),
1082 ees->jump_fsecs = delta_sfsec;
1083 ees->using_ramp = 1;
1085 ees->last_step_late += sincelast - ((sum) ? sum : ees->last_step_secs);
1086 else ees->last_step_late = 30;
1087 if (ees->last_step_late < -60 || ees->last_step_late > 120) ees->last_step_late = 30;
1088 if (ees->last_step_late < 0) ees->last_step_late = 0;
1089 if (ees->last_step_late >= 60) ees->last_step_late = 59;
1093 ees->last_step_late = 30;
1094 ees->jump_fsecs = delta_sfsec;
1095 ees->using_ramp = 1;
1098 ees->last_step = this_uisec;
1100 ees->unit, (long)msec(delta_sfsec), (long)subms(delta_sfsec),
1101 ees->second, old_sincelast, ees->last_step_late, count, sum,
1102 ees->last_step_secs);
1104 ees->unit, msec(delta_sfsec), subms(delta_sfsec), ees->second,
1105 old_sincelast, ees->last_step_late, count, sum, ees->last_step_secs);
1106 if (sum) ees->last_step_secs = sum;
1112 ees->unit, suspect_4ms_step, msec(delta_sfsec), subms(delta_sfsec),
1119 ees->second,
1121 if ((delta_f_abs > EES_STEP_NOTE) && ees->last_l.l_i) {
1126 ees->unit, (long)msec(delta_sfsec), (long)subms(delta_sfsec),
1127 ees->second, sincelast, ees_step_notes ? "" : " -- NO MORE !");
1129 ees->unit, msec(delta_sfsec), subms(delta_sfsec), ees->second, (ees->last_step) ? sincelast : -1, ees_step_notes ? "" : " -- NO MORE !");
1134 ees->last_l = ees->arrvtime;
1141 if (ees->using_ramp &&
1142 sincelast < (ees->last_step_secs)*2 &&
1143 ees->last_step_secs)
1144 { long sec_of_ramp = sincelast + ees->last_step_late;
1149 if (sec_of_ramp > (ees->last_step_secs + 120))
1150 sec_of_ramp = ees->last_step_secs;
1152 /* sec_of_ramp * ees->jump_fsecs may overflow 2**32 */
1153 fsecs = sec_of_ramp * (ees->jump_fsecs / ees->last_step_secs);
1158 ees->unit, sec_of_ramp, ees->last_step_secs, fsecs,
1162 ees->unit, sec_of_ramp, ees->last_step_secs, fsecs,
1170 L_SUB(&ees->arrvtime, &inc);
1174 L_ADD(&ees->arrvtime, &inc);
1179 "[%x] MSF%d: ees->using_ramp=%d, sincelast=%x / %x, ees->last_step_secs=%x",
1181 ees->unit, ees->using_ramp,
1183 (ees->last_step_secs)*2,
1184 ees->last_step_secs);
1186 "[%x] MSF%d: ees->using_ramp=%d, sincelast=%x / %x, ees->last_step_secs=%x\n",
1188 ees->unit, ees->using_ramp,
1190 (ees->last_step_secs)*2,
1191 ees->last_step_secs);
1194 L_SUB(&ees->arrvtime, &offset_fudge[ees->unit]);
1195 L_SUB(&pps_arrvstamp, &offset_fudge[ees->unit]);
1209 L_SUB(&ees->codeoffsets[n_sample], &ees->arrvtime);
1211 "MSF%d: [%x] %d (ees: %d %d) (pps: %d %d)%s",
1212 ees->unit, DB_LOG_DELTAS, n_sample,
1213 ees->codeoffsets[n_sample].l_f,
1214 ees->codeoffsets[n_sample].l_f / 4295,
1219 if (ees->nsamples++ == NCODES-1) ees_process(ees);
1242 struct eesunit *ees
1248 register l_fp *coffs = ees->codeoffsets;
1252 int samples = ees->nsamples;
1258 ees_reset(ees);
1260 if (sloppyclockflag[ees->unit]) {
1278 if (ees->dump_vals)
1301 if (ees->dump_vals) dump_buf(coffs, i, noff, "Reduced to:");
1307 if (sloppyclockflag[ees->unit]) {
1332 (sloppyclockflag[ees->unit]) ? " by averaging" : "",
1347 if (ees->usealldata && ees->offset.l_uf) {
1348 long diff = (long) (ees->offset.l_uf - offset.l_uf);
1387 ees->usealldata, ees->offset.l_f, ees->offset.l_uf,
1388 offset.l_f, ees->offset.l_f - offset.l_f);
1391 ees->offset = offset;
1392 ees->lowoffset = coffs[i];
1393 ees->highoffset = coffs[noff-1];
1407 lostsync = current_time - ees->clocklastgood > 300 ? 1 : 0;
1408 isinsync = (lostsync || ees->leaphold > current_time) ? 0 : 1;
1413 if (ees->fix_pending) {
1415 ees->fix_pending, ees->unit, offset.l_i, offset.l_f);
1416 ees->fix_pending = 0;
1419 refclock_receive(ees->peer);
1420 ees_event(ees, lostsync ? CEVNT_PROP : CEVNT_NOMINAL);
1431 msyslog(LOG_ERR, "ees clock poll: INTERNAL: unit %d invalid",
1436 msyslog(LOG_ERR, "ees clock poll: INTERNAL: unit %d unused",