2 * /src/NTP/ntp-4/libparse/clk_trimtaip.c,v 4.7 1999/11/28 09:13:51 kardel RELEASE_19991128_A
4 * clk_trimtaip.c,v 4.7 1999/11/28 09:13:51 kardel RELEASE_19991128_A
6 * Trimble SV6 clock support - several collected codepieces
13 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_TRIMTAIP)
16 #include "ntp_unixtime.h"
17 #include "ntp_calendar.h"
22 #include "ntp_stdlib.h"
25 #include "sys/parsestreams.h"
26 extern void printf P((const char *, ...));
29 /* 0000000000111111111122222222223333333 / char
30 * 0123456789012345678901234567890123456 \ posn
31 * >RTMhhmmssdddDDMMYYYYoodnnvrrrrr;*xx< Actual
32 * ----33445566600112222BB7__-_____--99- Parse
36 #define hexval(x) (('0' <= (x) && (x) <= '9') ? (x) - '0' : \
37 ('a' <= (x) && (x) <= 'f') ? (x) - 'a' + 10 : \
38 ('A' <= (x) && (x) <= 'F') ? (x) - 'A' + 10 : \
41 #define O_GPSFIX O_FLAGS
42 #define O_CHKSUM O_UTCHOFFSET
43 static struct format trimsv6_fmt =
44 { { { 13, 2 }, {15, 2}, { 17, 4}, /* Day, Month, Year */
45 { 4, 2 }, { 6, 2}, { 8, 2}, /* Hour, Minute, Second */
46 { 10, 3 }, {23, 1}, { 0, 0}, /* uSec, FIXes (WeekDAY, FLAGS, ZONE) */
47 { 34, 2 }, { 0, 0}, { 21, 2}, /* cksum, -, utcS (UTC[HMS]OFFSET) */
49 (const unsigned char *)">RTM 1 ;* <",
53 static unsigned long cvt_trimtaip P((unsigned char *, int, struct format *, clocktime_t *, void *));
54 static unsigned long inp_trimtaip P((parse_t *, unsigned int, timestamp_t *));
56 clockformat_t clock_trimtaip =
58 inp_trimtaip, /* no input handling */
59 cvt_trimtaip, /* Trimble conversion */
60 pps_one, /* easy PPS monitoring */
61 (void *)&trimsv6_fmt, /* conversion configuration */
63 37, /* string buffer */
64 0 /* no private data */
69 unsigned char *buffer,
71 struct format *format,
72 clocktime_t *clock_time,
81 if (!Strok(buffer, format->fixed_string)) return CVT_NONE;
82 #define OFFS(x) format->field_offsets[(x)].offset
84 Stoi(&buffer[OFFS(x)], y, \
85 format->field_offsets[(x)].length)
86 if ( STOI(O_DAY, &clock_time->day) ||
87 STOI(O_MONTH, &clock_time->month) ||
88 STOI(O_YEAR, &clock_time->year) ||
89 STOI(O_HOUR, &clock_time->hour) ||
90 STOI(O_MIN, &clock_time->minute) ||
91 STOI(O_SEC, &clock_time->second) ||
92 STOI(O_USEC, &clock_time->usecond)||
93 STOI(O_GPSFIX, &gpsfix)
94 ) return CVT_FAIL|CVT_BADFMT;
96 clock_time->usecond *= 1000;
97 /* Check that the checksum is right */
98 for (i=OFFS(O_CHKSUM)-1; i >= 0; i--) calc_csum ^= buffer[i];
99 recv_csum = (hexval(buffer[OFFS(O_CHKSUM)]) << 4) |
100 hexval(buffer[OFFS(O_CHKSUM)+1]);
101 if (recv_csum < 0) return CVT_FAIL|CVT_BADTIME;
102 if (((u_char) recv_csum) != calc_csum) return CVT_FAIL|CVT_BADTIME;
104 clock_time->utcoffset = 0;
106 /* What should flags be set to ? */
107 clock_time->flags = PARSEB_UTC;
109 /* if the current GPS fix is 9 (unknown), reject */
110 if (0 > gpsfix || gpsfix > 9) clock_time->flags |= PARSEB_POWERUP;
118 * grep data from input stream
129 parseprintf(DD_PARSE, ("inp_trimtaip(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
134 parseprintf(DD_PARSE, ("inp_trimptaip: START seen\n"));
136 parseio->parse_index = 1;
137 parseio->parse_data[0] = ch;
138 parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */
139 return PARSE_INP_SKIP;
142 parseprintf(DD_PARSE, ("inp_trimtaip: END seen\n"));
143 if ((rtc = parse_addchar(parseio, ch)) == PARSE_INP_SKIP)
144 return parse_end(parseio);
150 return parse_addchar(parseio, ch);
154 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_TRIMTAIP) */
156 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_TRIMTAIP) */
162 * Revision 4.7 1999/11/28 09:13:51 kardel
165 * Revision 4.6 1998/08/16 18:46:27 kardel
166 * (clock_trimtaip =): changed format name
168 * Revision 4.5 1998/06/14 21:09:38 kardel
171 * Revision 4.4 1998/06/13 12:06:57 kardel
172 * fix SYSV clock name clash
174 * Revision 4.3 1998/06/12 15:22:29 kardel
177 * Revision 4.2 1998/06/12 09:13:26 kardel
178 * conditional compile macros fixed
181 * Revision 4.1 1998/05/24 09:39:54 kardel
182 * implementation of the new IO handling model
184 * Revision 4.0 1998/04/10 19:45:31 kardel
185 * Start 4.0 release version numbering
187 * from V3 1.4 log info deleted 1998/04/11 kardel