clk_rawdcf.c revision 54359
176195Sbrian/* 276195Sbrian * /src/NTP/ntp-4/libparse/clk_rawdcf.c,v 4.6 1998/06/14 21:09:37 kardel RELEASE_19990228_A 376358Sbrian * 476358Sbrian * clk_rawdcf.c,v 4.6 1998/06/14 21:09:37 kardel RELEASE_19990228_A 576358Sbrian * 676195Sbrian * Raw DCF77 pulse clock support 776195Sbrian * 876195Sbrian * Copyright (C) 1992-1998 by Frank Kardel 976195Sbrian * Friedrich-Alexander Universit�t Erlangen-N�rnberg, Germany 1076195Sbrian * 1176195Sbrian * This program is distributed in the hope that it will be useful, 1276195Sbrian * but WITHOUT ANY WARRANTY; without even the implied warranty of 1376195Sbrian * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 1476195Sbrian * 1576195Sbrian */ 1676195Sbrian 1776195Sbrian#ifdef HAVE_CONFIG_H 1876195Sbrian# include <config.h> 1976195Sbrian#endif 2076195Sbrian 2176195Sbrian#if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_RAWDCF) 2276195Sbrian 2376195Sbrian#include <sys/types.h> 2476195Sbrian#include <sys/time.h> 2576195Sbrian 2676195Sbrian#include "ntp_fp.h" 2776195Sbrian#include "ntp_unixtime.h" 2876195Sbrian#include "ntp_calendar.h" 2976195Sbrian 3076195Sbrian#include "parse.h" 3176195Sbrian#ifdef PARSESTREAM 3276195Sbrian# include <sys/parsestreams.h> 3376195Sbrian#endif 3476195Sbrian 3576195Sbrian#ifndef PARSEKERNEL 3676195Sbrian# include "ntp_stdlib.h" 3776195Sbrian#endif 3890684Sbde 3990684Sbde/* 4076195Sbrian * DCF77 raw time code 4176195Sbrian * 4276195Sbrian * From "Zur Zeit", Physikalisch-Technische Bundesanstalt (PTB), Braunschweig 4376195Sbrian * und Berlin, Maerz 1989 4476195Sbrian * 4576195Sbrian * Timecode transmission: 4676195Sbrian * AM: 4776195Sbrian * time marks are send every second except for the second before the 48129879Sphk * next minute mark 4976195Sbrian * time marks consist of a reduction of transmitter power to 25% 5076195Sbrian * of the nominal level 5176195Sbrian * the falling edge is the time indication (on time) 5276195Sbrian * time marks of a 100ms duration constitute a logical 0 5376195Sbrian * time marks of a 200ms duration constitute a logical 1 5476195Sbrian * FM: 5576195Sbrian * see the spec. (basically a (non-)inverted psuedo random phase shift) 5676848Sbrian * 5776853Sbrian * Encoding: 5876853Sbrian * Second Contents 5976853Sbrian * 0 - 10 AM: free, FM: 0 6076853Sbrian * 11 - 14 free 6176195Sbrian * 15 R - alternate antenna 6276195Sbrian * 16 A1 - expect zone change (1 hour before) 6376195Sbrian * 17 - 18 Z1,Z2 - time zone 6476195Sbrian * 0 0 illegal 6576195Sbrian * 0 1 MEZ (MET) 6676195Sbrian * 1 0 MESZ (MED, MET DST) 6776195Sbrian * 1 1 illegal 6876195Sbrian * 19 A2 - expect leap insertion/deletion (1 hour before) 6976195Sbrian * 20 S - start of time code (1) 7076195Sbrian * 21 - 24 M1 - BCD (lsb first) Minutes 7176195Sbrian * 25 - 27 M10 - BCD (lsb first) 10 Minutes 7276195Sbrian * 28 P1 - Minute Parity (even) 7376195Sbrian * 29 - 32 H1 - BCD (lsb first) Hours 7476195Sbrian * 33 - 34 H10 - BCD (lsb first) 10 Hours 7576195Sbrian * 35 P2 - Hour Parity (even) 7676195Sbrian * 36 - 39 D1 - BCD (lsb first) Days 7776195Sbrian * 40 - 41 D10 - BCD (lsb first) 10 Days 7876195Sbrian * 42 - 44 DW - BCD (lsb first) day of week (1: Monday -> 7: Sunday) 7976195Sbrian * 45 - 49 MO - BCD (lsb first) Month 8076195Sbrian * 50 MO0 - 10 Months 8176195Sbrian * 51 - 53 Y1 - BCD (lsb first) Years 8276195Sbrian * 54 - 57 Y10 - BCD (lsb first) 10 Years 8376195Sbrian * 58 P3 - Date Parity (even) 8476195Sbrian * 59 - usually missing (minute indication), except for leap insertion 8576195Sbrian */ 8676195Sbrian 8776195Sbrianstatic u_long pps_rawdcf P((parse_t *, int, timestamp_t *)); 8876195Sbrianstatic u_long cvt_rawdcf P((unsigned char *, int, struct format *, clocktime_t *, void *)); 8976195Sbrianstatic u_long inp_rawdcf P((parse_t *, unsigned int, timestamp_t *)); 9076195Sbrian 9176195Sbrianclockformat_t clock_rawdcf = 9276195Sbrian{ 9376195Sbrian inp_rawdcf, /* DCF77 input handling */ 9476195Sbrian cvt_rawdcf, /* raw dcf input conversion */ 9576195Sbrian pps_rawdcf, /* examining PPS information */ 9676195Sbrian 0, /* no private configuration data */ 9776195Sbrian "RAW DCF77 Timecode", /* direct decoding / time synthesis */ 9876195Sbrian 9976195Sbrian 61, /* bit buffer */ 10076195Sbrian 0 /* no private data (currently in input buffer) */ 10176195Sbrian}; 10276195Sbrian 10376195Sbrianstatic struct dcfparam 10476195Sbrian{ 10576195Sbrian unsigned char onebits[60]; 10676195Sbrian unsigned char zerobits[60]; 10776195Sbrian} dcfparameter = 10889062Smsmith{ 10991445Speter "###############RADMLS1248124P124812P1248121241248112481248P", /* 'ONE' representation */ 11076195Sbrian "--------------------s-------p------p----------------------p" /* 'ZERO' representation */ 11176195Sbrian}; 11276195Sbrian 11376195Sbrianstatic struct rawdcfcode 11476195Sbrian{ 11576195Sbrian char offset; /* start bit */ 11676195Sbrian} rawdcfcode[] = 11776195Sbrian{ 11876195Sbrian { 0 }, { 15 }, { 16 }, { 17 }, { 19 }, { 20 }, { 21 }, { 25 }, { 28 }, { 29 }, 11976195Sbrian { 33 }, { 35 }, { 36 }, { 40 }, { 42 }, { 45 }, { 49 }, { 50 }, { 54 }, { 58 }, { 59 } 12076195Sbrian}; 12176195Sbrian 12276195Sbrian#define DCF_M 0 12376195Sbrian#define DCF_R 1 12476195Sbrian#define DCF_A1 2 12576195Sbrian#define DCF_Z 3 12676195Sbrian#define DCF_A2 4 12776195Sbrian#define DCF_S 5 12876195Sbrian#define DCF_M1 6 12976195Sbrian#define DCF_M10 7 13076195Sbrian#define DCF_P1 8 13176195Sbrian#define DCF_H1 9 13276195Sbrian#define DCF_H10 10 13376195Sbrian#define DCF_P2 11 13476195Sbrian#define DCF_D1 12 13576195Sbrian#define DCF_D10 13 13676195Sbrian#define DCF_DW 14 13776195Sbrian#define DCF_MO 15 13876195Sbrian#define DCF_MO0 16 13976195Sbrian#define DCF_Y1 17 14076195Sbrian#define DCF_Y10 18 14176195Sbrian#define DCF_P3 19 14276195Sbrian 14376195Sbrianstatic struct partab 14476195Sbrian{ 14576195Sbrian char offset; /* start bit of parity field */ 146126080Sphk} partab[] = 147111815Sphk{ 148111815Sphk { 21 }, { 29 }, { 36 }, { 59 } 149111815Sphk}; 150111815Sphk 151111815Sphk#define DCF_P_P1 0 152111815Sphk#define DCF_P_P2 1 153126080Sphk#define DCF_P_P3 2 15476195Sbrian 15576195Sbrian#define DCF_Z_MET 0x2 15676195Sbrian#define DCF_Z_MED 0x1 15776195Sbrian 15876195Sbrianstatic u_long 15976195Sbrianext_bf( 16076195Sbrian register unsigned char *buf, 16176195Sbrian register int idx, 16276195Sbrian register unsigned char *zero 16376195Sbrian ) 16476195Sbrian{ 16576195Sbrian register u_long sum = 0; 16676195Sbrian register int i, first; 16776195Sbrian 16876195Sbrian first = rawdcfcode[idx].offset; 16976195Sbrian 17076195Sbrian for (i = rawdcfcode[idx+1].offset - 1; i >= first; i--) 17176195Sbrian { 17276195Sbrian sum <<= 1; 17376195Sbrian sum |= (buf[i] != zero[i]); 17476195Sbrian } 17576195Sbrian return sum; 17676195Sbrian} 17776195Sbrian 17876195Sbrianstatic unsigned 17976195Sbrianpcheck( 18076195Sbrian unsigned char *buf, 18176195Sbrian int idx, 18276195Sbrian unsigned char *zero 18376195Sbrian ) 18476195Sbrian{ 18576195Sbrian int i,last; 18676195Sbrian unsigned psum = 1; 18776195Sbrian 18876195Sbrian last = partab[idx+1].offset; 18976195Sbrian 19076195Sbrian for (i = partab[idx].offset; i < last; i++) 19176195Sbrian psum ^= (buf[i] != zero[i]); 19276195Sbrian 19376195Sbrian return psum; 19476195Sbrian} 19576195Sbrian 19676195Sbrianstatic u_long 19776195Sbrianconvert_rawdcf( 19876195Sbrian unsigned char *buffer, 19976195Sbrian int size, 20076195Sbrian struct dcfparam *dcfprm, 20176195Sbrian clocktime_t *clock_time 20276195Sbrian ) 20376195Sbrian{ 20476195Sbrian register unsigned char *s = buffer; 20576195Sbrian register unsigned char *b = dcfprm->onebits; 20676195Sbrian register unsigned char *c = dcfprm->zerobits; 20776195Sbrian register int i; 20876195Sbrian 20976195Sbrian parseprintf(DD_RAWDCF,("parse: convert_rawdcf: \"%s\"\n", buffer)); 21076195Sbrian 21176195Sbrian if (size < 57) 21276195Sbrian { 21376195Sbrian#ifndef PARSEKERNEL 21476195Sbrian msyslog(LOG_ERR, "parse: convert_rawdcf: INCOMPLETE DATA - time code only has %d bits\n", size); 21576195Sbrian#endif 21676195Sbrian return CVT_NONE; 21776195Sbrian } 21894358Sbrian 21994361Sbrian for (i = 0; i < 58; i++) 22094340Sbrian { 22194340Sbrian if ((*s != *b) && (*s != *c)) 22294361Sbrian { 22394340Sbrian /* 22494361Sbrian * we only have two types of bytes (ones and zeros) 22594340Sbrian */ 22694340Sbrian#ifndef PARSEKERNEL 22776195Sbrian msyslog(LOG_ERR, "parse: convert_rawdcf: BAD DATA - no conversion for \"%s\"\n", buffer); 22876195Sbrian#endif 22976195Sbrian return CVT_NONE; 23076195Sbrian } 23176195Sbrian b++; 23276195Sbrian c++; 23376195Sbrian s++; 23476195Sbrian } 23576195Sbrian 23676195Sbrian /* 23776195Sbrian * check Start and Parity bits 23876195Sbrian */ 23976195Sbrian if ((ext_bf(buffer, DCF_S, dcfprm->zerobits) == 1) && 24076195Sbrian pcheck(buffer, DCF_P_P1, dcfprm->zerobits) && 24176195Sbrian pcheck(buffer, DCF_P_P2, dcfprm->zerobits) && 24276195Sbrian pcheck(buffer, DCF_P_P3, dcfprm->zerobits)) 24376195Sbrian { 24476195Sbrian /* 24576195Sbrian * buffer OK 24676195Sbrian */ 24776195Sbrian parseprintf(DD_RAWDCF,("parse: convert_rawdcf: parity check passed\n")); 24876195Sbrian 24976195Sbrian clock_time->flags = PARSEB_S_ANTENNA|PARSEB_S_LEAP; 25076195Sbrian clock_time->utctime= 0; 25176195Sbrian clock_time->usecond= 0; 25276195Sbrian clock_time->second = 0; 25376195Sbrian clock_time->minute = ext_bf(buffer, DCF_M10, dcfprm->zerobits); 25476195Sbrian clock_time->minute = TIMES10(clock_time->minute) + ext_bf(buffer, DCF_M1, dcfprm->zerobits); 25576195Sbrian clock_time->hour = ext_bf(buffer, DCF_H10, dcfprm->zerobits); 25676195Sbrian clock_time->hour = TIMES10(clock_time->hour) + ext_bf(buffer, DCF_H1, dcfprm->zerobits); 25776195Sbrian clock_time->day = ext_bf(buffer, DCF_D10, dcfprm->zerobits); 25876195Sbrian clock_time->day = TIMES10(clock_time->day) + ext_bf(buffer, DCF_D1, dcfprm->zerobits); 25976195Sbrian clock_time->month = ext_bf(buffer, DCF_MO0, dcfprm->zerobits); 26076195Sbrian clock_time->month = TIMES10(clock_time->month) + ext_bf(buffer, DCF_MO, dcfprm->zerobits); 26176195Sbrian clock_time->year = ext_bf(buffer, DCF_Y10, dcfprm->zerobits); 26276195Sbrian clock_time->year = TIMES10(clock_time->year) + ext_bf(buffer, DCF_Y1, dcfprm->zerobits); 26376195Sbrian 26476195Sbrian switch (ext_bf(buffer, DCF_Z, dcfprm->zerobits)) 26576195Sbrian { 26676195Sbrian case DCF_Z_MET: 26776195Sbrian clock_time->utcoffset = -1*60*60; 26876195Sbrian break; 26976195Sbrian 27076195Sbrian case DCF_Z_MED: 27176195Sbrian clock_time->flags |= PARSEB_DST; 27276195Sbrian clock_time->utcoffset = -2*60*60; 27376195Sbrian break; 27476195Sbrian 27576195Sbrian default: 27676195Sbrian parseprintf(DD_RAWDCF,("parse: convert_rawdcf: BAD TIME ZONE\n")); 27776195Sbrian return CVT_FAIL|CVT_BADFMT; 27876195Sbrian } 27976195Sbrian 28076195Sbrian if (ext_bf(buffer, DCF_A1, dcfprm->zerobits)) 28176195Sbrian clock_time->flags |= PARSEB_ANNOUNCE; 28276195Sbrian 28376195Sbrian if (ext_bf(buffer, DCF_A2, dcfprm->zerobits)) 28476195Sbrian clock_time->flags |= PARSEB_LEAPADD; /* default: DCF77 data format deficiency */ 28576195Sbrian 28676195Sbrian if (ext_bf(buffer, DCF_R, dcfprm->zerobits)) 28776195Sbrian clock_time->flags |= PARSEB_ALTERNATE; 28876195Sbrian 28976195Sbrian parseprintf(DD_RAWDCF,("parse: convert_rawdcf: TIME CODE OK: %d:%d, %d.%d.%d, flags 0x%lx\n", 29076195Sbrian (int)clock_time->hour, (int)clock_time->minute, (int)clock_time->day, (int)clock_time->month,(int) clock_time->year, 29176195Sbrian (u_long)clock_time->flags)); 29276195Sbrian return CVT_OK; 29376195Sbrian } 29476195Sbrian else 29576195Sbrian { 29676195Sbrian /* 29776195Sbrian * bad format - not for us 29876195Sbrian */ 29976195Sbrian#ifndef PARSEKERNEL 30076195Sbrian msyslog(LOG_ERR, "parse: convert_rawdcf: parity check FAILED for \"%s\"\n", buffer); 30176195Sbrian#endif 30276195Sbrian return CVT_FAIL|CVT_BADFMT; 30376195Sbrian } 30494323Sbrian} 30576195Sbrian 30676195Sbrian/* 30776195Sbrian * raw dcf input routine - needs to fix up 50 baud 30876195Sbrian * characters for 1/0 decision 30994323Sbrian */ 31076195Sbrianstatic u_long 31194949Sbriancvt_rawdcf( 31294323Sbrian unsigned char *buffer, 31394323Sbrian int size, 31476195Sbrian struct format *param, 31576195Sbrian clocktime_t *clock_time, 31694361Sbrian void *local 31776195Sbrian ) 31876195Sbrian{ 31976195Sbrian register unsigned char *s = (unsigned char *)buffer; 32076195Sbrian register unsigned char *e = s + size; 32176195Sbrian register unsigned char *b = dcfparameter.onebits; 32276195Sbrian register unsigned char *c = dcfparameter.zerobits; 32376195Sbrian register unsigned rtc = CVT_NONE; 32476195Sbrian register unsigned int i, lowmax, highmax, cutoff, span; 32576195Sbrian#define BITS 9 32676195Sbrian unsigned char histbuf[BITS]; 32776195Sbrian /* 32876195Sbrian * the input buffer contains characters with runs of consecutive 32976195Sbrian * bits set. These set bits are an indication of the DCF77 pulse 33076195Sbrian * length. We assume that we receive the pulse at 50 Baud. Thus 33176195Sbrian * a 100ms pulse would generate a 4 bit train (20ms per bit and 33276195Sbrian * start bit) 33376195Sbrian * a 200ms pulse would create all zeroes (and probably a frame error) 33476195Sbrian */ 33576195Sbrian 33676195Sbrian for (i = 0; i < BITS; i++) 33776195Sbrian { 33876195Sbrian histbuf[i] = 0; 33976195Sbrian } 34076195Sbrian 34176195Sbrian cutoff = 0; 34276195Sbrian lowmax = 0; 34376195Sbrian 34476195Sbrian while (s < e) 34576195Sbrian { 34676195Sbrian register unsigned int ch = *s ^ 0xFF; 34776195Sbrian /* 34876195Sbrian * these lines are left as an excercise to the reader 8-) 34976195Sbrian */ 35076195Sbrian if (!((ch+1) & ch) || !*s) 35176195Sbrian { 35276195Sbrian 35376195Sbrian for (i = 0; ch; i++) 35494323Sbrian { 35576195Sbrian ch >>= 1; 35676195Sbrian } 35776195Sbrian 35876195Sbrian *s = i; 35976195Sbrian histbuf[i]++; 36076195Sbrian cutoff += i; 36176195Sbrian lowmax++; 36276195Sbrian } 36376195Sbrian else 36476195Sbrian { 36594323Sbrian parseprintf(DD_RAWDCF,("parse: cvt_rawdcf: character check for 0x%x@%d FAILED\n", *s, (int)(s - (unsigned char *)buffer))); 36676195Sbrian *s = (unsigned char)~0; 36794949Sbrian rtc = CVT_FAIL|CVT_BADFMT; 36876195Sbrian } 36976195Sbrian s++; 37076195Sbrian } 37176195Sbrian 37294361Sbrian if (lowmax) 37376195Sbrian { 37476195Sbrian cutoff /= lowmax; 37576195Sbrian } 37676195Sbrian else 37776195Sbrian { 37894949Sbrian cutoff = 4; /* doesn't really matter - it'll fail anyway, but gives error output */ 37976195Sbrian } 38076195Sbrian 38176195Sbrian parseprintf(DD_RAWDCF,("parse: cvt_rawdcf: average bit count: %d\n", cutoff)); 38276195Sbrian 38376195Sbrian lowmax = 0; 38494361Sbrian highmax = 0; 38576195Sbrian 38676195Sbrian parseprintf(DD_RAWDCF,("parse: cvt_rawdcf: histogram:")); 38776195Sbrian for (i = 0; i <= cutoff; i++) 38876195Sbrian { 38976195Sbrian lowmax+=histbuf[i] * i; 39076195Sbrian highmax += histbuf[i]; 39176195Sbrian parseprintf(DD_RAWDCF,(" %d", histbuf[i])); 39276195Sbrian } 39376195Sbrian parseprintf(DD_RAWDCF, (" <M>")); 39476195Sbrian 39576195Sbrian lowmax += highmax / 2; 39676195Sbrian 39776195Sbrian if (highmax) 39876195Sbrian { 39976195Sbrian lowmax /= highmax; 40076195Sbrian } 40176195Sbrian else 40276195Sbrian { 40376195Sbrian lowmax = 0; 40476195Sbrian } 40576195Sbrian 40676195Sbrian highmax = 0; 40776195Sbrian cutoff = 0; 40876195Sbrian 40976195Sbrian for (; i < BITS; i++) 41076195Sbrian { 41176195Sbrian highmax+=histbuf[i] * i; 41276195Sbrian cutoff +=histbuf[i]; 41376195Sbrian parseprintf(DD_RAWDCF,(" %d", histbuf[i])); 41476195Sbrian } 41576195Sbrian parseprintf(DD_RAWDCF,("\n")); 41676195Sbrian 41776195Sbrian if (cutoff) 41894949Sbrian { 41976195Sbrian highmax /= cutoff; 42076195Sbrian } 42176195Sbrian else 42276195Sbrian { 42376195Sbrian highmax = BITS-1; 42494361Sbrian } 42576195Sbrian 42676195Sbrian span = cutoff = lowmax; 42776195Sbrian for (i = lowmax; i <= highmax; i++) 42876195Sbrian { 42976195Sbrian if (histbuf[cutoff] > histbuf[i]) 43076195Sbrian { 43176195Sbrian cutoff = i; 43276195Sbrian span = i; 43376195Sbrian } 43476195Sbrian else 43576195Sbrian if (histbuf[cutoff] == histbuf[i]) 43676195Sbrian { 43776195Sbrian span = i; 43876195Sbrian } 43976195Sbrian } 44076195Sbrian 44176195Sbrian cutoff = (cutoff + span) / 2; 44276195Sbrian 44376195Sbrian parseprintf(DD_RAWDCF,("parse: cvt_rawdcf: lower maximum %d, higher maximum %d, cutoff %d\n", lowmax, highmax, cutoff)); 44476195Sbrian 44576195Sbrian s = (unsigned char *)buffer; 44676195Sbrian while ((s < e) && *c && *b) 44776195Sbrian { 44876195Sbrian if (*s == (unsigned char)~0) 44976195Sbrian { 45076195Sbrian *s = '?'; 45176195Sbrian } 45276195Sbrian else 45376195Sbrian { 45476195Sbrian *s = (*s >= cutoff) ? *b : *c; 45576195Sbrian } 45676195Sbrian s++; 45776195Sbrian b++; 45876195Sbrian c++; 45976195Sbrian } 46076195Sbrian 46176195Sbrian return (rtc == CVT_NONE) ? convert_rawdcf(buffer, size, &dcfparameter, clock_time) : rtc; 46276195Sbrian} 46376195Sbrian 46476195Sbrian/* 46576195Sbrian * pps_rawdcf 46676195Sbrian * 46776195Sbrian * currently a very stupid version - should be extended to decode 46876195Sbrian * also ones and zeros (which is easy) 46976195Sbrian */ 47076195Sbrian/*ARGSUSED*/ 47176195Sbrianstatic u_long 47276195Sbrianpps_rawdcf( 47376195Sbrian register parse_t *parseio, 47476195Sbrian register int status, 47576195Sbrian register timestamp_t *ptime 47676195Sbrian ) 47776195Sbrian{ 47876195Sbrian if (!status) /* negative edge for simpler wiring (Rx->DCD) */ 47976195Sbrian { 48076195Sbrian parseio->parse_dtime.parse_ptime = *ptime; 48176195Sbrian parseio->parse_dtime.parse_state |= PARSEB_PPS|PARSEB_S_PPS; 48276195Sbrian } 48376195Sbrian 48476195Sbrian return CVT_NONE; 48576195Sbrian} 48676195Sbrian 48776195Sbrianstatic u_long 48876195Sbriansnt_rawdcf( 48976195Sbrian register parse_t *parseio, 49076195Sbrian register timestamp_t *ptime 49176195Sbrian ) 49276195Sbrian{ 49376195Sbrian if ((parseio->parse_dtime.parse_status & CVT_MASK) == CVT_OK) 49476195Sbrian { 49576195Sbrian parseio->parse_dtime.parse_stime = *ptime; 49676195Sbrian 49776195Sbrian#ifdef PARSEKERNEL 49876195Sbrian parseio->parse_dtime.parse_time.tv.tv_sec++; 49976195Sbrian#else 50076195Sbrian parseio->parse_dtime.parse_time.fp.l_ui++; 50176195Sbrian#endif 50276195Sbrian 50394949Sbrian parseprintf(DD_RAWDCF,("parse: snt_rawdcf: time stamp synthesized offset %d seconds\n", parseio->parse_index - 1)); 50476195Sbrian 50576195Sbrian return updatetimeinfo(parseio, parseio->parse_lstate); 50676195Sbrian } 50776195Sbrian return CVT_NONE; 50876195Sbrian} 50976195Sbrian 51094361Sbrian/* 51176195Sbrian * inp_rawdcf 51276195Sbrian * 51376195Sbrian * grep DCF77 data from input stream 51476195Sbrian */ 51576195Sbrianstatic u_long 51676195Sbrianinp_rawdcf( 51776195Sbrian parse_t *parseio, 51876195Sbrian unsigned int ch, 51976195Sbrian timestamp_t *tstamp 52076195Sbrian ) 52176195Sbrian{ 52276195Sbrian static struct timeval timeout = { 1, 500000 }; /* 1.5 secongs denote second #60 */ 52376195Sbrian 52476195Sbrian parseprintf(DD_PARSE, ("inp_rawdcf(0x%x, 0x%x, ...)\n", (int)parseio, (int)ch)); 52576195Sbrian 52676195Sbrian parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */ 52776195Sbrian 52876195Sbrian if (parse_timedout(parseio, tstamp, &timeout)) 52976195Sbrian { 53076195Sbrian parseprintf(DD_PARSE, ("inp_rawdcf: time out seen\n")); 53176195Sbrian 53276195Sbrian (void) parse_end(parseio); 53376195Sbrian (void) parse_addchar(parseio, ch); 53476195Sbrian return PARSE_INP_TIME; 53576195Sbrian } 53676195Sbrian else 53776195Sbrian { 53876195Sbrian unsigned int rtc; 53976195Sbrian 54076195Sbrian rtc = parse_addchar(parseio, ch); 54176195Sbrian if (rtc == PARSE_INP_SKIP) 54277004Sbrian { 543111119Simp if (snt_rawdcf(parseio, tstamp) == CVT_OK) 54476195Sbrian return PARSE_INP_SYNTH; 54576195Sbrian } 54676195Sbrian return rtc; 54777004Sbrian } 548111119Simp} 54976195Sbrian 55076195Sbrian#else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_RAWDCF) */ 55176195Sbrianint clk_rawdcf_bs; 55276195Sbrian#endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_RAWDCF) */ 55376195Sbrian 55476195Sbrian/* 55576195Sbrian * History: 55676195Sbrian * 55776195Sbrian * clk_rawdcf.c,v 55876195Sbrian * Revision 4.6 1998/06/14 21:09:37 kardel 55976195Sbrian * Sun acc cleanup 56076195Sbrian * 56176195Sbrian * Revision 4.5 1998/06/13 12:04:16 kardel 56276195Sbrian * fix SYSV clock name clash 56376195Sbrian * 56476195Sbrian * Revision 4.4 1998/06/12 15:22:28 kardel 56576195Sbrian * fix prototypes 56676195Sbrian * 56776195Sbrian * Revision 4.3 1998/06/06 18:33:36 kardel 56876195Sbrian * simplified condidional compile expression 56976195Sbrian * 57076195Sbrian * Revision 4.2 1998/05/24 11:04:18 kardel 57176195Sbrian * triggering PPS on negative edge for simpler wiring (Rx->DCD) 57276195Sbrian * 57376195Sbrian * Revision 4.1 1998/05/24 09:39:53 kardel 57476195Sbrian * implementation of the new IO handling model 57576195Sbrian * 57676195Sbrian * Revision 4.0 1998/04/10 19:45:30 kardel 57776195Sbrian * Start 4.0 release version numbering 57876195Sbrian * 57976195Sbrian * from V3 3.24 log info deleted 1998/04/11 kardel 58076195Sbrian * 58176195Sbrian */ 58276195Sbrian