summaryrefslogtreecommitdiffstats
path: root/usr.sbin/xntpd/parse/clk_dcf7000.c
blob: 82e791578a33f17f88d9f0dcfc2d9464eb5b68b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#if defined(REFCLOCK) && (defined(PARSE) || defined(PARSEPPS)) && defined(CLOCK_DCF7000)
/*
 * /src/NTP/REPOSITORY/v3/parse/clk_dcf7000.c,v 3.12 1994/05/30 10:19:57 kardel Exp
 *
 * clk_dcf7000.c,v 3.12 1994/05/30 10:19:57 kardel Exp
 *
 * ELV DCF7000 module
 *
 * Copyright (c) 1992,1993,1994
 * Frank Kardel Friedrich-Alexander Universitaet Erlangen-Nuernberg
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 */

#include "sys/types.h"
#include "sys/time.h"
#include "sys/errno.h"
#include "ntp_fp.h"
#include "ntp_unixtime.h"
#include "ntp_calendar.h"

#include "parse.h"

static struct format dcf7000_fmt =
{				/* ELV DCF7000 */
  {
    {  6, 2}, {  3, 2}, {  0, 2},
    { 12, 2}, { 15, 2}, { 18, 2},
    {  9, 2}, { 21, 2},
  },
  "  -  -  -  -  -  -  -  \r",
  0
};

static u_long cvt_dcf7000();

clockformat_t clock_dcf7000 =
{
  (unsigned LONG (*)())0,	/* no input handling */
  cvt_dcf7000,			/* ELV DCF77 conversion */
  syn_simple,			/* easy time stamps */
  (u_long (*)())0,		/* no direct PPS monitoring */
  (u_long (*)())0,		/* no time code synthesizer monitoring */
  (void *)&dcf7000_fmt,		/* conversion configuration */
  "ELV DCF7000",		/* ELV clock */
  24,				/* string buffer */
  F_END|SYNC_END,		/* END packet delimiter / synchronisation */
  0,				/* no private data (complete pakets) */
  { 0, 0},
  '\0',
  '\r',
  '\0'
};

/*
 * cvt_dcf7000
 *
 * convert dcf7000 type format
 */
static u_long
cvt_dcf7000(buffer, size, format, clock)
  register char          *buffer;
  register int            size;
  register struct format *format;
  register clocktime_t   *clock;
{
  if (!Strok(buffer, format->fixed_string))
    {
      return CVT_NONE;
    }
  else
    {
      if (Stoi(&buffer[format->field_offsets[O_DAY].offset], &clock->day,
	       format->field_offsets[O_DAY].length) ||
	  Stoi(&buffer[format->field_offsets[O_MONTH].offset], &clock->month,
	       format->field_offsets[O_MONTH].length) ||
	  Stoi(&buffer[format->field_offsets[O_YEAR].offset], &clock->year,
	       format->field_offsets[O_YEAR].length) ||
	  Stoi(&buffer[format->field_offsets[O_HOUR].offset], &clock->hour,
	       format->field_offsets[O_HOUR].length) ||
	  Stoi(&buffer[format->field_offsets[O_MIN].offset], &clock->minute,
	       format->field_offsets[O_MIN].length) ||
	  Stoi(&buffer[format->field_offsets[O_SEC].offset], &clock->second,
	       format->field_offsets[O_SEC].length))
	{
	  return CVT_FAIL|CVT_BADFMT;
	}
      else
	{
	  char *f = &buffer[format->field_offsets[O_FLAGS].offset];
	  long flags;

	  clock->flags = 0;
	  clock->usecond = 0;

	  if (Stoi(f, &flags, format->field_offsets[O_FLAGS].length))
	    {
	      return CVT_FAIL|CVT_BADFMT;
	    }
	  else
	    {
	      if (flags & 0x1)
		clock->utcoffset = -2*60*60;
	      else
		clock->utcoffset = -1*60*60;

	      if (flags & 0x2)
		clock->flags |= PARSEB_ANNOUNCE;

	      if (flags & 0x4)
		clock->flags |= PARSEB_NOSYNC;
	    }
	  return CVT_OK;
	}
    }
}
#endif /* defined(PARSE) && defined(CLOCK_DCF7000) */

/*
 * History:
 *
 * clk_dcf7000.c,v
 * Revision 3.12  1994/05/30  10:19:57  kardel
 * LONG cleanup
 *
 * Revision 3.11  1994/02/02  17:45:14  kardel
 * rcs ids fixed
 *
 * Revision 3.6  1993/10/09  15:01:27  kardel
 * file structure unified
 *
 * Revision 3.5  1993/10/03  19:10:41  kardel
 * restructured I/O handling
 *
 * Revision 3.4  1993/09/27  21:08:02  kardel
 * utcoffset now in seconds
 *
 * Revision 3.3  1993/09/26  23:40:20  kardel
 * new parse driver logic
 *
 * Revision 3.2  1993/07/09  11:37:15  kardel
 * Initial restructured version + GPS support
 *
 * Revision 3.1  1993/07/06  10:00:14  kardel
 * DCF77 driver goes generic...
 *
 */
OpenPOWER on IntegriCloud