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