[time-nuts] Cesium C Field Set?

Poul-Henning Kamp phk at phk.freebsd.dk
Sat Feb 12 08:26:47 EST 2005


In message <420DFE49.4010808 at febo.com>, John Ackermann N8UR writes:

>Yes, I'm interested!  I messed with the binary mode a year or so ago but 
>never got it working right.  I'd love to see your magic.

OK, here we go :-)

		u_char buf[100]
                int n0, n12;
                double t;

		/* Read five bytes from GPIB */
                j = ibrd(dmm, buf, 5);
                if (j)
                        errx(1, "ibrd = %d\n", j);

		/* N0 is a 1-complement signed 16 bit number */
                n0 = (buf[3] << 8) + buf[4];

		/* check sign bit in status word */
                if (!(buf[0] & 0x20))
                        n0 = -n0;

		/* N11N2 is an 18 bit 2-complement number */
                n12 = ((buf[0] & 3) << 16) + (buf[1] << 8) + buf[2];

		/* Handle sign */
                if (n12 & (1 << 17))
                        n12 -= (1 << 18);

		/*
		 * The number we want is:
		 *
		 *   dt = 5 * ((257/256) * (N1 - N2) + N0)
		 *
		 * n12 contains (257 * (N1 - N2))
		 */
                t = n12 / 256.0;
                t += n0;
                t *= 5e-9;

                printf("TI = %.11e %4d", t, ibcnt);


-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.




More information about the time-nuts mailing list