[LinuxPPS] refclock_nmea patch
Udo van den Heuvel
udovdh at xs4all.nl
Mon Oct 22 19:43:33 CEST 2007
Rodolfo Giometti wrote:
>> static int day1tab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
>> static int day2tab[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
>>
>> +char id[LENPPS] = "";
>> +
>
> I don't understand why you need it...
id was in the old syslog messages. Do we lose functionality if I remove
the id variable?
> Ok, you are very near to the final patch! :)
I dared to test the previous version:
Oct 22 19:19:53 epia ntpd[3498]: ntpd 4.2.4p2 at 1.1495-o Sun Oct 21
12:07:11 UTC 2007 (1)
Oct 22 19:19:53 epia ntpd[3499]: precision = 1.000 usec
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #0 wildcard,
0.0.0.0#123 Disabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #1 wildcard,
::#123 Disabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #2 sit0,
::192.168.10.98#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #3 lo, ::1#123
Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #4 sit0,
::10.0.0.150#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #5 eth1,
fe80::240:63ff:fee9:176d#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #6 sit0,
::127.0.0.1#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #7 eth0,
fe80::240:63ff:fee9:176c#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #8 eth0,
192.168.10.98#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #9 eth1,
10.0.0.150#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #10 lo,
127.0.0.1#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: Listening on interface #11 ppp0,
82.92.197.115#123 Enabled
Oct 22 19:19:53 epia ntpd[3499]: kernel time sync status 0040
Oct 22 19:19:53 epia ntpd[3499]: refclock_nmea: try alternate PPS device
/dev/pps0
Oct 22 19:19:53 epia ntpd[3499]: refclock_nmea: found PPS source
"/dev/pps%d" at id #6 on ""
Oct 22 19:19:53 epia ntpd[3499]: refclock_nmea: time_pps_kcbind failed:
Operation not supported
Oct 22 19:19:53 epia ntpd[3499]: refclock_atom: time_pps_kcbind failed:
Operation not supported
Oct 22 19:19:53 epia ntpd[3499]: frequency initialized -114.295 PPM from
/var/lib/ntp/drift
Oct 22 19:20:46 epia ntpd[3499]: time reset +0.202196 s
Oct 22 19:20:46 epia ntpd[3499]: kernel time sync status change 0001
Note the %d in the message string and that the first gps0 device is not
used. %d was fixed with your suggestion.
/dev/gps0 points to /dev/ttyS0. Is the fd still open when it reaches the
LinuxPPS part that we change? Maybe reopen the fd?
I see:
[root at epia ntpd]# setserial /dev/ttyS0
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4, Flags: hardpps low_latency
[root at epia ntpd]# setserial /dev/gps0
/dev/gps0, UART: 16550A, Port: 0x03f8, IRQ: 4, Flags: hardpps low_latency
[root at epia ntpd]# setserial /dev/pps0
[root at epia ntpd]# ls -l /dev/?ps0
lrwxrwxrwx 1 root root 10 2007-10-22 19:17 /dev/gps0 -> /dev/ttyS0
crw------- 1 root root 254, 0 2007-10-22 19:17 /dev/pps0
[root at epia ntpd]# ls -l /dev/ttyS0
crw-rw---- 1 root uucp 4, 64 2007-10-22 19:36 /dev/ttyS0
Any ideas!?
and:
# ntpq -pn
remote refid st t when poll reach delay offset
jitter
==============================================================================
127.127.1.0 .LOCL. 10 l 45 64 17 0.000 0.000
0.001
+127.127.20.0 .GPS. 0 l 15 16 377 0.000 5.161
0.833
o127.127.22.0 .PPS. 0 l 11 16 377 0.000 5.198
0.881
x194.109.22.18 193.79.237.14 2 u 40 64 17 7.679 0.734
2.499
213.84.46.114 130.149.17.8 2 u 60 64 17 15.933 7.398
2.503
80.85.129.25 130.235.20.3 3 u 13 64 17 11.608 6.658
1.764
213.249.66.35 193.190.230.65 2 u 29 64 17 8.687 5.542
2.941
83.81.175.82 130.149.17.8 2 u 64 64 17 18.075 5.007
2.510
81.19.16.225 .STEP. 16 u - 64 0 0.000 0.000
0.000
+85.91.1.164 193.120.10.3 2 u 2 64 37 27.219 4.832
2.343
62.84.188.34 193.67.79.202 2 u 2 64 37 15.396 1.178
2.488
So looks reasonable for this short run?
BTW: I did not change the PPS driver patch but it runs!?
-------------- next part --------------
--- org.ntp-4.2.4p2/ntpd/refclock_nmea.c 2006-06-06 22:16:53.000000000 +0200
+++ ntp-4.2.4p2/ntpd/refclock_nmea.c 2007-10-22 19:35:33.000000000 +0200
@@ -61,6 +61,7 @@
# define DEVICE "COM%d:" /* COM 1 - 3 supported */
#else
# define DEVICE "/dev/gps%d" /* name of radio device */
+# define DEVICEPPS "/dev/pps%d" /* name of alternate PPS radio device */
#endif
#define SPEED232 B4800 /* uart speed (4800 bps) */
#define PRECISION (-9) /* precision assumed (about 2 ms) */
@@ -71,6 +72,7 @@
#define RANGEGATE 500000 /* range gate (ns) */
#define LENNMEA 75 /* min timecode length */
+#define LENPPS PPS_MAX_NAME_LEN
/*
* Tables to compute the ddd of year form icky dd/mm timecode. Viva la
@@ -231,15 +233,27 @@
* the assert edge and do not enable the kernel hardpps.
*/
if (time_pps_create(fd, &up->handle) < 0) {
- up->handle = 0;
- msyslog(LOG_ERR,
- "refclock_nmea: time_pps_create failed: %m");
- return (1);
+ /* Try the alternare PPS device */
+ (void) sprintf(device, DEVICEPPS, unit);
+ msyslog(LOG_ERR, "refclock_nmea: try alternate PPS device %s", device);
+ fd = open(device, O_RDWR);
+ if (fd < 0)
+ goto pps_error;
+ if (time_pps_create(fd, &up->handle) < 0)
+ goto pps_error;
}
+ else (void) sprintf(device, DEVICE, unit); /* just rebuild device's name */
+ msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\" at id #%d", device , fd);
return(nmea_ppsapi(peer, 0, 0));
-#else
+#else /* HAVE_PPSAPI */
return (1);
#endif /* HAVE_PPSAPI */
+
+pps_error:
+ /* No luck, no PPS unit available! */
+ up->handle = -1;
+ msyslog(LOG_ERR, "refclock_nmea: no PPS devices found at " DEVICE " nor " DEVICEPPS ": %m", unit, unit);
+ return (1);
}
/*
@@ -257,8 +271,7 @@
pp = peer->procptr;
up = (struct nmeaunit *)pp->unitptr;
#ifdef HAVE_PPSAPI
- if (up->handle != 0)
- time_pps_destroy(up->handle);
+ time_pps_destroy(up->handle);
#endif /* HAVE_PPSAPI */
io_closeclock(&pp->io);
free(up);
@@ -366,7 +379,7 @@
/*
* Convert the timespec nanoseconds field to ntp l_fp units.
*/
- if (up->handle == 0)
+ if (up->handle == -1)
return (0);
timeout.tv_sec = 0;
timeout.tv_nsec = 0;
More information about the LinuxPPS
mailing list