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