2000-09-12 Harlan Stenn <stenn@whimsy.udel.edu>
+ * ntpd/refclock_conf.c:
+ * ntpd/refclock_oncore.c: Re-enabled oncore driver for HAVE_PPSAPI
+ case only.
+
+2000-09-12 Philippe De Muyter <phdm@macqel.be>
+
+ * ntpd/refclock_parse.c (we400a_pollinfo): Useless variable removed.
+ [WHARTON slot]: Set NO_POLL, NO_INIT and NO_DATA; fix `fixed format'
+ and `offset' fields.
+
+ * include/ntp_tty.h: New file
+ * libntp/icom.c: Use it.
+
+ * ntp_update (UPDATE_OPTIONS): Use -d, too. Fix Pass 1 comment.
+
+2000-09-12 Harlan Stenn <stenn@whimsy.udel.edu>
+
+ * ntpd/refclock_oncore.c: shmem_fname added. oncore_init_shmem()
+ updated.
+ (oncore_start): Comment cleanup
+ (oncore_read_config): Move call to oncore_shmem_init()
+ (oncore_init_shmem): Prototype change
+ (oncore_init_shmem): Don't exit on errors
+ (oncore_msg_any): timespec/timeval cleanup
+ (oncore_msg_Cj_id): shmem_fname changes
+ (oncore_msg_BaEaHa): saw_At bugfix
+ (oncore_get_timestamp): Added current_mode/current_params. Commented.
+ Added time_pps_getcap() calls.
+ From: Reg Clemens <reg@dwf.com>
+
* ntpd/ntp_io.c (input_handler): Better recvfrom() error message
From: Dean Gibson <timekeeper@tcp-udp.net>
--- /dev/null
+/*
+ * ntp_tty.h - header file for serial lines handling
+ */
+
+#ifndef NTP_TTY_H
+#define NTP_TTY_H
+
+#if defined(HAVE_BSD_TTYS)
+#include <sgtty.h>
+#define TTY struct sgttyb
+#endif /* HAVE_BSD_TTYS */
+
+#if defined(HAVE_SYSV_TTYS)
+#include <termio.h>
+#define TTY struct termio
+#ifndef tcsetattr
+#define tcsetattr(fd, cmd, arg) ioctl(fd, cmd, arg)
+#endif
+#ifndef TCSANOW
+#define TCSANOW TCSETA
+#endif
+#ifndef TCIFLUSH
+#define TCIFLUSH 0
+#endif
+#ifndef TCOFLUSH
+#define TCOFLUSH 1
+#endif
+#ifndef TCIOFLUSH
+#define TCIOFLUSH 2
+#endif
+#ifndef tcflush
+#define tcflush(fd, arg) ioctl(fd, TCFLSH, arg)
+#endif
+#endif /* HAVE_SYSV_TTYS */
+
+#if defined(HAVE_TERMIOS)
+# ifdef TERMIOS_NEEDS__SVID3
+# define _SVID3
+# endif
+# include <termios.h>
+# ifdef TERMIOS_NEEDS__SVID3
+# undef _SVID3
+# endif
+#define TTY struct termios
+#endif
+
+#if defined(HAVE_SYS_MODEM_H)
+#include <sys/modem.h>
+#endif
+
+#if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
+#define BSD_TTYS
+#endif /* SYSV_TTYS STREAM BSD_TTYS */
+
+/*
+ * Line discipline flags. These require line discipline or streams
+ * modules to be installed/loaded in the kernel. If specified, but not
+ * installed, the code runs as if unspecified.
+ */
+#define LDISC_STD 0x0 /* standard */
+#define LDISC_CLK 0x1 /* tty_clk \n intercept */
+#define LDISC_CLKPPS 0x2 /* tty_clk \377 intercept */
+#define LDISC_ACTS 0x4 /* tty_clk #* intercept */
+#define LDISC_CHU 0x8 /* depredated */
+#define LDISC_PPS 0x10 /* ppsclock, ppsapi */
+#define LDISC_RAW 0x20 /* raw binary */
+
+#endif /* NTP_TTY_H */
#include <config.h>
#endif
-#if defined(REFCLOCK) && defined(CLOCK_ONCORE) && defined(HAVE_PPSAPI) && 0
+#if defined(REFCLOCK) && defined(CLOCK_ONCORE) && defined(HAVE_PPSAPI)
#include <stdio.h>
#include <ctype.h>
long offset; /* ns */
u_char *shmem;
+ char *shmem_fname;
u_int shmem_Cb;
u_int shmem_Ba;
u_int shmem_Ea;
static void oncore_shutdown P((int, struct peer *));
static int oncore_start P((int, struct peer *));
static void oncore_get_timestamp P((struct instance *, long, long));
-static void oncore_init_shmem P((struct instance *, char *));
+static void oncore_init_shmem P((struct instance *));
static void oncore_print_As P((struct instance *));
static void oncore_msg_any P((struct instance *, u_char *, size_t, int));
instance->pps_p.clear_offset.tv_nsec = 0;
}
instance->pps_p.mode |= PPS_TSFMT_TSPEC;
- instance->pps_p.mode &= mode; /* only do it if it is legal */
+ instance->pps_p.mode &= mode; /* only set what is legal */
if (time_pps_setparams(instance->pps_h, &instance->pps_p) < 0) {
perror("time_pps_setparams");
for (; *ca && isascii((int)*ca) && (isspace((int)*ca) || (*ca == '=')); ca++)
continue;
- if (!strncmp(cc, "STATUS", (size_t) 6)) {
- oncore_init_shmem(instance, ca);
+ /*
+ * move call to oncore_shmem_init() from here to after
+ * we have determined Oncore Model, so we can ignore
+ * request if model doesnt 'support' it
+ */
+
+ if (!strncmp(cc, "STATUS", (size_t) 6) || !strncmp(cc, "SHMEM", (size_t) 5)) {
+ i = strlen(ca);
+ instance->shmem_fname = (char *) malloc((unsigned) (i+1));
+ strcpy(instance->shmem_fname, ca);
continue;
}
static void
oncore_init_shmem(
- struct instance *instance,
- char *filename
+ struct instance *instance
)
{
#ifdef ONCORE_SHMEM_STATUS
return;
instance->shmem_first++;
+
+ if ((instance->statusfd = open(instance->shmem_fname, O_RDWR|O_CREAT|O_TRUNC, 0644)) < 0) {
+ perror(instance->shmem_fname);
+ return;
+ }
+
n = 1;
for (mp = oncore_messages; mp->flag[0]; mp++) {
mp->shmem = n;
oncore_shmem_length = n + 2;
fprintf(stderr, "ONCORE: SHMEM length: %d bytes\n", (int) oncore_shmem_length);
- instance->statusfd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0644);
- if (instance->statusfd < 0) {
- perror(filename);
- exit(4);
- }
buf = malloc(oncore_shmem_length);
if (buf == NULL) {
perror("malloc");
- exit(4);
+ return;
}
memset(buf, 0, sizeof(buf));
i = write(instance->statusfd, buf, oncore_shmem_length);
if (i != oncore_shmem_length) {
- perror(filename);
- exit(4);
+ perror(instance->shmem_fname);
+ return;
}
free(buf);
instance->shmem = (u_char *) mmap(0, oncore_shmem_length,
if (instance->shmem == (u_char *)MAP_FAILED) {
instance->shmem = 0;
close (instance->statusfd);
- exit(4);
+ return;
}
for (mp = oncore_messages; mp->flag[0]; mp++) {
l = mp->shmem;
int i;
const char *fmt = oncore_messages[idx].fmt;
const char *p;
+#ifdef HAVE_STRUCT_TIMESPEC
+ struct timespec tv;
+#else
struct timeval tv;
+#endif
if (debug > 3) {
GETTIMEOFDAY(&tv, 0);
*/
/*BAD M12*/ if (instance->model == ONCORE_M12 && instance->version == 1 && instance->revision <= 3) {
- instance->shmem = 0;
+ instance->shmem_fname = 0;
cp = "*** SHMEM turned off for ONCORE M12 ***";
record_clock_stats(&(instance->peer->srcadr), cp);
}
+ /*
+ * we now know model number and have zeroed
+ * instance->shmem_fname if SHMEM is not supported
+ */
+
+ if (instance->shmem_fname);
+ oncore_init_shmem(instance);
+
if (instance->shmem)
cp = "SHMEM is available";
else
cp = "state = ONCORE_TEST_SENT";
record_clock_stats(&(instance->peer->srcadr), cp);
instance->timeout = 4;
-
}
}
/* stuck in here as it only gets done once */
- if (!instance->saw_At) {
+ if (instance->chan != 12 && !instance->saw_At) {
cp = "Not Good, no @@At command, must be a GT/GT+";
record_clock_stats(&(instance->peer->srcadr), cp);
oncore_sendmsg(instance->ttyfd, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
struct timeval *tsp = 0;
#endif
#ifdef HAVE_PPSAPI
+ int current_mode;
+ pps_params_t current_params;
struct timespec timeout;
pps_info_t pps_i;
#else /* ! HAVE_PPSAPI */
else
instance->pps_p.clear_offset.tv_nsec = -dt2;
- if (time_pps_setparams(instance->pps_h, &instance->pps_p))
+ /* The following code is necessary, and not just a time_pps_setparams,
+ * using the saved instance->pps_p, since some other process on the
+ * machine may have diddled with the mode bits (say adding something
+ * that it needs). We take what is there and ADD what we need.
+ * [[ The results from the time_pps_getcap is unlikely to change so
+ * we could probably just save it, but I choose to do the call ]]
+ * Unfortunately, there is only ONE set of mode bits in the kernel per
+ * interface, and not one set for each open handle.
+ *
+ * There is still a race condition here where we might mess up someone
+ * elses mode, but if he is being careful too, he should survive.
+ */
+
+ if (time_pps_getcap(instance->pps_h, ¤t_mode) < 0) {
+ msyslog(LOG_ERR,
+ "refclock_ioctl: time_pps_getcap failed: %m");
+ return (0);
+ }
+
+ if (time_pps_getparams(instance->pps_h, ¤t_params) < 0) {
+ msyslog(LOG_ERR,
+ "refclock_ioctl: time_pps_getparams failed: %m");
+ return (0);
+ }
+
+ /* or current and mine */
+ current_params.mode |= instance->pps_p.mode;
+ /* but only set whats legal */
+ current_params.mode &= current_mode;
+
+ current_params.assert_offset.tv_sec = 0;
+ current_params.assert_offset.tv_nsec = -dt2;
+ current_params.clear_offset.tv_sec = 0;
+ current_params.clear_offset.tv_nsec = -dt2;
+
+ if (time_pps_setparams(instance->pps_h, ¤t_params))
perror("time_pps_setparams");
#else
/* if not PPSAPI, no way to inform kernel of OFFSET, just add the */
#define COMPUTIME_SAMPLES 5
#define COMPUTIME_KEEP 3
-static poll_info_t we400a_pollinfo = { 60, "T", 1 };
-
/*
* Varitext Radio Clock Receiver
*/
},
{ /* mode 15 */
0, /* operation flags (io modes) */
- poll_dpoll, /* active poll routine */
- poll_init, /* active poll init routine */
+ NO_POLL, /* active poll routine */
+ NO_INIT, /* active poll init routine */
NO_EVENT, /* special event handling (e.g. reset clock) */
NO_END, /* active poll end routine */
NO_MESSAGE, /* process a lower layer message */
- ((void *)(&we400a_pollinfo)), /* local data area for "poll" mechanism */
+ NO_DATA, /* local data area for "poll" mechanism */
0, /* rootdelay */
- 1.0 / 960, /* current offset by which the RS232
+ 11.0 /* bits */ / 9600, /* current offset by which the RS232
time code is delayed from the actual time */
DCF_ID, /* ID code */
"WHARTON 400A Series clock", /* device name */
- "WHARTON 400A Series clock Output Format 5", /* fixed format */
+ "WHARTON 400A Series clock Output Format 1", /* fixed format */
/* Must match a format-name in a libparse/clk_xxx.c file */
DCF_TYPE, /* clock type (ntp control) */
(1*60*60), /* time to trust oscillator after loosing synch */