#include "ntp_stdlib.h"
+int dbg = 0;
/*
fudgefactor = fudgetime1;
os_delay = fudgetime2;
offset_fudge = os_delay + fudgefactor + inherent_delay;
stratumtouse = fudgeval1 & 0xf
- debug = fudgeval2;
+ dbg = fudgeval2;
sloppyclockflag = flags & CLK_FLAG1;
1 log smoothing summary when processing sample
4 dump the buffer from the clock
ees = (struct eesunit *)rbufp->recv_srcclock;
dpt = (u_char *)&rbufp->recv_space;
dpend = dpt + rbufp->recv_length;
- if ((debug & DB_LOG_AWAITMORE) && (rbufp->recv_length != LENEESCODE))
+ if ((dbg & DB_LOG_AWAITMORE) && (rbufp->recv_length != LENEESCODE))
printf("[%d] ", rbufp->recv_length);
/* Check out our state and process appropriately */
/* Gave up because it was end of the buffer, rather than ff */
if (dpt == dpend) {
/* Incomplete. Wait for more. */
- if (debug & DB_LOG_AWAITMORE)
+ if (dbg & DB_LOG_AWAITMORE)
msyslog(LOG_INFO,
"I: ees clock %d: %p == %p: await more",
ees->unit, dpt, dpend);
memset((char *) &ppsclockev, 0, sizeof ppsclockev);
rc = ioctl(ees->io.fd, request, (char *) &ppsclockev);
- if (debug & DB_PRINT_EV) fprintf(stderr,
+ if (dbg & DB_PRINT_EV) fprintf(stderr,
"[%x] CIOGETEV u%d %d (%x %d) gave %d (%d): %08lx %08lx %ld\n",
DB_PRINT_EV, ees->unit, ees->io.fd, request, is_pps(ees),
rc, errno, ptr[0], ptr[1], ptr[2]);
diff = pps_arrvstamp;
conv = 0;
L_SUB(&diff, &ees->arrvtime);
- if (debug & DB_PRINT_CDT)
+ if (dbg & DB_PRINT_CDT)
printf("[%x] Have %lx.%08lx and %lx.%08lx -> %lx.%08lx @ %s",
DB_PRINT_CDT, (long)ees->arrvtime.l_ui, (long)ees->arrvtime.l_uf,
(long)pps_arrvstamp.l_ui, (long)pps_arrvstamp.l_uf,
}
}
ees->last_pps_no = ppsclockev.serial;
- if (debug & DB_PRINT_CDTC)
+ if (dbg & DB_PRINT_CDTC)
printf(
"[%x] %08lx %08lx %d u%d (%d %d)\n",
DB_PRINT_CDTC, (long)pps_arrvstamp.l_ui,
if (delta_f_abs < 0) delta_f_abs = -delta_f_abs;
/* Dump the deltas each minute */
- if (debug & DB_DUMP_DELTAS)
+ if (dbg & DB_DUMP_DELTAS)
{ if (/*0 <= ees->second && */
ees->second < ((sizeof deltas) / (sizeof deltas[0]))) deltas[ees->second] = delta_sfsec;
/* Dump on second 1, as second 0 sometimes missed */
/* sec_of_ramp * ees->jump_fsecs may overflow 2**32 */
fsecs = sec_of_ramp * (ees->jump_fsecs / ees->last_step_secs);
- if (debug & DB_LOG_DELTAS) msyslog(LOG_ERR,
+ if (dbg & DB_LOG_DELTAS) msyslog(LOG_ERR,
"[%x] MSF%d: %3ld/%03d -> d=%11ld (%d|%ld)",
DB_LOG_DELTAS,
ees->unit, sec_of_ramp, ees->last_step_secs, fsecs,
pps_arrvstamp.l_f, pps_arrvstamp.l_f + fsecs);
- if (debug & DB_PRINT_DELTAS) printf(
+ if (dbg & DB_PRINT_DELTAS) printf(
"MSF%d: %3ld/%03d -> d=%11ld (%ld|%ld)\n",
ees->unit, sec_of_ramp, ees->last_step_secs, fsecs,
(long)pps_arrvstamp.l_f, pps_arrvstamp.l_f + fsecs);
/* Must sign extend the result */
inc.l_i = (fsecs < 0) ? -1 : 0;
inc.l_f = fsecs;
- if (debug & DB_INC_PPS)
+ if (dbg & DB_INC_PPS)
{ L_SUB(&pps_arrvstamp, &inc);
L_SUB(&ees->arrvtime, &inc);
}
}
}
else {
- if (debug & DB_LOG_DELTAS) msyslog(LOG_ERR,
+ if (dbg & DB_LOG_DELTAS) msyslog(LOG_ERR,
"[%x] MSF%d: ees->using_ramp=%d, sincelast=%x / %x, ees->last_step_secs=%x",
DB_LOG_DELTAS,
ees->unit, ees->using_ramp,
sincelast,
(ees->last_step_secs)*2,
ees->last_step_secs);
- if (debug & DB_PRINT_DELTAS) printf(
+ if (dbg & DB_PRINT_DELTAS) printf(
"[%x] MSF%d: ees->using_ramp=%d, sincelast=%x / %x, ees->last_step_secs=%x\n",
DB_LOG_DELTAS,
ees->unit, ees->using_ramp,
L_SUB(&ees->arrvtime, &offset_fudge[ees->unit]);
L_SUB(&pps_arrvstamp, &offset_fudge[ees->unit]);
- if (call_pps_sample && !(debug & DB_NO_PPS)) {
+ if (call_pps_sample && !(dbg & DB_NO_PPS)) {
/* Sigh -- it expects its args negated */
L_NEG(&pps_arrvstamp);
/*
/* Subtract off the local clock time stamp */
L_SUB(&ees->codeoffsets[n_sample], &ees->arrvtime);
- if (debug & DB_LOG_SAMPLES) msyslog(LOG_ERR,
+ if (dbg & DB_LOG_SAMPLES) msyslog(LOG_ERR,
"MSF%d: [%x] %d (ees: %d %d) (pps: %d %d)%s",
ees->unit, DB_LOG_DELTAS, n_sample,
ees->codeoffsets[n_sample].l_f,
ees->codeoffsets[n_sample].l_f / 4295,
pps_arrvstamp.l_f,
pps_arrvstamp.l_f /4295,
- (debug & DB_NO_PPS) ? " [no PPS]" : "");
+ (dbg & DB_NO_PPS) ? " [no PPS]" : "");
if (ees->nsamples++ == NCODES-1) ees_process(ees);
L_SUB(&tmp, &coffs[i]);
#define FRACT_SEC(n) ((1 << 30) / (n/2))
dispersion = LFPTOFP(&tmp) / 2; /* ++++ */
- if (debug & (DB_SYSLOG_SMPLI | DB_SYSLOG_SMPLE)) msyslog(
- (debug & DB_SYSLOG_SMPLE) ? LOG_ERR : LOG_INFO,
+ if (dbg & (DB_SYSLOG_SMPLI | DB_SYSLOG_SMPLE)) msyslog(
+ (dbg & DB_SYSLOG_SMPLE) ? LOG_ERR : LOG_INFO,
"I: [%x] Offset=%06d (%d), disp=%f%s [%d], %d %d=%d %d:%d %d=%d %d",
- debug & (DB_SYSLOG_SMPLI | DB_SYSLOG_SMPLE),
+ dbg & (DB_SYSLOG_SMPLI | DB_SYSLOG_SMPLE),
offset.l_f / 4295, offset.l_f,
(dispersion * 1526) / 100,
(sloppyclockflag[ees->unit]) ? " by averaging" : "",
offset.l_ui += (new < 0) ? -1 : 1;
}
dispersion /= 4;
- if (debug & (DB_SYSLOG_SMTHI | DB_SYSLOG_SMTHE)) msyslog(
- (debug & DB_SYSLOG_SMTHE) ? LOG_ERR : LOG_INFO,
+ if (dbg & (DB_SYSLOG_SMTHI | DB_SYSLOG_SMTHE)) msyslog(
+ (dbg & DB_SYSLOG_SMTHE) ? LOG_ERR : LOG_INFO,
"I: [%x] Smooth data: %ld -> %ld, dispersion now %f",
- debug & (DB_SYSLOG_SMTHI | DB_SYSLOG_SMTHE),
+ dbg & (DB_SYSLOG_SMTHI | DB_SYSLOG_SMTHE),
((long) offset.l_uf) / 4295, new / 4295,
(dispersion * 1526) / 100);
offset.l_uf = (unsigned long) new;
}
- else if (debug & (DB_SYSLOG_NSMTHI | DB_SYSLOG_NSMTHE)) msyslog(
- (debug & DB_SYSLOG_NSMTHE) ? LOG_ERR : LOG_INFO,
+ else if (dbg & (DB_SYSLOG_NSMTHI | DB_SYSLOG_NSMTHE)) msyslog(
+ (dbg & DB_SYSLOG_NSMTHE) ? LOG_ERR : LOG_INFO,
"[%x] No smooth as delta not %d < %ld < %d",
- debug & (DB_SYSLOG_NSMTHI | DB_SYSLOG_NSMTHE),
+ dbg & (DB_SYSLOG_NSMTHI | DB_SYSLOG_NSMTHE),
- FRACT_SEC(100), diff, FRACT_SEC(100));
}
- else if (debug & (DB_SYSLOG_NSMTHI | DB_SYSLOG_NSMTHE)) msyslog(
- (debug & DB_SYSLOG_NSMTHE) ? LOG_ERR : LOG_INFO,
+ else if (dbg & (DB_SYSLOG_NSMTHI | DB_SYSLOG_NSMTHE)) msyslog(
+ (dbg & DB_SYSLOG_NSMTHE) ? LOG_ERR : LOG_INFO,
"I: [%x] No smooth as flag=%x and old=%x=%d (%d:%d)",
- debug & (DB_SYSLOG_NSMTHI | DB_SYSLOG_NSMTHE),
+ dbg & (DB_SYSLOG_NSMTHI | DB_SYSLOG_NSMTHE),
ees->usealldata, ees->offset.l_f, ees->offset.l_uf,
offset.l_f, ees->offset.l_f - offset.l_f);
for (i=1; i < rcvptr-1; i++)
if (rcvbuf[i] == '@' && rcvbuf[i+1] == '@')
break;
+#ifdef DEBUG
if (debug > 4)
printf("ONCORE[%d]: >>> skipping %d chars\n", instance->unit, i);
+#endif
if (i != rcvptr)
memcpy(rcvbuf, rcvbuf+i, (size_t)(rcvptr-i));
rcvptr -= i;
if (!strncmp(oncore_messages[m].flag, (char *)(rcvbuf+2), (size_t) 2))
break;
if (m == l) {
+#ifdef DEBUG
if (debug > 4)
printf("ONCORE[%d]: >>> Unknown MSG, skipping 4 (%c%c)\n", instance->unit, rcvbuf[2], rcvbuf[3]);
+#endif
memcpy(rcvbuf, rcvbuf+4, (size_t) 4);
rcvptr -= 4;
continue;
/* are we at the end of message? should be <Cksum><CR><LF> */
if (rcvbuf[l-2] != '\r' || rcvbuf[l-1] != '\n') {
+#ifdef DEBUG
if (debug)
printf("ONCORE[%d]: NO <CR><LF> at end of message\n", instance->unit);
+#endif
} else { /* check the CheckSum */
if (oncore_checksum_ok(rcvbuf, l)) {
if (instance->shmem != NULL) {
oncore_msg_any(instance, rcvbuf, (size_t) (l-3), m);
if (oncore_messages[m].handler)
oncore_messages[m].handler(instance, rcvbuf, (size_t) (l-3));
- } else if (debug) {
+ }
+#ifdef DEBUG
+ else if (debug) {
printf("ONCORE[%d]: Checksum mismatch!\n", instance->unit);
printf("ONCORE[%d]: @@%c%c ", instance->unit, rcvbuf[2], rcvbuf[3]);
for (i=4; i<l; i++)
printf("%03o ", rcvbuf[i]);
printf("\n");
}
+#endif
}
if (l != rcvptr)
if (instance->assert) {
tsp = &pps_i.assert_timestamp;
+#ifdef DEBUG
if (debug > 2) {
i = (u_long) pps_i.assert_sequence;
-#ifdef HAVE_STRUCT_TIMESPEC
+# ifdef HAVE_STRUCT_TIMESPEC
printf("ONCORE[%d]: serial/j (%lu, %lu) %ld.%09ld\n",
instance->unit, i, j,
(long)tsp->tv_sec, (long)tsp->tv_nsec);
-#else
+# else
printf("ONCORE[%d]: serial/j (%lu, %lu) %ld.%06ld\n",
instance->unit, i, j,
(long)tsp->tv_sec, (long)tsp->tv_usec);
-#endif
+# endif
}
+#endif
if (pps_i.assert_sequence == j) {
printf("ONCORE: oncore_get_timestamp, error serial pps\n");
} else {
tsp = &pps_i.clear_timestamp;
+#ifdef DEBUG
if (debug > 2) {
i = (u_long) pps_i.clear_sequence;
-#ifdef HAVE_STRUCT_TIMESPEC
+# ifdef HAVE_STRUCT_TIMESPEC
printf("ONCORE[%d]: serial/j (%lu, %lu) %ld.%09ld\n",
instance->unit, i, j, (long)tsp->tv_sec, (long)tsp->tv_nsec);
-#else
+# else
printf("ONCORE[%d]: serial/j (%lu, %lu) %ld.%06ld\n",
instance->unit, i, j, (long)tsp->tv_sec, (long)tsp->tv_usec);
-#endif
+# endif
}
+#endif
if (pps_i.clear_sequence == j) {
printf("ONCORE: oncore_get_timestamp, error serial pps\n");
);
}
+#ifdef DEBUG
if (debug > 2) {
int n;
+
n = strlen(instance->pp->a_lastcode);
printf("ONCORE[%d]: len = %d %s\n", instance->unit, n, instance->pp->a_lastcode);
}
+#endif
/* and some things I dont understand (magic ntp things) */
#endif
struct timeval tv;
+#ifdef DEBUG
if (debug > 3) {
-#ifdef HAVE_GETCLOCK
+# ifdef HAVE_GETCLOCK
(void) getclock(TIMEOFDAY, &ts);
tv.tv_sec = ts.tv_sec;
tv.tv_usec = ts.tv_nsec / 1000;
-#else
+# else
GETTIMEOFDAY(&tv, 0);
-#endif
+# endif
printf("ONCORE[%d]: %ld.%06ld\n", instance->unit, (long) tv.tv_sec, (long) tv.tv_usec);
if (!*fmt) {
printf("\n");
}
}
+#endif
}
instance->timeout = 0;
+#ifdef DEBUG
if (debug > 2) {
if (buf[2] == 'I')
printf("ONCORE[%d]: >>@@%ca %x %x %x\n", instance->unit, buf[2], buf[4], buf[5], buf[6]);
else
printf("ONCORE[%d]: >>@@%ca %x %x\n", instance->unit, buf[2], buf[4], buf[5]);
}
+#endif
antenna = (buf[4] & 0xc0) >> 6;
buf[4] &= ~0xc0;
{
u_char cs = 0;
+#ifdef DEBUG
if (debug > 4)
printf("ONCORE: Send @@%c%c %d\n", ptr[0], ptr[1], (int) len);
+#endif
write(fd, "@@", (size_t) 2);
write(fd, ptr, len);
while (len--)
)
{
if (instance->rsm.bad_almanac) {
+#ifdef DEBUG
if (debug)
printf("ONCORE[%d]: waiting for almanac\n", instance->unit);
+#endif
/*
* If we get here (first time) then we don't have an almanac in memory.