Deleted Added
sdiff udiff text old ( 182007 ) new ( 200576 )
full compact
1/*
2 * refclock_jjy - clock driver for JJY receivers
3 */
4
5/**********************************************************************/
6/* */
7/* Copyright (C) 2001-2004, Takao Abe. All rights reserved. */
8/* */

--- 60 unchanged lines hidden (view full) ---

69/* */
70/* 2004/11/28 */
71/* [Add] Support the Echo Keisokuki LT-2000 receiver */
72/* */
73/* 2006/11/04 */
74/* [Fix] C-DEX JST2000 */
75/* Thanks to Hideo Kuramatsu for the patch */
76/* */
77/**********************************************************************/
78
79#ifdef HAVE_CONFIG_H
80#include <config.h>
81#endif
82
83#if defined(REFCLOCK) && defined(CLOCK_JJY)
84

--- 41 unchanged lines hidden (view full) ---

126/* ------------ ---------------------- --------------------- */
127/* # Mode 1 (Request&Send) */
128/* T YYMMDDWHHMMSS<BCC1><BCC2><CR> */
129/* C Mode 2 (Continuous) */
130/* YYMMDDWHHMMSS<ST1><ST2><ST3><ST4><CR> */
131/* <SUB> Second signal */
132/* */
133/**********************************************************************/
134
135/*
136 * Interface definitions
137 */
138#define DEVICE "/dev/jjy%d" /* device name and unit */
139#define SPEED232 B9600 /* uart speed (9600 baud) */
140#define REFID "JJY" /* reference ID */
141#define DESCRIPTION "JJY Receiver"
142#define PRECISION (-3) /* precision assumed (about 100 ms) */
143
144/*
145 * JJY unit control structure
146 */
147struct jjyunit {
148 char unittype ; /* UNITTYPE_XXXXXXXXXX */
149 short operationmode ; /* Echo Keisokuki LT-2000 : 1 or 2 */
150 short version ;
151 short linediscipline ; /* LDISC_CLK or LDISC_RAW */
152 int linecount ;
153 int lineerror ;
154 int year, month, day, hour, minute, second, msecond ;
155/* LDISC_RAW only */
156#define MAX_LINECOUNT 8
157#define MAX_RAWBUF 64
158 int lineexpect ;
159 int charexpect [ MAX_LINECOUNT ] ;
160 int charcount ;
161 char rawbuf [ MAX_RAWBUF ] ;
162};
163
164#define UNITTYPE_TRISTATE_JJY01 1
165#define UNITTYPE_CDEX_JST2000 2
166#define UNITTYPE_ECHOKEISOKUKI_LT2000 3
167
168/*
169 * Function prototypes
170 */
171static int jjy_start P((int, struct peer *));
172static void jjy_shutdown P((int, struct peer *));
173static void jjy_poll P((int, struct peer *));
174static void jjy_poll_tristate_jjy01 P((int, struct peer *));
175static void jjy_poll_cdex_jst2000 P((int, struct peer *));
176static void jjy_poll_echokeisokuki_lt2000 P((int, struct peer *));
177static void jjy_receive P((struct recvbuf *));
178static int jjy_receive_tristate_jjy01 P((struct recvbuf *));
179static int jjy_receive_cdex_jst2000 P((struct recvbuf *));
180static int jjy_receive_echokeisokuki_lt2000 P((struct recvbuf *));
181
182/*
183 * Transfer vector
184 */
185struct refclock refclock_jjy = {
186 jjy_start, /* start up driver */
187 jjy_shutdown, /* shutdown driver */
188 jjy_poll, /* transmit poll message */

--- 23 unchanged lines hidden (view full) ---

212jjy_start ( int unit, struct peer *peer )
213{
214
215 struct jjyunit *up ;
216 struct refclockproc *pp ;
217 int fd ;
218 char *pDeviceName ;
219 short iDiscipline ;
220
221#ifdef DEBUG
222 if ( debug ) {
223 printf ( "jjy_start (refclock_jjy.c) : %s mode=%d ", ntoa(&peer->srcadr), peer->ttl ) ;
224 printf ( DEVICE, unit ) ;
225 printf ( "\n" ) ;
226 }
227#endif

--- 5 unchanged lines hidden (view full) ---

233 }
234 sprintf ( pDeviceName, DEVICE, unit ) ;
235
236 /*
237 * peer->ttl is a mode number specified by "127.127.40.X mode N" in the ntp.conf
238 */
239 switch ( peer->ttl ) {
240 case 0 :
241 case 1 : iDiscipline = LDISC_CLK ; break ;
242 case 2 : iDiscipline = LDISC_RAW ; break ;
243 case 3 : iDiscipline = LDISC_CLK ; break ;
244 default :
245 msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode",
246 ntoa(&peer->srcadr), peer->ttl ) ;
247 free ( (void*) pDeviceName ) ;
248 return RC_START_ERROR ;
249 }
250
251 if ( ! ( fd = refclock_open ( pDeviceName, SPEED232, iDiscipline ) ) ) {
252 free ( (void*) pDeviceName ) ;
253 return RC_START_ERROR ;
254 }
255 free ( (void*) pDeviceName ) ;
256
257 /*
258 * Allocate and initialize unit structure
259 */

--- 34 unchanged lines hidden (view full) ---

294 case 1 :
295 up->charexpect[0] = 15 ; /* YYMMDDWHHMMSS<BCC1><BCC2><CR> */
296 break ;
297 case 2 :
298 up->charexpect[0] = 17 ; /* YYMMDDWHHMMSS<ST1><ST2><ST3><ST4><CR> */
299 break ;
300 }
301 break ;
302 default :
303 msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode",
304 ntoa(&peer->srcadr), peer->ttl ) ;
305 close ( fd ) ;
306 free ( (void*) up ) ;
307 return RC_START_ERROR ;
308 }
309

--- 119 unchanged lines hidden (view full) ---

429 case UNITTYPE_CDEX_JST2000 :
430 rc = jjy_receive_cdex_jst2000 ( rbufp ) ;
431 break ;
432
433 case UNITTYPE_ECHOKEISOKUKI_LT2000 :
434 rc = jjy_receive_echokeisokuki_lt2000 ( rbufp ) ;
435 break ;
436
437 default :
438 rc = 0 ;
439 break ;
440
441 }
442
443 if ( up->linediscipline == LDISC_RAW ) {
444 if ( up->linecount <= up->lineexpect && up->charcount > up->charexpect[up->linecount-1] ) {
445 for ( i = 0 ; i < up->charcount - up->charexpect[up->linecount-1] ; i ++ ) {
446 up->rawbuf[i] = up->rawbuf[i+up->charexpect[up->linecount-1]] ;
447 }
448 up->charcount -= up->charexpect[up->linecount-1] ;
449 } else {
450 up->charcount = 0 ;
451 }
452 }
453
454 if ( rc == 0 ) return ;
455
456 if ( up->lineerror != 0 ) {
457 refclock_report ( peer, CEVNT_BADREPLY ) ;
458 strcpy ( sLogText, "BAD REPLY [" ) ;
459 if ( up->linediscipline == LDISC_RAW ) {
460 strncat ( sLogText, up->rawbuf, MAX_LOGTEXT - strlen ( sLogText ) - 1 ) ;
461 } else {
462 strncat ( sLogText, pp->a_lastcode, MAX_LOGTEXT - strlen ( sLogText ) - 1 ) ;
463 }

--- 397 unchanged lines hidden (view full) ---

861
862 }
863
864 return 1 ;
865
866}
867
868/**************************************************************************************************/
869/* jjy_poll - called by the transmit procedure */
870/**************************************************************************************************/
871static void
872jjy_poll ( int unit, struct peer *peer )
873{
874
875 struct jjyunit *up;
876 struct refclockproc *pp;

--- 11 unchanged lines hidden (view full) ---

888#ifdef DEBUG
889 if ( debug ) {
890 printf ( "jjy_poll (refclock_jjy.c) : %ld\n", pp->polls ) ;
891 }
892#endif
893
894 pp->polls ++ ;
895
896 up->linecount = 0 ;
897 up->lineerror = 0 ;
898 up->charcount = 0 ;
899
900 switch ( up->unittype ) {
901
902 case UNITTYPE_TRISTATE_JJY01 :
903 jjy_poll_tristate_jjy01 ( unit, peer ) ;
904 break ;
905
906 case UNITTYPE_CDEX_JST2000 :
907 jjy_poll_cdex_jst2000 ( unit, peer ) ;
908 break ;
909
910 case UNITTYPE_ECHOKEISOKUKI_LT2000 :
911 jjy_poll_echokeisokuki_lt2000 ( unit, peer ) ;
912 break ;
913
914 default :
915 break ;
916
917 }
918
919}
920
921/**************************************************************************************************/

--- 79 unchanged lines hidden (view full) ---

1001#endif
1002
1003 if ( write ( pp->io.fd, sCmd, 1 ) != 1 ) {
1004 refclock_report ( peer, CEVNT_FAULT ) ;
1005 }
1006
1007}
1008
1009#else
1010int refclock_jjy_bs ;
1011#endif /* REFCLOCK */