clk_wharton.c revision 82498
1112758Ssam/* 2112758Ssam * /src/NTP/ntp-4/libparse/clk_wharton.c,v 4.1 1999/02/28 15:27:24 kardel RELEASE_19990228_A 3315514Sae * 4112758Ssam * clk_wharton.c,v 4.1 1999/02/28 15:27:24 kardel RELEASE_19990228_A 5112758Ssam * 6112758Ssam * From Philippe De Muyter <phdm@macqel.be>, 1999 7112758Ssam */ 8112758Ssam#ifdef HAVE_CONFIG_H 9112758Ssam#include <config.h> 10112758Ssam#endif 11112758Ssam 12112758Ssam#if defined(REFCLOCK) && defined(CLOCK_PARSE) && defined(CLOCK_WHARTON_400A) 13112758Ssam/* 14112758Ssam * Support for WHARTON 400A Series clock + 404.2 serial interface. 15112758Ssam * 16112758Ssam * Copyright (C) 1999, 2000 by Philippe De Muyter <phdm@macqel.be> 17112758Ssam * 18112758Ssam * This program is distributed in the hope that it will be useful, but WITHOUT 19112758Ssam * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20112758Ssam * FITNESS FOR A PARTICULAR PURPOSE. 21112758Ssam * 22112758Ssam */ 23112758Ssam 24112758Ssam#include "ntp_fp.h" 25112758Ssam#include "ascii.h" 26112758Ssam#include "parse.h" 27112758Ssam 28112758Ssam#ifndef PARSESTREAM 29105197Ssam#include "ntp_stdlib.h" 30105197Ssam#include <stdio.h> 31105197Ssam#else 32105197Ssam#include "sys/parsestreams.h" 33105197Ssamextern void printf P((const char *, ...)); 34105197Ssam#endif 35105197Ssam 36315514Sae/* 37105197Ssam * In private e-mail alastair@wharton.co.uk said : 38105197Ssam * "If you are going to use the 400A and 404.2 system [for ntp] I recommend 39105197Ssam * that you set the 400A to output the message every second. The start of 40105197Ssam * transmission of the first byte of the message is synchronised to the 41105197Ssam * second edge." 42105197Ssam * The WHARTON 400A Series is able to send date/time serial messages 43105197Ssam * in 7 output formats. We use format 1 here because it is the shortest. 44105197Ssam * For use with this driver, the WHARTON 400A Series clock must be set-up 45291292Sae * as follows : 46105197Ssam * Programmable Selected 47105197Ssam * Option No Option 48105197Ssam * BST or CET display 3 9 or 11 49291292Sae * No external controller 7 0 50257176Sglebius * Serial Output Format 1 9 1 51195699Srwatson * Baud rate 9600 bps 10 96 52105197Ssam * Bit length 8 bits 11 8 53105197Ssam * Parity even 12 E 54105197Ssam * 55105197Ssam * WHARTON 400A Series output format 1 is as follows : 56105197Ssam * 57105197Ssam * Timestamp STXssmmhhDDMMYYSETX 58105197Ssam * Pos 0 12345678901234 59105197Ssam * 0 00000000011111 60105197Ssam * 61105197Ssam * STX start transmission (ASCII 0x02) 62105197Ssam * ETX end transmission (ASCII 0x03) 63105197Ssam * ss Second expressed in reversed decimal (units then tens) 64105197Ssam * mm Minute expressed in reversed decimal 65105197Ssam * hh Hour expressed in reversed decimal 66281692Sae * DD Day of month expressed in reversed decimal 67105197Ssam * MM Month expressed in reversed decimal (January is 1) 68105197Ssam * YY Year (without century) expressed in reversed decimal 69105197Ssam * S Status byte : 0x30 + 70105197Ssam * bit 0 0 = MSF source 1 = DCF source 71105197Ssam * bit 1 0 = Winter time 1 = Summer time 72315514Sae * bit 2 0 = not synchronised 1 = synchronised 73315514Sae * bit 3 0 = no early warning 1 = early warning 74315514Sae * 75105197Ssam */ 76315514Sae 77315514Sae/* 78315514Sae * cvt_wharton_400a 79105197Ssam * 80105197Ssam * convert simple type format 81105197Ssam */ 82105197Ssamstatic u_long 83105197Ssamcvt_wharton_400a( 84105197Ssam unsigned char *buffer, 85105197Ssam int size, 86105197Ssam struct format *format, 87105197Ssam clocktime_t *clock_time, 88105197Ssam void *local 89105197Ssam ) 90105197Ssam{ 91105197Ssam int i; 92105197Ssam 93105197Ssam /* The given `size' includes a terminating null-character. */ 94105197Ssam if (size != 16 || buffer[0] != STX || buffer[14] != ETX 95315514Sae || buffer[13] < '0' || buffer[13] > ('0' + 0xf)) 96315514Sae return CVT_NONE; 97315514Sae for (i = 1; i < 13; i += 1) 98315514Sae if (buffer[i] < '0' || buffer[i] > '9') 99315514Sae return CVT_NONE; 100315514Sae clock_time->second = (buffer[2] - '0') * 10 + buffer[1] - '0'; 101315514Sae clock_time->minute = (buffer[4] - '0') * 10 + buffer[3] - '0'; 102315514Sae clock_time->hour = (buffer[6] - '0') * 10 + buffer[5] - '0'; 103315514Sae clock_time->day = (buffer[8] - '0') * 10 + buffer[7] - '0'; 104315514Sae clock_time->month = (buffer[10] - '0') * 10 + buffer[9] - '0'; 105315514Sae clock_time->year = (buffer[12] - '0') * 10 + buffer[11] - '0'; 106315514Sae clock_time->usecond = 0; 107315514Sae if (buffer[13] & 0x1) /* We have CET time */ 108315514Sae clock_time->utcoffset = -1*60*60; 109315514Sae else /* We have BST time */ 110315514Sae clock_time->utcoffset = 0; 111315514Sae if (buffer[13] & 0x2) { 112315514Sae clock_time->flags |= PARSEB_DST; 113315514Sae clock_time->utcoffset += -1*60*60; 114315514Sae } 115315514Sae if (!(buffer[13] & 0x4)) 116315514Sae clock_time->flags |= PARSEB_NOSYNC; 117315514Sae if (buffer[13] & 0x8) 118315514Sae clock_time->flags |= PARSEB_ANNOUNCE; 119315514Sae 120315514Sae return CVT_OK; 121315514Sae} 122315514Sae 123315514Sae/* 124315514Sae * inp_wharton_400a 125315514Sae * 126315514Sae * grep data from input stream 127315514Sae */ 128315514Saestatic u_long 129315514Saeinp_wharton_400a( 130315514Sae parse_t *parseio, 131315514Sae unsigned int ch, 132315514Sae timestamp_t *tstamp 133315514Sae ) 134315514Sae{ 135315514Sae unsigned int rtc; 136315514Sae 137315514Sae parseprintf(DD_PARSE, ("inp_wharton_400a(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); 138315514Sae 139315514Sae switch (ch) 140315514Sae { 141315514Sae case STX: 142315514Sae parseprintf(DD_PARSE, ("inp_wharton_400a: STX seen\n")); 143315514Sae 144315514Sae parseio->parse_index = 1; 145315514Sae parseio->parse_data[0] = ch; 146315514Sae parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */ 147315514Sae return PARSE_INP_SKIP; 148315514Sae 149315514Sae case ETX: 150315514Sae parseprintf(DD_PARSE, ("inp_wharton_400a: ETX seen\n")); 151315514Sae if ((rtc = parse_addchar(parseio, ch)) == PARSE_INP_SKIP) 152315514Sae return parse_end(parseio); 153315514Sae else 154315514Sae return rtc; 155315514Sae 156315514Sae default: 157315514Sae return parse_addchar(parseio, ch); 158315514Sae } 159315514Sae} 160315514Sae 161315514Saeclockformat_t clock_wharton_400a = 162315514Sae{ 163315514Sae inp_wharton_400a, /* input handling function */ 164315514Sae cvt_wharton_400a, /* conversion function */ 165315514Sae 0, /* no PPS monitoring */ 166315514Sae 0, /* conversion configuration */ 167315514Sae "WHARTON 400A Series clock Output Format 1", /* String format name */ 168315514Sae 15, /* string buffer */ 169315514Sae 0 /* no private data (complete pakets) */ 170315514Sae}; 171315514Sae 172315514Sae#else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_WHARTON_400A) */ 173315514Saeint clk_wharton_400a_bs; 174315514Sae#endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_WHARTON_400A) */ 175315514Sae 176315514Sae/* 177315514Sae * clk_wharton.c,v 178315514Sae * Revision 4.1 1999/02/28 15:27:24 kardel 179315514Sae * wharton clock integration 180315514Sae * 181315514Sae */ 182315514Sae