2 * refclock_jjy - clock driver for JJY receivers
5 /**********************************************************************/
7 /* Copyright (C) 2001-2004, Takao Abe. All rights reserved. */
9 /* Permission to use, copy, modify, and distribute this software */
10 /* and its documentation for any purpose is hereby granted */
11 /* without fee, provided that the following conditions are met: */
13 /* One retains the entire copyright notice properly, and both the */
14 /* copyright notice and this license. in the documentation and/or */
15 /* other materials provided with the distribution. */
17 /* This software and the name of the author must not be used to */
18 /* endorse or promote products derived from this software without */
19 /* prior written permission. */
21 /* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESSED OR IMPLIED */
22 /* WARRANTIES OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, THE */
23 /* IMPLIED WARRANTIES OF MERCHANTABLILITY AND FITNESS FOR A */
24 /* PARTICULAR PURPOSE. */
25 /* IN NO EVENT SHALL THE AUTHOR TAKAO ABE BE LIABLE FOR ANY DIRECT, */
26 /* INDIRECT, GENERAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
27 /* ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
28 /* GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS */
29 /* INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, */
30 /* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ( INCLUDING */
31 /* NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF */
32 /* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
34 /* This driver is developed in my private time, and is opened as */
35 /* voluntary contributions for the NTP. */
36 /* The manufacturer of the JJY receiver has not participated in */
37 /* a development of this driver. */
38 /* The manufacturer does not warrant anything about this driver, */
39 /* and is not liable for anything about this driver. */
41 /**********************************************************************/
43 /* Author Takao Abe */
44 /* Email abetakao@bea.hi-ho.ne.jp */
45 /* Homepage http://www.bea.hi-ho.ne.jp/abetakao/ */
47 /**********************************************************************/
52 /* [New] Support the Tristate Ltd. JJY receiver */
55 /* [Change] Log to clockstats even if bad reply */
56 /* [Fix] PRECISION = (-3) (about 100 ms) */
57 /* [Add] Support the C-DEX Co.Ltd. JJY receiver */
60 /* [Fix] C-DEX JST2000 ( fukusima@goto.info.waseda.ac.jp ) */
63 /* [Fix] Portability for FreeBSD ( patched by the user ) */
66 /* [Change] Command send timing for the Tristate Ltd. JJY receiver */
67 /* JJY-01 ( Firmware version 2.01 ) */
68 /* Thanks to Andy Taki for testing under FreeBSD */
71 /* [Add] Support the Echo Keisokuki LT-2000 receiver */
74 /* [Fix] C-DEX JST2000 */
75 /* Thanks to Hideo Kuramatsu for the patch */
77 /**********************************************************************/
83 #if defined(REFCLOCK) && defined(CLOCK_JJY)
94 #include "ntp_refclock.h"
95 #include "ntp_calendar.h"
96 #include "ntp_stdlib.h"
98 /**********************************************************************/
100 /* The Tristate Ltd. JJY receiver JJY01 */
102 /* Command Response Remarks */
103 /* ------------ ---------------------- --------------------- */
104 /* date<CR><LF> YYYY/MM/DD XXX<CR><LF> */
105 /* time<CR><LF> HH:MM:SS<CR><LF> */
106 /* stim<CR><LF> HH:MM:SS<CR><LF> Reply at just second */
108 /* During synchronization after a receiver is turned on, */
109 /* It replies the past time from 2000/01/01 00:00:00. */
110 /* The function "refclock_process" checks the time and tells */
111 /* as an insanity time. */
113 /**********************************************************************/
115 /* The C-DEX Co. Ltd. JJY receiver JST2000 */
117 /* Command Response Remarks */
118 /* ------------ ---------------------- --------------------- */
119 /* <ENQ>1J<ETX> <STX>JYYMMDD HHMMSSS<ETX> */
121 /**********************************************************************/
123 /* The Echo Keisokuki Co. Ltd. JJY receiver LT2000 */
125 /* Command Response Remarks */
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 */
133 /**********************************************************************/
136 * Interface definitions
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) */
145 * JJY unit control structure
148 char unittype ; /* UNITTYPE_XXXXXXXXXX */
149 short operationmode ; /* Echo Keisokuki LT-2000 : 1 or 2 */
151 short linediscipline ; /* LDISC_CLK or LDISC_RAW */
154 int year, month, day, hour, minute, second, msecond ;
156 #define MAX_LINECOUNT 8
157 #define MAX_RAWBUF 64
159 int charexpect [ MAX_LINECOUNT ] ;
161 char rawbuf [ MAX_RAWBUF ] ;
164 #define UNITTYPE_TRISTATE_JJY01 1
165 #define UNITTYPE_CDEX_JST2000 2
166 #define UNITTYPE_ECHOKEISOKUKI_LT2000 3
169 * Function prototypes
171 static int jjy_start P((int, struct peer *));
172 static void jjy_shutdown P((int, struct peer *));
173 static void jjy_poll P((int, struct peer *));
174 static void jjy_poll_tristate_jjy01 P((int, struct peer *));
175 static void jjy_poll_cdex_jst2000 P((int, struct peer *));
176 static void jjy_poll_echokeisokuki_lt2000 P((int, struct peer *));
177 static void jjy_receive P((struct recvbuf *));
178 static int jjy_receive_tristate_jjy01 P((struct recvbuf *));
179 static int jjy_receive_cdex_jst2000 P((struct recvbuf *));
180 static int jjy_receive_echokeisokuki_lt2000 P((struct recvbuf *));
185 struct refclock refclock_jjy = {
186 jjy_start, /* start up driver */
187 jjy_shutdown, /* shutdown driver */
188 jjy_poll, /* transmit poll message */
189 noentry, /* not used */
190 noentry, /* not used */
191 noentry, /* not used */
192 NOFLAGS /* not used */
196 * Start up driver return code
198 #define RC_START_SUCCESS 1
199 #define RC_START_ERROR 0
202 * Local constants definition
205 #define MAX_LOGTEXT 64
208 /**************************************************************************************************/
209 /* jjy_start - open the devices and initialize data for processing */
210 /**************************************************************************************************/
212 jjy_start ( int unit, struct peer *peer )
216 struct refclockproc *pp ;
223 printf ( "jjy_start (refclock_jjy.c) : %s mode=%d ", ntoa(&peer->srcadr), peer->ttl ) ;
224 printf ( DEVICE, unit ) ;
231 if ( ! ( pDeviceName = (char*) emalloc ( strlen(DEVICE) + 10 ) ) ) {
232 return RC_START_ERROR ;
234 sprintf ( pDeviceName, DEVICE, unit ) ;
237 * peer->ttl is a mode number specified by "127.127.40.X mode N" in the ntp.conf
239 switch ( peer->ttl ) {
241 case 1 : iDiscipline = LDISC_CLK ; break ;
242 case 2 : iDiscipline = LDISC_RAW ; break ;
243 case 3 : iDiscipline = LDISC_CLK ; break ;
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 ;
251 if ( ! ( fd = refclock_open ( pDeviceName, SPEED232, iDiscipline ) ) ) {
252 free ( (void*) pDeviceName ) ;
253 return RC_START_ERROR ;
255 free ( (void*) pDeviceName ) ;
258 * Allocate and initialize unit structure
260 if ( ! ( up = (struct jjyunit *) emalloc (sizeof(struct jjyunit)) ) ) {
262 return RC_START_ERROR ;
265 memset ( (char*)up, 0, sizeof(struct jjyunit) ) ;
266 up->linediscipline = iDiscipline ;
269 * peer->ttl is a mode number specified by "127.127.40.X mode N" in the ntp.conf
271 switch ( peer->ttl ) {
274 * The mode 0 is a default clock type at this time.
275 * But this will be change to auto-detect mode in the future.
278 up->unittype = UNITTYPE_TRISTATE_JJY01 ;
281 up->charexpect[0] = 14 ; /* YYYY/MM/DD WWW<CR><LF> */
282 up->charexpect[1] = 8 ; /* HH:MM:SS<CR><LF> */
285 up->unittype = UNITTYPE_CDEX_JST2000 ;
287 up->charexpect[0] = 15 ; /* <STX>JYYMMDD HHMMSSS<ETX> */
290 up->unittype = UNITTYPE_ECHOKEISOKUKI_LT2000 ;
291 up->operationmode = 2 ; /* Mode 2 : Continuous mode */
293 switch ( up->operationmode ) {
295 up->charexpect[0] = 15 ; /* YYMMDDWHHMMSS<BCC1><BCC2><CR> */
298 up->charexpect[0] = 17 ; /* YYMMDDWHHMMSS<ST1><ST2><ST3><ST4><CR> */
303 msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode",
304 ntoa(&peer->srcadr), peer->ttl ) ;
306 free ( (void*) up ) ;
307 return RC_START_ERROR ;
311 pp->unitptr = (caddr_t) up ;
312 pp->io.clock_recv = jjy_receive ;
313 pp->io.srcclock = (caddr_t) peer ;
316 if ( ! io_addclock(&pp->io) ) {
318 free ( (void*) up ) ;
319 return RC_START_ERROR ;
323 * Initialize miscellaneous variables
325 peer->precision = PRECISION ;
327 pp->clockdesc = DESCRIPTION ;
328 memcpy ( (char*)&pp->refid, REFID, strlen(REFID) ) ;
330 return RC_START_SUCCESS ;
335 /**************************************************************************************************/
336 /* jjy_shutdown - shutdown the clock */
337 /**************************************************************************************************/
339 jjy_shutdown ( int unit, struct peer *peer )
343 struct refclockproc *pp;
346 up = (struct jjyunit *) pp->unitptr ;
347 io_closeclock ( &pp->io ) ;
348 free ( (void*) up ) ;
353 /**************************************************************************************************/
354 /* jjy_receive - receive data from the serial interface */
355 /**************************************************************************************************/
357 jjy_receive ( struct recvbuf *rbufp )
361 struct refclockproc *pp ;
364 l_fp tRecvTimestamp; /* arrival timestamp */
366 char sLogText [ MAX_LOGTEXT ] ;
370 * Initialize pointers and read the timecode and timestamp
372 peer = (struct peer *) rbufp->recv_srcclock ;
374 up = (struct jjyunit *) pp->unitptr ;
377 * Get next input line
379 pp->lencode = refclock_gtlin ( rbufp, pp->a_lastcode, BMAX, &tRecvTimestamp ) ;
381 if ( up->linediscipline == LDISC_RAW ) {
383 * The reply with <STX> and <ETX> may give a blank line
385 if ( pp->lencode == 0 && up->charcount == 0 ) return ;
387 * Copy received charaters to temporary buffer
389 for ( i = 0 ; i < pp->lencode && up->charcount < MAX_RAWBUF - 2 ; i ++ , up->charcount ++ ) {
390 up->rawbuf[up->charcount] = pp->a_lastcode[i] ;
392 while ( up->charcount > 0 && up->rawbuf[0] < ' ' ) {
393 for ( i = 0 ; i < up->charcount - 1 ; i ++ ) up->rawbuf[i] = up->rawbuf[i+1] ;
397 for ( i = 0 ; i < up->charcount ; i ++ ) {
398 if ( up->rawbuf[i] < ' ' ) {
403 if ( pp->lencode > 0 && up->linecount < up->lineexpect ) {
404 if ( bCntrlChar == 0 && up->charcount < up->charexpect[up->linecount] ) return ;
406 up->rawbuf[up->charcount] = 0 ;
409 * The reply with <CR><LF> gives a blank line
411 if ( pp->lencode == 0 ) return ;
414 * We get down to business
417 pp->lastrec = tRecvTimestamp ;
421 if ( up->lineerror != 0 ) return ;
423 switch ( up->unittype ) {
425 case UNITTYPE_TRISTATE_JJY01 :
426 rc = jjy_receive_tristate_jjy01 ( rbufp ) ;
429 case UNITTYPE_CDEX_JST2000 :
430 rc = jjy_receive_cdex_jst2000 ( rbufp ) ;
433 case UNITTYPE_ECHOKEISOKUKI_LT2000 :
434 rc = jjy_receive_echokeisokuki_lt2000 ( rbufp ) ;
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]] ;
448 up->charcount -= up->charexpect[up->linecount-1] ;
454 if ( rc == 0 ) return ;
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 ) ;
462 strncat ( sLogText, pp->a_lastcode, MAX_LOGTEXT - strlen ( sLogText ) - 1 ) ;
464 sLogText[MAX_LOGTEXT-1] = 0 ;
465 if ( strlen ( sLogText ) < MAX_LOGTEXT - 2 ) strcat ( sLogText, "]" ) ;
466 record_clock_stats ( &peer->srcadr, sLogText ) ;
470 pp->year = up->year ;
471 pp->day = ymd2yd ( up->year, up->month, up->day ) ;
472 pp->hour = up->hour ;
473 pp->minute = up->minute ;
474 pp->second = up->second ;
475 pp->nsec = up->msecond * 1000000;
481 if ( pp->hour < 0 ) {
486 pp->day = ymd2yd ( pp->year, 12, 31 ) ;
491 printf ( "jjy_receive (refclock_jjy.c) : %04d/%02d/%02d %02d:%02d:%02d.%1d JST ",
492 up->year, up->month, up->day, up->hour, up->minute, up->second, up->msecond/100 ) ;
493 printf ( "( %04d/%03d %02d:%02d:%02d.%1d UTC )\n",
494 pp->year, pp->day, pp->hour, pp->minute, pp->second, (int)(pp->nsec/100000000) ) ;
499 * Process the new sample in the median filter and determine the
500 * timecode timestamp.
503 sprintf ( sLogText, "%04d/%02d/%02d %02d:%02d:%02d.%1d JST",
504 up->year, up->month, up->day, up->hour, up->minute, up->second, up->msecond/100 ) ;
505 record_clock_stats ( &peer->srcadr, sLogText ) ;
507 if ( ! refclock_process ( pp ) ) {
508 refclock_report(peer, CEVNT_BADTIME);
512 pp->lastref = pp->lastrec;
513 refclock_receive(peer);
517 /**************************************************************************************************/
520 jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp )
523 static char *sFunctionName = "jjy_receive_tristate_jjy01" ;
526 struct refclockproc *pp ;
534 * Initialize pointers and read the timecode and timestamp
536 peer = (struct peer *) rbufp->recv_srcclock ;
538 up = (struct jjyunit *) pp->unitptr ;
540 if ( up->linediscipline == LDISC_RAW ) {
542 iLen = up->charcount ;
544 pBuf = pp->a_lastcode ;
548 switch ( up->linecount ) {
550 case 1 : /* YYYY/MM/DD WWW */
555 printf ( "%s (refclock_jjy.c) : Reply length error ( up->linecount=%d iLen=%d )\n", sFunctionName, up->linecount, iLen ) ;
561 rc = sscanf ( pBuf, "%4d/%2d/%2d", &up->year, &up->month, &up->day ) ;
562 if ( rc != 3 || up->year < 2000 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 ) {
565 printf ( "%s (refclock_jjy.c) : Date error ( up->linecount=%d )\n", sFunctionName, up->linecount ) ;
572 /*** Start of modification on 2004/10/31 */
574 * Following codes are moved from the function jjy_poll_tristate_jjy01 in this source.
575 * The Tristate JJY-01 ( Firmware version 1.01 ) accepts "time" and "stim" commands without any delay.
576 * But the JJY-01 ( Firmware version 2.01 ) does not accept these commands continuously,
577 * so this driver issues the second command "stim" after the reply of the first command "date".
581 * Send "stim<CR><LF>" or "time<CR><LF>" command
585 if ( up->version >= 100 ) {
588 printf ( "%s (refclock_jjy.c) : send 'stim<CR><LF>'\n", sFunctionName ) ;
591 if ( write ( pp->io.fd, "stim\r\n",6 ) != 6 ) {
592 refclock_report ( peer, CEVNT_FAULT ) ;
597 printf ( "%s (refclock_jjy.c) : send 'time<CR><LF>'\n", sFunctionName ) ;
600 if ( write ( pp->io.fd, "time\r\n",6 ) != 6 ) {
601 refclock_report ( peer, CEVNT_FAULT ) ;
604 /*** End of modification ***/
608 case 2 : /* HH:MM:SS */
613 printf ( "%s (refclock_jjy.c) : Reply length error ( up->linecount=%d iLen=%d )\n", sFunctionName, up->linecount, iLen ) ;
619 rc = sscanf ( pBuf, "%2d:%2d:%2d", &up->hour, &up->minute, &up->second ) ;
620 if ( rc != 3 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
623 printf ( "%s (refclock_jjy.c) : Time error ( up->linecount=%d )\n", sFunctionName, up->linecount ) ;
630 if ( up->hour == 0 && up->minute == 0 && up->second <= 2 ) {
632 * The command "date" and "time" ( or "stim" ) were sent to the JJY receiver continuously.
633 * But the JJY receiver replies a date and time separately.
634 * Just after midnight transitions, we ignore this time.
640 default : /* Unexpected reply */
651 /**************************************************************************************************/
654 jjy_receive_cdex_jst2000 ( struct recvbuf *rbufp )
657 static char *sFunctionName = "jjy_receive_cdex_jst2000" ;
660 struct refclockproc *pp ;
668 * Initialize pointers and read the timecode and timestamp
670 peer = (struct peer *) rbufp->recv_srcclock ;
672 up = (struct jjyunit *) pp->unitptr ;
674 if ( up->linediscipline == LDISC_RAW ) {
676 iLen = up->charcount ;
678 pBuf = pp->a_lastcode ;
682 switch ( up->linecount ) {
684 case 1 : /* JYYMMDD HHMMSSS */
689 printf ( "%s (refclock_jjy.c) : Reply length error ( iLen=%d )\n", sFunctionName, iLen ) ;
695 rc = sscanf ( pBuf, "J%2d%2d%2d%*1d%2d%2d%2d%1d",
696 &up->year, &up->month, &up->day, &up->hour, &up->minute, &up->second, &up->msecond ) ;
697 if ( rc != 7 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31
698 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
701 printf ( "%s (refclock_jjy.c) : Time error (rc=%d) [ %02d %02d %02d * %02d %02d %02d.%1d ]\n", sFunctionName,
702 rc, up->year, up->month, up->day, up->hour, up->minute, up->second, up->msecond ) ;
712 default : /* Unexpected reply */
723 /**************************************************************************************************/
726 jjy_receive_echokeisokuki_lt2000 ( struct recvbuf *rbufp )
729 static char *sFunctionName = "jjy_receive_echokeisokuki_lt2000" ;
732 struct refclockproc *pp ;
738 int i, ibcc, ibcc1, ibcc2 ;
741 * Initialize pointers and read the timecode and timestamp
743 peer = (struct peer *) rbufp->recv_srcclock ;
745 up = (struct jjyunit *) pp->unitptr ;
747 if ( up->linediscipline == LDISC_RAW ) {
749 iLen = up->charcount ;
751 pBuf = pp->a_lastcode ;
755 switch ( up->linecount ) {
757 case 1 : /* YYMMDDWHHMMSS<BCC1><BCC2> or YYMMDDWHHMMSS<ST1><ST2><ST3><ST4> */
759 if ( ( up->operationmode == 1 && iLen != 15 ) || ( up->operationmode == 2 && iLen != 17 ) ) {
762 printf ( "%s (refclock_jjy.c) : Reply length error ( iLen=%d )\n", sFunctionName, iLen ) ;
765 if ( up->operationmode == 1 ) {
768 printf ( "%s (refclock_jjy.c) : send '#'\n", sFunctionName ) ;
771 if ( write ( pp->io.fd, "#",1 ) != 1 ) {
772 refclock_report ( peer, CEVNT_FAULT ) ;
779 if ( up->operationmode == 1 ) {
781 for ( i = ibcc = 0 ; i < 13 ; i ++ ) ibcc ^= pBuf[i] ;
782 ibcc1 = 0x30 | ( ( ibcc >> 4 ) & 0xF ) ;
783 ibcc2 = 0x30 | ( ( ibcc ) & 0xF ) ;
784 if ( pBuf[13] != ibcc1 || pBuf[14] != ibcc2 ) {
787 printf ( "%s (refclock_jjy.c) : BCC error ( Recv=%02X,%02X / Calc=%02X,%02X)\n", sFunctionName, pBuf[13]&0xFF, pBuf[14]&0xFF, ibcc1, ibcc2 ) ;
796 rc = sscanf ( pBuf, "%2d%2d%2d%*1d%2d%2d%2d",
797 &up->year, &up->month, &up->day, &up->hour, &up->minute, &up->second ) ;
798 if ( rc != 6 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31
799 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
802 printf ( "%s (refclock_jjy.c) : Time error (rc=%d) [ %02d %02d %02d * %02d %02d %02d ]\n", sFunctionName,
803 rc, up->year, up->month, up->day, up->hour, up->minute, up->second ) ;
812 if ( up->operationmode == 2 ) {
814 /* A time stamp comes on every 0.5 seccond in the mode 2 of the LT-2000. */
817 if ( pp->second < 0 ) {
820 if ( pp->minute < 0 ) {
823 if ( pp->hour < 0 ) {
828 pp->day = ymd2yd ( pp->year, 12, 31 ) ;
834 /* Switch from mode 2 to mode 1 in order to restraint of useless time stamp. */
837 printf ( "%s (refclock_jjy.c) : send '#'\n", sFunctionName ) ;
840 if ( write ( pp->io.fd, "#",1 ) != 1 ) {
841 refclock_report ( peer, CEVNT_FAULT ) ;
848 default : /* Unexpected reply */
852 printf ( "%s (refclock_jjy.c) : send '#'\n", sFunctionName ) ;
855 if ( write ( pp->io.fd, "#",1 ) != 1 ) {
856 refclock_report ( peer, CEVNT_FAULT ) ;
868 /**************************************************************************************************/
869 /* jjy_poll - called by the transmit procedure */
870 /**************************************************************************************************/
872 jjy_poll ( int unit, struct peer *peer )
876 struct refclockproc *pp;
879 up = (struct jjyunit *) pp->unitptr ;
881 if ( pp->polls > 0 && up->linecount == 0 ) {
883 * No reply for last command
885 refclock_report ( peer, CEVNT_TIMEOUT ) ;
890 printf ( "jjy_poll (refclock_jjy.c) : %ld\n", pp->polls ) ;
900 switch ( up->unittype ) {
902 case UNITTYPE_TRISTATE_JJY01 :
903 jjy_poll_tristate_jjy01 ( unit, peer ) ;
906 case UNITTYPE_CDEX_JST2000 :
907 jjy_poll_cdex_jst2000 ( unit, peer ) ;
910 case UNITTYPE_ECHOKEISOKUKI_LT2000 :
911 jjy_poll_echokeisokuki_lt2000 ( unit, peer ) ;
921 /**************************************************************************************************/
924 jjy_poll_tristate_jjy01 ( int unit, struct peer *peer )
927 struct refclockproc *pp;
932 * Send "date<CR><LF>" command
937 printf ( "jjy_poll_tristate_jjy01 (refclock_jjy.c) : send 'date<CR><LF>'\n" ) ;
941 if ( write ( pp->io.fd, "date\r\n",6 ) != 6 ) {
942 refclock_report ( peer, CEVNT_FAULT ) ;
947 /**************************************************************************************************/
950 jjy_poll_cdex_jst2000 ( int unit, struct peer *peer )
953 struct refclockproc *pp;
958 * Send "<ENQ>1J<ETX>" command
963 printf ( "jjy_poll_cdex_jst2000 (refclock_jjy.c) : send '<ENQ>1J<ETX>'\n" ) ;
967 if ( write ( pp->io.fd, "\0051J\003", 4 ) != 4 ) {
968 refclock_report ( peer, CEVNT_FAULT ) ;
973 /**************************************************************************************************/
976 jjy_poll_echokeisokuki_lt2000 ( int unit, struct peer *peer )
980 struct refclockproc *pp;
985 up = (struct jjyunit *) pp->unitptr ;
988 * Send "T" or "C" command
991 switch ( up->operationmode ) {
992 case 1 : sCmd[0] = 'T' ; break ;
993 case 2 : sCmd[0] = 'C' ; break ;
999 printf ( "jjy_poll_echokeisokuki_lt2000 (refclock_jjy.c) : send '%s'\n", sCmd ) ;
1003 if ( write ( pp->io.fd, sCmd, 1 ) != 1 ) {
1004 refclock_report ( peer, CEVNT_FAULT ) ;
1010 int refclock_jjy_bs ;
1011 #endif /* REFCLOCK */