Lines Matching +full:double +full:- +full:channel
2 * refclock_chu - clock driver for Canadian CHU time/frequency station
44 * kHz and mu-law companding. This is the same standard as used by the
57 * maximum-likelihood technique which exploits the considerable degree
62 * consists of nine, ten-character bursts transmitted at 300 bps between
87 * the DUT1 (d in deciseconds), Gregorian year (yyyy), difference TAI -
101 * coincides with 0.5 - 9 * 11/300 = 0.170 second. Depending on the
110 * connections. With debugging enabled (-d on the ntpd command line),
113 * chuA or chuB followed by the status code and signal level (0-9999).
120 * where n is the number of characters in the burst (0-10), b the burst
121 * distance (0-40), f the field alignment (-1, 0, 1), s the
122 * synchronization distance (0-16), m the burst number (2-9) and code
130 * The nibble-swapped timecode shows day 58, hour 21, minute 29 and
137 * where n is the number of characters in the burst (0-10), b the burst
138 * distance (0-40), s the synchronization distance (0-40) and code the
145 * The nibble-swapped timecode shows DUT1 +0.1 second, year 1998 and TAI
146 * - UTC 31 seconds.
149 * the audio driver is compiled, the current gain (0-255) and relative
150 * signal level (0-9999) follow the code. The receiver volume control
152 * range 0-255, which results in a signal level near 1000.
168 * agc audio gain (0 - 255)
170 * m signal metric (0 - 100)
171 * b number of timecodes for the previous minute (0 - 59)
182 * (default) and 1 is the line-in port. It does not seem useful to
196 * specifies a nonzero mode (ICOM ID select code). The C-IV speed is
198 * if one. The C-IV trace is turned on if the debug level is greater
204 * CEVNT_PROP propagation failure - no stations heard
210 #define PRECISION (-10) /* precision assumed (about 1 ms) */
251 #define MINMETRIC 50 /* min channel metric (of 160) */
254 * The on-time synchronization point for the driver is the last stop bit
262 * The resulting offsets with a 2.4-GHz P4 running FreeBSD 6.1 are
263 * generally within 0.5 ms short term with 0.3 ms jitter. The long-term
301 * Maximum-likelihood UART structure. There are eight of these
306 double shift[12]; /* sample shift register */
307 double span; /* shift register envelope span */
308 double dist; /* sample distance */
319 double integ[ISTAGE]; /* circular integrator */
320 double metric; /* integrator sum */
330 u_char decode[20][16]; /* maximum-likelihood decoding matrix */
339 char ident[5]; /* station ID and channel */
342 int chan; /* radio channel */
357 double maxsignal; /* signal level (modem only) */
365 int tai; /* TAI - UTC correction */
373 double comp[SIZE]; /* decompanding table */
383 double bpf[9]; /* IIR bandpass filter */
384 double disc[LAG]; /* discriminator shift register */
385 double lpf[27]; /* FIR lowpass filter */
386 double monitor; /* audio monitor */
390 * Maximum-likelihood UART variables
392 double baud; /* baud interval */
418 static double chu_major (struct peer *);
420 static void chu_uart (struct surv *, double);
421 static void chu_rf (struct peer *, double);
426 static int chu_newchan (struct peer *, double);
441 static double qsy[NCHAN] = {3.330, 7.850, 14.670}; /* freq (MHz) */
459 * chu_start - open the devices and initialize data for processing
477 double step; /* codec adjustment */ in chu_start()
496 fd = refclock_open(&peer->srcadr, device, SPEED232, LDISC_RAW); in chu_start()
504 fd = refclock_open(&peer->srcadr, device, SPEED232, LDISC_RAW); in chu_start()
514 pp = peer->procptr; in chu_start()
515 pp->unitptr = up; in chu_start()
516 pp->io.clock_recv = chu_receive; in chu_start()
517 pp->io.srcclock = peer; in chu_start()
518 pp->io.datalen = 0; in chu_start()
519 pp->io.fd = fd; in chu_start()
520 if (!io_addclock(&pp->io)) { in chu_start()
522 pp->io.fd = -1; in chu_start()
524 pp->unitptr = NULL; in chu_start()
531 peer->precision = PRECISION; in chu_start()
532 pp->clockdesc = DESCRIPTION; in chu_start()
533 strlcpy(up->ident, "CHU", sizeof(up->ident)); in chu_start()
534 memcpy(&pp->refid, up->ident, 4); in chu_start()
535 DTOLFP(CHAR, &up->charstamp); in chu_start()
539 * The companded samples are encoded sign-magnitude. The table in chu_start()
543 up->fd_audio = fd_audio; in chu_start()
544 up->gain = 127; in chu_start()
545 up->comp[0] = up->comp[OFFSET] = 0.; in chu_start()
546 up->comp[1] = 1; up->comp[OFFSET + 1] = -1.; in chu_start()
547 up->comp[2] = 3; up->comp[OFFSET + 2] = -3.; in chu_start()
550 up->comp[i] = up->comp[i - 1] + step; in chu_start()
551 up->comp[OFFSET + i] = -up->comp[i]; in chu_start()
555 DTOLFP(1. / SECOND, &up->tick); in chu_start()
563 if (peer->ttl > 0) { in chu_start()
564 if (peer->ttl & 0x80) in chu_start()
565 up->fd_icom = icom_init("/dev/icom", B1200, in chu_start()
568 up->fd_icom = icom_init("/dev/icom", B9600, in chu_start()
571 if (up->fd_icom > 0) { in chu_start()
574 close(up->fd_icom); in chu_start()
575 up->fd_icom = 0; in chu_start()
586 * chu_shutdown - shut down the clock
597 pp = peer->procptr; in chu_shutdown()
598 up = pp->unitptr; in chu_shutdown()
602 io_closeclock(&pp->io); in chu_shutdown()
604 if (up->fd_icom > 0) in chu_shutdown()
605 close(up->fd_icom); in chu_shutdown()
612 * chu_receive - receive data from the audio or serial device
624 peer = rbufp->recv_peer; in chu_receive()
625 pp = peer->procptr; in chu_receive()
626 up = pp->unitptr; in chu_receive()
636 if (up->fd_audio > 0) in chu_receive()
648 * chu_audio_receive - receive data from the audio device
659 double sample; /* codec sample */ in chu_audio_receive()
664 peer = rbufp->recv_peer; in chu_audio_receive()
665 pp = peer->procptr; in chu_audio_receive()
666 up = pp->unitptr; in chu_audio_receive()
669 * Main loop - read until there ain't no more. Note codec in chu_audio_receive()
670 * samples are bit-inverted. in chu_audio_receive()
672 DTOLFP((double)rbufp->recv_length / SECOND, <emp); in chu_audio_receive()
673 L_SUB(&rbufp->recv_time, <emp); in chu_audio_receive()
674 up->timestamp = rbufp->recv_time; in chu_audio_receive()
675 dpt = rbufp->recv_buffer; in chu_audio_receive()
676 for (bufcnt = 0; bufcnt < rbufp->recv_length; bufcnt++) { in chu_audio_receive()
677 sample = up->comp[~*dpt++ & 0xff]; in chu_audio_receive()
686 up->clipcnt++; in chu_audio_receive()
687 } else if (sample < -MAXAMP) { in chu_audio_receive()
688 sample = -MAXAMP; in chu_audio_receive()
689 up->clipcnt++; in chu_audio_receive()
692 L_ADD(&up->timestamp, &up->tick); in chu_audio_receive()
697 up->seccnt = (up->seccnt + 1) % SECOND; in chu_audio_receive()
698 if (up->seccnt == 0) { in chu_audio_receive()
706 if (pp->sloppyclockflag & CLK_FLAG2) in chu_audio_receive()
707 up->port = 2; in chu_audio_receive()
709 up->port = 1; in chu_audio_receive()
710 if (pp->sloppyclockflag & CLK_FLAG3) in chu_audio_receive()
711 up->mongain = MONGAIN; in chu_audio_receive()
713 up->mongain = 0; in chu_audio_receive()
718 * chu_rf - filter and demodulate the FSK signal
720 * This routine implements a 300-baud Bell 103 modem with mark 2225 Hz
722 * limiter, FM discriminator and lowpass filter. A maximum-likelihood
727 * code. Hopefully, the compiler will efficiently implement the move-
728 * and-muiltiply-and-add operations.
733 double sample /* analog sample */ in chu_rf()
743 double signal; /* bandpass signal */ in chu_rf()
744 double limit; /* limiter signal */ in chu_rf()
745 double disc; /* discriminator signal */ in chu_rf()
746 double lpf; /* lowpass signal */ in chu_rf()
747 double dist; /* UART signal distance */ in chu_rf()
750 pp = peer->procptr; in chu_rf()
751 up = pp->unitptr; in chu_rf()
754 * Bandpass filter. 4th-order elliptic, 500-Hz bandpass centered in chu_rf()
758 signal = (up->bpf[8] = up->bpf[7]) * 5.844676e-01; in chu_rf()
759 signal += (up->bpf[7] = up->bpf[6]) * 4.884860e-01; in chu_rf()
760 signal += (up->bpf[6] = up->bpf[5]) * 2.704384e+00; in chu_rf()
761 signal += (up->bpf[5] = up->bpf[4]) * 1.645032e+00; in chu_rf()
762 signal += (up->bpf[4] = up->bpf[3]) * 4.644557e+00; in chu_rf()
763 signal += (up->bpf[3] = up->bpf[2]) * 1.879165e+00; in chu_rf()
764 signal += (up->bpf[2] = up->bpf[1]) * 3.522634e+00; in chu_rf()
765 signal += (up->bpf[1] = up->bpf[0]) * 7.315738e-01; in chu_rf()
766 up->bpf[0] = sample - signal; in chu_rf()
767 signal = up->bpf[0] * 6.176213e-03 in chu_rf()
768 + up->bpf[1] * 3.156599e-03 in chu_rf()
769 + up->bpf[2] * 7.567487e-03 in chu_rf()
770 + up->bpf[3] * 4.344580e-03 in chu_rf()
771 + up->bpf[4] * 1.190128e-02 in chu_rf()
772 + up->bpf[5] * 4.344580e-03 in chu_rf()
773 + up->bpf[6] * 7.567487e-03 in chu_rf()
774 + up->bpf[7] * 3.156599e-03 in chu_rf()
775 + up->bpf[8] * 6.176213e-03; in chu_rf()
777 up->monitor = signal / 4.; /* note monitor after filter */ in chu_rf()
780 * Soft limiter/discriminator. The 11-sample discriminator lag in chu_rf()
783 * Hz. The discriminator output varies +-0.5 interval for input in chu_rf()
784 * frequency 2025-2225 Hz. However, we don't get to sample at in chu_rf()
791 else if (limit < -LIMIT) in chu_rf()
792 limit = -LIMIT; in chu_rf()
793 disc = up->disc[up->discptr] * -limit; in chu_rf()
794 up->disc[up->discptr] = limit; in chu_rf()
795 up->discptr = (up->discptr + 1 ) % LAG; in chu_rf()
799 disc = -SQRT(-disc); in chu_rf()
804 lpf = (up->lpf[26] = up->lpf[25]) * 2.538771e-02; in chu_rf()
805 lpf += (up->lpf[25] = up->lpf[24]) * 1.084671e-01; in chu_rf()
806 lpf += (up->lpf[24] = up->lpf[23]) * 2.003159e-01; in chu_rf()
807 lpf += (up->lpf[23] = up->lpf[22]) * 2.985303e-01; in chu_rf()
808 lpf += (up->lpf[22] = up->lpf[21]) * 4.003697e-01; in chu_rf()
809 lpf += (up->lpf[21] = up->lpf[20]) * 5.028552e-01; in chu_rf()
810 lpf += (up->lpf[20] = up->lpf[19]) * 6.028795e-01; in chu_rf()
811 lpf += (up->lpf[19] = up->lpf[18]) * 6.973249e-01; in chu_rf()
812 lpf += (up->lpf[18] = up->lpf[17]) * 7.831828e-01; in chu_rf()
813 lpf += (up->lpf[17] = up->lpf[16]) * 8.576717e-01; in chu_rf()
814 lpf += (up->lpf[16] = up->lpf[15]) * 9.183463e-01; in chu_rf()
815 lpf += (up->lpf[15] = up->lpf[14]) * 9.631951e-01; in chu_rf()
816 lpf += (up->lpf[14] = up->lpf[13]) * 9.907208e-01; in chu_rf()
817 lpf += (up->lpf[13] = up->lpf[12]) * 1.000000e+00; in chu_rf()
818 lpf += (up->lpf[12] = up->lpf[11]) * 9.907208e-01; in chu_rf()
819 lpf += (up->lpf[11] = up->lpf[10]) * 9.631951e-01; in chu_rf()
820 lpf += (up->lpf[10] = up->lpf[9]) * 9.183463e-01; in chu_rf()
821 lpf += (up->lpf[9] = up->lpf[8]) * 8.576717e-01; in chu_rf()
822 lpf += (up->lpf[8] = up->lpf[7]) * 7.831828e-01; in chu_rf()
823 lpf += (up->lpf[7] = up->lpf[6]) * 6.973249e-01; in chu_rf()
824 lpf += (up->lpf[6] = up->lpf[5]) * 6.028795e-01; in chu_rf()
825 lpf += (up->lpf[5] = up->lpf[4]) * 5.028552e-01; in chu_rf()
826 lpf += (up->lpf[4] = up->lpf[3]) * 4.003697e-01; in chu_rf()
827 lpf += (up->lpf[3] = up->lpf[2]) * 2.985303e-01; in chu_rf()
828 lpf += (up->lpf[2] = up->lpf[1]) * 2.003159e-01; in chu_rf()
829 lpf += (up->lpf[1] = up->lpf[0]) * 1.084671e-01; in chu_rf()
830 lpf += up->lpf[0] = disc * 2.538771e-02; in chu_rf()
833 * Maximum-likelihood decoder. The UART updates each of the in chu_rf()
835 * tentative decoded character. Valid 11-bit characters are in chu_rf()
841 up->baud += 1. / SECOND; in chu_rf()
842 if (up->baud > 1. / (BAUD * 8.)) { in chu_rf()
843 up->baud -= 1. / (BAUD * 8.); in chu_rf()
844 up->decptr = (up->decptr + 1) % 8; in chu_rf()
845 sp = &up->surv[up->decptr]; in chu_rf()
846 sp->cstamp = up->timestamp; in chu_rf()
847 chu_uart(sp, -lpf * AGAIN); in chu_rf()
848 if (up->dbrk > 0) { in chu_rf()
849 up->dbrk--; in chu_rf()
850 if (up->dbrk > 0) in chu_rf()
853 up->decpha = up->decptr; in chu_rf()
855 if (up->decptr != up->decpha) in chu_rf()
859 j = -1; in chu_rf()
867 if ((up->surv[i].uart & 0x601) != 0x600 || in chu_rf()
868 up->surv[i].span < SPAN) in chu_rf()
871 if (up->surv[i].dist > dist) { in chu_rf()
872 dist = up->surv[i].dist; in chu_rf()
885 up->maxsignal = up->surv[j].span; in chu_rf()
886 chu_decode(peer, (up->surv[j].uart >> 1) & 0xff, in chu_rf()
887 up->surv[j].cstamp); in chu_rf()
888 up->dbrk = 88; in chu_rf()
894 * chu_uart - maximum-likelihood UART
905 double sample /* baseband signal */ in chu_uart()
908 double es_max, es_min; /* max/min envelope */ in chu_uart()
909 double slice; /* slice level */ in chu_uart()
910 double dist; /* distance */ in chu_uart()
911 double dtemp; in chu_uart()
918 es_max = -1e6; in chu_uart()
920 sp->shift[0] = sample; in chu_uart()
921 for (i = 11; i > 0; i--) { in chu_uart()
922 sp->shift[i] = sp->shift[i - 1]; in chu_uart()
923 if (sp->shift[i] > es_max) in chu_uart()
924 es_max = sp->shift[i]; in chu_uart()
925 if (sp->shift[i] < es_min) in chu_uart()
926 es_min = sp->shift[i]; in chu_uart()
937 sp->span = es_max - es_min; in chu_uart()
938 slice = es_min + .45 * sp->span; in chu_uart()
940 sp->uart = 0; in chu_uart()
942 sp->uart <<= 1; in chu_uart()
943 dtemp = sp->shift[i]; in chu_uart()
945 sp->uart |= 0x1; in chu_uart()
947 dist += dtemp - es_min; in chu_uart()
949 dist += es_max - dtemp; in chu_uart()
952 dist += dtemp - es_min; in chu_uart()
954 dist += es_max - dtemp; in chu_uart()
957 sp->dist = dist / (11 * sp->span); in chu_uart()
963 * chu_serial_receive - receive data from the serial device
974 peer = rbufp->recv_peer; in chu_serial_receive()
976 dpt = (u_char *)&rbufp->recv_space; in chu_serial_receive()
977 chu_decode(peer, *dpt, rbufp->recv_time); in chu_serial_receive()
982 * chu_decode - decode the character data
995 double dtemp; in chu_decode()
997 pp = peer->procptr; in chu_decode()
998 up = pp->unitptr; in chu_decode()
1006 tstmp = up->timestamp; in chu_decode()
1007 if (L_ISZERO(&up->laststamp)) in chu_decode()
1008 up->laststamp = up->timestamp; in chu_decode()
1009 L_SUB(&tstmp, &up->laststamp); in chu_decode()
1010 up->laststamp = up->timestamp; in chu_decode()
1014 up->ndx = 0; in chu_decode()
1016 up->ndx = 0; in chu_decode()
1023 if (up->ndx < BURST) { in chu_decode()
1024 up->cbuf[up->ndx] = hexhex & 0xff; in chu_decode()
1025 up->cstamp[up->ndx] = cstamp; in chu_decode()
1026 up->ndx++; in chu_decode()
1033 * chu_burst - search for valid burst format
1045 pp = peer->procptr; in chu_burst()
1046 up = pp->unitptr; in chu_burst()
1054 if (up->ndx < MINCHARS) { in chu_burst()
1055 up->status |= RUNT; in chu_burst()
1058 up->burdist = 0; in chu_burst()
1059 for (i = 0; i < 5 && i < up->ndx - 5; i++) in chu_burst()
1060 up->burdist += chu_dist(up->cbuf[i], up->cbuf[i + 5]); in chu_burst()
1064 * format A burst; if the value is not greater than -MINDIST, it in chu_burst()
1069 if (up->burdist >= MINDIST) { in chu_burst()
1070 chu_a(peer, up->ndx); in chu_burst()
1071 } else if (up->burdist <= -MINDIST) { in chu_burst()
1072 chu_b(peer, up->ndx); in chu_burst()
1074 up->status |= NOISE; in chu_burst()
1084 if (peer->outdate != current_time) in chu_burst()
1085 peer->nextdate = current_time + 10; in chu_burst()
1090 * chu_b - decode format B burst
1108 pp = peer->procptr; in chu_b()
1109 up = pp->unitptr; in chu_b()
1119 up->status, up->maxsignal, nchar, -up->burdist); in chu_b()
1128 cb -= chars; in chu_b()
1130 snprintf(p, cb, "%02x", up->cbuf[i]); in chu_b()
1132 if (pp->sloppyclockflag & CLK_FLAG4) in chu_b()
1133 record_clock_stats(&peer->srcadr, tbuf); in chu_b()
1138 if (up->burdist > -40) { in chu_b()
1139 up->status |= BFRAME; in chu_b()
1148 code[2 * i] = hexchar[up->cbuf[i] & 0xf]; in chu_b()
1149 code[2 * i + 1] = hexchar[(up->cbuf[i] >> in chu_b()
1152 if (sscanf((char *)code, "%1x%1d%4d%2d%2x", &up->leap, &up->dut, in chu_b()
1153 &pp->year, &up->tai, &up->dst) != 5) { in chu_b()
1154 up->status |= BFORMAT; in chu_b()
1157 up->status |= BVALID; in chu_b()
1158 if (up->leap & 0x8) in chu_b()
1159 up->dut = -up->dut; in chu_b()
1164 * chu_a - decode format A burst
1184 pp = peer->procptr; in chu_a()
1185 up = pp->unitptr; in chu_a()
1189 * corresponding to in-phase, one character early or one in chu_a()
1196 up->syndist = k = 0; in chu_a()
1197 // val = -16; in chu_a()
1198 for (i = -1; i < 2; i++) { in chu_a()
1199 temp = up->cbuf[i + 4] & 0xf; in chu_a()
1201 temp |= (up->cbuf[i] & 0xf) << 4; in chu_a()
1203 temp = (up->cbuf[i + 5] & 0xf) << 4; in chu_a()
1205 temp |= up->cbuf[i + 9] & 0xf; in chu_a()
1207 if (val > up->syndist) { in chu_a()
1208 up->syndist = val; in chu_a()
1217 temp = (up->cbuf[k + 4] >> 4) & 0xf; in chu_a()
1219 ((up->cbuf[k + 9] >> 4) & 0xf)) in chu_a()
1222 "chuA %04x %4.0f %2d %2d %2d %2d %1d ", up->status, in chu_a()
1223 up->maxsignal, nchar, up->burdist, k, up->syndist, in chu_a()
1233 cb -= chars; in chu_a()
1235 snprintf(p, cb, "%02x", up->cbuf[i]); in chu_a()
1237 if (pp->sloppyclockflag & CLK_FLAG4) in chu_a()
1238 record_clock_stats(&peer->srcadr, tbuf); in chu_a()
1243 if (up->syndist < MINSYNC) { in chu_a()
1244 up->status |= AFRAME; in chu_a()
1256 up->status |= AFORMAT; in chu_a()
1258 up->status |= AVALID; in chu_a()
1259 up->second = pp->second = 30 + temp; in chu_a()
1264 offset = up->charstamp; in chu_a()
1267 for (; i < nchar && (i - 10) < k; i++) { in chu_a()
1268 up->tstamp[up->ntstamp] = up->cstamp[i]; in chu_a()
1269 L_SUB(&up->tstamp[up->ntstamp], &offset); in chu_a()
1270 L_ADD(&offset, &up->charstamp); in chu_a()
1271 if (up->ntstamp < MAXSTAGE - 1) in chu_a()
1272 up->ntstamp++; in chu_a()
1274 while (temp > up->prevsec) { in chu_a()
1275 for (j = 15; j > 0; j--) { in chu_a()
1276 up->decode[9][j] = up->decode[9][j - 1]; in chu_a()
1277 up->decode[19][j] = in chu_a()
1278 up->decode[19][j - 1]; in chu_a()
1280 up->decode[9][j] = up->decode[19][j] = 0; in chu_a()
1281 up->prevsec++; in chu_a()
1288 i = -(2 * k); in chu_a()
1294 up->decode[i][up->cbuf[j] & 0xf]++; in chu_a()
1296 up->decode[i][(up->cbuf[j] >> 4) & 0xf]++; in chu_a()
1299 up->burstcnt++; in chu_a()
1304 * chu_poll - called by the transmit procedure
1314 pp = peer->procptr; in chu_poll()
1315 pp->polls++; in chu_poll()
1320 * chu_second - process minute data
1333 double dtemp; in chu_second()
1335 pp = peer->procptr; in chu_second()
1336 up = pp->unitptr; in chu_second()
1343 up->second = (up->second + 1) % 60; in chu_second()
1344 if (up->second != 0) in chu_second()
1354 minset = ((current_time - peer->update) + 30) / 60; in chu_second()
1357 if (up->status & (BFRAME | AFRAME)) in chu_second()
1359 if (up->status & (BFORMAT | AFORMAT)) in chu_second()
1361 if (up->status & DECODE) in chu_second()
1363 if (up->status & STAMP) in chu_second()
1365 if (up->status & BVALID && dtemp >= MINMETRIC) in chu_second()
1366 up->status |= INSYNC; in chu_second()
1368 if (!(up->status & INSYNC)) { in chu_second()
1369 pp->leap = LEAP_NOTINSYNC; in chu_second()
1371 } else if (up->leap & 0x2) { in chu_second()
1372 pp->leap = LEAP_ADDSECOND; in chu_second()
1374 } else if (up->leap & 0x4) { in chu_second()
1375 pp->leap = LEAP_DELSECOND; in chu_second()
1378 pp->leap = LEAP_NOWARNING; in chu_second()
1380 snprintf(pp->a_lastcode, sizeof(pp->a_lastcode), in chu_second()
1382 synchar, qual, pp->year, pp->day, pp->hour, pp->minute, in chu_second()
1383 pp->second, leapchar, up->dst, up->dut, minset, up->gain, in chu_second()
1384 up->ident, dtemp, up->ntstamp); in chu_second()
1385 pp->lencode = strlen(pp->a_lastcode); in chu_second()
1392 if (up->status & INSYNC && !(up->status & (DECODE | STAMP)) && in chu_second()
1394 if (!clocktime(pp->day, pp->hour, pp->minute, 0, GMT, in chu_second()
1395 up->tstamp[0].l_ui, &pp->yearstart, &offset.l_ui)) { in chu_second()
1396 up->errflg = CEVNT_BADTIME; in chu_second()
1399 for (i = 0; i < up->ntstamp; i++) in chu_second()
1401 up->tstamp[i], PDELAY + in chu_second()
1402 pp->fudgetime1); in chu_second()
1403 pp->lastref = up->timestamp; in chu_second()
1408 record_clock_stats(&peer->srcadr, pp->a_lastcode); in chu_second()
1411 printf("chu: timecode %d %s\n", pp->lencode, in chu_second()
1412 pp->a_lastcode); in chu_second()
1418 if (up->errflg) in chu_second()
1419 refclock_report(peer, up->errflg); in chu_second()
1420 up->errflg = 0; in chu_second()
1425 * chu_major - majority decoder
1427 static double
1442 pp = peer->procptr; in chu_major()
1443 up = pp->unitptr; in chu_major()
1451 * position and the corresponding digit is the maximum- in chu_major()
1463 temp = up->decode[i][j] + up->decode[i + 10][j]; in chu_major()
1469 if (val1 <= up->burstcnt) in chu_major()
1470 up->status |= DECODE; in chu_major()
1482 if (sscanf((char *)code, "%1x%3d%2d%2d", &synchar, &pp->day, in chu_major()
1483 &pp->hour, &pp->minute) != 4) in chu_major()
1484 up->status |= DECODE; in chu_major()
1485 if (up->ntstamp < MINSTAMP) in chu_major()
1486 up->status |= STAMP; in chu_major()
1492 * chu_clear - clear decoding matrix
1503 pp = peer->procptr; in chu_clear()
1504 up = pp->unitptr; in chu_clear()
1509 up->ndx = up->prevsec = 0; in chu_clear()
1510 up->burstcnt = up->ntstamp = 0; in chu_clear()
1511 up->status &= INSYNC | METRIC; in chu_clear()
1514 up->decode[i][j] = 0; in chu_clear()
1520 * chu_newchan - called once per minute to find the best channel;
1526 double met in chu_newchan()
1533 double metric; in chu_newchan()
1536 pp = peer->procptr; in chu_newchan()
1537 up = pp->unitptr; in chu_newchan()
1541 * (7850 kHz) and 2 (14670 kHz). There are five one-minute in chu_newchan()
1543 * tuned to one of the three channels to measure the channel in chu_newchan()
1544 * metric. The channel is selected as the one least recently in chu_newchan()
1546 * to the channel with the highest channel metric. in chu_newchan()
1548 if (up->fd_icom <= 0) in chu_newchan()
1552 * Update the current channel metric and age of all channels. in chu_newchan()
1555 sp = &up->xmtr[up->chan]; in chu_newchan()
1556 sp->metric -= sp->integ[sp->iptr]; in chu_newchan()
1557 sp->integ[sp->iptr] = met; in chu_newchan()
1558 sp->metric += sp->integ[sp->iptr]; in chu_newchan()
1559 sp->probe = 0; in chu_newchan()
1560 sp->iptr = (sp->iptr + 1) % ISTAGE; in chu_newchan()
1563 up->xmtr[i].probe++; in chu_newchan()
1564 if (up->xmtr[i].metric > metric) { in chu_newchan()
1565 up->status |= METRIC; in chu_newchan()
1566 metric = up->xmtr[i].metric; in chu_newchan()
1567 up->chan = i; in chu_newchan()
1573 * been heard, continue round-robin scan. in chu_newchan()
1575 up->dwell = (up->dwell + 1) % DWELL; in chu_newchan()
1576 if (up->dwell == 0 || metric == 0) { in chu_newchan()
1579 if (up->xmtr[i].probe > rval) { in chu_newchan()
1580 rval = up->xmtr[i].probe; in chu_newchan()
1581 up->chan = i; in chu_newchan()
1589 rval = icom_freq(up->fd_icom, peer->ttl & 0x7f, qsy[up->chan] + in chu_newchan()
1591 snprintf(up->ident, sizeof(up->ident), "CHU%d", up->chan); in chu_newchan()
1592 memcpy(&pp->refid, up->ident, 4); in chu_newchan()
1593 memcpy(&peer->refid, up->ident, 4); in chu_newchan()
1594 if (metric == 0 && up->status & METRIC) { in chu_newchan()
1595 up->status &= ~METRIC; in chu_newchan()
1604 * chu_dist - determine the distance of two octet arguments
1628 val--; in chu_dist()
1637 * chu_gain - adjust codec gain
1654 pp = peer->procptr; in chu_gain()
1655 up = pp->unitptr; in chu_gain()
1662 if (up->clipcnt == 0) { in chu_gain()
1663 up->gain += 4; in chu_gain()
1664 if (up->gain > MAXGAIN) in chu_gain()
1665 up->gain = MAXGAIN; in chu_gain()
1666 } else if (up->clipcnt > MAXCLP) { in chu_gain()
1667 up->gain -= 4; in chu_gain()
1668 if (up->gain < 0) in chu_gain()
1669 up->gain = 0; in chu_gain()
1671 audio_gain(up->gain, up->mongain, up->port); in chu_gain()
1672 up->clipcnt = 0; in chu_gain()