Change the name to match patch convention
[openwrt/svn-archive/archive.git] / net / ntpd / patches / 100-ntpd_nmea.patch
1 diff -Naurp ntp-4.2.2p4.orig/ntpd/refclock_nmea.c ntp-4.2.2p4.mash/ntpd/refclock_nmea.c
2 --- ntp-4.2.2p4.orig/ntpd/refclock_nmea.c 2006-06-06 22:16:53.000000000 +0200
3 +++ ntp-4.2.2p4.mash/ntpd/refclock_nmea.c 2006-12-13 16:22:26.000000000 +0100
4 @@ -16,6 +16,7 @@
5
6 #include <stdio.h>
7 #include <ctype.h>
8 +#include <sys/ioctl.h>
9
10 #include "ntpd.h"
11 #include "ntp_io.h"
12 @@ -72,6 +72,7 @@
13 #define RANGEGATE 500000 /* range gate (ns) */
14
15 #define LENNMEA 75 /* min timecode length */
16 +#define LENPPS LINUXPPS_MAX_NAME_LEN
17
18 /*
19 * Tables to compute the ddd of year form icky dd/mm timecode. Viva la
20 @@ -92,6 +93,7 @@ struct nmeaunit {
21 pps_params_t pps_params; /* pps parameters */
22 pps_info_t pps_info; /* last pps data */
23 pps_handle_t handle; /* pps handlebars */
24 + int handle_created; /* pps handle created flag */
25 #endif /* HAVE_PPSAPI */
26 };
27
28 @@ -140,7 +142,12 @@ nmea_start(
29 register struct nmeaunit *up;
30 struct refclockproc *pp;
31 int fd;
32 +#ifdef PPS_HAVE_FINDPATH
33 + char id[LENPPS] = "",
34 + path[LENPPS];
35 +#endif /* PPS_HAVE_FINDPATH */
36 char device[20];
37 + uint bits, mask=~0, outb=0;
38
39 /*
40 * Open serial port. Use CLK line discipline, if available.
41 @@ -225,18 +232,42 @@ nmea_start(
42 memcpy((char *)&pp->refid, REFID, 4);
43 up->pollcnt = 2;
44 gps_send(pp->io.fd,"$PMOTG,RMC,0000*1D\r\n", peer);
45 + gps_send(pp->io.fd,"$PGRMO,,2\r\n", peer);
46 + gps_send(pp->io.fd,"$PGRMO,GPRMC,1\r\n", peer);
47 + gps_send(pp->io.fd,"$PGRMO,,,,,,,,,,,,2\r\n", peer);
48 +
49 + mask &= ~TIOCM_RTS;
50 + mask &= ~TIOCM_DTR;
51 + outb |= TIOCM_RTS;
52 + ioctl(fd, TIOCMGET, &bits);
53 + bits &= mask;
54 + bits |= outb;
55 + ioctl(fd, TIOCMSET, &bits);
56
57 #ifdef HAVE_PPSAPI
58 /*
59 * Start the PPSAPI interface if it is there. Default to use
60 * the assert edge and do not enable the kernel hardpps.
61 */
62 +#ifdef PPS_HAVE_FINDPATH
63 + /* Get the PPS source's real name */
64 + time_pps_readlink(device, LENPPS, path, LENPPS);
65 +
66 + /* Try to find the source */
67 + fd = time_pps_findpath(path, LENPPS, id, LENPPS);
68 + if (fd < 0) {
69 + msyslog(LOG_ERR, "refclock_nmea: cannot find PPS path \"%s\" in the system", path);
70 + return (0);
71 + }
72 + msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id);
73 +#endif /* PPS_HAVE_FINDPATH */
74 if (time_pps_create(fd, &up->handle) < 0) {
75 - up->handle = 0;
76 + up->handle_created = 0;
77 msyslog(LOG_ERR,
78 "refclock_nmea: time_pps_create failed: %m");
79 return (1);
80 }
81 + up->handle_created = ~0;
82 return(nmea_ppsapi(peer, 0, 0));
83 #else
84 return (1);
85 @@ -258,8 +289,10 @@ nmea_shutdown(
86 pp = peer->procptr;
87 up = (struct nmeaunit *)pp->unitptr;
88 #ifdef HAVE_PPSAPI
89 - if (up->handle != 0)
90 + if (up->handle_created) {
91 time_pps_destroy(up->handle);
92 + up->handle_created = 0;
93 + }
94 #endif /* HAVE_PPSAPI */
95 io_closeclock(&pp->io);
96 free(up);
97 @@ -367,7 +400,7 @@ nmea_pps(
98 /*
99 * Convert the timespec nanoseconds field to ntp l_fp units.
100 */
101 - if (up->handle == 0)
102 + if (!up->handle_created)
103 return (0);
104 timeout.tv_sec = 0;
105 timeout.tv_nsec = 0;