Lines Matching +full:em +full:- +full:uart

2  * refclock_jjy - clock driver for JJY receivers
7 /* Copyright (C) 2001-2020, Takao Abe. All rights reserved. */
45 /* Homepage http://www.bea.hi-ho.ne.jp/abetakao/ */
47 /* The email address abetakao@bea.hi-ho.ne.jp is never read */
49 /* "hi-ho.ne.jp", and lots of spam mail are reached. */
62 /* [Fix] PRECISION = (-3) (about 100 ms) */
63 /* [Add] Support the C-DEX Co.Ltd. JJY receiver */
66 /* [Fix] C-DEX JST2000 ( fukusima@goto.info.waseda.ac.jp ) */
73 /* JJY-01 ( Firmware version 2.01 ) */
77 /* [Add] Support the Echo Keisokuki LT-2000 receiver */
80 /* [Fix] C-DEX JST2000 */
84 /* [Add] Support the CITIZEN T.I.C JJY-200 receiver */
93 /* ( DATE,STIM -> DCST,STUS,DATE,STIM ) */
96 /* [Add] Support the Tristate Ltd. TS-GPSclock-01 */
102 /* Change over midnight handling of TS-JJY01 and TS-GPS01 */
107 /* [Add] Support the SEIKO TIME SYSTEMS TDC-300 */
110 /* [Fix] C-DEX JST2000 */
119 /* [Change] Handling TS-JJY01/02 status of the the STUS reply. */
152 #define SPEED232_TRISTATE_JJY01 B9600 /* UART speed (9600 baud) */
153 #define SPEED232_CDEX_JST2000 B9600 /* UART speed (9600 baud) */
154 #define SPEED232_ECHOKEISOKUKI_LT2000 B9600 /* UART speed (9600 baud) */
155 #define SPEED232_CITIZENTIC_JJY200 B4800 /* UART speed (4800 baud) */
157 #define SPEED232_SEIKO_TIMESYS_TDC_300 B2400 /* UART speed (2400 baud) */
158 #define SPEED232_TELEPHONE B2400 /* UART speed (4800 baud) */
161 #define PRECISION (-3) /* precision assumed (about 100 ms) */
179 short operationmode ; /* Echo Keisokuki LT-2000 */
187 short iCommandSeq ; /* 0:Idle Non-Zero:Issued */
192 int iTimestampCount ; /* TS-JJY01, TS-GPS01, Telephone-JJY */
193 int iTimestamp [ MAX_TIMESTAMP ] ; /* Serial second ( 0 - 86399 ) */
204 /* TS-JJY01, TS-JJY02 */
251 * |-- jjy_start_tristate_jjy01
252 * |-- jjy_start_cdex_jst2000
253 * |-- jjy_start_echokeisokuki_lt2000
254 * |-- jjy_start_citizentic_jjy200
255 * |-- jjy_start_tristate_gpsclock01
256 * |-- jjy_start_seiko_tsys_tdc_300
257 * |-- jjy_start_telephone
262 * |-- jjy_poll_tristate_jjy01
263 * |-- jjy_poll_cdex_jst2000
264 * |-- jjy_poll_echokeisokuki_lt2000
265 * |-- jjy_poll_citizentic_jjy200
266 * |-- jjy_poll_tristate_gpsclock01
267 * |-- jjy_poll_seiko_tsys_tdc_300
268 * |-- jjy_poll_telephone
269 * |-- teljjy_control
270 * |-- teljjy_XXXX_YYYY ( XXXX_YYYY is an event handler name. )
271 * |-- modem_connect
272 * |-- modem_control
273 * |-- modem_XXXX_YYYY ( XXXX_YYYY is an event handler name. )
277 * |-- jjy_receive_tristate_jjy01
278 * | |-- jjy_synctime
279 * |-- jjy_receive_cdex_jst2000
280 * | |-- jjy_synctime
281 * |-- jjy_receive_echokeisokuki_lt2000
282 * | |-- jjy_synctime
283 * |-- jjy_receive_citizentic_jjy200
284 * | |-- jjy_synctime
285 * |-- jjy_receive_tristate_gpsclock01
286 * | |-- jjy_synctime
287 * |-- jjy_receive_seiko_tsys_tdc_300
288 * | |-- jjy_synctime
289 * |-- jjy_receive_telephone
290 * |-- modem_receive
291 * | |-- modem_control
292 * | |-- modem_XXXX_YYYY ( XXXX_YYYY is an event handler name. )
293 * |-- teljjy_control
294 * |-- teljjy_XXXX_YYYY ( XXXX_YYYY is an event handler name. )
295 * |-- jjy_synctime
296 * |-- modem_disconnect
297 * |-- modem_control
298 * |-- modem_XXXX_YYYY ( XXXX_YYYY is an event handler name. )
301 * |-- jjy_timer_telephone
302 * |-- modem_timer
303 * | |-- modem_control
304 * | |-- modem_XXXX_YYYY ( XXXX_YYYY is an event handler name. )
305 * |-- teljjy_control
306 * |-- teljjy_XXXX_YYYY ( XXXX_YYYY is an event handler name. )
307 * |-- modem_disconnect
308 * |-- modem_control
309 * |-- modem_XXXX_YYYY ( XXXX_YYYY is an event handler name. )
441 …d iTimestampCount=%d iLen=%d\n", sFunc, up->iProcessState, up->bLineError, up->iCommandSeq, up->iL…
447 /* jjy_start - open the devices and initialize data for processing */
462 ntoa(&peer->srcadr), peer->ttl, DEVICE, unit ) ; in jjy_start()
474 up->bInitError = FALSE ; in jjy_start()
475 up->iProcessState = JJY_PROCESS_STATE_IDLE ; in jjy_start()
476 up->bReceiveFlag = FALSE ; in jjy_start()
477 up->iCommandSeq = 0 ; in jjy_start()
478 up->iLineCount = 0 ; in jjy_start()
479 up->iTimestampCount = 0 ; in jjy_start()
480 up->bWaitBreakString = FALSE ; in jjy_start()
481 up->iRawBufLen = up->iLineBufLen = up->iTextBufLen = 0 ; in jjy_start()
482 up->bSkipCntrlCharOnly = TRUE ; in jjy_start()
487 snprintf( sLog, sizeof(sLog), "mode=%d dev=%s", peer->ttl, sDeviceName ) ; in jjy_start()
491 * peer->ttl is a mode number specified by "127.127.40.X mode N" in the ntp.conf in jjy_start()
493 switch ( peer->ttl ) { in jjy_start()
517 if ( 101 <= peer->ttl && peer->ttl <= 180 ) { in jjy_start()
521 ntoa(&peer->srcadr), peer->ttl ) ; in jjy_start()
529 ntoa(&peer->srcadr), peer->ttl ) ; in jjy_start()
535 fd = refclock_open ( &peer->srcadr, sDeviceName, up->linespeed, up->linediscipline ) ; in jjy_start()
544 pp = peer->procptr ; in jjy_start()
546 pp->clockdesc = DESCRIPTION ; in jjy_start()
547 pp->unitptr = up ; in jjy_start()
548 pp->io.clock_recv = jjy_receive ; in jjy_start()
549 pp->io.srcclock = peer ; in jjy_start()
550 pp->io.datalen = 0 ; in jjy_start()
551 pp->io.fd = fd ; in jjy_start()
552 if ( ! io_addclock(&pp->io) ) { in jjy_start()
554 pp->io.fd = -1 ; in jjy_start()
556 pp->unitptr = NULL ; in jjy_start()
559 memcpy( (char*)&pp->refid, REFID, strlen(REFID) ) ; in jjy_start()
561 peer->precision = PRECISION ; in jjy_start()
563 snprintf( sLog, sizeof(sLog), "minpoll=%d maxpoll=%d", peer->minpoll, peer->maxpoll ) ; in jjy_start()
571 /* jjy_shutdown - shutdown the clock */
582 pp = peer->procptr ; in jjy_shutdown()
583 up = pp->unitptr ; in jjy_shutdown()
584 if ( -1 != pp->io.fd ) { in jjy_shutdown()
585 io_closeclock ( &pp->io ) ; in jjy_shutdown()
591 snprintf( sLog, sizeof(sLog), "JJY stopped. unit=%d mode=%d", unit, peer->ttl ) ; in jjy_shutdown()
592 record_clock_stats( &peer->srcadr, sLog ) ; in jjy_shutdown()
597 /* jjy_receive - receive data from the serial interface */
619 peer = rbufp->recv_peer ; in jjy_receive()
620 pp = peer->procptr ; in jjy_receive()
621 up = pp->unitptr ; in jjy_receive()
626 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive()
628 pp->lencode = refclock_gtraw ( rbufp, pp->a_lastcode, BMAX-1, &tRecvTimestamp ) ; in jjy_receive()
629 /* 3rd argument can be BMAX, but the coverity scan tool claim "Memory - corruptions (OVERRUN)" */ in jjy_receive()
631 /* To avoid its claim, pass the value BMAX-1. */ in jjy_receive()
637 i < pp->lencode && up->iRawBufLen < MAX_RAWBUF - 2 ; in jjy_receive()
638 i ++ , up->iRawBufLen ++ ) { in jjy_receive()
639 up->sRawBuf[up->iRawBufLen] = pp->a_lastcode[i] ; in jjy_receive()
641 up->sRawBuf[up->iRawBufLen] = 0 ; in jjy_receive()
646 pp->lencode = refclock_gtlin ( rbufp, pp->a_lastcode, BMAX, &tRecvTimestamp ) ; in jjy_receive()
650 printf( "\nrefclock_jjy.c : %s : Len=%d ", sFunctionName, pp->lencode ) ; in jjy_receive()
651 for ( i = 0 ; i < pp->lencode ; i ++ ) { in jjy_receive()
652 if ( iscntrl( (u_char)(pp->a_lastcode[i] & 0x7F) ) ) { in jjy_receive()
653 printf( "<x%02X>", pp->a_lastcode[i] & 0xFF ) ; in jjy_receive()
655 printf( "%c", pp->a_lastcode[i] ) ; in jjy_receive()
665 if ( pp->lencode == 0 ) return ; in jjy_receive()
671 if ( up->iProcessState == JJY_PROCESS_STATE_IDLE in jjy_receive()
672 || up->iProcessState == JJY_PROCESS_STATE_DONE in jjy_receive()
673 || up->iProcessState == JJY_PROCESS_STATE_ERROR ) { in jjy_receive()
675 up->iRawBufLen = 0 ; in jjy_receive()
688 pp->lastrec = tRecvTimestamp ; in jjy_receive()
690 up->iLineCount ++ ; in jjy_receive()
692 up->iProcessState = JJY_PROCESS_STATE_RECEIVE ; in jjy_receive()
693 up->bReceiveFlag = TRUE ; in jjy_receive()
696 iBreakPosition = up->iRawBufLen - 1 ; in jjy_receive()
697 for ( ; up->iProcessState == JJY_PROCESS_STATE_RECEIVE ; ) { in jjy_receive()
699 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive()
701 if ( up->bWaitBreakString ) { in jjy_receive()
703 if ( iBreakPosition == -1 ) { in jjy_receive()
705 if ( up->iRawBufLen < MAX_RAWBUF - 2 in jjy_receive()
711 iBreakPosition = up->iRawBufLen - 1 ; in jjy_receive()
715 iBreakPosition = up->iRawBufLen - 1 ; in jjy_receive()
719 up->iLineBufLen = up->iTextBufLen = 0 ; in jjy_receive()
723 up->sLineBuf[up->iLineBufLen] = up->sRawBuf[i] ; in jjy_receive()
724 up->iLineBufLen ++ ; in jjy_receive()
727 if ( ! iscntrl( (u_char)up->sRawBuf[i] ) ) { in jjy_receive()
728 up->sTextBuf[up->iTextBufLen] = up->sRawBuf[i] ; in jjy_receive()
729 up->iTextBufLen ++ ; in jjy_receive()
733 up->sLineBuf[up->iLineBufLen] = 0 ; in jjy_receive()
734 up->sTextBuf[up->iTextBufLen] = 0 ; in jjy_receive()
736 printf( "refclock_jjy.c : %s : up->iLineBufLen=%d up->iTextBufLen=%d\n", in jjy_receive()
737 sFunctionName, up->iLineBufLen, up->iTextBufLen ) ; in jjy_receive()
740 if ( up->bSkipCntrlCharOnly && up->iTextBufLen == 0 ) { in jjy_receive()
742 …printf( "refclock_jjy.c : %s : Skip cntrl char only : up->iRawBufLen=%d iReadRawBuf=%d iBreakPosit… in jjy_receive()
743 sFunctionName, up->iRawBufLen, iReadRawBuf, iBreakPosition ) ; in jjy_receive()
745 if ( iBreakPosition + 1 < up->iRawBufLen ) { in jjy_receive()
756 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive()
757 pBuf = up->sLineBuf ; in jjy_receive()
758 iLen = up->iLineBufLen ; in jjy_receive()
760 pBuf = pp->a_lastcode ; in jjy_receive()
761 iLen = pp->lencode ; in jjy_receive()
764 iCopyLen = ( iLen <= sizeof(sLogText)-1 ? iLen : sizeof(sLogText)-1 ) ; in jjy_receive()
769 switch ( up->unittype ) { in jjy_receive()
808 up->iProcessState = JJY_PROCESS_STATE_DONE ; in jjy_receive()
811 up->iProcessState = JJY_PROCESS_STATE_ERROR ; in jjy_receive()
817 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive()
822 if ( iReadRawBuf >= up->iRawBufLen ) { in jjy_receive()
828 if ( up->linediscipline == LDISC_CLK ) { in jjy_receive()
834 if ( up->linediscipline == LDISC_RAW && iReadRawBuf > 0 ) { in jjy_receive()
835 for ( i = 0, j = iReadRawBuf ; j < up->iRawBufLen ; i ++, j++ ) { in jjy_receive()
836 up->sRawBuf[i] = up->sRawBuf[j] ; in jjy_receive()
838 up->iRawBufLen -= iReadRawBuf ; in jjy_receive()
839 if ( up->iRawBufLen < 0 ) { in jjy_receive()
840 up->iRawBufLen = 0 ; in jjy_receive()
844 up->bReceiveFlag = FALSE ; in jjy_receive()
856 if ( iStart >= up->iRawBufLen ) { in getRawDataBreakPosition()
858 printf( "refclock_jjy.c : getRawDataBreakPosition : iStart=%d return=-1\n", iStart ) ; in getRawDataBreakPosition()
860 return -1 ; in getRawDataBreakPosition()
863 for ( i = iStart ; i < up->iRawBufLen ; i ++ ) { in getRawDataBreakPosition()
865 for ( j = 0 ; up->pRawBreak[j].pString != NULL ; j ++ ) { in getRawDataBreakPosition()
867 if ( i + up->pRawBreak[j].iLength <= up->iRawBufLen ) { in getRawDataBreakPosition()
869 if ( strncmp( up->sRawBuf + i, in getRawDataBreakPosition()
870 up->pRawBreak[j].pString, in getRawDataBreakPosition()
871 up->pRawBreak[j].iLength ) == 0 ) { in getRawDataBreakPosition()
875 iStart, i + up->pRawBreak[j].iLength - 1 ) ; in getRawDataBreakPosition()
877 return i + up->pRawBreak[j].iLength - 1 ; in getRawDataBreakPosition()
885 printf( "refclock_jjy.c : getRawDataBreakPosition : iStart=%d return=-1\n", iStart ) ; in getRawDataBreakPosition()
887 return -1 ; in getRawDataBreakPosition()
892 /* jjy_poll - called by the transmit procedure */
903 pp = peer->procptr; in jjy_poll()
904 up = pp->unitptr ; in jjy_poll()
906 if ( up->bInitError ) { in jjy_poll()
911 if ( pp->polls > 0 && up->iLineCount == 0 ) { in jjy_poll()
918 pp->polls ++ ; in jjy_poll()
920 sReach[0] = peer->reach & 0x80 ? '1' : '0' ; in jjy_poll()
921 sReach[1] = peer->reach & 0x40 ? '1' : '0' ; in jjy_poll()
922 sReach[2] = peer->reach & 0x20 ? '1' : '0' ; in jjy_poll()
923 sReach[3] = peer->reach & 0x10 ? '1' : '0' ; in jjy_poll()
924 sReach[4] = peer->reach & 0x08 ? '1' : '0' ; in jjy_poll()
925 sReach[5] = peer->reach & 0x04 ? '1' : '0' ; in jjy_poll()
926 sReach[6] = peer->reach & 0x02 ? '1' : '0' ; in jjy_poll()
930 snprintf( sLog, sizeof(sLog), "polls=%ld reach=%s", pp->polls, sReach ) ; in jjy_poll()
933 up->iProcessState = JJY_PROCESS_STATE_POLL ; in jjy_poll()
934 up->iCommandSeq = 0 ; in jjy_poll()
935 up->iReceiveSeq = 0 ; in jjy_poll()
936 up->iLineCount = 0 ; in jjy_poll()
937 up->bLineError = FALSE ; in jjy_poll()
938 up->iRawBufLen = 0 ; in jjy_poll()
940 switch ( up->unittype ) { in jjy_poll()
978 /* jjy_timer - called at one-second intervals */
993 pp = peer->procptr ; in jjy_timer()
994 up = pp->unitptr ; in jjy_timer()
996 if ( up->bReceiveFlag ) { in jjy_timer()
999 printf ( "refclock_jjy.c : jjy_timer : up->bReceiveFlag= TRUE : Timer skipped.\n" ) ; in jjy_timer()
1005 switch ( up->unittype ) { in jjy_timer()
1028 pp->year = up->year ; in jjy_synctime()
1029 pp->day = ymd2yd( up->year, up->month, up->day ) ; in jjy_synctime()
1030 pp->hour = up->hour ; in jjy_synctime()
1031 pp->minute = up->minute ; in jjy_synctime()
1032 pp->second = up->second ; in jjy_synctime()
1033 pp->nsec = up->msecond * 1000000 ; in jjy_synctime()
1038 pp->hour -= 9 ; in jjy_synctime()
1039 if ( pp->hour < 0 ) { in jjy_synctime()
1040 pp->hour += 24 ; in jjy_synctime()
1041 pp->day -- ; in jjy_synctime()
1042 if ( pp->day < 1 ) { in jjy_synctime()
1043 pp->year -- ; in jjy_synctime()
1044 pp->day = ymd2yd( pp->year, 12, 31 ) ; in jjy_synctime()
1058 pp->lastref = pp->lastrec ; in jjy_synctime()
1067 up->year, up->month, up->day, in jjy_synctime()
1068 up->hour, up->minute, up->second, up->msecond, in jjy_synctime()
1069 pp->year, pp->day, pp->hour, pp->minute, pp->second, in jjy_synctime()
1070 (int)(pp->nsec/1000000) ) ; in jjy_synctime()
1076 switch ( peer->status ) { in jjy_synctime()
1080 case 3 : cStatus = '-' ; pStatus = "Outlier" ; break ; in jjy_synctime()
1090 peer->status, cStatus, pStatus, peer->offset * 1000, peer->jitter * 1000 ) ; in jjy_synctime()
1098 /*## The Tristate Ltd. JJY receiver TS-JJY01, TS-JJY02 ##*/
1106 /* -------------------- ---------------------------------------- ---------------------------- */
1160 …jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: Tristate Ltd. TS-JJY01, TS-JJY02" … in jjy_start_tristate_jjy01()
1162 up->unittype = UNITTYPE_TRISTATE_JJY01 ; in jjy_start_tristate_jjy01()
1163 up->linespeed = SPEED232_TRISTATE_JJY01 ; in jjy_start_tristate_jjy01()
1164 up->linediscipline = LDISC_CLK ; in jjy_start_tristate_jjy01()
1166 time( &(up->tLastAdjustedTimestamp) ) ; in jjy_start_tristate_jjy01()
1167 up->bStusReplyAdjustedAtLeastOnce = FALSE ; in jjy_start_tristate_jjy01()
1194 peer = rbufp->recv_peer ; in jjy_receive_tristate_jjy01()
1195 pp = peer->procptr ; in jjy_receive_tristate_jjy01()
1196 up = pp->unitptr ; in jjy_receive_tristate_jjy01()
1198 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive_tristate_jjy01()
1199 pBuf = up->sTextBuf ; in jjy_receive_tristate_jjy01()
1200 iLen = up->iTextBufLen ; in jjy_receive_tristate_jjy01()
1202 pBuf = pp->a_lastcode ; in jjy_receive_tristate_jjy01()
1203 iLen = pp->lencode ; in jjy_receive_tristate_jjy01()
1210 if ( tristate_jjy01_command_sequence[up->iCommandSeq].command == NULL ) { in jjy_receive_tristate_jjy01()
1212 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY, in jjy_receive_tristate_jjy01()
1215 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1221 if ( iLen != tristate_jjy01_command_sequence[up->iCommandSeq].iExpectedReplyLength[0] in jjy_receive_tristate_jjy01()
1222 && iLen != tristate_jjy01_command_sequence[up->iCommandSeq].iExpectedReplyLength[1] ) { in jjy_receive_tristate_jjy01()
1224 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH, in jjy_receive_tristate_jjy01()
1227 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1233 switch ( tristate_jjy01_command_sequence[up->iCommandSeq].commandNumber ) { in jjy_receive_tristate_jjy01()
1238 &up->year, &up->month, &up->day ) ; in jjy_receive_tristate_jjy01()
1240 if ( rc != 3 || up->year < 2000 || 2099 <= up->year in jjy_receive_tristate_jjy01()
1241 || up->month < 1 || 12 < up->month in jjy_receive_tristate_jjy01()
1242 || up->day < 1 || 31 < up->day ) { in jjy_receive_tristate_jjy01()
1244 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATE, in jjy_receive_tristate_jjy01()
1245 rc, up->year, up->month, up->day ) ; in jjy_receive_tristate_jjy01()
1247 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1256 if ( up->iTimestampCount >= 2 ) { in jjy_receive_tristate_jjy01()
1258 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_TOO_MANY_REPLY, in jjy_receive_tristate_jjy01()
1259 up->iTimestampCount ) ; in jjy_receive_tristate_jjy01()
1261 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1266 &up->hour, &up->minute, &up->second ) ; in jjy_receive_tristate_jjy01()
1268 if ( rc != 3 || up->hour > 23 || up->minute > 59 || in jjy_receive_tristate_jjy01()
1269 up->second > 60 ) { in jjy_receive_tristate_jjy01()
1271 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME, in jjy_receive_tristate_jjy01()
1272 rc, up->hour, up->minute, up->second ) ; in jjy_receive_tristate_jjy01()
1274 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1278 up->iTimestamp[up->iTimestampCount] = ( up->hour * 60 + up->minute ) * 60 + up->second ; in jjy_receive_tristate_jjy01()
1280 up->iTimestampCount++ ; in jjy_receive_tristate_jjy01()
1282 up->msecond = 0 ; in jjy_receive_tristate_jjy01()
1291 up->bStusReplyAdjusted = TRUE ; in jjy_receive_tristate_jjy01()
1292 up->bStusReplyAdjustedAtLeastOnce = TRUE ; in jjy_receive_tristate_jjy01()
1293 time( &(up->tLastAdjustedTimestamp) ) ; in jjy_receive_tristate_jjy01()
1297 up->bStusReplyAdjusted = FALSE ; in jjy_receive_tristate_jjy01()
1300 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY, in jjy_receive_tristate_jjy01()
1303 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1318 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY, in jjy_receive_tristate_jjy01()
1321 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1329 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY, in jjy_receive_tristate_jjy01()
1332 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1337 if ( up->iTimestampCount == 2 ) { in jjy_receive_tristate_jjy01()
1341 fSeconds = difftime( now, up->tLastAdjustedTimestamp ) ; in jjy_receive_tristate_jjy01()
1343 if ( ( pp->sloppyclockflag & CLK_FLAG2 ) != 0 in jjy_receive_tristate_jjy01()
1344 && ( ! up->bStusReplyAdjusted ) in jjy_receive_tristate_jjy01()
1345 && ( fSeconds >= ( pp->fudgetime2 * 3600 ) || ( ! up->bStusReplyAdjustedAtLeastOnce ) ) ) { in jjy_receive_tristate_jjy01()
1348 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds, "seconds" ) ; in jjy_receive_tristate_jjy01()
1350 …snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 60, "minutes" )… in jjy_receive_tristate_jjy01()
1352 …snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 3600, "hours" )… in jjy_receive_tristate_jjy01()
1354 …snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 86400, "days" )… in jjy_receive_tristate_jjy01()
1358 } else if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0] in jjy_receive_tristate_jjy01()
1359 && up->iTimestamp[0] <= up->iTimestamp[1] ) { in jjy_receive_tristate_jjy01()
1363 } else if ( up->iTimestamp[0] > up->iTimestamp[1] ) { in jjy_receive_tristate_jjy01()
1365 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_OVER_MIDNIGHT_2, in jjy_receive_tristate_jjy01()
1366 up->iTimestamp[0], up->iTimestamp[1] ) ; in jjy_receive_tristate_jjy01()
1371 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SLOW_REPLY_2, in jjy_receive_tristate_jjy01()
1372 up->iTimestamp[0], up->iTimestamp[1] ) ; in jjy_receive_tristate_jjy01()
1374 up->bLineError = TRUE ; in jjy_receive_tristate_jjy01()
1382 if ( tristate_jjy01_command_sequence[up->iCommandSeq].command != NULL ) { in jjy_receive_tristate_jjy01()
1383 up->iCommandSeq ++ ; in jjy_receive_tristate_jjy01()
1386 if ( tristate_jjy01_command_sequence[up->iCommandSeq].command == NULL ) { in jjy_receive_tristate_jjy01()
1391 pCmd = tristate_jjy01_command_sequence[up->iCommandSeq].command ; in jjy_receive_tristate_jjy01()
1392 iCmdLen = tristate_jjy01_command_sequence[up->iCommandSeq].commandLength ; in jjy_receive_tristate_jjy01()
1393 if ( write ( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) { in jjy_receive_tristate_jjy01()
1418 pp = peer->procptr; in jjy_poll_tristate_jjy01()
1419 up = pp->unitptr ; in jjy_poll_tristate_jjy01()
1421 up->bLineError = FALSE ; in jjy_poll_tristate_jjy01()
1422 up->iTimestampCount = 0 ; in jjy_poll_tristate_jjy01()
1424 if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) { in jjy_poll_tristate_jjy01()
1426 up->iCommandSeq = 2 ; in jjy_poll_tristate_jjy01()
1427 up->iLineCount = 2 ; in jjy_poll_tristate_jjy01()
1430 up->bStusReplyAdjusted = FALSE ; in jjy_poll_tristate_jjy01()
1434 printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCount=%d\n", in jjy_poll_tristate_jjy01()
1435 sFunctionName, pp->sloppyclockflag, CLK_FLAG1, in jjy_poll_tristate_jjy01()
1436 up->iLineCount ) ; in jjy_poll_tristate_jjy01()
1444 up->iCommandSeq ++ ; in jjy_poll_tristate_jjy01()
1446 pCmd = tristate_jjy01_command_sequence[up->iCommandSeq].command ; in jjy_poll_tristate_jjy01()
1447 iCmdLen = tristate_jjy01_command_sequence[up->iCommandSeq].commandLength ; in jjy_poll_tristate_jjy01()
1448 if ( write ( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) { in jjy_poll_tristate_jjy01()
1459 /*## The C-DEX Co. Ltd. JJY receiver JST2000 ##*/
1467 /* -------------------- ---------------------------------------- ---------------------------- */
1483 jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: C-DEX Co. Ltd. JST2000" ) ; in jjy_start_cdex_jst2000()
1485 up->unittype = UNITTYPE_CDEX_JST2000 ; in jjy_start_cdex_jst2000()
1486 up->linespeed = SPEED232_CDEX_JST2000 ; in jjy_start_cdex_jst2000()
1487 up->linediscipline = LDISC_RAW ; in jjy_start_cdex_jst2000()
1489 up->pRawBreak = cdex_jst2000_raw_break ; in jjy_start_cdex_jst2000()
1490 up->bWaitBreakString = TRUE ; in jjy_start_cdex_jst2000()
1492 up->bSkipCntrlCharOnly = FALSE ; in jjy_start_cdex_jst2000()
1514 peer = rbufp->recv_peer ; in jjy_receive_cdex_jst2000()
1515 pp = peer->procptr ; in jjy_receive_cdex_jst2000()
1516 up = pp->unitptr ; in jjy_receive_cdex_jst2000()
1518 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive_cdex_jst2000()
1519 pBuf = up->sTextBuf ; in jjy_receive_cdex_jst2000()
1520 iLen = up->iTextBufLen ; in jjy_receive_cdex_jst2000()
1522 pBuf = pp->a_lastcode ; in jjy_receive_cdex_jst2000()
1523 iLen = pp->lencode ; in jjy_receive_cdex_jst2000()
1530 if ( up->iCommandSeq != 1 ) { in jjy_receive_cdex_jst2000()
1532 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY, in jjy_receive_cdex_jst2000()
1535 up->bLineError = TRUE ; in jjy_receive_cdex_jst2000()
1541 if ( up->iLineBufLen < 17 || up->sLineBuf[up->iLineBufLen-1] != 0x03 ) { in jjy_receive_cdex_jst2000()
1549 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH, in jjy_receive_cdex_jst2000()
1552 up->bLineError = TRUE ; in jjy_receive_cdex_jst2000()
1559 &up->year, &up->month, &up->day, in jjy_receive_cdex_jst2000()
1560 &up->hour, &up->minute, &up->second, in jjy_receive_cdex_jst2000()
1561 &up->msecond ) ; in jjy_receive_cdex_jst2000()
1563 if ( rc != 7 || up->month < 1 || up->month > 12 || in jjy_receive_cdex_jst2000()
1564 up->day < 1 || up->day > 31 || up->hour > 23 || in jjy_receive_cdex_jst2000()
1565 up->minute > 59 || up->second > 60 ) { in jjy_receive_cdex_jst2000()
1567 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME, in jjy_receive_cdex_jst2000()
1568 rc, up->year, up->month, up->day, in jjy_receive_cdex_jst2000()
1569 up->hour, up->minute, up->second ) ; in jjy_receive_cdex_jst2000()
1571 up->bLineError = TRUE ; in jjy_receive_cdex_jst2000()
1575 up->year += 2000 ; in jjy_receive_cdex_jst2000()
1576 up->msecond *= 100 ; in jjy_receive_cdex_jst2000()
1593 pp = peer->procptr ; in jjy_poll_cdex_jst2000()
1594 up = pp->unitptr ; in jjy_poll_cdex_jst2000()
1596 up->bLineError = FALSE ; in jjy_poll_cdex_jst2000()
1597 up->iRawBufLen = 0 ; in jjy_poll_cdex_jst2000()
1598 up->iLineBufLen = 0 ; in jjy_poll_cdex_jst2000()
1599 up->iTextBufLen = 0 ; in jjy_poll_cdex_jst2000()
1605 up->iCommandSeq ++ ; in jjy_poll_cdex_jst2000()
1607 if ( write ( pp->io.fd, "\0051J\003", 4 ) != 4 ) { in jjy_poll_cdex_jst2000()
1626 /* -------------------- ---------------------------------------- ---------------------------- */
1651 up->unittype = UNITTYPE_ECHOKEISOKUKI_LT2000 ; in jjy_start_echokeisokuki_lt2000()
1652 up->linespeed = SPEED232_ECHOKEISOKUKI_LT2000 ; in jjy_start_echokeisokuki_lt2000()
1653 up->linediscipline = LDISC_CLK ; in jjy_start_echokeisokuki_lt2000()
1655 up->operationmode = ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS ; in jjy_start_echokeisokuki_lt2000()
1678 peer = rbufp->recv_peer ; in jjy_receive_echokeisokuki_lt2000()
1679 pp = peer->procptr ; in jjy_receive_echokeisokuki_lt2000()
1680 up = pp->unitptr ; in jjy_receive_echokeisokuki_lt2000()
1682 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive_echokeisokuki_lt2000()
1683 pBuf = up->sTextBuf ; in jjy_receive_echokeisokuki_lt2000()
1684 iLen = up->iTextBufLen ; in jjy_receive_echokeisokuki_lt2000()
1686 pBuf = pp->a_lastcode ; in jjy_receive_echokeisokuki_lt2000()
1687 iLen = pp->lencode ; in jjy_receive_echokeisokuki_lt2000()
1694 if ( ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_REQUEST_SEND in jjy_receive_echokeisokuki_lt2000()
1696 || ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_CONTINUOUS in jjy_receive_echokeisokuki_lt2000()
1698 || ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS in jjy_receive_echokeisokuki_lt2000()
1701 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH, in jjy_receive_echokeisokuki_lt2000()
1704 up->bLineError = TRUE ; in jjy_receive_echokeisokuki_lt2000()
1708 if ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_REQUEST_SEND && iLen == 15 ) { in jjy_receive_echokeisokuki_lt2000()
1718 snprintf( sErr, sizeof(sErr)-1, " BCC error : Recv=%02X,%02X / Calc=%02X,%02X ", in jjy_receive_echokeisokuki_lt2000()
1721 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY, in jjy_receive_echokeisokuki_lt2000()
1724 up->bLineError = TRUE ; in jjy_receive_echokeisokuki_lt2000()
1730 if ( ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_REQUEST_SEND in jjy_receive_echokeisokuki_lt2000()
1732 || ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_CONTINUOUS in jjy_receive_echokeisokuki_lt2000()
1734 || ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS in jjy_receive_echokeisokuki_lt2000()
1739 &up->year, &up->month, &up->day, in jjy_receive_echokeisokuki_lt2000()
1740 &up->hour, &up->minute, &up->second ) ; in jjy_receive_echokeisokuki_lt2000()
1742 if ( rc != 6 || up->month < 1 || up->month > 12 in jjy_receive_echokeisokuki_lt2000()
1743 || up->day < 1 || up->day > 31 in jjy_receive_echokeisokuki_lt2000()
1744 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { in jjy_receive_echokeisokuki_lt2000()
1746 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME, in jjy_receive_echokeisokuki_lt2000()
1747 rc, up->year, up->month, up->day, in jjy_receive_echokeisokuki_lt2000()
1748 up->hour, up->minute, up->second ) ; in jjy_receive_echokeisokuki_lt2000()
1750 up->bLineError = TRUE ; in jjy_receive_echokeisokuki_lt2000()
1754 up->year += 2000 ; in jjy_receive_echokeisokuki_lt2000()
1756 if ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_CONTINUOUS in jjy_receive_echokeisokuki_lt2000()
1757 || up->operationmode == ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS ) { in jjy_receive_echokeisokuki_lt2000()
1758 /* A time stamp comes on every 0.5 second in the mode 2 of the LT-2000. */ in jjy_receive_echokeisokuki_lt2000()
1760 up->msecond = 500 ; in jjy_receive_echokeisokuki_lt2000()
1761 up->second -- ; in jjy_receive_echokeisokuki_lt2000()
1762 if ( up->second < 0 ) { in jjy_receive_echokeisokuki_lt2000()
1763 up->second = 59 ; in jjy_receive_echokeisokuki_lt2000()
1764 up->minute -- ; in jjy_receive_echokeisokuki_lt2000()
1765 if ( up->minute < 0 ) { in jjy_receive_echokeisokuki_lt2000()
1766 up->minute = 59 ; in jjy_receive_echokeisokuki_lt2000()
1767 up->hour -- ; in jjy_receive_echokeisokuki_lt2000()
1768 if ( up->hour < 0 ) { in jjy_receive_echokeisokuki_lt2000()
1769 up->hour = 23 ; in jjy_receive_echokeisokuki_lt2000()
1770 up->day -- ; in jjy_receive_echokeisokuki_lt2000()
1771 if ( up->day < 1 ) { in jjy_receive_echokeisokuki_lt2000()
1772 up->month -- ; in jjy_receive_echokeisokuki_lt2000()
1773 if ( up->month < 1 ) { in jjy_receive_echokeisokuki_lt2000()
1774 up->month = 12 ; in jjy_receive_echokeisokuki_lt2000()
1775 up->year -- ; in jjy_receive_echokeisokuki_lt2000()
1789 if (up->operationmode == ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS ) { in jjy_receive_echokeisokuki_lt2000()
1793 if ( write ( pp->io.fd, ECHOKEISOKUKI_LT2000_COMMAND_REQUEST_SEND, iLen ) != iLen ) { in jjy_receive_echokeisokuki_lt2000()
1816 pp = peer->procptr ; in jjy_poll_echokeisokuki_lt2000()
1817 up = pp->unitptr ; in jjy_poll_echokeisokuki_lt2000()
1819 up->bLineError = FALSE ; in jjy_poll_echokeisokuki_lt2000()
1825 switch ( up->operationmode ) { in jjy_poll_echokeisokuki_lt2000()
1836 if ( write ( pp->io.fd, sCmd, 1 ) != 1 ) { in jjy_poll_echokeisokuki_lt2000()
1855 /* -------------------- ---------------------------------------- ---------------------------- */
1856 /* 'XX YY/MM/DD W HH:MM:SS<CR> XX:OK|NG|ER W:0(Mon)-6(Sun) */
1866 up->unittype = UNITTYPE_CITIZENTIC_JJY200 ; in jjy_start_citizentic_jjy200()
1867 up->linespeed = SPEED232_CITIZENTIC_JJY200 ; in jjy_start_citizentic_jjy200()
1868 up->linediscipline = LDISC_CLK ; in jjy_start_citizentic_jjy200()
1892 peer = rbufp->recv_peer ; in jjy_receive_citizentic_jjy200()
1893 pp = peer->procptr ; in jjy_receive_citizentic_jjy200()
1894 up = pp->unitptr ; in jjy_receive_citizentic_jjy200()
1896 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive_citizentic_jjy200()
1897 pBuf = up->sTextBuf ; in jjy_receive_citizentic_jjy200()
1898 iLen = up->iTextBufLen ; in jjy_receive_citizentic_jjy200()
1900 pBuf = pp->a_lastcode ; in jjy_receive_citizentic_jjy200()
1901 iLen = pp->lencode ; in jjy_receive_citizentic_jjy200()
1907 * JJY-200 sends a timestamp every second. in jjy_receive_citizentic_jjy200()
1911 if ( up->iProcessState != JJY_PROCESS_STATE_RECEIVE ) { in jjy_receive_citizentic_jjy200()
1919 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH, in jjy_receive_citizentic_jjy200()
1922 up->bLineError = TRUE ; in jjy_receive_citizentic_jjy200()
1930 &up->year, &up->month, &up->day, &iWeekday, in jjy_receive_citizentic_jjy200()
1931 &up->hour, &up->minute, &up->second ) ; in jjy_receive_citizentic_jjy200()
1938 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 in jjy_receive_citizentic_jjy200()
1940 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { in jjy_receive_citizentic_jjy200()
1942 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME, in jjy_receive_citizentic_jjy200()
1943 rc, up->year, up->month, up->day, in jjy_receive_citizentic_jjy200()
1944 up->hour, up->minute, up->second ) ; in jjy_receive_citizentic_jjy200()
1946 up->bLineError = TRUE ; in jjy_receive_citizentic_jjy200()
1951 snprintf( sMsg, sizeof(sMsg)-1, "status=%s", sStatus ) ; in jjy_receive_citizentic_jjy200()
1952 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_TIMESTAMP_UNSURE, in jjy_receive_citizentic_jjy200()
1958 up->year += 2000 ; in jjy_receive_citizentic_jjy200()
1959 up->msecond = 0 ; in jjy_receive_citizentic_jjy200()
1976 pp = peer->procptr ; in jjy_poll_citizentic_jjy200()
1977 up = pp->unitptr ; in jjy_poll_citizentic_jjy200()
1979 up->bLineError = FALSE ; in jjy_poll_citizentic_jjy200()
1986 /*## The Tristate Ltd. GPS clock TS-GPS01 ##*/
1995 /* by the onboard switch SW4, and make sure the LED-Y is tured on. */
2000 /* -------------------- ---------------------------------------- ---------------------------- */
2045 jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: Tristate Ltd. TS-GPS01" ) ; in jjy_start_tristate_gpsclock01()
2047 up->unittype = UNITTYPE_TRISTATE_GPSCLOCK01 ; in jjy_start_tristate_gpsclock01()
2048 up->linespeed = SPEED232_TRISTATE_GPSCLOCK01 ; in jjy_start_tristate_gpsclock01()
2049 up->linediscipline = LDISC_CLK ; in jjy_start_tristate_gpsclock01()
2078 peer = rbufp->recv_peer ; in jjy_receive_tristate_gpsclock01()
2079 pp = peer->procptr ; in jjy_receive_tristate_gpsclock01()
2080 up = pp->unitptr ; in jjy_receive_tristate_gpsclock01()
2082 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive_tristate_gpsclock01()
2083 pBuf = up->sTextBuf ; in jjy_receive_tristate_gpsclock01()
2084 iLen = up->iTextBufLen ; in jjy_receive_tristate_gpsclock01()
2086 pBuf = pp->a_lastcode ; in jjy_receive_tristate_gpsclock01()
2087 iLen = pp->lencode ; in jjy_receive_tristate_gpsclock01()
2106 * Skip command prompt '$Cmd>' from the TS-GPSclock-01 in jjy_receive_tristate_gpsclock01()
2112 iLen -= 5 ; in jjy_receive_tristate_gpsclock01()
2131 if ( tristate_gps01_command_sequence[up->iCommandSeq].command == NULL ) { in jjy_receive_tristate_gpsclock01()
2133 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY, in jjy_receive_tristate_gpsclock01()
2136 up->bLineError = TRUE ; in jjy_receive_tristate_gpsclock01()
2142 if ( iLen != tristate_gps01_command_sequence[up->iCommandSeq].iExpectedReplyLength ) { in jjy_receive_tristate_gpsclock01()
2144 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH, in jjy_receive_tristate_gpsclock01()
2147 up->bLineError = TRUE ; in jjy_receive_tristate_gpsclock01()
2153 switch ( tristate_gps01_command_sequence[up->iCommandSeq].commandNumber ) { in jjy_receive_tristate_gpsclock01()
2157 rc = sscanf ( pBuf, "%4d/%2d/%2d", &up->year, &up->month, &up->day ) ; in jjy_receive_tristate_gpsclock01()
2159 if ( rc != 3 || up->year < 2000 || 2099 <= up->year in jjy_receive_tristate_gpsclock01()
2160 || up->month < 1 || 12 < up->month in jjy_receive_tristate_gpsclock01()
2161 || up->day < 1 || 31 < up->day ) { in jjy_receive_tristate_gpsclock01()
2163 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATE, in jjy_receive_tristate_gpsclock01()
2164 rc, up->year, up->month, up->day ) ; in jjy_receive_tristate_gpsclock01()
2166 up->bLineError = TRUE ; in jjy_receive_tristate_gpsclock01()
2174 if ( up->iTimestampCount >= 2 ) { in jjy_receive_tristate_gpsclock01()
2176 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_TOO_MANY_REPLY, in jjy_receive_tristate_gpsclock01()
2177 up->iTimestampCount ) ; in jjy_receive_tristate_gpsclock01()
2179 up->bLineError = TRUE ; in jjy_receive_tristate_gpsclock01()
2184 &up->hour, &up->minute, &up->second ) ; in jjy_receive_tristate_gpsclock01()
2187 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { in jjy_receive_tristate_gpsclock01()
2189 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME, in jjy_receive_tristate_gpsclock01()
2190 rc, up->hour, up->minute, up->second ) ; in jjy_receive_tristate_gpsclock01()
2192 up->bLineError = TRUE ; in jjy_receive_tristate_gpsclock01()
2196 up->iTimestamp[up->iTimestampCount] = ( up->hour * 60 + up->minute ) * 60 + up->second ; in jjy_receive_tristate_gpsclock01()
2198 up->iTimestampCount++ ; in jjy_receive_tristate_gpsclock01()
2200 up->msecond = 0 ; in jjy_receive_tristate_gpsclock01()
2212 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY, in jjy_receive_tristate_gpsclock01()
2215 up->bLineError = TRUE ; in jjy_receive_tristate_gpsclock01()
2223 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY, in jjy_receive_tristate_gpsclock01()
2226 up->bLineError = TRUE ; in jjy_receive_tristate_gpsclock01()
2231 if ( up->iTimestampCount == 2 ) { in jjy_receive_tristate_gpsclock01()
2234 if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0] in jjy_receive_tristate_gpsclock01()
2235 && up->iTimestamp[0] <= up->iTimestamp[1] ) { in jjy_receive_tristate_gpsclock01()
2239 } else if ( up->iTimestamp[0] > up->iTimestamp[1] ) { in jjy_receive_tristate_gpsclock01()
2241 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_OVER_MIDNIGHT_2, in jjy_receive_tristate_gpsclock01()
2242 up->iTimestamp[0], up->iTimestamp[1] ) ; in jjy_receive_tristate_gpsclock01()
2247 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SLOW_REPLY_2, in jjy_receive_tristate_gpsclock01()
2248 up->iTimestamp[0], up->iTimestamp[1] ) ; in jjy_receive_tristate_gpsclock01()
2250 up->bLineError = TRUE ; in jjy_receive_tristate_gpsclock01()
2256 if ( tristate_gps01_command_sequence[up->iCommandSeq].command == NULL ) { in jjy_receive_tristate_gpsclock01()
2264 if ( tristate_gps01_command_sequence[up->iCommandSeq].command != NULL ) { in jjy_receive_tristate_gpsclock01()
2265 up->iCommandSeq ++ ; in jjy_receive_tristate_gpsclock01()
2268 if ( tristate_gps01_command_sequence[up->iCommandSeq].command == NULL ) { in jjy_receive_tristate_gpsclock01()
2270 up->iProcessState = JJY_PROCESS_STATE_DONE ; in jjy_receive_tristate_gpsclock01()
2274 pCmd = tristate_gps01_command_sequence[up->iCommandSeq].command ; in jjy_receive_tristate_gpsclock01()
2275 iCmdLen = tristate_gps01_command_sequence[up->iCommandSeq].commandLength ; in jjy_receive_tristate_gpsclock01()
2276 if ( write ( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) { in jjy_receive_tristate_gpsclock01()
2301 pp = peer->procptr ; in jjy_poll_tristate_gpsclock01()
2302 up = pp->unitptr ; in jjy_poll_tristate_gpsclock01()
2304 up->iTimestampCount = 0 ; in jjy_poll_tristate_gpsclock01()
2306 if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) { in jjy_poll_tristate_gpsclock01()
2308 up->iCommandSeq = 1 ; in jjy_poll_tristate_gpsclock01()
2309 up->iLineCount = 1 ; in jjy_poll_tristate_gpsclock01()
2314 printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCount=%d\n", in jjy_poll_tristate_gpsclock01()
2315 sFunctionName, pp->sloppyclockflag, CLK_FLAG1, in jjy_poll_tristate_gpsclock01()
2316 up->iLineCount ) ; in jjy_poll_tristate_gpsclock01()
2324 up->iCommandSeq ++ ; in jjy_poll_tristate_gpsclock01()
2326 pCmd = tristate_gps01_command_sequence[up->iCommandSeq].command ; in jjy_poll_tristate_gpsclock01()
2327 iCmdLen = tristate_gps01_command_sequence[up->iCommandSeq].commandLength ; in jjy_poll_tristate_gpsclock01()
2328 if ( write ( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) { in jjy_poll_tristate_gpsclock01()
2339 /*## The SEIKO TIME SYSTEMS TDC-300 ##*/
2347 /* -------------------- ---------------------------------------- ---------------------------- */
2349 /* Type 2 <STX>YYMMDDHHMMSSWLSCU<ETX> W:0(Sun)-6(Sat) */
2350 /* Type 3 <STX>YYMMDDWHHMMSS<ETX> W:0(Sun)-6(Sat) */
2366 jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: SEIKO TIME SYSTEMS TDC-300" ) ; in jjy_start_seiko_tsys_tdc_300()
2368 up->unittype = UNITTYPE_SEIKO_TIMESYS_TDC_300 ; in jjy_start_seiko_tsys_tdc_300()
2369 up->linespeed = SPEED232_SEIKO_TIMESYS_TDC_300 ; in jjy_start_seiko_tsys_tdc_300()
2370 up->linediscipline = LDISC_RAW ; in jjy_start_seiko_tsys_tdc_300()
2372 up->pRawBreak = seiko_tsys_tdc_300_raw_break ; in jjy_start_seiko_tsys_tdc_300()
2373 up->bWaitBreakString = TRUE ; in jjy_start_seiko_tsys_tdc_300()
2375 up->bSkipCntrlCharOnly = FALSE ; in jjy_start_seiko_tsys_tdc_300()
2399 peer = rbufp->recv_peer ; in jjy_receive_seiko_tsys_tdc_300()
2400 pp = peer->procptr ; in jjy_receive_seiko_tsys_tdc_300()
2401 up = pp->unitptr ; in jjy_receive_seiko_tsys_tdc_300()
2403 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive_seiko_tsys_tdc_300()
2404 pBuf = up->sTextBuf ; in jjy_receive_seiko_tsys_tdc_300()
2405 iLen = up->iTextBufLen ; in jjy_receive_seiko_tsys_tdc_300()
2407 pBuf = pp->a_lastcode ; in jjy_receive_seiko_tsys_tdc_300()
2408 iLen = pp->lencode ; in jjy_receive_seiko_tsys_tdc_300()
2414 * TDC-300 sends a timestamp every second. in jjy_receive_seiko_tsys_tdc_300()
2418 if ( up->iProcessState != JJY_PROCESS_STATE_RECEIVE ) { in jjy_receive_seiko_tsys_tdc_300()
2424 up->iReceiveSeq ++ ; in jjy_receive_seiko_tsys_tdc_300()
2435 &up->hour, &up->minute, &up->second ) ; in jjy_receive_seiko_tsys_tdc_300()
2438 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { in jjy_receive_seiko_tsys_tdc_300()
2440 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME, in jjy_receive_seiko_tsys_tdc_300()
2441 rc, up->hour, up->minute, up->second ) ; in jjy_receive_seiko_tsys_tdc_300()
2443 up->bLineError = TRUE ; in jjy_receive_seiko_tsys_tdc_300()
2445 } else if ( up->hour == 23 && up->minute == 59 && up->second >= 55 ) { in jjy_receive_seiko_tsys_tdc_300()
2452 up->year = pTime->tm_year ; in jjy_receive_seiko_tsys_tdc_300()
2453 up->month = pTime->tm_mon + 1 ; in jjy_receive_seiko_tsys_tdc_300()
2454 up->day = pTime->tm_mday ; in jjy_receive_seiko_tsys_tdc_300()
2465 &up->year, &up->month, &up->day, in jjy_receive_seiko_tsys_tdc_300()
2466 &up->hour, &up->minute, &up->second, &iWeekday ) ; in jjy_receive_seiko_tsys_tdc_300()
2469 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 in jjy_receive_seiko_tsys_tdc_300()
2471 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { in jjy_receive_seiko_tsys_tdc_300()
2473 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME, in jjy_receive_seiko_tsys_tdc_300()
2474 rc, up->year, up->month, up->day, in jjy_receive_seiko_tsys_tdc_300()
2475 up->hour, up->minute, up->second ) ; in jjy_receive_seiko_tsys_tdc_300()
2477 up->bLineError = TRUE ; in jjy_receive_seiko_tsys_tdc_300()
2486 &up->year, &up->month, &up->day, &iWeekday, in jjy_receive_seiko_tsys_tdc_300()
2487 &up->hour, &up->minute, &up->second ) ; in jjy_receive_seiko_tsys_tdc_300()
2490 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 in jjy_receive_seiko_tsys_tdc_300()
2492 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { in jjy_receive_seiko_tsys_tdc_300()
2494 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME, in jjy_receive_seiko_tsys_tdc_300()
2495 rc, up->year, up->month, up->day, in jjy_receive_seiko_tsys_tdc_300()
2496 up->hour, up->minute, up->second ) ; in jjy_receive_seiko_tsys_tdc_300()
2498 up->bLineError = TRUE ; in jjy_receive_seiko_tsys_tdc_300()
2508 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY, in jjy_receive_seiko_tsys_tdc_300()
2509 up->sLineBuf ) ; in jjy_receive_seiko_tsys_tdc_300()
2511 up->bLineError = TRUE ; in jjy_receive_seiko_tsys_tdc_300()
2513 } else if ( up->iReceiveSeq == 1 ) { in jjy_receive_seiko_tsys_tdc_300()
2515 up->iReceiveSeq -- ; in jjy_receive_seiko_tsys_tdc_300()
2517 } else if ( up->iReceiveSeq >= 3 ) { in jjy_receive_seiko_tsys_tdc_300()
2519 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY, in jjy_receive_seiko_tsys_tdc_300()
2520 up->sLineBuf ) ; in jjy_receive_seiko_tsys_tdc_300()
2522 up->bLineError = TRUE ; in jjy_receive_seiko_tsys_tdc_300()
2530 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH, in jjy_receive_seiko_tsys_tdc_300()
2533 up->bLineError = TRUE ; in jjy_receive_seiko_tsys_tdc_300()
2538 up->year += 2000 ; in jjy_receive_seiko_tsys_tdc_300()
2539 up->msecond = 0 ; in jjy_receive_seiko_tsys_tdc_300()
2556 pp = peer->procptr ; in jjy_poll_seiko_tsys_tdc_300()
2557 up = pp->unitptr ; in jjy_poll_seiko_tsys_tdc_300()
2559 up->bLineError = FALSE ; in jjy_poll_seiko_tsys_tdc_300()
2574 /* -------------------- -------------------- -------------------- -------------------------- */
2577 /* > LEAPSEC<CR> XX<CR> One of <SP>0, +1, -1 */
2729 …d iClockCommandSeq=%d\n", sFunc, up->iClockState, up->iClockEvent, up->iTeljjySilentTimer, up->iTe…
2747 up->unittype = UNITTYPE_TELEPHONE ; in jjy_start_telephone()
2748 up->linespeed = SPEED232_TELEPHONE ; in jjy_start_telephone()
2749 up->linediscipline = LDISC_RAW ; in jjy_start_telephone()
2751 up->pRawBreak = teljjy_raw_break ; in jjy_start_telephone()
2752 up->bWaitBreakString = TRUE ; in jjy_start_telephone()
2754 up->bSkipCntrlCharOnly = TRUE ; in jjy_start_telephone()
2756 up->iClockState = TELJJY_STATE_IDLE ; in jjy_start_telephone()
2757 up->iClockEvent = TELJJY_EVENT_NULL ; in jjy_start_telephone()
2763 up->bInitError = TRUE ; in jjy_start_telephone()
2769 up->bInitError = TRUE ; in jjy_start_telephone()
2776 if ( iFirstThreeDigitsCount < sizeof(sFirstThreeDigits)-1 ) { in jjy_start_telephone()
2784 up->bInitError = TRUE ; in jjy_start_telephone()
2789 } else if ( sys_phone[0][i] != '-' ) { in jjy_start_telephone()
2791 up->bInitError = TRUE ; in jjy_start_telephone()
2800 up->bInitError = TRUE ; in jjy_start_telephone()
2805 …if ( iNumberOfDigitsOfPhoneNumber - iCommaPosition < 6 || 10 < iNumberOfDigitsOfPhoneNumber - iCom… in jjy_start_telephone()
2808 up->bInitError = TRUE ; in jjy_start_telephone()
2821 up->bInitError = TRUE ; in jjy_start_telephone()
2828 if ( peer->minpoll < 8 ) { in jjy_start_telephone()
2830 int oldminpoll = peer->minpoll ; in jjy_start_telephone()
2831 peer->minpoll = 8 ; in jjy_start_telephone()
2832 if ( peer->ppoll < peer->minpoll ) { in jjy_start_telephone()
2833 peer->ppoll = peer->minpoll ; in jjy_start_telephone()
2835 if ( peer->maxpoll < peer->minpoll ) { in jjy_start_telephone()
2836 peer->maxpoll = peer->minpoll ; in jjy_start_telephone()
2838 snprintf( sLog, sizeof(sLog), "minpoll=%d -> %d", oldminpoll, peer->minpoll ) ; in jjy_start_telephone()
2862 peer = rbufp->recv_peer ; in jjy_receive_telephone()
2863 pp = peer->procptr ; in jjy_receive_telephone()
2864 up = pp->unitptr ; in jjy_receive_telephone()
2868 if ( up->iClockState == TELJJY_STATE_IDLE in jjy_receive_telephone()
2869 || up->iClockState == TELJJY_STATE_DAILOUT in jjy_receive_telephone()
2870 || up->iClockState == TELJJY_STATE_BYE ) { in jjy_receive_telephone()
2876 if ( iPreviousModemState != up->iModemState ) { in jjy_receive_telephone()
2878 if ( isModemStateDisconnect( up->iModemState ) ) { in jjy_receive_telephone()
2879 up->iClockEvent = TELJJY_EVENT_DISCONNECT ; in jjy_receive_telephone()
2881 } else if ( isModemStateConnect( up->iModemState ) ) { in jjy_receive_telephone()
2882 up->iClockEvent = TELJJY_EVENT_CONNECT ; in jjy_receive_telephone()
2891 if ( up->linediscipline == LDISC_RAW ) { in jjy_receive_telephone()
2892 pBuf = up->sTextBuf ; in jjy_receive_telephone()
2893 iLen = up->iTextBufLen ; in jjy_receive_telephone()
2895 pBuf = pp->a_lastcode ; in jjy_receive_telephone()
2896 iLen = pp->lencode ; in jjy_receive_telephone()
2899 up->iTeljjySilentTimer = 0 ; in jjy_receive_telephone()
2900 …if ( iLen == 7 && strncmp( pBuf, "Name ? ", 7 ) == 0 ) { up->iClockEvent = TELJJY_EVENT_LOGIN… in jjy_receive_telephone()
2901 …else if ( iLen == 1 && strncmp( pBuf, ">" , 1 ) == 0 ) { up->iClockEvent = TELJJY_EVENT_PROMP… in jjy_receive_telephone()
2902 …else if ( iLen >= 1 && strncmp( pBuf, "?" , 1 ) == 0 ) { up->iClockEvent = TELJJY_EVENT_ERROR… in jjy_receive_telephone()
2903 …else { up->iClockEvent = TELJJY_EVENT_DATA … in jjy_receive_telephone()
2923 pp = peer->procptr ; in jjy_poll_telephone()
2924 up = pp->unitptr ; in jjy_poll_telephone()
2928 if ( up->iClockState == TELJJY_STATE_IDLE ) { in jjy_poll_telephone()
2929 up->iRawBufLen = 0 ; in jjy_poll_telephone()
2930 up->iLineBufLen = 0 ; in jjy_poll_telephone()
2931 up->iTextBufLen = 0 ; in jjy_poll_telephone()
2934 up->iClockEvent = TELJJY_EVENT_START ; in jjy_poll_telephone()
2952 pp = peer->procptr ; in jjy_timer_telephone()
2953 up = pp->unitptr ; in jjy_timer_telephone()
2957 if ( iTeljjySilentTimeout[up->iClockState] != 0 ) { in jjy_timer_telephone()
2958 up->iTeljjySilentTimer++ ; in jjy_timer_telephone()
2959 if ( iTeljjySilentTimeout[up->iClockState] <= up->iTeljjySilentTimer ) { in jjy_timer_telephone()
2960 up->iClockEvent = TELJJY_EVENT_SILENT ; in jjy_timer_telephone()
2965 if ( iTeljjyStateTimeout[up->iClockState] != 0 ) { in jjy_timer_telephone()
2966 up->iTeljjyStateTimer++ ; in jjy_timer_telephone()
2967 if ( iTeljjyStateTimeout[up->iClockState] <= up->iTeljjyStateTimer ) { in jjy_timer_telephone()
2968 up->iClockEvent = TELJJY_EVENT_TIMEOUT ; in jjy_timer_telephone()
2979 if ( iPreviousModemState != up->iModemState ) { in jjy_timer_telephone()
2981 if ( isModemStateDisconnect( up->iModemState ) ) { in jjy_timer_telephone()
2982 up->iClockEvent = TELJJY_EVENT_DISCONNECT ; in jjy_timer_telephone()
2984 } else if ( isModemStateConnect( up->iModemState ) ) { in jjy_timer_telephone()
2985 up->iClockEvent = TELJJY_EVENT_CONNECT ; in jjy_timer_telephone()
3005 rc = (*pTeljjyHandler[up->iClockEvent][up->iClockState])( peer, pp, up ) ; in teljjy_control()
3008 iPostEvent = iTeljjyPostEvent[up->iClockEvent][up->iClockState] ; in teljjy_control()
3011 printf( "refclock_jjy.c : teljjy_control : iClockState=%hd -> %hd iPostEvent=%hd\n", in teljjy_control()
3012 up->iClockState, iTeljjyNextState[up->iClockEvent][up->iClockState], iPostEvent ) ; in teljjy_control()
3015 up->iTeljjySilentTimer = 0 ; in teljjy_control()
3016 if ( up->iClockState != iTeljjyNextState[up->iClockEvent][up->iClockState] ) { in teljjy_control()
3018 up->iTeljjyStateTimer = 0 ; in teljjy_control()
3019 up->bLineError = FALSE ; in teljjy_control()
3020 up->iClockCommandSeq = 0 ; in teljjy_control()
3021 up->iTimestampCount = 0 ; in teljjy_control()
3022 up->iLoopbackCount = 0 ; in teljjy_control()
3024 up->bLoopbackTimeout[i] = FALSE ; in teljjy_control()
3026 if (iTeljjyNextState[up->iClockEvent][up->iClockState] == TELJJY_STATE_IDLE ) { in teljjy_control()
3028 up->iProcessState = JJY_PROCESS_STATE_DONE ; in teljjy_control()
3031 up->iClockState = iTeljjyNextState[up->iClockEvent][up->iClockState] ; in teljjy_control()
3036 up->iClockEvent = iPostEvent ; in teljjy_control()
3040 up->iClockEvent = TELJJY_EVENT_NULL ; in teljjy_control()
3053 gettimeofday( &(up->delayTime[up->iLoopbackCount]), NULL ) ; in teljjy_setDelay()
3055 up->delayTime[up->iLoopbackCount].tv_sec -= up->sendTime[up->iLoopbackCount].tv_sec ; in teljjy_setDelay()
3056 up->delayTime[up->iLoopbackCount].tv_usec -= up->sendTime[up->iLoopbackCount].tv_usec ; in teljjy_setDelay()
3057 if ( up->delayTime[up->iLoopbackCount].tv_usec < 0 ) { in teljjy_setDelay()
3058 up->delayTime[up->iLoopbackCount].tv_sec -- ; in teljjy_setDelay()
3059 up->delayTime[up->iLoopbackCount].tv_usec += 1000000 ; in teljjy_setDelay()
3062 milliSecond = up->delayTime[up->iLoopbackCount].tv_usec / 1000 ; in teljjy_setDelay()
3063 microSecond = up->delayTime[up->iLoopbackCount].tv_usec - milliSecond * 1000 ; in teljjy_setDelay()
3064 milliSecond += up->delayTime[up->iLoopbackCount].tv_sec * 1000 ; in teljjy_setDelay()
3095 …iThresholdMicroSecond = ( TELJJY_LOOPBACK_DELAY_THRESHOLD - ( TELJJY_LOOPBACK_DELAY_THRESHOLD / 10… in teljjy_getDelay()
3097 up->iLoopbackValidCount = 0 ; in teljjy_getDelay()
3099 for ( i = 0 ; i < MAX_LOOPBACK && i < up->iLoopbackCount ; i ++ ) { in teljjy_getDelay()
3100 if ( up->bLoopbackTimeout[i] in teljjy_getDelay()
3101 || up->delayTime[i].tv_sec > iThresholdSecond in teljjy_getDelay()
3102 || ( up->delayTime[i].tv_sec == iThresholdSecond in teljjy_getDelay()
3103 && up->delayTime[i].tv_usec > iThresholdMicroSecond ) ) { in teljjy_getDelay()
3106 if ( up->iLoopbackValidCount == 0 ) { in teljjy_getDelay()
3107 minTime.tv_sec = up->delayTime[i].tv_sec ; in teljjy_getDelay()
3108 minTime.tv_usec = up->delayTime[i].tv_usec ; in teljjy_getDelay()
3109 maxTime.tv_sec = up->delayTime[i].tv_sec ; in teljjy_getDelay()
3110 maxTime.tv_usec = up->delayTime[i].tv_usec ; in teljjy_getDelay()
3112 } else if ( minTime.tv_sec > up->delayTime[i].tv_sec in teljjy_getDelay()
3113 || ( minTime.tv_sec == up->delayTime[i].tv_sec in teljjy_getDelay()
3114 && minTime.tv_usec > up->delayTime[i].tv_usec ) ) { in teljjy_getDelay()
3115 minTime.tv_sec = up->delayTime[i].tv_sec ; in teljjy_getDelay()
3116 minTime.tv_usec = up->delayTime[i].tv_usec ; in teljjy_getDelay()
3118 } else if ( maxTime.tv_sec < up->delayTime[i].tv_sec in teljjy_getDelay()
3119 || ( maxTime.tv_sec == up->delayTime[i].tv_sec in teljjy_getDelay()
3120 && maxTime.tv_usec < up->delayTime[i].tv_usec ) ) { in teljjy_getDelay()
3121 maxTime.tv_sec = up->delayTime[i].tv_sec ; in teljjy_getDelay()
3122 maxTime.tv_usec = up->delayTime[i].tv_usec ; in teljjy_getDelay()
3125 up->iLoopbackValidCount ++ ; in teljjy_getDelay()
3128 if ( up->iLoopbackValidCount < 2 ) { in teljjy_getDelay()
3129 return -1 ; in teljjy_getDelay()
3134 for ( i = 0 ; i < MAX_LOOPBACK && i < up->iLoopbackCount ; i ++ ) { in teljjy_getDelay()
3135 if ( up->bLoopbackTimeout[i] in teljjy_getDelay()
3136 || up->delayTime[i].tv_sec > iThresholdSecond in teljjy_getDelay()
3137 || ( up->delayTime[i].tv_sec == iThresholdSecond in teljjy_getDelay()
3138 && up->delayTime[i].tv_usec > iThresholdMicroSecond ) ) { in teljjy_getDelay()
3141 if ( up->iLoopbackValidCount >= 3 && i == maxIndex ) { in teljjy_getDelay()
3144 if ( up->iLoopbackValidCount >= 4 && i == minIndex ) { in teljjy_getDelay()
3147 averTime.tv_usec += up->delayTime[i].tv_usec ; in teljjy_getDelay()
3153 /* Previous for-if-for blocks assure iAverCount > 0. */ in teljjy_getDelay()
3155 return -1 ; in teljjy_getDelay()
3160 iPercent = ( peer->ttl - 100 ) ; in teljjy_getDelay()
3186 modem_connect ( peer->refclkunit, peer ) ; in teljjy_idle_dialout()
3256 up->bLineError = FALSE ; in teljjy_login_conn()
3257 up->iClockCommandSeq = 0 ; in teljjy_login_conn()
3258 up->iTimestampCount = 0 ; in teljjy_login_conn()
3259 up->iLoopbackCount = 0 ; in teljjy_login_conn()
3261 up->bLoopbackTimeout[i] = FALSE ; in teljjy_login_conn()
3283 if ( write( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) { in teljjy_login_login()
3300 if ( write( pp->io.fd, "\r", 1 ) != 1 ) { in teljjy_login_silent()
3306 up->iTeljjySilentTimer = 0 ; in teljjy_login_silent()
3356 if ( up->iClockCommandSeq > 0 in teljjy_conn_send()
3357 && teljjy_command_sequence[up->iClockCommandSeq].command == NULL ) { in teljjy_conn_send()
3362 if ( up->iClockCommandSeq == 0 && peer->ttl == 100 ) { in teljjy_conn_send()
3365 up->iClockCommandSeq = TELJJY_COMMAND_START_SKIP_LOOPBACK ; in teljjy_conn_send()
3367 } else if ( up->iClockCommandSeq == 0 && peer->ttl != 100 ) { in teljjy_conn_send()
3370 up->iLoopbackCount = 0 ; in teljjy_conn_send()
3372 up->bLoopbackTimeout[i] = FALSE ; in teljjy_conn_send()
3375 } else if ( up->iClockCommandSeq > 0 && peer->ttl != 100 in teljjy_conn_send()
3376 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK in teljjy_conn_send()
3377 && up->iLoopbackCount < MAX_LOOPBACK ) { in teljjy_conn_send()
3382 up->iClockCommandSeq, up->iLoopbackCount ) ; in teljjy_conn_send()
3388 up->iLoopbackCount ++ ; in teljjy_conn_send()
3392 up->iClockCommandSeq++ ; in teljjy_conn_send()
3394 pCmd = teljjy_command_sequence[up->iClockCommandSeq].command ; in teljjy_conn_send()
3395 iLen = teljjy_command_sequence[up->iClockCommandSeq].commandLength ; in teljjy_conn_send()
3399 if ( write( pp->io.fd, pCmd, iLen ) != iLen ) { in teljjy_conn_send()
3403 if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK ) { in teljjy_conn_send()
3405 if ( up->iLoopbackCount < MAX_LOOPBACK ) { in teljjy_conn_send()
3406 gettimeofday( &(up->sendTime[up->iLoopbackCount]), NULL ) ; in teljjy_conn_send()
3407 up->bLoopbackMode = TRUE ; in teljjy_conn_send()
3409 /* This else-block is never come. */ in teljjy_conn_send()
3411 …snprintf( sLog, sizeof(sLog)-1, "refclock_jjy.c ; teljjy_conn_send ; iClockCommandSeq=%d iLoopback… in teljjy_conn_send()
3412 up->iClockCommandSeq, up->iLoopbackCount, MAX_LOOPBACK ) ; in teljjy_conn_send()
3415 up->bLoopbackMode = FALSE ; in teljjy_conn_send()
3419 up->bLoopbackMode = FALSE ; in teljjy_conn_send()
3424 if ( teljjy_command_sequence[up->iClockCommandSeq+1].command == NULL ) { in teljjy_conn_send()
3455 if ( up->linediscipline == LDISC_RAW ) { in teljjy_conn_data()
3456 pBuf = up->sTextBuf ; in teljjy_conn_data()
3457 iLen = up->iTextBufLen ; in teljjy_conn_data()
3459 pBuf = pp->a_lastcode ; in teljjy_conn_data()
3460 iLen = pp->lencode ; in teljjy_conn_data()
3463 if ( teljjy_command_sequence[up->iClockCommandSeq].iEchobackReplyLength == iLen in teljjy_conn_data()
3464 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK in teljjy_conn_data()
3465 && up->sTextBuf[0] == *(teljjy_command_sequence[up->iClockCommandSeq].command) in teljjy_conn_data()
3466 && up->iLoopbackCount < MAX_LOOPBACK ) { in teljjy_conn_data()
3471 up->iLoopbackCount ++ ; in teljjy_conn_data()
3473 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iEchobackReplyLength == iLen in teljjy_conn_data()
3474 && strncmp( pBuf, teljjy_command_sequence[up->iClockCommandSeq].command, iLen ) == 0 ) { in teljjy_conn_data()
3479 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyLength == iLen in teljjy_conn_data()
3480 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_4DATE ) { in teljjy_conn_data()
3481 /* 4DATE<CR> -> YYYYMMDD<CR> */ in teljjy_conn_data()
3483 rc = sscanf ( pBuf, "%4d%2d%2d", &up->year, &up->month, &up->day ) ; in teljjy_conn_data()
3485 if ( rc != 3 || up->year < 2000 || 2099 <= up->year in teljjy_conn_data()
3486 || up->month < 1 || 12 < up->month || up->day < 1 || 31 < up->day ) { in teljjy_conn_data()
3488 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATE, in teljjy_conn_data()
3489 rc, up->year, up->month, up->day ) ; in teljjy_conn_data()
3491 up->bLineError = TRUE ; in teljjy_conn_data()
3494 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyLength == iLen in teljjy_conn_data()
3495 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LEAPSEC in teljjy_conn_data()
3496 …&& ( strncmp( pBuf, " 0", 2 ) == 0 || strncmp( pBuf, "+1", 2 ) == 0 || strncmp( pBuf, "-1", 2 ) ==… in teljjy_conn_data()
3497 /* LEAPSEC<CR> -> XX<CR> ( One of <SP>0, +1, -1 ) */ in teljjy_conn_data()
3499 rc = sscanf ( pBuf, "%2d", &up->leapsecond ) ; in teljjy_conn_data()
3501 if ( rc != 1 || up->leapsecond < -1 || 1 < up->leapsecond ) { in teljjy_conn_data()
3503 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_LEAP, in teljjy_conn_data()
3506 up->bLineError = TRUE ; in teljjy_conn_data()
3509 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyLength == iLen in teljjy_conn_data()
3510 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_TIME ) { in teljjy_conn_data()
3511 /* TIME<CR> -> HHMMSS<CR> ( 3 times on second ) */ in teljjy_conn_data()
3513 rc = sscanf ( pBuf, "%2d%2d%2d", &up->hour, &up->minute, &up->second ) ; in teljjy_conn_data()
3515 if ( rc != 3 || up->hour > 23 || up->minute > 59 || up->second > 60 ) { in teljjy_conn_data()
3517 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME, in teljjy_conn_data()
3518 rc, up->hour, up->minute, up->second ) ; in teljjy_conn_data()
3520 up->bLineError = TRUE ; in teljjy_conn_data()
3522 up->iTimestamp[up->iTimestampCount] = ( up->hour * 60 + up->minute ) * 60 + up->second ; in teljjy_conn_data()
3524 up->iTimestampCount++ ; in teljjy_conn_data()
3526 if ( up->iTimestampCount == 6 && ! up->bLineError ) { in teljjy_conn_data()
3529 up->bLineError, in teljjy_conn_data()
3530 up->iTimestamp[3], up->iTimestamp[4], up->iTimestamp[5] ) ; in teljjy_conn_data()
3534 if ( peer->ttl == 100 ) { in teljjy_conn_data()
3536 up->msecond = 0 ; in teljjy_conn_data()
3539 up->msecond = teljjy_getDelay( peer, up ) ; in teljjy_conn_data()
3540 if (up->msecond < 0 ) { in teljjy_conn_data()
3541 up->msecond = 0 ; in teljjy_conn_data()
3546 if ( ( up->iTimestamp[3] - 15 ) <= up->iTimestamp[2] in teljjy_conn_data()
3547 && up->iTimestamp[2] <= up->iTimestamp[3] in teljjy_conn_data()
3548 && ( up->iTimestamp[3] + 1 ) == up->iTimestamp[4] in teljjy_conn_data()
3549 && ( up->iTimestamp[4] + 1 ) == up->iTimestamp[5] ) { in teljjy_conn_data()
3554 if ( peer->ttl != 100 ) { in teljjy_conn_data()
3558 up->msecond, up->iLoopbackValidCount, MAX_LOOPBACK ) ; in teljjy_conn_data()
3563 up->iLoopbackValidCount, MAX_LOOPBACK ) ; in teljjy_conn_data()
3571 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iEchobackReplyLength != iLen in teljjy_conn_data()
3572 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK ) { in teljjy_conn_data()
3575 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_IGNORE_REPLY, in teljjy_conn_data()
3581 up->bLineError = TRUE ; in teljjy_conn_data()
3583 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY, in teljjy_conn_data()
3602 if ( up->iClockCommandSeq >= 1 in teljjy_conn_silent()
3603 && up->iClockCommandSeq < TELJJY_COMMAND_START_SKIP_LOOPBACK ) { in teljjy_conn_silent()
3610 if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK ) { in teljjy_conn_silent()
3611 up->bLoopbackTimeout[up->iLoopbackCount] = TRUE ; in teljjy_conn_silent()
3613 up->iTeljjySilentTimer = 0 ; in teljjy_conn_silent()
3619 if ( write( pp->io.fd, pCmd, 1 ) != 1 ) { in teljjy_conn_silent()
3625 up->iTeljjySilentTimer = 0 ; in teljjy_conn_silent()
3671 modem_disconnect ( peer->refclkunit, peer ) ; in teljjy_bye_modem()
3803 …ilentTimer=%d iModemStateTimer=%d\n", sFunc, up->iModemState, up->iModemEvent, up->iModemSilentTim…
3813 return up->iModemState ; in getModemState()
3837 return ( iModemSilentTimeout[up->iModemState] != 0 || iModemStateTimeout[up->iModemState] != 0 ) ; in isModemStateTimerOn()
3848 pp = peer->procptr ; in modem_connect()
3849 up = pp->unitptr ; in modem_connect()
3853 up->iModemEvent = MODEM_EVENT_INITIALIZE ; in modem_connect()
3867 pp = peer->procptr ; in modem_disconnect()
3868 up = pp->unitptr ; in modem_disconnect()
3872 up->iModemEvent = MODEM_EVENT_DISCONNECT ; in modem_disconnect()
3894 peer = rbufp->recv_peer ; in modem_receive()
3895 pp = peer->procptr ; in modem_receive()
3896 up = pp->unitptr ; in modem_receive()
3900 if ( up->linediscipline == LDISC_RAW ) { in modem_receive()
3901 pBuf = up->sTextBuf ; in modem_receive()
3902 iLen = up->iTextBufLen ; in modem_receive()
3904 pBuf = pp->a_lastcode ; in modem_receive()
3905 iLen = pp->lencode ; in modem_receive()
3908 …if ( iLen == 2 && strncmp( pBuf, "OK" , 2 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3909 …else if ( iLen == 7 && strncmp( pBuf, "CONNECT" , 7 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3910 …else if ( iLen == 4 && strncmp( pBuf, "RING" , 4 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3911 …else if ( iLen == 10 && strncmp( pBuf, "NO CARRIER" , 10 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3912 …else if ( iLen == 5 && strncmp( pBuf, "ERROR" , 5 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3913 …else if ( iLen >= 8 && strncmp( pBuf, "CONNECT " , 8 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3914 …else if ( iLen == 11 && strncmp( pBuf, "NO DAILTONE", 11 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3915 …else if ( iLen == 4 && strncmp( pBuf, "BUSY" , 4 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3916 …else if ( iLen == 9 && strncmp( pBuf, "NO ANSWER" , 9 ) == 0 ) { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3917 …else { up->iModemEvent = MODEM_EVENT_… in modem_receive()
3923 iCopyLen = ( iLen <= sizeof(sResp)-1 ? iLen : sizeof(sResp)-1 ) ; in modem_receive()
3924 strncpy( sResp, pBuf, iLen <= sizeof(sResp)-1 ? iLen : sizeof(sResp)-1 ) ; in modem_receive()
3926 …_jjy.c : modem_receive : iLen=%zu pBuf=[%s] iModemEvent=%d\n", iCopyLen, sResp, up->iModemEvent ) ; in modem_receive()
3944 pp = peer->procptr ; in modem_timer()
3945 up = pp->unitptr ; in modem_timer()
3949 if ( iModemSilentTimeout[up->iModemState] != 0 ) { in modem_timer()
3950 up->iModemSilentTimer++ ; in modem_timer()
3951 if ( iModemSilentTimeout[up->iModemState] <= up->iModemSilentTimer ) { in modem_timer()
3952 up->iModemEvent = MODEM_EVENT_SILENT ; in modem_timer()
3957 if ( iModemStateTimeout[up->iModemState] != 0 ) { in modem_timer()
3958 up->iModemStateTimer++ ; in modem_timer()
3959 if ( iModemStateTimeout[up->iModemState] <= up->iModemStateTimer ) { in modem_timer()
3960 up->iModemEvent = MODEM_EVENT_TIMEOUT ; in modem_timer()
3978 rc = (*pModemHandler[up->iModemEvent][up->iModemState])( peer, pp, up ) ; in modem_control()
3981 iPostEvent = iModemPostEvent[up->iModemEvent][up->iModemState] ; in modem_control()
3984 printf( "refclock_jjy.c : modem_control : iModemState=%d -> %d iPostEvent=%d\n", in modem_control()
3985 up->iModemState, iModemNextState[up->iModemEvent][up->iModemState], iPostEvent ) ; in modem_control()
3989 if ( up->iModemState != iModemNextState[up->iModemEvent][up->iModemState] ) { in modem_control()
3990 up->iModemSilentCount = 0 ; in modem_control()
3991 up->iModemStateTimer = 0 ; in modem_control()
3992 up->iModemCommandSeq = 0 ; in modem_control()
3995 up->iModemState = iModemNextState[up->iModemEvent][up->iModemState] ; in modem_control()
3999 up->iModemEvent = iPostEvent ; in modem_control()
4003 up->iModemEvent = MODEM_EVENT_NULL ; in modem_control()
4047 up->iModemCommandSeq = 0 ; in modem_init_start()
4072 up->iModemCommandSeq++ ; in modem_init_resp00()
4074 switch ( up->iModemCommandSeq ) { in modem_init_resp00()
4085 if ( ( pp->sloppyclockflag & CLK_FLAG3 ) == 0 ) { in modem_init_resp00()
4094 if ( ( pp->sloppyclockflag & CLK_FLAG4 ) == 0 ) { in modem_init_resp00()
4123 if ( ( pp->sloppyclockflag & CLK_FLAG2 ) == 0 ) { in modem_init_resp00()
4136 /* Hn = Hook 0:Hook-On ( Disconnect ) 1:Hook-Off ( Connect ) */ in modem_init_resp00()
4155 if ( write( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) { in modem_init_resp00()
4217 if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) { in modem_dial_dialout()
4230 if ( write( pp->io.fd, sCmd, iCmdLen ) != iCmdLen ) { in modem_dial_dialout()
4333 if ( write( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) { in modem_esc_escape()
4350 up->iModemSilentTimer = 0 ; in modem_esc_data()
4363 up->iModemSilentCount ++ ; in modem_esc_silent()
4365 …if ( up->iModemSilentCount < iModemStateTimeout[up->iModemState] / iModemSilentTimeout[up->iModemS… in modem_esc_silent()
4372 up->iModemSilentTimer = 0 ; in modem_esc_silent()
4399 if ( write( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) { in modem_esc_disc()
4430 pMark = "--> " ; in jjy_write_clockstats()
4433 pMark = "<-- " ; in jjy_write_clockstats()
4436 pMark = "--- " ; in jjy_write_clockstats()
4442 pMark = "-W- " ; in jjy_write_clockstats()
4445 pMark = "-X- " ; in jjy_write_clockstats()
4458 printableString( sLog+iMarkLen, sizeof(sLog)-iMarkLen, pData, iDataLen ) ; in jjy_write_clockstats()
4465 record_clock_stats( &peer->srcadr, sLog ) ; in jjy_write_clockstats()
4487 "<CAN>", "<EM>" , "<SUB>", "<ESC>", in printableString()
4510 OutputLen - j ) ; in printableString()
4515 snprintf( sOutput + j, OutputLen - j, "<x%X>", in printableString()
4521 sOutput[min(j, (size_t)iOutputLen - 1)] = '\0' ; in printableString()