[LinuxPPS] LinuxPPS 5.0.0-rc1
Rodolfo Giometti
giometti at enneenne.com
Fri Aug 10 16:55:51 CEST 2007
On Fri, Aug 10, 2007 at 04:42:03PM +0200, Udo van den Heuvel wrote:
> I quickly threw together this NMEA patch which should more or less do
> what is needed for the latest V5 API.
> I don't know if I understood all but at least the code compiles. Don't
> know about the workings yet.
>
> Please review and give feedback so we all can learn.
>
> --- refclock_nmea.c.origineel 2007-08-10 16:16:16.000000000 +0200
> +++ refclock_nmea.c 2007-08-10 16:38:01.000000000 +0200
> @@ -58,9 +58,10 @@
> * Definitions
> */
> #ifdef SYS_WINNT
> -# define DEVICE "COM%d:" /* COM 1 - 3 supported */
> +# define GPSDEVICE "COM%d:" /* COM 1 - 3 supported */
> #else
> -# define DEVICE "/dev/gps%d" /* name of radio device */
> +# define GPSDEVICE "/dev/nmea.serial.%d" /* name of radio device */
> +# define PPSDEVICE "/dev/nmea.pps.%d" /* name of 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
> @@ -91,6 +93,7 @@
> pps_params_t pps_params; /* pps parameters */
> pps_info_t pps_info; /* last pps data */
> pps_handle_t handle; /* pps handlebars */
> + int handle_created; /* pps handle created flag */
Now this is not needed anymore since pps_handle_t is becomed an "int"
again... however this is not an error, but your patch may result
smaller if you don't use it! :)
> #endif /* HAVE_PPSAPI */
> };
>
> @@ -138,16 +141,20 @@
> {
> register struct nmeaunit *up;
> struct refclockproc *pp;
> - int fd;
> - char device[20];
> + int gps_fd;
> + int pps_fd;
> + char gpsdevice[20];
> + char ppsdevice[20];
>
> /*
> * Open serial port. Use CLK line discipline, if available.
> */
> - (void)sprintf(device, DEVICE, unit);
> + (void)sprintf(gpsdevice, GPSDEVICE, unit);
> + (void)sprintf(ppsdevice, PPSDEVICE, unit);
>
> - fd = refclock_open(device, SPEED232, LDISC_CLK);
> - if (fd <= 0) {
> + gps_fd = refclock_open(gpsdevice, SPEED232, LDISC_CLK);
> + pps_fd = refclock_open(ppsdevice, SPEED232, LDISC_CLK);
> + if (gps_fd <= 0) {
Make attention here! Refclock should work in both ways:
1) the GPS source and PPS source are the same device, or
2) the GPS source and PPS source are __different__ devices.
Your code assumes case 2 only. I suggest you in using bit 7 as PARSE
refclock in order to know what to do (please see my preovious letter
on this topic for a code example).
> #ifdef HAVE_READLINK
> /* nmead support added by Jon Miner (cp_n18 at yahoo.com)
> *
> @@ -163,11 +170,12 @@
> char *nmea_host;
> int nmea_port;
> int len;
> + int fd;
> struct hostent *he;
> struct protoent *p;
> struct sockaddr_in so_addr;
>
> - if ((len = readlink(device,buffer,sizeof(buffer))) == -1)
> + if ((len = readlink(gpsdevice,buffer,sizeof(buffer))) == -1)
> return(0);
> buffer[len] = 0;
>
> @@ -200,7 +208,8 @@
> */
> up = (struct nmeaunit *)emalloc(sizeof(struct nmeaunit));
> if (up == NULL) {
> - (void) close(fd);
> + (void) close(gps_fd);
> + (void) close(pps_fd);
> return (0);
> }
> memset((char *)up, 0, sizeof(struct nmeaunit));
> @@ -208,9 +217,10 @@
> pp->io.clock_recv = nmea_receive;
> pp->io.srcclock = (caddr_t)peer;
> pp->io.datalen = 0;
> - pp->io.fd = fd;
> + pp->io.fd = gps_fd;
> if (!io_addclock(&pp->io)) {
> - (void) close(fd);
> + (void) close(gps_fd);
> + (void) close(pps_fd);
> free(up);
> return (0);
> }
> @@ -230,12 +240,13 @@
> * Start the PPSAPI interface if it is there. Default to use
> * the assert edge and do not enable the kernel hardpps.
> */
> - if (time_pps_create(fd, &up->handle) < 0) {
> - up->handle = 0;
> + if (time_pps_create(pps_fd, &up->handle) < 0) {
> + up->handle_created = 0;
> msyslog(LOG_ERR,
> "refclock_nmea: time_pps_create failed: %m");
> return (1);
> }
> + up->handle_created = ~0;
> return(nmea_ppsapi(peer, 0, 0));
> #else
> return (1);
> @@ -257,8 +268,10 @@
> pp = peer->procptr;
> up = (struct nmeaunit *)pp->unitptr;
> #ifdef HAVE_PPSAPI
> - if (up->handle != 0)
> + if (up->handle_created) {
> time_pps_destroy(up->handle);
> + up->handle_created = 0;
> + }
> #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_created)
> return (0);
> timeout.tv_sec = 0;
> timeout.tv_nsec = 0;
> _______________________________________________
> LinuxPPS mailing list
> LinuxPPS at ml.enneenne.com
> http://ml.enneenne.com/cgi-bin/mailman/listinfo/linuxpps
> Wiki: http://wiki.enneenne.com/index.php/LinuxPPS_support
--
GNU/Linux Solutions e-mail: giometti at enneenne.com
Linux Device Driver giometti at gnudd.com
Embedded Systems giometti at linux.it
UNIX programming phone: +39 349 2432127
More information about the LinuxPPS
mailing list