Lines Matching +full:three +full:- +full:conversion +full:- +full:cycles
2 …* /src/NTP/REPOSITORY/ntp4-dev/parseutil/dcfd.c,v 4.18 2005/10/07 22:08:18 kardel RELEASE_20051008…
14 * Leap second handling (at that level you should switch to NTP Version 4 - really!)
16 * Copyright (c) 1995-2015 by Frank Kardel <kardel <AT> ntp.org>
17 …* Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universitaet Erlangen-Nuernberg, Ge…
90 if ((_a_)->tv_usec >= 1000000) \
92 (_a_)->tv_sec += (_a_)->tv_usec / 1000000; \
93 (_a_)->tv_usec = (_a_)->tv_usec % 1000000; \
95 if ((_a_)->tv_usec < 0) \
97 (_a_)->tv_sec -= 1 + (-(_a_)->tv_usec / 1000000); \
98 (_a_)->tv_usec = 999999 - (-(_a_)->tv_usec - 1); \
105 (_a_)->tv_sec += (_b_)->tv_sec; \
106 (_a_)->tv_usec += (_b_)->tv_usec; \
113 (_a_)->tv_sec -= (_b_)->tv_sec; \
114 (_a_)->tv_usec -= (_b_)->tv_usec; \
157 * The two states we can be in - eithe we receive nothing
168 static char pat[] = "-\\|/";
170 #define LINES (24-2) /* error lines after which the two headlines are repeated */
176 * clock adjustment PLL - see NTP protocol spec (RFC1305) for details
186 #define R_SHIFT(_X_, _Y_) (((_X_) < 0) ? -(-(_X_) >> (_Y_)) : ((_X_) >> (_Y_)))
205 long wday; /* Day of week: 1: Monday - 7: Sunday */
229 #define TIMES60(_X_) ((((_X_) << 4) - (_X_)) << 2) /* *(16 - 1) *4 */
235 #define l_abs(_x_) (((_x_) < 0) ? -(_x_) : (_x_))
238 * conversion related return/error codes
240 #define CVT_MASK 0x0000000F /* conversion exit code */
242 #define CVT_FAIL 0x00000002 /* conversion failed - error code returned */
243 #define CVT_OK 0x00000004 /* conversion succeeded */
244 #define CVT_BADFMT 0x00000010 /* general format error - (unparsable) */
251 * From "Zur Zeit", Physikalisch-Technische Bundesanstalt (PTB), Braunschweig
264 * see the spec. (basically a (non-)inverted psuedo random phase shift)
268 * 0 - 10 AM: free, FM: 0
269 * 11 - 14 free
270 * 15 R - "call bit" used to signalize irregularities in the control facilities
272 * 16 A1 - expect zone change (1 hour before)
273 * 17 - 18 Z1,Z2 - time zone
278 * 19 A2 - expect leap insertion/deletion (1 hour before)
279 * 20 S - start of time code (1)
280 * 21 - 24 M1 - BCD (lsb first) Minutes
281 * 25 - 27 M10 - BCD (lsb first) 10 Minutes
282 * 28 P1 - Minute Parity (even)
283 * 29 - 32 H1 - BCD (lsb first) Hours
284 * 33 - 34 H10 - BCD (lsb first) 10 Hours
285 * 35 P2 - Hour Parity (even)
286 * 36 - 39 D1 - BCD (lsb first) Days
287 * 40 - 41 D10 - BCD (lsb first) 10 Days
288 * 42 - 44 DW - BCD (lsb first) day of week (1: Monday -> 7: Sunday)
289 * 45 - 49 MO - BCD (lsb first) Month
290 * 50 MO0 - 10 Months
291 * 51 - 53 Y1 - BCD (lsb first) Years
292 * 54 - 57 Y10 - BCD (lsb first) 10 Years
293 * 58 P3 - Date Parity (even)
294 * 59 - usually missing (minute indication), except for leap insertion
297 /*-----------------------------------------------------------------------
298 * conversion table to map DCF77 bit stream into data fields.
314 /*-----------------------------------------------------------------------
339 /*-----------------------------------------------------------------------
352 /*-----------------------------------------------------------------------
359 /*-----------------------------------------------------------------------
365 /*-----------------------------------------------------------------------
375 "--------------------s-------p------p----------------------p" /* 'ZERO' representation */
378 /*-----------------------------------------------------------------------
396 for (i = rawdcfcode[idx+1].offset - 1; i >= first; i--) in ext_bf()
404 /*-----------------------------------------------------------------------
428 /*-----------------------------------------------------------------------
446 PRINTF("%-30s", "*** INCOMPLETE"); in convert_rawdcf()
459 * buffer OK - extract all fields and build wall clock time from them in convert_rawdcf()
462 clock_time->flags = 0; in convert_rawdcf()
463 clock_time->usecond= 0; in convert_rawdcf()
464 clock_time->second = 0; in convert_rawdcf()
465 clock_time->minute = ext_bf(buffer, DCF_M10); in convert_rawdcf()
466 clock_time->minute = TIMES10(clock_time->minute) + ext_bf(buffer, DCF_M1); in convert_rawdcf()
467 clock_time->hour = ext_bf(buffer, DCF_H10); in convert_rawdcf()
468 clock_time->hour = TIMES10(clock_time->hour) + ext_bf(buffer, DCF_H1); in convert_rawdcf()
469 clock_time->day = ext_bf(buffer, DCF_D10); in convert_rawdcf()
470 clock_time->day = TIMES10(clock_time->day) + ext_bf(buffer, DCF_D1); in convert_rawdcf()
471 clock_time->month = ext_bf(buffer, DCF_MO0); in convert_rawdcf()
472 clock_time->month = TIMES10(clock_time->month) + ext_bf(buffer, DCF_MO); in convert_rawdcf()
473 clock_time->year = ext_bf(buffer, DCF_Y10); in convert_rawdcf()
474 clock_time->year = TIMES10(clock_time->year) + ext_bf(buffer, DCF_Y1); in convert_rawdcf()
475 clock_time->wday = ext_bf(buffer, DCF_DW); in convert_rawdcf()
483 clock_time->utcoffset = -60; in convert_rawdcf()
487 clock_time->flags |= DCFB_DST; in convert_rawdcf()
488 clock_time->utcoffset = -120; in convert_rawdcf()
492 PRINTF("%-30s", "*** BAD TIME ZONE"); in convert_rawdcf()
500 clock_time->flags |= DCFB_ANNOUNCE; in convert_rawdcf()
503 clock_time->flags |= DCFB_LEAP; in convert_rawdcf()
506 clock_time->flags |= DCFB_CALLBIT; in convert_rawdcf()
513 * bad format - not for us in convert_rawdcf()
515 PRINTF("%-30s", "*** BAD FORMAT (invalid/parity)"); in convert_rawdcf()
520 /*-----------------------------------------------------------------------
521 * raw dcf input routine - fix up 50 baud
599 (u_int)*s, (long)(s - buffer))); in cvt_rawdcf()
607 * first cutoff estimate (average bit count - must be between both in cvt_rawdcf()
616 cutoff = 4; /* doesn't really matter - it'll fail anyway, but gives error output */ in cvt_rawdcf()
678 highmax = BITS-1; in cvt_rawdcf()
706 * minimum not better yet - but it spans more than in cvt_rawdcf()
707 * one bit value - follow it in cvt_rawdcf()
722 * convert the bit counts to symbolic 1/0 information for data conversion in cvt_rawdcf()
748 * conversion routine else just the accumulated errors in cvt_rawdcf()
752 PRINTF("%-30s", "*** BAD DATA"); in cvt_rawdcf()
758 /*-----------------------------------------------------------------------
779 if ( clock_time->year < YEAR_PIVOT ) /* in case of Y2KFixes [ */ in dcf_to_unixtime()
780 clock_time->year += 100; /* *year%100, make tm_year */ in dcf_to_unixtime()
782 if ( clock_time->year < YEAR_BREAK ) /* (failsafe if) */ in dcf_to_unixtime()
783 clock_time->year += 1900; /* Y2KFixes ] */ in dcf_to_unixtime()
786 * must have been a really bad year code - drop it in dcf_to_unixtime()
788 if (clock_time->year < (YEAR_PIVOT + 1900) ) /* Y2KFixes */ in dcf_to_unixtime()
791 return -1; in dcf_to_unixtime()
794 * sorry, slow section here - but it's not time critical anyway in dcf_to_unixtime()
800 t = julian0( clock_time->year ) - julian0( 1970 ); in dcf_to_unixtime()
803 if (clock_time->month <= 0 || clock_time->month > 12) in dcf_to_unixtime()
806 return -1; /* bad month */ in dcf_to_unixtime()
810 if (clock_time->month < 3 && days_per_year(clock_time->year) == 366) in dcf_to_unixtime()
811 t--; in dcf_to_unixtime()
817 for (i = 1; i < clock_time->month; i++) in dcf_to_unixtime()
822 if (clock_time->day < 1 || ((clock_time->month == 2 && days_per_year(clock_time->year) == 366) ? in dcf_to_unixtime()
823 clock_time->day > 29 : clock_time->day > days_of_month[clock_time->month])) in dcf_to_unixtime()
826 return -1; /* bad day */ in dcf_to_unixtime()
832 t += clock_time->day - 1; in dcf_to_unixtime()
835 if (clock_time->hour < 0 || clock_time->hour >= 24) in dcf_to_unixtime()
838 return -1; /* bad hour */ in dcf_to_unixtime()
844 t = TIMES24(t) + clock_time->hour; in dcf_to_unixtime()
847 if (clock_time->minute < 0 || clock_time->minute > 59) in dcf_to_unixtime()
850 return -1; /* bad min */ in dcf_to_unixtime()
856 t = TIMES60(t) + clock_time->minute; in dcf_to_unixtime()
862 t += clock_time->utcoffset; in dcf_to_unixtime()
864 if (clock_time->second < 0 || clock_time->second > 60) /* allow for LEAPs */ in dcf_to_unixtime()
867 return -1; /* bad sec */ in dcf_to_unixtime()
871 * calculate UTC in seconds - phew ! in dcf_to_unixtime()
873 t = TIMES60(t) + clock_time->second; in dcf_to_unixtime()
878 /*-----------------------------------------------------------------------
879 * cheap half baked 1/0 decision - for interactive operation only
890 /*-----------------------------------------------------------------------
905 /*-----------------------------------------------------------------------
915 if (val->tv_sec == 0) in pr_timeval()
917 (val->tv_usec < 0) ? '-' : '+', in pr_timeval()
918 (long int)l_abs(val->tv_usec)); in pr_timeval()
921 (long int)val->tv_sec, in pr_timeval()
922 (long int)l_abs(val->tv_usec)); in pr_timeval()
926 /*-----------------------------------------------------------------------
942 if (gettimeofday(&the_time, 0L) == -1) in set_time()
949 if (settimeofday(&the_time, 0L) == -1) in set_time()
956 /*-----------------------------------------------------------------------
973 if (adjtime(&time_offset, 0L) == -1) in adj_time()
977 /*-----------------------------------------------------------------------
1004 /*-----------------------------------------------------------------------
1020 int fdrift = accum_drift & ((1<<USECSCALE)-1); in update_drift()
1025 (offset < 0) ? '-' : '+', (long int)(l_abs(offset) / 1000000), in update_drift()
1032 /*-----------------------------------------------------------------------
1063 * hopeless - set the clock - and clear the timing in adjust_clock()
1071 usecoffset = offset->tv_sec * 1000000 + offset->tv_usec; in adjust_clock()
1082 accum_drift += R_SHIFT(usecoffset << USECSCALE, TIMECONSTANT+TIMECONSTANT+FREQ_WEIGHT-tmp); in adjust_clock()
1087 if (accum_drift < -MAX_DRIFT) in adjust_clock()
1088 accum_drift = -MAX_DRIFT; in adjust_clock()
1096 /*-----------------------------------------------------------------------
1110 clock_adjust -= adjustment; in periodic_adjust()
1117 /*-----------------------------------------------------------------------
1136 if ((ticks - last_sync) > MAX_UNSYNC) in tick()
1152 * in NO_SYNC state - look whether its time to speak up again in tick()
1154 if ((ticks - last_notice) > NOTICE_INTERVAL) in tick()
1156 syslog(LOG_NOTICE, "still not synchronized to DCF77 - check receiver/signal"); in tick()
1166 /*-----------------------------------------------------------------------
1168 * or process group related signals (-> daemon operation)
1209 if (setsid() == (pid_t)-1) in detach()
1212 if (setpgid(0, 0) == -1) in detach()
1236 /*-----------------------------------------------------------------------
1244 …fprintf(stderr, "usage: %s [-n] [-f] [-l] [-t] [-i] [-o] [-d <drift_file>] [-D <input delay>] <dev… in usage()
1245 fprintf(stderr, "\t-n do not change time\n"); in usage()
1246 fprintf(stderr, "\t-i interactive\n"); in usage()
1247 fprintf(stderr, "\t-t trace (print all datagrams)\n"); in usage()
1248 fprintf(stderr, "\t-f print all databits (includes PTB private data)\n"); in usage()
1249 fprintf(stderr, "\t-l print loop filter debug information\n"); in usage()
1250 fprintf(stderr, "\t-o print offet average for current minute\n"); in usage()
1251 fprintf(stderr, "\t-Y make internal Y2K checks then exit\n"); /* Y2KFixes */ in usage()
1252 fprintf(stderr, "\t-d <drift_file> specify alternate drift file\n"); in usage()
1253 …fprintf(stderr, "\t-D <input delay>specify delay from input edge to processing in micro seconds\n"… in usage()
1256 /*-----------------------------------------------------------------------
1257 * check_y2k() - internal check of Y2K logic
1266 * 32-bit systems: through 2036, the in check_y2k()
1268 * 64-bit systems: a reasonable upper in check_y2k()
1286 ? ( 400 * 3 ) /* three greater gregorian cycles */ in check_y2k()
1287 : ((int)(0x7FFFFFFF / 365.242 / 24/60/60)* 2 ); /*32-bit limit*/ in check_y2k()
1291 * 2036 (the current 32-bit limit). If all checks in check_y2k()
1327 t = julian0(year) - julian0(1970); /* Julian day from 1970 */ in check_y2k()
1335 ((long)Observed - (long)Expected) ); in check_y2k()
1345 /*--------------------------------------------------
1346 * rawdcf_init - set up modem lines for RAWDCF receivers
1366 if (ioctl(fd, TIOCMSET, (caddr_t)&sl232) == -1) in rawdcf_init()
1381 /*-----------------------------------------------------------------------
1382 * main loop - argument interpreter / setup / main loop
1405 while (--ac) in main()
1408 if (*arg == '-') in main()
1445 ac--; in main()
1449 fprintf(stderr, "%s: -D requires integer argument\n", argv[0]); in main()
1458 ac--; in main()
1462 fprintf(stderr, "%s: -d requires file name argument\n", argv[0]); in main()
1472 fprintf(stderr, "%s: unknown option -%c\n", argv[0], c); in main()
1505 if (fd == -1) in main()
1544 if (TTY_GETATTR(fd, &term) == -1) in main()
1564 if (TTY_SETATTR(fd, &term) == -1) in main()
1599 if (sigaction(SIGALRM, &act, (struct sigaction *)0) == -1) in main()
1614 if (sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1) in main()
1634 if (setitimer(ITIMER_REAL, &it, (struct itimerval *)0) == -1) in main()
1644 PRINTF(" DCF77 monitor %s - Copyright (C) 1993-2005 by Frank Kardel\n\n", revision); in main()
1674 PRINTF(" %s", &"---------------RADMLS1248124P124812P1248121241248112481248P\n"[offset]); in main()
1679 * timeout -> possible minute mark -> interpretation in main()
1683 PRINTF("%c %.*s ", pat[i % (sizeof(pat)-1)], 59 - offset, &pbuf[offset]); in main()
1688 * this data was bad - well - forget synchronisation for now in main()
1701 PRINTF("\r %.*s ", 59 - offset, &buf[offset]); in main()
1713 pbuf[0] = type(c) ? '#' : '-'; in main()
1733 pbuf[i] = type(c) ? '#' : '-'; in main()
1735 PRINTF("%c %.*s ", pat[i % (sizeof(pat)-1)], 59 - offset, &pbuf[offset]); in main()
1741 * we got a good time code here - try to convert it to in main()
1744 if ((utc_time = dcf_to_unixtime(&clock_time, &rtc)) == -1) in main()
1746 PRINTF("*** BAD CONVERSION\n"); in main()
1775 * valid time code - determine offset and in main()
1786 * we had at least one minute SYNC - thus in main()
1801 usecerror += (time_offset.tv_sec - tt.tv_sec) * 1000000 + time_offset.tv_usec in main()
1802 -tt.tv_usec; in main()
1816 (lasterror < 0) ? '-' : '+', l_abs(lasterror) / 1000000, l_abs(lasterror) % 1000000 in main()
1843 } while ((rrc == -1) && (errno == EINTR)); in main()
1846 * lost IO - sorry guys in main()
1848 syslog(LOG_ERR, "TERMINATING - cannot read from device %s (%m)", file); in main()