1 //////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2009,2012 -
3 // Schweitzer Engineering Laboratories, Inc. <opensource@selinc.com>
4 //////////////////////////////////////////////////////////////////////////////
6 // Need to have _XOPEN_SOURCE defined for time.h to give the
7 // correct strptime signature. As per feature_test_macros(7),
8 // define this before including any header files.
10 // #ifndef _XOPEN_SOURCE
11 // #define _XOPEN_SOURCE
18 #if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_SEL240X)
20 #include "ntp_syslog.h"
21 #include "ntp_types.h"
23 #include "ntp_unixtime.h"
24 #include "ntp_calendar.h"
25 #include "ntp_machine.h"
26 #include "ntp_stdlib.h"
33 # include "sys/parsestreams.h"
38 //////////////////////////////////////////////////////////////////////////////
39 // The B8 output has the following format B8 = '\x01YYYY:ddd:hh:mm:ssq\r\n'
40 // where q = ' ' locked
46 // Based on this we need to recored the stime when we receive the <SOH>
47 // character and end it when we see the \n.
49 // The q or quality character indicates satellite lock and sync. For the
50 // purposes of NTP we are going to call it valid when we receive anything but
51 // a '?'. But we are only going to call it synced when we receive a ' '
52 //////////////////////////////////////////////////////////////////////////////
54 static parse_inp_fnc_t inp_sel240x;
55 static parse_cvt_fnc_t cvt_sel240x;
57 // Parse clock format structure describing the message above
58 static struct format sel240x_fmt =
72 (const unsigned char *)"\x01 : : : : \x0d\x0a",
76 // Structure desctibing the parser
77 clockformat_t clock_sel240x =
88 //////////////////////////////////////////////////////////////////////////////
90 inp_sel240x( parse_t *parseio,
97 parseprintf( DD_PARSE,
98 ("inp_sel240x(0x%lx, 0x%x, ...)\n",(long)parseio, ch));
103 parseio->parse_index = 1;
104 parseio->parse_data[0] = ch;
105 parseio->parse_dtime.parse_stime = *tstamp;
109 if( (rc = parse_addchar(parseio, ch)) == PARSE_INP_SKIP )
111 rc = parse_end( parseio );
115 rc = parse_addchar( parseio, ch );
121 //////////////////////////////////////////////////////////////////////////////
123 cvt_sel240x( unsigned char *buffer,
125 struct format *format,
126 clocktime_t *clock_time,
130 unsigned long rc = CVT_NONE;
132 if( Strok(buffer, format->fixed_string) )
136 buffer = (unsigned char *) strptime(
137 (const char *)buffer, "%Y:%j:%H:%M:%S", &ptime );
138 if( *(buffer+1) != '\x0d' )
140 rc = CVT_FAIL | CVT_BADFMT;
144 clock_time->day = ptime.tm_mday;
145 clock_time->month = ptime.tm_mon + 1;
146 clock_time->year = ptime.tm_year + 1900;
147 clock_time->hour = ptime.tm_hour;
148 clock_time->minute = ptime.tm_min;
149 clock_time->second = ptime.tm_sec;
150 clock_time->usecond = 0;
151 clock_time->utcoffset = 0;
152 clock_time->flags = PARSEB_UTC;
156 clock_time->flags |= PARSEB_POWERUP;
158 else if( *buffer != ' ' )
160 clock_time->flags |= PARSEB_NOSYNC;
170 #else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_SEL240X) */
172 #endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_SEL240X) */