2 * This software was developed by the Software and Component Technologies
3 * group of Trimble Navigation, Ltd.
5 * Copyright (c) 1997, 1998, 1999, 2000 Trimble Navigation Ltd.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Trimble Navigation, Ltd.
19 * 4. The name of Trimble Navigation Ltd. may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY TRIMBLE NAVIGATION LTD. ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL TRIMBLE NAVIGATION LTD. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * refclock_palisade - clock driver for the Trimble Palisade GPS
40 * For detailed information on this program, please refer to the html
41 * Refclock 29 page accompanying the NTP distribution.
43 * for questions / bugs / comments, contact:
44 * sven_dietrich@trimble.com
46 * Sven-Thorsten Dietrich
47 * 645 North Mary Avenue
48 * Post Office Box 3642
49 * Sunnyvale, CA 94088-3642
51 * Version 2.45; July 14, 1999
55 * 31/03/06: Added support for Thunderbolt GPS Disciplined Clock.
56 * Contact: Fernando Pablo Hauscarriaga
57 * E-mail: fernandoph@iar.unlp.edu.ar
58 * Home page: www.iar.unlp.edu.ar/~fernandoph
59 * Instituto Argentino de Radioastronomia
62 * 14/01/07: Conditinal compilation for Thunderbolt support no longer needed
63 * now we use mode 2 for decode thunderbolt packets.
64 * Fernando P. Hauscarriaga
66 * 30/08/09: Added support for Trimble Acutime Gold Receiver.
67 * Fernando P. Hauscarriaga (fernandoph@iar.unlp.edu.ar)
74 #if defined(REFCLOCK) && defined(CLOCK_PALISADE)
77 extern int async_write(int, const void *, unsigned int);
79 #define write(fd, data, octets) async_write(fd, data, octets)
82 #include "refclock_palisade.h"
85 const char * Tracking_Status[15][15] = {
86 { "Doing Fixes\0" }, { "Good 1SV\0" }, { "Approx. 1SV\0" },
87 {"Need Time\0" }, { "Need INIT\0" }, { "PDOP too High\0" },
88 { "Bad 1SV\0" }, { "0SV Usable\0" }, { "1SV Usable\0" },
89 { "2SV Usable\0" }, { "3SV Usable\0" }, { "No Integrity\0" },
90 { "Diff Corr\0" }, { "Overdet Clock\0" }, { "Invalid\0" } };
96 struct refclock refclock_palisade = {
97 palisade_start, /* start up driver */
98 palisade_shutdown, /* shut down driver */
99 palisade_poll, /* transmit poll message */
100 noentry, /* not used */
101 noentry, /* initialize driver (not used) */
102 noentry, /* not used */
103 NOFLAGS /* not used */
106 static int decode_date(struct refclockproc *pp, const char *cp);
108 /* Extract the clock type from the mode setting */
109 #define CLK_TYPE(x) ((int)(((x)->ttl) & 0x7F))
111 /* Supported clock types */
112 #define CLK_TRIMBLE 0 /* Trimble Palisade */
113 #define CLK_PRAECIS 1 /* Endrun Technologies Praecis */
114 #define CLK_THUNDERBOLT 2 /* Trimble Thunderbolt GPS Receiver */
115 #define CLK_ACUTIME 3 /* Trimble Acutime Gold */
116 #define CLK_ACUTIMEB 4 /* Trimble Actutime Gold Port B */
119 static void praecis_parse(struct recvbuf *rbufp, struct peer *peer);
121 /* These routines are for sending packets to the Thunderbolt receiver
122 * They are taken from Markus Prosch
125 #ifdef PALISADE_SENDCMD_RESURRECTED
127 * sendcmd - Build data packet for sending
131 struct packettx *buffer,
136 *(buffer->data + 1) = (unsigned char)c;
139 #endif /* PALISADE_SENDCMD_RESURRECTED */
142 * sendsupercmd - Build super data packet for sending
146 struct packettx *buffer,
152 *(buffer->data + 1) = (unsigned char)c1;
153 *(buffer->data + 2) = (unsigned char)c2;
162 struct packettx *buffer,
167 *(buffer->data+buffer->size++) = DLE;
168 *(buffer->data+buffer->size++) = (unsigned char)b;
176 struct packettx *buffer,
180 sendbyte(buffer, (unsigned char)((a>>8) & 0xff));
181 sendbyte(buffer, (unsigned char)(a & 0xff));
185 * sendetx - Send packet or super packet to the device
189 struct packettx *buffer,
195 *(buffer->data+buffer->size++) = DLE;
196 *(buffer->data+buffer->size++) = ETX;
197 result = write(fd, buffer->data, (unsigned long)buffer->size);
206 * init_thunderbolt - Prepares Thunderbolt receiver to be used with
207 * NTP (also taken from Markus Prosch).
217 tx.data = (u_char *) emalloc(100);
220 sendsupercmd (&tx, 0x8E, 0xA2);
224 /* activate packets 0x8F-AB and 0x8F-AC */
225 sendsupercmd (&tx, 0x8E, 0xA5);
233 * init_acutime - Prepares Acutime Receiver to be used with NTP
240 /* Disable all outputs, Enable Event-Polling on PortA so
241 we can ask for time packets */
245 tx.data = (u_char *) emalloc(100);
247 sendsupercmd(&tx, 0x8E, 0xA5);
258 * palisade_start - open the devices and initialize data for processing
266 struct palisade_unit *up;
267 struct refclockproc *pp;
272 snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
277 fd = refclock_open(gpsdev, SPEED232, LDISC_RAW);
280 printf("Palisade(%d) start: open %s failed\n", unit, gpsdev);
285 msyslog(LOG_NOTICE, "Palisade(%d) fd: %d dev: %s", unit, fd,
288 if (tcgetattr(fd, &tio) < 0) {
290 "Palisade(%d) tcgetattr(fd, &tio): %m",unit);
292 printf("Palisade(%d) tcgetattr(fd, &tio)\n",unit);
298 tio.c_cflag |= (PARENB|PARODD);
299 tio.c_iflag &= ~ICRNL;
302 * Allocate and initialize unit structure
304 up = emalloc_zero(sizeof(*up));
306 up->type = CLK_TYPE(peer);
309 /* Normal mode, do nothing */
312 msyslog(LOG_NOTICE, "Palisade(%d) Praecis mode enabled"
315 case CLK_THUNDERBOLT:
316 msyslog(LOG_NOTICE, "Palisade(%d) Thunderbolt mode enabled"
318 tio.c_cflag = (CS8|CLOCAL|CREAD);
321 msyslog(LOG_NOTICE, "Palisade(%d) Acutime Gold mode enabled"
325 msyslog(LOG_NOTICE, "Palisade(%d) mode unknown",unit);
328 if (tcsetattr(fd, TCSANOW, &tio) == -1) {
329 msyslog(LOG_ERR, "Palisade(%d) tcsetattr(fd, &tio): %m",unit);
331 printf("Palisade(%d) tcsetattr(fd, &tio)\n",unit);
339 pp->io.clock_recv = palisade_io;
340 pp->io.srcclock = peer;
343 if (!io_addclock(&pp->io)) {
345 printf("Palisade(%d) io_addclock\n",unit);
354 * Initialize miscellaneous variables
357 pp->clockdesc = DESCRIPTION;
359 peer->precision = PRECISION;
360 peer->sstclktype = CTL_SST_TS_UHF;
361 peer->minpoll = TRMB_MINPOLL;
362 peer->maxpoll = TRMB_MAXPOLL;
363 memcpy((char *)&pp->refid, REFID, 4);
366 up->unit = (short) unit;
367 up->rpt_status = TSIP_PARSED_EMPTY;
370 if (up->type == CLK_THUNDERBOLT)
371 init_thunderbolt(fd);
372 if (up->type == CLK_ACUTIME)
380 * palisade_shutdown - shut down the clock
388 struct palisade_unit *up;
389 struct refclockproc *pp;
393 io_closeclock(&pp->io);
403 static inline uint8_t
407 return ((const u_char*)cp)[0];
410 static inline uint16_t
414 return ((uint16_t)get_u8(cp) << 8) | get_u8(cp + 1);
418 * unpack & fix date (the receiver provides a valid time for 1024 weeks
419 * after 1997-12-14 and therefore folds back in 2017, 2037,...)
421 * Returns -1 on error, day-of-month + (month * 32) othertwise.
425 struct refclockproc *pp,
428 static int32_t s_baseday = 0;
433 if (0 == s_baseday) {
434 if (!ntpcal_get_build_date(&jd)) {
439 s_baseday = ntpcal_date_to_rd(&jd);
442 /* get date fields and convert to RDN */
443 jd.monthday = get_u8 ( cp );
444 jd.month = get_u8 (cp + 1);
445 jd.year = get_u16(cp + 2);
446 rd = ntpcal_date_to_rd(&jd);
448 /* for the paranoid: do reverse calculation and cross-check */
449 ntpcal_rd_to_date(&jd, rd);
450 if ((jd.monthday != get_u8 ( cp )) ||
451 (jd.month != get_u8 (cp + 1)) ||
452 (jd.year != get_u16(cp + 2)) )
455 /* calculate cycle shift to base day and calculate re-folded
458 * One could do a proper modulo calculation here, but a counting
459 * loop is probably faster for the next few rollovers...
461 while (rd < s_baseday)
463 ntpcal_rd_to_date(&jd, rd);
465 /* fill refclock structure & indicate success */
466 pp->day = jd.yearday;
468 return ((int)jd.month << 5) | jd.monthday;
473 * TSIP_decode - decode the TSIP data packets
484 unsigned short event = 0;
487 struct palisade_unit *up;
488 struct refclockproc *pp;
494 * Check the time packet, decode its contents.
495 * If the timecode has invalid length or is not in
496 * proper format, declare bad format and exit.
499 if ((up->type != CLK_THUNDERBOLT) & (up->type != CLK_ACUTIME)){
500 if ((up->rpt_buf[0] == (char) 0x41) ||
501 (up->rpt_buf[0] == (char) 0x46) ||
502 (up->rpt_buf[0] == (char) 0x54) ||
503 (up->rpt_buf[0] == (char) 0x4B) ||
504 (up->rpt_buf[0] == (char) 0x6D)) {
506 /* standard time packet - GPS time and GPS week number */
508 printf("Palisade Port B packets detected. Connect to Port A\n");
516 * We cast both to u_char to as 0x8f uses the sign bit on a char
518 if ((u_char) up->rpt_buf[0] == (u_char) 0x8f) {
522 event = (unsigned short) (getint((u_char *) &mb(1)) & 0xffff);
523 if (!((pp->sloppyclockflag & CLK_FLAG2) || event))
527 switch (mb(0) & 0xff) {
536 if (up->rpt_cnt != LENCODE_8F0B) /* check length */
542 double lat, lon, alt;
543 lat = getdbl((u_char *) &mb(42)) * R2D;
544 lon = getdbl((u_char *) &mb(50)) * R2D;
545 alt = getdbl((u_char *) &mb(58));
547 printf("TSIP_decode: unit %d: Latitude: %03.4f Longitude: %03.4f Alt: %05.2f m\n",
548 up->unit, lat,lon,alt);
549 printf("TSIP_decode: unit %d: Sats:",
551 for (st = 66, ts = 0; st <= 73; st++)
553 if (mb(st) > 0) ts++;
554 printf(" %02d", mb(st));
556 printf(" : Tracking %d\n", ts);
560 GPS_UTC_Offset = getint((u_char *) &mb(16));
561 if (GPS_UTC_Offset == 0) { /* Check UTC offset */
563 printf("TSIP_decode: UTC Offset Unknown\n");
568 secs = getdbl((u_char *) &mb(3));
569 secint = (long) secs;
570 secfrac = secs - secint; /* 0.0 <= secfrac < 1.0 */
572 pp->nsec = (long) (secfrac * 1000000000);
574 secint %= 86400; /* Only care about today */
575 pp->hour = secint / 3600;
577 pp->minute = secint / 60;
579 pp->second = secint % 60;
581 mmday = decode_date(pp, &mb(11));
587 printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%09ld %02d/%02d/%04d UTC %02d\n",
588 up->unit, mb(0) & 0xff, event, pp->hour, pp->minute,
589 pp->second, pp->nsec, (mmday >> 5), (mmday & 31), pp->year, GPS_UTC_Offset);
591 /* Only use this packet when no
592 * 8F-AD's are being received
595 if (up->leap_status) {
604 /* Palisade-NTP Packet */
606 if (up->rpt_cnt != LENCODE_NTP) /* check length */
609 up->leap_status = mb(19);
614 /* Check Tracking Status */
616 if (st < 0 || st > 14)
618 if ((st >= 2 && st <= 7) || st == 11 || st == 12) {
620 printf("TSIP_decode: Not Tracking Sats : %s\n",
621 *Tracking_Status[st]);
623 refclock_report(peer, CEVNT_BADTIME);
629 mmday = decode_date(pp, &mb(14));
632 up->month = (mmday >> 5); /* Save for LEAP check */
634 if ( (up->leap_status & PALISADE_LEAP_PENDING) &&
635 /* Avoid early announce: https://bugs.ntp.org/2773 */
636 (6 == up->month || 12 == up->month) ) {
637 if (up->leap_status & PALISADE_UTC_TIME)
638 pp->leap = LEAP_ADDSECOND;
640 pp->leap = LEAP_DELSECOND;
642 else if (up->leap_status)
643 pp->leap = LEAP_NOWARNING;
645 else { /* UTC flag is not set:
646 * Receiver may have been reset, and lost
647 * its UTC almanac data */
648 pp->leap = LEAP_NOTINSYNC;
650 printf("TSIP_decode: UTC Almanac unavailable: %d\n",
653 refclock_report(peer, CEVNT_BADTIME);
658 pp->nsec = (long) (getdbl((u_char *) &mb(3))
667 printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%09ld %02d/%02d/%04d UTC %02x %s\n",
668 up->unit, mb(0) & 0xff, event, pp->hour, pp->minute,
669 pp->second, pp->nsec, (mmday >> 5), (mmday & 31), pp->year,
670 mb(19), *Tracking_Status[st]);
679 if (up->rpt_cnt != LENCODE_8FAC)/* check length */
684 double lat, lon, alt;
685 lat = getdbl((u_char *) &mb(36)) * R2D;
686 lon = getdbl((u_char *) &mb(44)) * R2D;
687 alt = getdbl((u_char *) &mb(52));
689 printf("TSIP_decode: unit %d: Latitude: %03.4f Longitude: %03.4f Alt: %05.2f m\n",
690 up->unit, lat,lon,alt);
691 printf("TSIP_decode: unit %d\n", up->unit);
694 if ( (getint((u_char *) &mb(10)) & 0x80) &&
695 /* Avoid early announce: https://bugs.ntp.org/2773 */
696 (6 == up->month || 12 == up->month) )
697 pp->leap = LEAP_ADDSECOND; /* we ASSUME addsecond */
699 pp->leap = LEAP_NOWARNING;
703 printf("TSIP_decode: unit %d: 0x%02x leap %d\n",
704 up->unit, mb(0) & 0xff, pp->leap);
706 printf("Receiver MODE: 0x%02X\n", (u_char)mb(1));
708 printf(" AUTOMATIC\n");
710 printf(" SINGLE SATELLITE\n");
712 printf(" HORIZONTAL(2D)\n");
714 printf(" FULL POSITION(3D)\n");
716 printf(" DGPR REFERENCE\n");
718 printf(" CLOCK HOLD(2D)\n");
720 printf(" OVERDETERMINED CLOCK\n");
722 printf("\n** Disciplining MODE 0x%02X:\n", (u_char)mb(2));
726 printf(" POWER-UP\n");
728 printf(" AUTO HOLDOVER\n");
730 printf(" MANUAL HOLDOVER\n");
732 printf(" RECOVERY\n");
734 printf(" DISCIPLINING DISABLED\n");
741 /* Thunderbolt Primary Timing Packet */
743 if (up->rpt_cnt != LENCODE_8FAB) /* check length */
749 GPS_UTC_Offset = getint((u_char *) &mb(7));
751 if (GPS_UTC_Offset == 0){ /* Check UTC Offset */
753 printf("TSIP_decode: UTC Offset Unknown\n");
759 if ((mb(9) & 0x1d) == 0x0) {
760 /* if we know the GPS time and the UTC offset,
761 we expect UTC timing information !!! */
763 pp->leap = LEAP_NOTINSYNC;
764 refclock_report(peer, CEVNT_BADTIME);
771 printf("\nTiming Flags are:\n");
772 printf("Timing flag value is: 0x%X\n", mb(9));
773 if ((mb(9) & 0x01) != 0)
774 printf (" Getting UTC time\n");
776 printf (" Getting GPS time\n");
777 if ((mb(9) & 0x02) != 0)
778 printf (" PPS is from UTC\n");
780 printf (" PPS is from GPS\n");
781 if ((mb(9) & 0x04) != 0)
782 printf (" Time is not Set\n");
784 printf (" Time is Set\n");
785 if ((mb(9) & 0x08) != 0)
786 printf(" I dont have UTC info\n");
788 printf (" I have UTC info\n");
789 if ((mb(9) & 0x10) != 0)
790 printf (" Time is from USER\n\n");
792 printf (" Time is from GPS\n\n");
795 mmday = decode_date(pp, &mb(13));
798 tow = getlong((u_char *) &mb(1));
801 printf("pp->day: %d\n", pp->day);
802 printf("TOW: %ld\n", tow);
803 printf("DAY: %d\n", (mmday & 31));
813 printf("TSIP_decode: unit %d: %02X #%d %02d:%02d:%02d.%09ld %02d/%02d/%04d ",
814 up->unit, mb(0) & 0xff, event, pp->hour, pp->minute, pp->second,
815 pp->nsec, (mmday >> 5), (mmday & 31), pp->year);
824 } /* if 8F packets */
826 else if (up->rpt_buf[0] == (u_char)0x42) {
830 else if (up->rpt_buf[0] == (u_char)0x43) {
834 else if ((up->rpt_buf[0] == PACKET_41) & (up->type == CLK_THUNDERBOLT)){
835 printf("Undocumented 0x41 packet on Thunderbolt\n");
838 else if ((up->rpt_buf[0] == PACKET_41A) & (up->type == CLK_ACUTIME)) {
840 printf("GPS TOW: %ld\n", (long)getlong((u_char *) &mb(0)));
841 printf("GPS WN: %d\n", getint((u_char *) &mb(4)));
842 printf("GPS UTC-GPS Offser: %ld\n", (long)getlong((u_char *) &mb(6)));
847 /* Health Status for Acutime Receiver */
848 else if ((up->rpt_buf[0] == PACKET_46) & (up->type == CLK_ACUTIME)) {
854 printf ("Doing Position Fixes\n");
857 printf ("Do no have GPS time yet\n");
860 printf ("PDOP is too high\n");
863 printf ("No usable satellites\n");
866 printf ("Only 1 usable satellite\n");
869 printf ("Only 2 usable satellites\n");
872 printf ("Only 3 usable satellites\n");
875 printf("The Chosen satellite is unusable\n");
882 refclock_report(peer, CEVNT_BADTIME);
887 printf ("Signal Processor Error, reset unit.\n");
889 printf ("Alignment error, channel or chip 1, reset unit.\n");
891 printf ("Alignment error, channel or chip 2, reset unit.\n");
893 printf ("Antenna feed line fault (open or short)\n");
895 printf ("Excessive reference frequency error, refer to packet 0x2D and packet 0x4D documentation for further information\n");
902 else if (up->rpt_buf[0] == 0x54)
905 else if (up->rpt_buf[0] == PACKET_6D) {
909 if ((mb(0) & 0x01) && (mb(0) & 0x02))
910 printf("2d Fix Dimension\n");
912 printf("3d Fix Dimension\n");
915 printf("Fix Mode is MANUAL\n");
917 printf("Fix Mode is AUTO\n");
921 printf("Tracking %d Satellites\n", sats);
924 } /* else if not super packet */
925 refclock_report(peer, CEVNT_BADREPLY);
928 printf("TSIP_decode: unit %d: bad packet %02x-%02x event %d len %d\n",
929 up->unit, up->rpt_buf[0] & 0xff, mb(0) & 0xff,
936 * palisade__receive - receive data from the serial interface
944 struct palisade_unit *up;
945 struct refclockproc *pp;
948 * Initialize pointers and read the timecode and timestamp.
953 if (! TSIP_decode(peer)) return;
956 return; /* no poll pending, already received or timeout */
958 up->polled = 0; /* Poll reply received */
959 pp->lencode = 0; /* clear time code */
963 "palisade_receive: unit %d: %4d %03d %02d:%02d:%02d.%09ld\n",
964 up->unit, pp->year, pp->day, pp->hour, pp->minute,
965 pp->second, pp->nsec);
970 * Generate timecode: YYYY DoY HH:MM:SS.microsec
974 snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
975 "%4d %03d %02d:%02d:%02d.%09ld",
977 pp->hour,pp->minute, pp->second, pp->nsec);
980 if (!refclock_process(pp)) {
981 refclock_report(peer, CEVNT_BADTIME);
984 printf("palisade_receive: unit %d: refclock_process failed!\n",
990 record_clock_stats(&peer->srcadr, pp->a_lastcode);
994 printf("palisade_receive: unit %d: %s\n",
995 up->unit, prettydate(&pp->lastrec));
997 pp->lastref = pp->lastrec;
998 refclock_receive(peer);
1003 * palisade_poll - called by the transmit procedure
1012 struct palisade_unit *up;
1013 struct refclockproc *pp;
1019 if (up->polled > 0) /* last reply never arrived or error */
1020 refclock_report(peer, CEVNT_TIMEOUT);
1022 up->polled = 2; /* synchronous packet + 1 event */
1026 printf("palisade_poll: unit %d: polling %s\n", unit,
1027 (pp->sloppyclockflag & CLK_FLAG2) ?
1028 "synchronous packet" : "event");
1031 if (pp->sloppyclockflag & CLK_FLAG2)
1032 return; /* using synchronous packet input */
1034 if(up->type == CLK_PRAECIS) {
1035 if(write(peer->procptr->io.fd,"SPSTAT\r\n",8) < 0)
1036 msyslog(LOG_ERR, "Palisade(%d) write: %m:",unit);
1043 if (HW_poll(pp) < 0)
1044 refclock_report(peer, CEVNT_FAULT);
1049 struct recvbuf *rbufp,
1053 static char buf[100];
1055 struct refclockproc *pp;
1059 memcpy(buf+p,rbufp->recv_space.X_recv_buffer, rbufp->recv_length);
1060 p += rbufp->recv_length;
1062 if(buf[p-2] == '\r' && buf[p-1] == '\n') {
1064 record_clock_stats(&peer->srcadr, buf);
1069 if (HW_poll(pp) < 0)
1070 refclock_report(peer, CEVNT_FAULT);
1077 struct recvbuf *rbufp
1081 * Initialize pointers and read the timecode and timestamp.
1083 struct palisade_unit *up;
1084 struct refclockproc *pp;
1089 peer = rbufp->recv_peer;
1093 if(up->type == CLK_PRAECIS) {
1095 praecis_parse(rbufp,peer);
1100 c = (char *) &rbufp->recv_space;
1101 d = c + rbufp->recv_length;
1105 /* Build time packet */
1106 switch (up->rpt_status) {
1108 case TSIP_PARSED_DLE_1:
1114 up->rpt_status = TSIP_PARSED_EMPTY;
1118 up->rpt_status = TSIP_PARSED_DATA;
1119 /* save packet ID */
1120 up->rpt_buf[0] = *c;
1125 case TSIP_PARSED_DATA:
1127 up->rpt_status = TSIP_PARSED_DLE_2;
1129 mb(up->rpt_cnt++) = *c;
1132 case TSIP_PARSED_DLE_2:
1134 up->rpt_status = TSIP_PARSED_DATA;
1139 up->rpt_status = TSIP_PARSED_FULL;
1141 /* error: start new report packet */
1142 up->rpt_status = TSIP_PARSED_DLE_1;
1143 up->rpt_buf[0] = *c;
1147 case TSIP_PARSED_FULL:
1148 case TSIP_PARSED_EMPTY:
1151 up->rpt_status = TSIP_PARSED_EMPTY;
1153 up->rpt_status = TSIP_PARSED_DLE_1;
1159 if (up->rpt_status == TSIP_PARSED_DLE_1) {
1161 if (pp->sloppyclockflag & CLK_FLAG2)
1163 get_systime(&pp->lastrec);
1165 else if (up->rpt_status == TSIP_PARSED_EMPTY)
1168 else if (up->rpt_cnt > BMAX)
1169 up->rpt_status =TSIP_PARSED_EMPTY;
1171 if (up->rpt_status == TSIP_PARSED_FULL)
1172 palisade_receive(peer);
1174 } /* while chars in buffer */
1179 * Trigger the Palisade's event input, which is driven off the RTS
1181 * Take a system time stamp to match the GPS time stamp.
1186 struct refclockproc * pp /* pointer to unit structure */
1189 int x; /* state before & after RTS set */
1190 struct palisade_unit *up;
1194 /* read the current status, so we put things back right */
1195 if (ioctl(pp->io.fd, TIOCMGET, &x) < 0) {
1196 DPRINTF(1, ("Palisade HW_poll: unit %d: GET %m\n",
1198 msyslog(LOG_ERR, "Palisade(%d) HW_poll: ioctl(fd,GET): %m",
1203 x |= TIOCM_RTS; /* turn on RTS */
1206 if (up->type == CLK_ACUTIME)
1207 write (pp->io.fd, "", 1);
1209 if (ioctl(pp->io.fd, TIOCMSET, &x) < 0) {
1212 printf("Palisade HW_poll: unit %d: SET \n", up->unit);
1215 "Palisade(%d) HW_poll: ioctl(fd, SET, RTS_on): %m",
1220 x &= ~TIOCM_RTS; /* turn off RTS */
1222 /* poll timestamp */
1223 get_systime(&pp->lastrec);
1225 if (ioctl(pp->io.fd, TIOCMSET, &x) == -1) {
1228 printf("Palisade HW_poll: unit %d: UNSET \n", up->unit);
1231 "Palisade(%d) HW_poll: ioctl(fd, UNSET, RTS_off): %m",
1240 * copy/swap a big-endian palisade double into a host double
1247 #ifdef WORDS_BIGENDIAN
1250 memcpy(&out, bp, sizeof(out));
1263 memcpy(ui.ch, bp, sizeof(ui.ch));
1264 /* least-significant 32 bits of double from swapped bp[4] to bp[7] */
1265 uo.u32[0] = ntohl(ui.u32[1]);
1266 /* most-significant 32 bits from swapped bp[0] to bp[3] */
1267 uo.u32[1] = ntohl(ui.u32[0]);
1274 * copy/swap a big-endian palisade short into a host short
1283 memcpy(&us, bp, sizeof(us));
1284 return (short)ntohs(us);
1288 * copy/swap a big-endian palisade 32-bit int into a host 32-bit int
1297 memcpy(&u32, bp, sizeof(u32));
1298 return (int32)(u_int32)ntohl(u32);
1301 #else /* REFCLOCK && CLOCK_PALISADE*/
1302 int refclock_palisade_c_notempty;