diff options
Diffstat (limited to 'contrib/ntp/ntpd/refclock_neoclock4x.c')
-rw-r--r-- | contrib/ntp/ntpd/refclock_neoclock4x.c | 119 |
1 files changed, 82 insertions, 37 deletions
diff --git a/contrib/ntp/ntpd/refclock_neoclock4x.c b/contrib/ntp/ntpd/refclock_neoclock4x.c index 082b1cf..374c81a 100644 --- a/contrib/ntp/ntpd/refclock_neoclock4x.c +++ b/contrib/ntp/ntpd/refclock_neoclock4x.c @@ -3,12 +3,12 @@ * Refclock_neoclock4x.c * - NeoClock4X driver for DCF77 or FIA Timecode * - * Date: 2003-07-07 v1.13 + * Date: 2006-01-11 v1.15 * * see http://www.linum.com/redir/jump/id=neoclock4x&action=redir * for details about the NeoClock4X device * - * Copyright (C) 2002-2003 by Linum Software GmbH <neoclock4x@linum.com> + * Copyright (C) 2002-2004 by Linum Software GmbH <neoclock4x@linum.com> * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -39,9 +39,11 @@ #if defined HAVE_SYS_MODEM_H # include <sys/modem.h> -# define TIOCMSET MCSETA -# define TIOCMGET MCGETA -# define TIOCM_RTS MRTS +# ifndef __QNXNTO__ +# define TIOCMSET MCSETA +# define TIOCMGET MCGETA +# define TIOCM_RTS MRTS +# endif #endif #ifdef HAVE_TERMIOS_H @@ -59,6 +61,17 @@ #endif /* + * NTP version 4.20 change the pp->msec field to pp->nsec. + * To allow to support older ntp versions with this sourcefile + * you can define NTP_PRE_420 to allow this driver to compile + * with ntp version back to 4.1.2. + * + */ +#if 0 +#define NTP_PRE_420 +#endif + +/* * If you want the driver for whatever reason to not use * the TX line to send anything to your NeoClock4X * device you must tell the NTP refclock driver which @@ -74,6 +87,7 @@ #define NEOCLOCK4X_FIRMWARE NEOCLOCK4X_FIRMWARE_VERSION_A #endif +/* at this time only firmware version A is known */ #define NEOCLOCK4X_FIRMWARE_VERSION_A 'A' #define NEOCLOCK4X_TIMECODELEN 37 @@ -95,7 +109,9 @@ #define NEOCLOCK4X_OFFSET_ANTENNA2 33 #define NEOCLOCK4X_OFFSET_CRC 35 -#define NEOCLOCK4X_DRIVER_VERSION "1.12 (2003-01-10)" +#define NEOCLOCK4X_DRIVER_VERSION "1.15 (2006-01-11)" + +#define NSEC_TO_MILLI 1000000 struct neoclock4x_unit { l_fp laststamp; /* last receive timestamp */ @@ -133,9 +149,6 @@ static int neol_hexatoi_len P((const char str[], int *, int)); static void neol_jdn_to_ymd P((unsigned long, int *, int *, int *)); static void neol_localtime P((unsigned long, int* , int*, int*, int*, int*, int*)); static unsigned long neol_mktime P((int, int, int, int, int, int)); -#if 0 -static void neol_mdelay P((int)); -#endif #if !defined(NEOCLOCK4X_FIRMWARE) static int neol_query_firmware P((int, int, char *, int)); static int neol_check_firmware P((int, const char*, char *)); @@ -172,13 +185,37 @@ neoclock4x_start(int unit, /* LDISC_STD, LDISC_RAW * Open serial port. Use CLK line discipline, if available. */ - fd = refclock_open(dev, B2400, LDISC_CLK); + fd = refclock_open(dev, B2400, LDISC_STD); if(fd <= 0) { return (0); } #if defined(HAVE_TERMIOS) + +#if 1 + if(tcgetattr(fd, &termsettings) < 0) + { + msyslog(LOG_CRIT, "NeoClock4X(%d): (tcgetattr) can't query serial port settings: %m", unit); + (void) close(fd); + return (0); + } + + /* 2400 Baud 8N2 */ + termsettings.c_iflag = IGNBRK | IGNPAR | ICRNL; + termsettings.c_oflag = 0; + termsettings.c_cflag = CS8 | CSTOPB | CLOCAL | CREAD; + (void)cfsetispeed(&termsettings, (u_int)B2400); + (void)cfsetospeed(&termsettings, (u_int)B2400); + + if(tcsetattr(fd, TCSANOW, &termsettings) < 0) + { + msyslog(LOG_CRIT, "NeoClock4X(%d): (tcsetattr) can't set serial port 2400 8N2: %m", unit); + (void) close(fd); + return (0); + } + +#else if(tcgetattr(fd, &termsettings) < 0) { msyslog(LOG_CRIT, "NeoClock4X(%d): (tcgetattr) can't query serial port settings: %m", unit); @@ -198,6 +235,8 @@ neoclock4x_start(int unit, (void) close(fd); return (0); } +#endif + #elif defined(HAVE_SYSV_TTYS) if(ioctl(fd, TCGETA, &termsettings) < 0) { @@ -307,7 +346,7 @@ neoclock4x_start(int unit, strcpy(up->firmware, "(c) 2002 NEOL S.A. FRANCE / L0.01 NDF:A:* (compile time)"); up->firmwaretag = 'A'; #else - msyslog(LOG_EMERG, "NeoClock4X(%d): Unkown firmware defined at compile time for NeoClock4X", + msyslog(LOG_EMERG, "NeoClock4X(%d): unknown firmware defined at compile time for NeoClock4X", unit); (void) close(fd); pp->io.fd = -1; @@ -524,7 +563,11 @@ neoclock4x_receive(struct recvbuf *rbufp) neol_atoi_len(&pp->a_lastcode[NEOCLOCK4X_OFFSET_MINUTE], &pp->minute, 2); neol_atoi_len(&pp->a_lastcode[NEOCLOCK4X_OFFSET_SECOND], &pp->second, 2); neol_atoi_len(&pp->a_lastcode[NEOCLOCK4X_OFFSET_HSEC], &dsec, 2); - pp->nsec = dsec * 10000; /* convert 1/100s from neoclock to nanoseconds */ +#if defined(NTP_PRE_420) + pp->msec = dsec * 10; /* convert 1/100s from neoclock to real miliseconds */ +#else + pp->nsec = dsec * 10 * NSEC_TO_MILLI; /* convert 1/100s from neoclock to nanoseconds */ +#endif memcpy(up->radiosignal, &pp->a_lastcode[NEOCLOCK4X_OFFSET_RADIOSIGNAL], 3); up->radiosignal[3] = 0; @@ -583,7 +626,13 @@ neoclock4x_receive(struct recvbuf *rbufp) msyslog(LOG_DEBUG, "NeoClock4X(%d): calculated UTC date/time: %04d-%02d-%02d %02d:%02d:%02d.%03ld", up->unit, pp->year, month, day, - pp->hour, pp->minute, pp->second, pp->nsec/1000); + pp->hour, pp->minute, pp->second, +#if defined(NTP_PRE_420) + pp->msec +#else + pp->nsec/NSEC_TO_MILLI +#endif + ); } up->utc_year = pp->year; @@ -592,7 +641,11 @@ neoclock4x_receive(struct recvbuf *rbufp) up->utc_hour = pp->hour; up->utc_minute = pp->minute; up->utc_second = pp->second; - up->utc_msec = pp->nsec/1000; +#if defined(NTP_PRE_420) + up->utc_msec = pp->msec; +#else + up->utc_msec = pp->nsec/NSEC_TO_MILLI; +#endif if(!refclock_process(pp)) { @@ -678,11 +731,9 @@ neoclock4x_control(int unit, if(NULL != out) { - static char outstatus[800]; /* status output buffer */ char *tt; char tmpbuf[80]; - outstatus[0] = '\0'; out->kv_list = (struct ctl_var *)0; out->type = REFCLK_NEOCLOCK4X; @@ -741,9 +792,9 @@ neol_hexatoi_len(const char str[], int i; int n = 0; - for(i=0; isxdigit(str[i]) && i < maxlen; i++) + for(i=0; isxdigit((int)str[i]) && i < maxlen; i++) { - hexdigit = isdigit(str[i]) ? toupper(str[i]) - '0' : toupper(str[i]) - 'A' + 10; + hexdigit = isdigit((int)str[i]) ? toupper(str[i]) - '0' : toupper(str[i]) - 'A' + 10; n = 16 * n + hexdigit; } *result = n; @@ -759,7 +810,7 @@ neol_atoi_len(const char str[], int i; int n = 0; - for(i=0; isdigit(str[i]) && i < maxlen; i++) + for(i=0; isdigit((int)str[i]) && i < maxlen; i++) { digit = str[i] - '0'; n = 10 * n + digit; @@ -849,24 +900,6 @@ neol_jdn_to_ymd(unsigned long jdn, *dd = (int)d; } -#if 0 -/* - * delay in milliseconds - */ -static void -neol_mdelay(int milliseconds) -{ - struct timeval tv; - - if(milliseconds) - { - tv.tv_sec = 0; - tv.tv_usec = milliseconds * 1000; - select(1, NULL, NULL, NULL, &tv); - } -} -#endif - #if !defined(NEOCLOCK4X_FIRMWARE) static int neol_query_firmware(int fd, @@ -1065,4 +1098,16 @@ int refclock_neoclock4x_bs; * - fix reporting of clock status * changes. previously a bad clock * status was never reset. + * + * 2004/04/07 cjh + * Revision 1.14 + * - open serial port in a way + * AIX and some other OS can + * handle much better + * + * 2006/01/11 cjh + * Revision 1.15 + * - remove some unsued #ifdefs + * - fix nsec calculation, closes #499 + * */ |