Lines Matching +full:up +full:-

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 */
88 /* Code clean up ( Remove unreachable codes ) in */
93 /* ( DATE,STIM -> DCST,STUS,DATE,STIM ) */
96 /* [Add] Support the Tristate Ltd. TS-GPSclock-01 */
100 /* [Change] Split the start up routine into each JJY receivers. */
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. */
161 #define PRECISION (-3) /* precision assumed (about 100 ms) */
177 /* Set up by the function "jjy_start_xxxxxxxx" */
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. )
366 jjy_start, /* start up driver */
376 * Start up driver return code
441 #define DEBUG_PRINTF_JJY_RECEIVE(sFunc,iLen) { if ( debug ) { printf ( "refclock_jjy.c : %s : iProcessState=%d bLineError=%d iCommandSeq=%d iLineCount=%d iTimestampCount=%d iLen=%d\n", sFunc, up->iProcessState, up->bLineError, up->iCommandSeq, up->iLineCount, up->iTimestampCount, iLen ) ; } }
447 /* jjy_start - open the devices and initialize data for processing */
454 struct jjyunit *up ;
462 ntoa(&peer->srcadr), peer->ttl, DEVICE, unit ) ;
467 up = emalloc( sizeof(*up) ) ;
468 if ( up == NULL ) {
472 memset ( up, 0, sizeof(*up) ) ;
474 up->bInitError = FALSE ;
475 up->iProcessState = JJY_PROCESS_STATE_IDLE ;
476 up->bReceiveFlag = FALSE ;
477 up->iCommandSeq = 0 ;
478 up->iLineCount = 0 ;
479 up->iTimestampCount = 0 ;
480 up->bWaitBreakString = FALSE ;
481 up->iRawBufLen = up->iLineBufLen = up->iTextBufLen = 0 ;
482 up->bSkipCntrlCharOnly = TRUE ;
484 /* Set up the device name */
487 snprintf( sLog, sizeof(sLog), "mode=%d dev=%s", peer->ttl, sDeviceName ) ;
491 * peer->ttl is a mode number specified by "127.127.40.X mode N" in the ntp.conf
493 switch ( peer->ttl ) {
496 rc = jjy_start_tristate_jjy01 ( unit, peer, up ) ;
499 rc = jjy_start_cdex_jst2000 ( unit, peer, up ) ;
502 rc = jjy_start_echokeisokuki_lt2000 ( unit, peer, up ) ;
505 rc = jjy_start_citizentic_jjy200 ( unit, peer, up ) ;
508 rc = jjy_start_tristate_gpsclock01 ( unit, peer, up ) ;
511 rc = jjy_start_seiko_tsys_tdc_300 ( unit, peer, up ) ;
514 rc = jjy_start_telephone ( unit, peer, up ) ;
517 if ( 101 <= peer->ttl && peer->ttl <= 180 ) {
518 rc = jjy_start_telephone ( unit, peer, up ) ;
521 ntoa(&peer->srcadr), peer->ttl ) ;
522 free ( (void*) up ) ;
529 ntoa(&peer->srcadr), peer->ttl ) ;
530 free ( (void*) up ) ;
535 fd = refclock_open ( &peer->srcadr, sDeviceName, up->linespeed, up->linediscipline ) ;
537 free ( (void*) up ) ;
544 pp = peer->procptr ;
546 pp->clockdesc = DESCRIPTION ;
547 pp->unitptr = up ;
548 pp->io.clock_recv = jjy_receive ;
549 pp->io.srcclock = peer ;
550 pp->io.datalen = 0 ;
551 pp->io.fd = fd ;
552 if ( ! io_addclock(&pp->io) ) {
554 pp->io.fd = -1 ;
555 free ( up ) ;
556 pp->unitptr = NULL ;
559 memcpy( (char*)&pp->refid, REFID, strlen(REFID) ) ;
561 peer->precision = PRECISION ;
563 snprintf( sLog, sizeof(sLog), "minpoll=%d maxpoll=%d", peer->minpoll, peer->maxpoll ) ;
571 /* jjy_shutdown - shutdown the clock */
577 struct jjyunit *up;
582 pp = peer->procptr ;
583 up = pp->unitptr ;
584 if ( -1 != pp->io.fd ) {
585 io_closeclock ( &pp->io ) ;
587 if ( NULL != up ) {
588 free ( up ) ;
591 snprintf( sLog, sizeof(sLog), "JJY stopped. unit=%d mode=%d", unit, peer->ttl ) ;
592 record_clock_stats( &peer->srcadr, sLog ) ;
597 /* jjy_receive - receive data from the serial interface */
606 struct jjyunit *up ;
619 peer = rbufp->recv_peer ;
620 pp = peer->procptr ;
621 up = pp->unitptr ;
626 if ( up->linediscipline == LDISC_RAW ) {
628 pp->lencode = refclock_gtraw ( rbufp, pp->a_lastcode, BMAX-1, &tRecvTimestamp ) ;
629 /* 3rd argument can be BMAX, but the coverity scan tool claim "Memory - corruptions (OVERRUN)" */
631 /* To avoid its claim, pass the value BMAX-1. */
637 i < pp->lencode && up->iRawBufLen < MAX_RAWBUF - 2 ;
638 i ++ , up->iRawBufLen ++ ) {
639 up->sRawBuf[up->iRawBufLen] = pp->a_lastcode[i] ;
641 up->sRawBuf[up->iRawBufLen] = 0 ;
646 pp->lencode = refclock_gtlin ( rbufp, pp->a_lastcode, BMAX, &tRecvTimestamp ) ;
650 printf( "\nrefclock_jjy.c : %s : Len=%d ", sFunctionName, pp->lencode ) ;
651 for ( i = 0 ; i < pp->lencode ; i ++ ) {
652 if ( iscntrl( (u_char)(pp->a_lastcode[i] & 0x7F) ) ) {
653 printf( "<x%02X>", pp->a_lastcode[i] & 0xFF ) ;
655 printf( "%c", pp->a_lastcode[i] ) ;
665 if ( pp->lencode == 0 ) return ;
671 if ( up->iProcessState == JJY_PROCESS_STATE_IDLE
672 || up->iProcessState == JJY_PROCESS_STATE_DONE
673 || up->iProcessState == JJY_PROCESS_STATE_ERROR ) {
675 up->iRawBufLen = 0 ;
688 pp->lastrec = tRecvTimestamp ;
690 up->iLineCount ++ ;
692 up->iProcessState = JJY_PROCESS_STATE_RECEIVE ;
693 up->bReceiveFlag = TRUE ;
696 iBreakPosition = up->iRawBufLen - 1 ;
697 for ( ; up->iProcessState == JJY_PROCESS_STATE_RECEIVE ; ) {
699 if ( up->linediscipline == LDISC_RAW ) {
701 if ( up->bWaitBreakString ) {
702 iBreakPosition = getRawDataBreakPosition( up, iReadRawBuf ) ;
703 if ( iBreakPosition == -1 ) {
705 if ( up->iRawBufLen < MAX_RAWBUF - 2
711 iBreakPosition = up->iRawBufLen - 1 ;
715 iBreakPosition = up->iRawBufLen - 1 ;
719 up->iLineBufLen = up->iTextBufLen = 0 ;
723 up->sLineBuf[up->iLineBufLen] = up->sRawBuf[i] ;
724 up->iLineBufLen ++ ;
727 if ( ! iscntrl( (u_char)up->sRawBuf[i] ) ) {
728 up->sTextBuf[up->iTextBufLen] = up->sRawBuf[i] ;
729 up->iTextBufLen ++ ;
733 up->sLineBuf[up->iLineBufLen] = 0 ;
734 up->sTextBuf[up->iTextBufLen] = 0 ;
736 printf( "refclock_jjy.c : %s : up->iLineBufLen=%d up->iTextBufLen=%d\n",
737 sFunctionName, up->iLineBufLen, up->iTextBufLen ) ;
740 if ( up->bSkipCntrlCharOnly && up->iTextBufLen == 0 ) {
742 printf( "refclock_jjy.c : %s : Skip cntrl char only : up->iRawBufLen=%d iReadRawBuf=%d iBreakPosition=%d\n",
743 sFunctionName, up->iRawBufLen, iReadRawBuf, iBreakPosition ) ;
745 if ( iBreakPosition + 1 < up->iRawBufLen ) {
756 if ( up->linediscipline == LDISC_RAW ) {
757 pBuf = up->sLineBuf ;
758 iLen = up->iLineBufLen ;
760 pBuf = pp->a_lastcode ;
761 iLen = pp->lencode ;
764 iCopyLen = ( iLen <= sizeof(sLogText)-1 ? iLen : sizeof(sLogText)-1 ) ;
769 switch ( up->unittype ) {
808 up->iProcessState = JJY_PROCESS_STATE_DONE ;
811 up->iProcessState = JJY_PROCESS_STATE_ERROR ;
817 if ( up->linediscipline == LDISC_RAW ) {
822 if ( iReadRawBuf >= up->iRawBufLen ) {
828 if ( up->linediscipline == LDISC_CLK ) {
834 if ( up->linediscipline == LDISC_RAW && iReadRawBuf > 0 ) {
835 for ( i = 0, j = iReadRawBuf ; j < up->iRawBufLen ; i ++, j++ ) {
836 up->sRawBuf[i] = up->sRawBuf[j] ;
838 up->iRawBufLen -= iReadRawBuf ;
839 if ( up->iRawBufLen < 0 ) {
840 up->iRawBufLen = 0 ;
844 up->bReceiveFlag = FALSE ;
851 getRawDataBreakPosition ( struct jjyunit *up, int iStart )
856 if ( iStart >= up->iRawBufLen ) {
858 printf( "refclock_jjy.c : getRawDataBreakPosition : iStart=%d return=-1\n", iStart ) ;
860 return -1 ;
863 for ( i = iStart ; i < up->iRawBufLen ; i ++ ) {
865 for ( j = 0 ; up->pRawBreak[j].pString != NULL ; j ++ ) {
867 if ( i + up->pRawBreak[j].iLength <= up->iRawBufLen ) {
869 if ( strncmp( up->sRawBuf + i,
870 up->pRawBreak[j].pString,
871 up->pRawBreak[j].iLength ) == 0 ) {
875 iStart, i + up->pRawBreak[j].iLength - 1 ) ;
877 return i + up->pRawBreak[j].iLength - 1 ;
885 printf( "refclock_jjy.c : getRawDataBreakPosition : iStart=%d return=-1\n", iStart ) ;
887 return -1 ;
892 /* jjy_poll - called by the transmit procedure */
900 struct jjyunit *up;
903 pp = peer->procptr;
904 up = pp->unitptr ;
906 if ( up->bInitError ) {
911 if ( pp->polls > 0 && up->iLineCount == 0 ) {
918 pp->polls ++ ;
920 sReach[0] = peer->reach & 0x80 ? '1' : '0' ;
921 sReach[1] = peer->reach & 0x40 ? '1' : '0' ;
922 sReach[2] = peer->reach & 0x20 ? '1' : '0' ;
923 sReach[3] = peer->reach & 0x10 ? '1' : '0' ;
924 sReach[4] = peer->reach & 0x08 ? '1' : '0' ;
925 sReach[5] = peer->reach & 0x04 ? '1' : '0' ;
926 sReach[6] = peer->reach & 0x02 ? '1' : '0' ;
930 snprintf( sLog, sizeof(sLog), "polls=%ld reach=%s", pp->polls, sReach ) ;
933 up->iProcessState = JJY_PROCESS_STATE_POLL ;
934 up->iCommandSeq = 0 ;
935 up->iReceiveSeq = 0 ;
936 up->iLineCount = 0 ;
937 up->bLineError = FALSE ;
938 up->iRawBufLen = 0 ;
940 switch ( up->unittype ) {
978 /* jjy_timer - called at one-second intervals */
985 struct jjyunit *up ;
993 pp = peer->procptr ;
994 up = pp->unitptr ;
996 if ( up->bReceiveFlag ) {
999 printf ( "refclock_jjy.c : jjy_timer : up->bReceiveFlag= TRUE : Timer skipped.\n" ) ;
1005 switch ( up->unittype ) {
1022 jjy_synctime ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
1028 pp->year = up->year ;
1029 pp->day = ymd2yd( up->year, up->month, up->day ) ;
1030 pp->hour = up->hour ;
1031 pp->minute = up->minute ;
1032 pp->second = up->second ;
1033 pp->nsec = up->msecond * 1000000 ;
1038 pp->hour -= 9 ;
1039 if ( pp->hour < 0 ) {
1040 pp->hour += 24 ;
1041 pp->day -- ;
1042 if ( pp->day < 1 ) {
1043 pp->year -- ;
1044 pp->day = ymd2yd( pp->year, 12, 31 ) ;
1058 pp->lastref = pp->lastrec ;
1067 up->year, up->month, up->day,
1068 up->hour, up->minute, up->second, up->msecond,
1069 pp->year, pp->day, pp->hour, pp->minute, pp->second,
1070 (int)(pp->nsec/1000000) ) ;
1076 switch ( peer->status ) {
1080 case 3 : cStatus = '-' ; pStatus = "Outlier" ; break ;
1090 peer->status, cStatus, pStatus, peer->offset * 1000, peer->jitter * 1000 ) ;
1098 /*## The Tristate Ltd. JJY receiver TS-JJY01, TS-JJY02 ##*/
1106 /* -------------------- ---------------------------------------- ---------------------------- */
1157 jjy_start_tristate_jjy01 ( int unit, struct peer *peer, struct jjyunit *up )
1160 jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: Tristate Ltd. TS-JJY01, TS-JJY02" ) ;
1162 up->unittype = UNITTYPE_TRISTATE_JJY01 ;
1163 up->linespeed = SPEED232_TRISTATE_JJY01 ;
1164 up->linediscipline = LDISC_CLK ;
1166 time( &(up->tLastAdjustedTimestamp) ) ;
1167 up->bStusReplyAdjustedAtLeastOnce = FALSE ;
1178 struct jjyunit *up ;
1194 peer = rbufp->recv_peer ;
1195 pp = peer->procptr ;
1196 up = pp->unitptr ;
1198 if ( up->linediscipline == LDISC_RAW ) {
1199 pBuf = up->sTextBuf ;
1200 iLen = up->iTextBufLen ;
1202 pBuf = pp->a_lastcode ;
1203 iLen = pp->lencode ;
1210 if ( tristate_jjy01_command_sequence[up->iCommandSeq].command == NULL ) {
1212 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY,
1215 up->bLineError = TRUE ;
1221 if ( iLen != tristate_jjy01_command_sequence[up->iCommandSeq].iExpectedReplyLength[0]
1222 && iLen != tristate_jjy01_command_sequence[up->iCommandSeq].iExpectedReplyLength[1] ) {
1224 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH,
1227 up->bLineError = TRUE ;
1233 switch ( tristate_jjy01_command_sequence[up->iCommandSeq].commandNumber ) {
1238 &up->year, &up->month, &up->day ) ;
1240 if ( rc != 3 || up->year < 2000 || 2099 <= up->year
1241 || up->month < 1 || 12 < up->month
1242 || up->day < 1 || 31 < up->day ) {
1244 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATE,
1245 rc, up->year, up->month, up->day ) ;
1247 up->bLineError = TRUE ;
1256 if ( up->iTimestampCount >= 2 ) {
1258 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_TOO_MANY_REPLY,
1259 up->iTimestampCount ) ;
1261 up->bLineError = TRUE ;
1266 &up->hour, &up->minute, &up->second ) ;
1268 if ( rc != 3 || up->hour > 23 || up->minute > 59 ||
1269 up->second > 60 ) {
1271 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME,
1272 rc, up->hour, up->minute, up->second ) ;
1274 up->bLineError = TRUE ;
1278 up->iTimestamp[up->iTimestampCount] = ( up->hour * 60 + up->minute ) * 60 + up->second ;
1280 up->iTimestampCount++ ;
1282 up->msecond = 0 ;
1291 up->bStusReplyAdjusted = TRUE ;
1292 up->bStusReplyAdjustedAtLeastOnce = TRUE ;
1293 time( &(up->tLastAdjustedTimestamp) ) ;
1297 up->bStusReplyAdjusted = FALSE ;
1300 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
1303 up->bLineError = TRUE ;
1318 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
1321 up->bLineError = TRUE ;
1329 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
1332 up->bLineError = TRUE ;
1337 if ( up->iTimestampCount == 2 ) {
1341 fSeconds = difftime( now, up->tLastAdjustedTimestamp ) ;
1343 if ( ( pp->sloppyclockflag & CLK_FLAG2 ) != 0
1344 && ( ! up->bStusReplyAdjusted )
1345 && ( fSeconds >= ( pp->fudgetime2 * 3600 ) || ( ! up->bStusReplyAdjustedAtLeastOnce ) ) ) {
1348 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds, "seconds" ) ;
1350 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 60, "minutes" ) ;
1352 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 3600, "hours" ) ;
1354 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 86400, "days" ) ;
1358 } else if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0]
1359 && up->iTimestamp[0] <= up->iTimestamp[1] ) {
1361 jjy_synctime( peer, pp, up ) ;
1363 } else if ( up->iTimestamp[0] > up->iTimestamp[1] ) {
1365 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_OVER_MIDNIGHT_2,
1366 up->iTimestamp[0], up->iTimestamp[1] ) ;
1371 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SLOW_REPLY_2,
1372 up->iTimestamp[0], up->iTimestamp[1] ) ;
1374 up->bLineError = TRUE ;
1382 if ( tristate_jjy01_command_sequence[up->iCommandSeq].command != NULL ) {
1383 up->iCommandSeq ++ ;
1386 if ( tristate_jjy01_command_sequence[up->iCommandSeq].command == NULL ) {
1391 pCmd = tristate_jjy01_command_sequence[up->iCommandSeq].command ;
1392 iCmdLen = tristate_jjy01_command_sequence[up->iCommandSeq].commandLength ;
1393 if ( write ( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) {
1413 struct jjyunit *up ;
1418 pp = peer->procptr;
1419 up = pp->unitptr ;
1421 up->bLineError = FALSE ;
1422 up->iTimestampCount = 0 ;
1424 if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) {
1426 up->iCommandSeq = 2 ;
1427 up->iLineCount = 2 ;
1430 up->bStusReplyAdjusted = FALSE ;
1434 printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCount=%d\n",
1435 sFunctionName, pp->sloppyclockflag, CLK_FLAG1,
1436 up->iLineCount ) ;
1444 up->iCommandSeq ++ ;
1446 pCmd = tristate_jjy01_command_sequence[up->iCommandSeq].command ;
1447 iCmdLen = tristate_jjy01_command_sequence[up->iCommandSeq].commandLength ;
1448 if ( write ( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) {
1459 /*## The C-DEX Co. Ltd. JJY receiver JST2000 ##*/
1467 /* -------------------- ---------------------------------------- ---------------------------- */
1480 jjy_start_cdex_jst2000 ( int unit, struct peer *peer, struct jjyunit *up )
1483 jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: C-DEX Co. Ltd. JST2000" ) ;
1485 up->unittype = UNITTYPE_CDEX_JST2000 ;
1486 up->linespeed = SPEED232_CDEX_JST2000 ;
1487 up->linediscipline = LDISC_RAW ;
1489 up->pRawBreak = cdex_jst2000_raw_break ;
1490 up->bWaitBreakString = TRUE ;
1492 up->bSkipCntrlCharOnly = FALSE ;
1504 struct jjyunit *up ;
1514 peer = rbufp->recv_peer ;
1515 pp = peer->procptr ;
1516 up = pp->unitptr ;
1518 if ( up->linediscipline == LDISC_RAW ) {
1519 pBuf = up->sTextBuf ;
1520 iLen = up->iTextBufLen ;
1522 pBuf = pp->a_lastcode ;
1523 iLen = pp->lencode ;
1530 if ( up->iCommandSeq != 1 ) {
1532 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY,
1535 up->bLineError = TRUE ;
1541 if ( up->iLineBufLen < 17 || up->sLineBuf[up->iLineBufLen-1] != 0x03 ) {
1549 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH,
1552 up->bLineError = TRUE ;
1559 &up->year, &up->month, &up->day,
1560 &up->hour, &up->minute, &up->second,
1561 &up->msecond ) ;
1563 if ( rc != 7 || up->month < 1 || up->month > 12 ||
1564 up->day < 1 || up->day > 31 || up->hour > 23 ||
1565 up->minute > 59 || up->second > 60 ) {
1567 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME,
1568 rc, up->year, up->month, up->day,
1569 up->hour, up->minute, up->second ) ;
1571 up->bLineError = TRUE ;
1575 up->year += 2000 ;
1576 up->msecond *= 100 ;
1578 jjy_synctime( peer, pp, up ) ;
1591 struct jjyunit *up ;
1593 pp = peer->procptr ;
1594 up = pp->unitptr ;
1596 up->bLineError = FALSE ;
1597 up->iRawBufLen = 0 ;
1598 up->iLineBufLen = 0 ;
1599 up->iTextBufLen = 0 ;
1605 up->iCommandSeq ++ ;
1607 if ( write ( pp->io.fd, "\0051J\003", 4 ) != 4 ) {
1626 /* -------------------- ---------------------------------------- ---------------------------- */
1646 jjy_start_echokeisokuki_lt2000 ( int unit, struct peer *peer, struct jjyunit *up )
1651 up->unittype = UNITTYPE_ECHOKEISOKUKI_LT2000 ;
1652 up->linespeed = SPEED232_ECHOKEISOKUKI_LT2000 ;
1653 up->linediscipline = LDISC_CLK ;
1655 up->operationmode = ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS ;
1667 struct jjyunit *up ;
1678 peer = rbufp->recv_peer ;
1679 pp = peer->procptr ;
1680 up = pp->unitptr ;
1682 if ( up->linediscipline == LDISC_RAW ) {
1683 pBuf = up->sTextBuf ;
1684 iLen = up->iTextBufLen ;
1686 pBuf = pp->a_lastcode ;
1687 iLen = pp->lencode ;
1694 if ( ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_REQUEST_SEND
1696 || ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_CONTINUOUS
1698 || ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS
1701 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH,
1704 up->bLineError = TRUE ;
1708 if ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_REQUEST_SEND && iLen == 15 ) {
1718 snprintf( sErr, sizeof(sErr)-1, " BCC error : Recv=%02X,%02X / Calc=%02X,%02X ",
1721 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
1724 up->bLineError = TRUE ;
1730 if ( ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_REQUEST_SEND
1732 || ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_CONTINUOUS
1734 || ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS
1739 &up->year, &up->month, &up->day,
1740 &up->hour, &up->minute, &up->second ) ;
1742 if ( rc != 6 || up->month < 1 || up->month > 12
1743 || up->day < 1 || up->day > 31
1744 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
1746 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME,
1747 rc, up->year, up->month, up->day,
1748 up->hour, up->minute, up->second ) ;
1750 up->bLineError = TRUE ;
1754 up->year += 2000 ;
1756 if ( up->operationmode == ECHOKEISOKUKI_LT2000_MODE_CONTINUOUS
1757 || up->operationmode == ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS ) {
1758 /* A time stamp comes on every 0.5 second in the mode 2 of the LT-2000. */
1760 up->msecond = 500 ;
1761 up->second -- ;
1762 if ( up->second < 0 ) {
1763 up->second = 59 ;
1764 up->minute -- ;
1765 if ( up->minute < 0 ) {
1766 up->minute = 59 ;
1767 up->hour -- ;
1768 if ( up->hour < 0 ) {
1769 up->hour = 23 ;
1770 up->day -- ;
1771 if ( up->day < 1 ) {
1772 up->month -- ;
1773 if ( up->month < 1 ) {
1774 up->month = 12 ;
1775 up->year -- ;
1784 jjy_synctime( peer, pp, up ) ;
1789 if (up->operationmode == ECHOKEISOKUKI_LT2000_MODE_SWITCHING_CONTINUOUS ) {
1793 if ( write ( pp->io.fd, ECHOKEISOKUKI_LT2000_COMMAND_REQUEST_SEND, iLen ) != iLen ) {
1812 struct jjyunit *up ;
1816 pp = peer->procptr ;
1817 up = pp->unitptr ;
1819 up->bLineError = FALSE ;
1825 switch ( up->operationmode ) {
1836 if ( write ( pp->io.fd, sCmd, 1 ) != 1 ) {
1855 /* -------------------- ---------------------------------------- ---------------------------- */
1856 /* 'XX YY/MM/DD W HH:MM:SS<CR> XX:OK|NG|ER W:0(Mon)-6(Sun) */
1861 jjy_start_citizentic_jjy200 ( int unit, struct peer *peer, struct jjyunit *up )
1866 up->unittype = UNITTYPE_CITIZENTIC_JJY200 ;
1867 up->linespeed = SPEED232_CITIZENTIC_JJY200 ;
1868 up->linediscipline = LDISC_CLK ;
1880 struct jjyunit *up ;
1892 peer = rbufp->recv_peer ;
1893 pp = peer->procptr ;
1894 up = pp->unitptr ;
1896 if ( up->linediscipline == LDISC_RAW ) {
1897 pBuf = up->sTextBuf ;
1898 iLen = up->iTextBufLen ;
1900 pBuf = pp->a_lastcode ;
1901 iLen = pp->lencode ;
1907 * JJY-200 sends a timestamp every second.
1911 if ( up->iProcessState != JJY_PROCESS_STATE_RECEIVE ) {
1919 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH,
1922 up->bLineError = TRUE ;
1930 &up->year, &up->month, &up->day, &iWeekday,
1931 &up->hour, &up->minute, &up->second ) ;
1938 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31
1940 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
1942 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME,
1943 rc, up->year, up->month, up->day,
1944 up->hour, up->minute, up->second ) ;
1946 up->bLineError = TRUE ;
1951 snprintf( sMsg, sizeof(sMsg)-1, "status=%s", sStatus ) ;
1952 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_TIMESTAMP_UNSURE,
1958 up->year += 2000 ;
1959 up->msecond = 0 ;
1961 jjy_synctime( peer, pp, up ) ;
1974 struct jjyunit *up ;
1976 pp = peer->procptr ;
1977 up = pp->unitptr ;
1979 up->bLineError = FALSE ;
1986 /*## The Tristate Ltd. GPS clock TS-GPS01 ##*/
1995 /* by the onboard switch SW4, and make sure the LED-Y is tured on. */
2000 /* -------------------- ---------------------------------------- ---------------------------- */
2042 jjy_start_tristate_gpsclock01 ( int unit, struct peer *peer, struct jjyunit *up )
2045 jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: Tristate Ltd. TS-GPS01" ) ;
2047 up->unittype = UNITTYPE_TRISTATE_GPSCLOCK01 ;
2048 up->linespeed = SPEED232_TRISTATE_GPSCLOCK01 ;
2049 up->linediscipline = LDISC_CLK ;
2064 struct jjyunit *up ;
2078 peer = rbufp->recv_peer ;
2079 pp = peer->procptr ;
2080 up = pp->unitptr ;
2082 if ( up->linediscipline == LDISC_RAW ) {
2083 pBuf = up->sTextBuf ;
2084 iLen = up->iTextBufLen ;
2086 pBuf = pp->a_lastcode ;
2087 iLen = pp->lencode ;
2106 * Skip command prompt '$Cmd>' from the TS-GPSclock-01
2112 iLen -= 5 ;
2131 if ( tristate_gps01_command_sequence[up->iCommandSeq].command == NULL ) {
2133 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY,
2136 up->bLineError = TRUE ;
2142 if ( iLen != tristate_gps01_command_sequence[up->iCommandSeq].iExpectedReplyLength ) {
2144 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH,
2147 up->bLineError = TRUE ;
2153 switch ( tristate_gps01_command_sequence[up->iCommandSeq].commandNumber ) {
2157 rc = sscanf ( pBuf, "%4d/%2d/%2d", &up->year, &up->month, &up->day ) ;
2159 if ( rc != 3 || up->year < 2000 || 2099 <= up->year
2160 || up->month < 1 || 12 < up->month
2161 || up->day < 1 || 31 < up->day ) {
2163 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATE,
2164 rc, up->year, up->month, up->day ) ;
2166 up->bLineError = TRUE ;
2174 if ( up->iTimestampCount >= 2 ) {
2176 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_TOO_MANY_REPLY,
2177 up->iTimestampCount ) ;
2179 up->bLineError = TRUE ;
2184 &up->hour, &up->minute, &up->second ) ;
2187 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
2189 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME,
2190 rc, up->hour, up->minute, up->second ) ;
2192 up->bLineError = TRUE ;
2196 up->iTimestamp[up->iTimestampCount] = ( up->hour * 60 + up->minute ) * 60 + up->second ;
2198 up->iTimestampCount++ ;
2200 up->msecond = 0 ;
2212 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
2215 up->bLineError = TRUE ;
2223 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
2226 up->bLineError = TRUE ;
2231 if ( up->iTimestampCount == 2 ) {
2234 if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0]
2235 && up->iTimestamp[0] <= up->iTimestamp[1] ) {
2237 jjy_synctime( peer, pp, up ) ;
2239 } else if ( up->iTimestamp[0] > up->iTimestamp[1] ) {
2241 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_OVER_MIDNIGHT_2,
2242 up->iTimestamp[0], up->iTimestamp[1] ) ;
2247 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SLOW_REPLY_2,
2248 up->iTimestamp[0], up->iTimestamp[1] ) ;
2250 up->bLineError = TRUE ;
2256 if ( tristate_gps01_command_sequence[up->iCommandSeq].command == NULL ) {
2258 jjy_synctime( peer, pp, up ) ;
2264 if ( tristate_gps01_command_sequence[up->iCommandSeq].command != NULL ) {
2265 up->iCommandSeq ++ ;
2268 if ( tristate_gps01_command_sequence[up->iCommandSeq].command == NULL ) {
2270 up->iProcessState = JJY_PROCESS_STATE_DONE ;
2274 pCmd = tristate_gps01_command_sequence[up->iCommandSeq].command ;
2275 iCmdLen = tristate_gps01_command_sequence[up->iCommandSeq].commandLength ;
2276 if ( write ( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) {
2296 struct jjyunit *up ;
2301 pp = peer->procptr ;
2302 up = pp->unitptr ;
2304 up->iTimestampCount = 0 ;
2306 if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) {
2308 up->iCommandSeq = 1 ;
2309 up->iLineCount = 1 ;
2314 printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCount=%d\n",
2315 sFunctionName, pp->sloppyclockflag, CLK_FLAG1,
2316 up->iLineCount ) ;
2324 up->iCommandSeq ++ ;
2326 pCmd = tristate_gps01_command_sequence[up->iCommandSeq].command ;
2327 iCmdLen = tristate_gps01_command_sequence[up->iCommandSeq].commandLength ;
2328 if ( write ( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) {
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) */
2363 jjy_start_seiko_tsys_tdc_300 ( int unit, struct peer *peer, struct jjyunit *up )
2366 jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: SEIKO TIME SYSTEMS TDC-300" ) ;
2368 up->unittype = UNITTYPE_SEIKO_TIMESYS_TDC_300 ;
2369 up->linespeed = SPEED232_SEIKO_TIMESYS_TDC_300 ;
2370 up->linediscipline = LDISC_RAW ;
2372 up->pRawBreak = seiko_tsys_tdc_300_raw_break ;
2373 up->bWaitBreakString = TRUE ;
2375 up->bSkipCntrlCharOnly = FALSE ;
2389 struct jjyunit *up ;
2399 peer = rbufp->recv_peer ;
2400 pp = peer->procptr ;
2401 up = pp->unitptr ;
2403 if ( up->linediscipline == LDISC_RAW ) {
2404 pBuf = up->sTextBuf ;
2405 iLen = up->iTextBufLen ;
2407 pBuf = pp->a_lastcode ;
2408 iLen = pp->lencode ;
2414 * TDC-300 sends a timestamp every second.
2418 if ( up->iProcessState != JJY_PROCESS_STATE_RECEIVE ) {
2424 up->iReceiveSeq ++ ;
2435 &up->hour, &up->minute, &up->second ) ;
2438 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
2440 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME,
2441 rc, up->hour, up->minute, up->second ) ;
2443 up->bLineError = TRUE ;
2445 } else if ( up->hour == 23 && up->minute == 59 && up->second >= 55 ) {
2452 up->year = pTime->tm_year ;
2453 up->month = pTime->tm_mon + 1 ;
2454 up->day = pTime->tm_mday ;
2465 &up->year, &up->month, &up->day,
2466 &up->hour, &up->minute, &up->second, &iWeekday ) ;
2469 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31
2471 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
2473 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME,
2474 rc, up->year, up->month, up->day,
2475 up->hour, up->minute, up->second ) ;
2477 up->bLineError = TRUE ;
2486 &up->year, &up->month, &up->day, &iWeekday,
2487 &up->hour, &up->minute, &up->second ) ;
2490 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31
2492 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
2494 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME,
2495 rc, up->year, up->month, up->day,
2496 up->hour, up->minute, up->second ) ;
2498 up->bLineError = TRUE ;
2508 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
2509 up->sLineBuf ) ;
2511 up->bLineError = TRUE ;
2513 } else if ( up->iReceiveSeq == 1 ) {
2515 up->iReceiveSeq -- ;
2517 } else if ( up->iReceiveSeq >= 3 ) {
2519 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY,
2520 up->sLineBuf ) ;
2522 up->bLineError = TRUE ;
2530 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH,
2533 up->bLineError = TRUE ;
2538 up->year += 2000 ;
2539 up->msecond = 0 ;
2541 jjy_synctime( peer, pp, up ) ;
2554 struct jjyunit *up ;
2556 pp = peer->procptr ;
2557 up = pp->unitptr ;
2559 up->bLineError = FALSE ;
2574 /* -------------------- -------------------- -------------------- -------------------------- */
2577 /* > LEAPSEC<CR> XX<CR> One of <SP>0, +1, -1 */
2729 #define DEBUG_TELJJY_PRINTF(sFunc) { if ( debug ) { printf ( "refclock_jjy.c : %s : iClockState=%d iClockEvent=%d iTeljjySilentTimer=%d iTeljjyStateTimer=%d iClockCommandSeq=%d\n", sFunc, up->iClockState, up->iClockEvent, up->iTeljjySilentTimer, up->iTeljjyStateTimer, up->iClockCommandSeq ) ; } }
2737 jjy_start_telephone ( int unit, struct peer *peer, struct jjyunit *up )
2747 up->unittype = UNITTYPE_TELEPHONE ;
2748 up->linespeed = SPEED232_TELEPHONE ;
2749 up->linediscipline = LDISC_RAW ;
2751 up->pRawBreak = teljjy_raw_break ;
2752 up->bWaitBreakString = TRUE ;
2754 up->bSkipCntrlCharOnly = TRUE ;
2756 up->iClockState = TELJJY_STATE_IDLE ;
2757 up->iClockEvent = TELJJY_EVENT_NULL ;
2763 up->bInitError = TRUE ;
2769 up->bInitError = TRUE ;
2776 if ( iFirstThreeDigitsCount < sizeof(sFirstThreeDigits)-1 ) {
2784 up->bInitError = TRUE ;
2789 } else if ( sys_phone[0][i] != '-' ) {
2791 up->bInitError = TRUE ;
2800 up->bInitError = TRUE ;
2805 if ( iNumberOfDigitsOfPhoneNumber - iCommaPosition < 6 || 10 < iNumberOfDigitsOfPhoneNumber - iCommaPosition ) {
2808 up->bInitError = TRUE ;
2821 up->bInitError = TRUE ;
2828 if ( peer->minpoll < 8 ) {
2830 int oldminpoll = peer->minpoll ;
2831 peer->minpoll = 8 ;
2832 if ( peer->ppoll < peer->minpoll ) {
2833 peer->ppoll = peer->minpoll ;
2835 if ( peer->maxpoll < peer->minpoll ) {
2836 peer->maxpoll = peer->minpoll ;
2838 snprintf( sLog, sizeof(sLog), "minpoll=%d -> %d", oldminpoll, peer->minpoll ) ;
2857 struct jjyunit *up ;
2862 peer = rbufp->recv_peer ;
2863 pp = peer->procptr ;
2864 up = pp->unitptr ;
2868 if ( up->iClockState == TELJJY_STATE_IDLE
2869 || up->iClockState == TELJJY_STATE_DAILOUT
2870 || up->iClockState == TELJJY_STATE_BYE ) {
2872 iPreviousModemState = getModemState( up ) ;
2876 if ( iPreviousModemState != up->iModemState ) {
2878 if ( isModemStateDisconnect( up->iModemState ) ) {
2879 up->iClockEvent = TELJJY_EVENT_DISCONNECT ;
2880 teljjy_control ( peer, pp, up ) ;
2881 } else if ( isModemStateConnect( up->iModemState ) ) {
2882 up->iClockEvent = TELJJY_EVENT_CONNECT ;
2883 teljjy_control ( peer, pp, up ) ;
2891 if ( up->linediscipline == LDISC_RAW ) {
2892 pBuf = up->sTextBuf ;
2893 iLen = up->iTextBufLen ;
2895 pBuf = pp->a_lastcode ;
2896 iLen = pp->lencode ;
2899 up->iTeljjySilentTimer = 0 ;
2900 if ( iLen == 7 && strncmp( pBuf, "Name ? ", 7 ) == 0 ) { up->iClockEvent = TELJJY_EVENT_LOGIN ; }
2901 else if ( iLen == 1 && strncmp( pBuf, ">" , 1 ) == 0 ) { up->iClockEvent = TELJJY_EVENT_PROMPT ; }
2902 else if ( iLen >= 1 && strncmp( pBuf, "?" , 1 ) == 0 ) { up->iClockEvent = TELJJY_EVENT_ERROR ; }
2903 else { up->iClockEvent = TELJJY_EVENT_DATA ; }
2905 teljjy_control ( peer, pp, up ) ;
2921 struct jjyunit *up ;
2923 pp = peer->procptr ;
2924 up = pp->unitptr ;
2928 if ( up->iClockState == TELJJY_STATE_IDLE ) {
2929 up->iRawBufLen = 0 ;
2930 up->iLineBufLen = 0 ;
2931 up->iTextBufLen = 0 ;
2934 up->iClockEvent = TELJJY_EVENT_START ;
2935 teljjy_control ( peer, pp, up ) ;
2949 struct jjyunit *up ;
2952 pp = peer->procptr ;
2953 up = pp->unitptr ;
2957 if ( iTeljjySilentTimeout[up->iClockState] != 0 ) {
2958 up->iTeljjySilentTimer++ ;
2959 if ( iTeljjySilentTimeout[up->iClockState] <= up->iTeljjySilentTimer ) {
2960 up->iClockEvent = TELJJY_EVENT_SILENT ;
2961 teljjy_control ( peer, pp, up ) ;
2965 if ( iTeljjyStateTimeout[up->iClockState] != 0 ) {
2966 up->iTeljjyStateTimer++ ;
2967 if ( iTeljjyStateTimeout[up->iClockState] <= up->iTeljjyStateTimer ) {
2968 up->iClockEvent = TELJJY_EVENT_TIMEOUT ;
2969 teljjy_control ( peer, pp, up ) ;
2973 if ( isModemStateTimerOn( up ) ) {
2975 iPreviousModemState = getModemState( up ) ;
2979 if ( iPreviousModemState != up->iModemState ) {
2981 if ( isModemStateDisconnect( up->iModemState ) ) {
2982 up->iClockEvent = TELJJY_EVENT_DISCONNECT ;
2983 teljjy_control ( peer, pp, up ) ;
2984 } else if ( isModemStateConnect( up->iModemState ) ) {
2985 up->iClockEvent = TELJJY_EVENT_CONNECT ;
2986 teljjy_control ( peer, pp, up ) ;
2997 teljjy_control ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3005 rc = (*pTeljjyHandler[up->iClockEvent][up->iClockState])( peer, pp, up ) ;
3008 iPostEvent = iTeljjyPostEvent[up->iClockEvent][up->iClockState] ;
3011 printf( "refclock_jjy.c : teljjy_control : iClockState=%hd -> %hd iPostEvent=%hd\n",
3012 up->iClockState, iTeljjyNextState[up->iClockEvent][up->iClockState], iPostEvent ) ;
3015 up->iTeljjySilentTimer = 0 ;
3016 if ( up->iClockState != iTeljjyNextState[up->iClockEvent][up->iClockState] ) {
3018 up->iTeljjyStateTimer = 0 ;
3019 up->bLineError = FALSE ;
3020 up->iClockCommandSeq = 0 ;
3021 up->iTimestampCount = 0 ;
3022 up->iLoopbackCount = 0 ;
3024 up->bLoopbackTimeout[i] = FALSE ;
3026 if (iTeljjyNextState[up->iClockEvent][up->iClockState] == TELJJY_STATE_IDLE ) {
3028 up->iProcessState = JJY_PROCESS_STATE_DONE ;
3031 up->iClockState = iTeljjyNextState[up->iClockEvent][up->iClockState] ;
3036 up->iClockEvent = iPostEvent ;
3037 teljjy_control ( peer, pp, up ) ;
3040 up->iClockEvent = TELJJY_EVENT_NULL ;
3047 teljjy_setDelay ( struct peer *peer, struct jjyunit *up )
3053 gettimeofday( &(up->delayTime[up->iLoopbackCount]), NULL ) ;
3055 up->delayTime[up->iLoopbackCount].tv_sec -= up->sendTime[up->iLoopbackCount].tv_sec ;
3056 up->delayTime[up->iLoopbackCount].tv_usec -= up->sendTime[up->iLoopbackCount].tv_usec ;
3057 if ( up->delayTime[up->iLoopbackCount].tv_usec < 0 ) {
3058 up->delayTime[up->iLoopbackCount].tv_sec -- ;
3059 up->delayTime[up->iLoopbackCount].tv_usec += 1000000 ;
3062 milliSecond = up->delayTime[up->iLoopbackCount].tv_usec / 1000 ;
3063 microSecond = up->delayTime[up->iLoopbackCount].tv_usec - milliSecond * 1000 ;
3064 milliSecond += up->delayTime[up->iLoopbackCount].tv_sec * 1000 ;
3082 teljjy_getDelay ( struct peer *peer, struct jjyunit *up )
3095 iThresholdMicroSecond = ( TELJJY_LOOPBACK_DELAY_THRESHOLD - ( TELJJY_LOOPBACK_DELAY_THRESHOLD / 1000 ) * 1000 ) * 1000 ;
3097 up->iLoopbackValidCount = 0 ;
3099 for ( i = 0 ; i < MAX_LOOPBACK && i < up->iLoopbackCount ; i ++ ) {
3100 if ( up->bLoopbackTimeout[i]
3101 || up->delayTime[i].tv_sec > iThresholdSecond
3102 || ( up->delayTime[i].tv_sec == iThresholdSecond
3103 && up->delayTime[i].tv_usec > iThresholdMicroSecond ) ) {
3106 if ( up->iLoopbackValidCount == 0 ) {
3107 minTime.tv_sec = up->delayTime[i].tv_sec ;
3108 minTime.tv_usec = up->delayTime[i].tv_usec ;
3109 maxTime.tv_sec = up->delayTime[i].tv_sec ;
3110 maxTime.tv_usec = up->delayTime[i].tv_usec ;
3112 } else if ( minTime.tv_sec > up->delayTime[i].tv_sec
3113 || ( minTime.tv_sec == up->delayTime[i].tv_sec
3114 && minTime.tv_usec > up->delayTime[i].tv_usec ) ) {
3115 minTime.tv_sec = up->delayTime[i].tv_sec ;
3116 minTime.tv_usec = up->delayTime[i].tv_usec ;
3118 } else if ( maxTime.tv_sec < up->delayTime[i].tv_sec
3119 || ( maxTime.tv_sec == up->delayTime[i].tv_sec
3120 && maxTime.tv_usec < up->delayTime[i].tv_usec ) ) {
3121 maxTime.tv_sec = up->delayTime[i].tv_sec ;
3122 maxTime.tv_usec = up->delayTime[i].tv_usec ;
3125 up->iLoopbackValidCount ++ ;
3128 if ( up->iLoopbackValidCount < 2 ) {
3129 return -1 ;
3134 for ( i = 0 ; i < MAX_LOOPBACK && i < up->iLoopbackCount ; i ++ ) {
3135 if ( up->bLoopbackTimeout[i]
3136 || up->delayTime[i].tv_sec > iThresholdSecond
3137 || ( up->delayTime[i].tv_sec == iThresholdSecond
3138 && up->delayTime[i].tv_usec > iThresholdMicroSecond ) ) {
3141 if ( up->iLoopbackValidCount >= 3 && i == maxIndex ) {
3144 if ( up->iLoopbackValidCount >= 4 && i == minIndex ) {
3147 averTime.tv_usec += up->delayTime[i].tv_usec ;
3153 /* Previous for-if-for blocks assure iAverCount > 0. */
3155 return -1 ;
3160 iPercent = ( peer->ttl - 100 ) ;
3170 teljjy_idle_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3181 teljjy_idle_dialout ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3186 modem_connect ( peer->refclkunit, peer ) ;
3194 teljjy_dial_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3205 teljjy_dial_login ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3216 teljjy_dial_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3227 teljjy_login_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3238 teljjy_login_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3249 teljjy_login_conn ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3256 up->bLineError = FALSE ;
3257 up->iClockCommandSeq = 0 ;
3258 up->iTimestampCount = 0 ;
3259 up->iLoopbackCount = 0 ;
3261 up->bLoopbackTimeout[i] = FALSE ;
3270 teljjy_login_login ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3283 if ( write( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) {
3295 teljjy_login_silent ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3300 if ( write( pp->io.fd, "\r", 1 ) != 1 ) {
3306 up->iTeljjySilentTimer = 0 ;
3314 teljjy_login_error ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3325 teljjy_conn_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3336 teljjy_conn_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3347 teljjy_conn_send ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3356 if ( up->iClockCommandSeq > 0
3357 && teljjy_command_sequence[up->iClockCommandSeq].command == NULL ) {
3362 if ( up->iClockCommandSeq == 0 && peer->ttl == 100 ) {
3365 up->iClockCommandSeq = TELJJY_COMMAND_START_SKIP_LOOPBACK ;
3367 } else if ( up->iClockCommandSeq == 0 && peer->ttl != 100 ) {
3370 up->iLoopbackCount = 0 ;
3372 up->bLoopbackTimeout[i] = FALSE ;
3375 } else if ( up->iClockCommandSeq > 0 && peer->ttl != 100
3376 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK
3377 && up->iLoopbackCount < MAX_LOOPBACK ) {
3382 up->iClockCommandSeq, up->iLoopbackCount ) ;
3386 teljjy_setDelay( peer, up ) ;
3388 up->iLoopbackCount ++ ;
3392 up->iClockCommandSeq++ ;
3394 pCmd = teljjy_command_sequence[up->iClockCommandSeq].command ;
3395 iLen = teljjy_command_sequence[up->iClockCommandSeq].commandLength ;
3399 if ( write( pp->io.fd, pCmd, iLen ) != iLen ) {
3403 if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK ) {
3405 if ( up->iLoopbackCount < MAX_LOOPBACK ) {
3406 gettimeofday( &(up->sendTime[up->iLoopbackCount]), NULL ) ;
3407 up->bLoopbackMode = TRUE ;
3409 /* This else-block is never come. */
3411 snprintf( sLog, sizeof(sLog)-1, "refclock_jjy.c ; teljjy_conn_send ; iClockCommandSeq=%d iLoopbackCount=%d MAX_LOOPBACK=%d",
3412 up->iClockCommandSeq, up->iLoopbackCount, MAX_LOOPBACK ) ;
3415 up->bLoopbackMode = FALSE ;
3419 up->bLoopbackMode = FALSE ;
3424 if ( teljjy_command_sequence[up->iClockCommandSeq+1].command == NULL ) {
3444 teljjy_conn_data ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3455 if ( up->linediscipline == LDISC_RAW ) {
3456 pBuf = up->sTextBuf ;
3457 iLen = up->iTextBufLen ;
3459 pBuf = pp->a_lastcode ;
3460 iLen = pp->lencode ;
3463 if ( teljjy_command_sequence[up->iClockCommandSeq].iEchobackReplyLength == iLen
3464 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK
3465 && up->sTextBuf[0] == *(teljjy_command_sequence[up->iClockCommandSeq].command)
3466 && up->iLoopbackCount < MAX_LOOPBACK ) {
3469 teljjy_setDelay( peer, up ) ;
3471 up->iLoopbackCount ++ ;
3473 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iEchobackReplyLength == iLen
3474 && strncmp( pBuf, teljjy_command_sequence[up->iClockCommandSeq].command, iLen ) == 0 ) {
3479 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyLength == iLen
3480 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_4DATE ) {
3481 /* 4DATE<CR> -> YYYYMMDD<CR> */
3483 rc = sscanf ( pBuf, "%4d%2d%2d", &up->year, &up->month, &up->day ) ;
3485 if ( rc != 3 || up->year < 2000 || 2099 <= up->year
3486 || up->month < 1 || 12 < up->month || up->day < 1 || 31 < up->day ) {
3488 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATE,
3489 rc, up->year, up->month, up->day ) ;
3491 up->bLineError = TRUE ;
3494 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyLength == iLen
3495 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LEAPSEC
3496 && ( strncmp( pBuf, " 0", 2 ) == 0 || strncmp( pBuf, "+1", 2 ) == 0 || strncmp( pBuf, "-1", 2 ) == 0 ) ) {
3497 /* LEAPSEC<CR> -> XX<CR> ( One of <SP>0, +1, -1 ) */
3499 rc = sscanf ( pBuf, "%2d", &up->leapsecond ) ;
3501 if ( rc != 1 || up->leapsecond < -1 || 1 < up->leapsecond ) {
3503 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_LEAP,
3506 up->bLineError = TRUE ;
3509 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyLength == iLen
3510 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_TIME ) {
3511 /* TIME<CR> -> HHMMSS<CR> ( 3 times on second ) */
3513 rc = sscanf ( pBuf, "%2d%2d%2d", &up->hour, &up->minute, &up->second ) ;
3515 if ( rc != 3 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
3517 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME,
3518 rc, up->hour, up->minute, up->second ) ;
3520 up->bLineError = TRUE ;
3522 up->iTimestamp[up->iTimestampCount] = ( up->hour * 60 + up->minute ) * 60 + up->second ;
3524 up->iTimestampCount++ ;
3526 if ( up->iTimestampCount == 6 && ! up->bLineError ) {
3529 up->bLineError,
3530 up->iTimestamp[3], up->iTimestamp[4], up->iTimestamp[5] ) ;
3534 if ( peer->ttl == 100 ) {
3536 up->msecond = 0 ;
3539 up->msecond = teljjy_getDelay( peer, up ) ;
3540 if (up->msecond < 0 ) {
3541 up->msecond = 0 ;
3546 if ( ( up->iTimestamp[3] - 15 ) <= up->iTimestamp[2]
3547 && up->iTimestamp[2] <= up->iTimestamp[3]
3548 && ( up->iTimestamp[3] + 1 ) == up->iTimestamp[4]
3549 && ( up->iTimestamp[4] + 1 ) == up->iTimestamp[5] ) {
3552 jjy_synctime( peer, pp, up ) ;
3554 if ( peer->ttl != 100 ) {
3558 up->msecond, up->iLoopbackValidCount, MAX_LOOPBACK ) ;
3563 up->iLoopbackValidCount, MAX_LOOPBACK ) ;
3571 } else if ( teljjy_command_sequence[up->iClockCommandSeq].iEchobackReplyLength != iLen
3572 && teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK ) {
3575 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_IGNORE_REPLY,
3581 up->bLineError = TRUE ;
3583 snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY,
3595 teljjy_conn_silent ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3602 if ( up->iClockCommandSeq >= 1
3603 && up->iClockCommandSeq < TELJJY_COMMAND_START_SKIP_LOOPBACK ) {
3610 if ( teljjy_command_sequence[up->iClockCommandSeq].iExpectedReplyType == TELJJY_REPLY_LOOPBACK ) {
3611 up->bLoopbackTimeout[up->iLoopbackCount] = TRUE ;
3613 up->iTeljjySilentTimer = 0 ;
3614 return teljjy_conn_send( peer, pp, up ) ;
3619 if ( write( pp->io.fd, pCmd, 1 ) != 1 ) {
3625 up->iTeljjySilentTimer = 0 ;
3633 teljjy_conn_error ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3644 teljjy_bye_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3655 teljjy_bye_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3666 teljjy_bye_modem ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3671 modem_disconnect ( peer->refclkunit, peer ) ;
3803 #define DEBUG_MODEM_PRINTF(sFunc) { if ( debug ) { printf ( "refclock_jjy.c : %s : iModemState=%d iModemEvent=%d iModemSilentTimer=%d iModemStateTimer=%d\n", sFunc, up->iModemState, up->iModemEvent, up->iModemSilentTimer, up->iModemStateTimer ) ; } }
3811 getModemState ( struct jjyunit *up )
3813 return up->iModemState ;
3835 isModemStateTimerOn ( struct jjyunit *up )
3837 return ( iModemSilentTimeout[up->iModemState] != 0 || iModemStateTimeout[up->iModemState] != 0 ) ;
3846 struct jjyunit *up;
3848 pp = peer->procptr ;
3849 up = pp->unitptr ;
3853 up->iModemEvent = MODEM_EVENT_INITIALIZE ;
3855 modem_control ( peer, pp, up ) ;
3865 struct jjyunit *up;
3867 pp = peer->procptr ;
3868 up = pp->unitptr ;
3872 up->iModemEvent = MODEM_EVENT_DISCONNECT ;
3874 modem_control ( peer, pp, up ) ;
3885 struct jjyunit *up;
3894 peer = rbufp->recv_peer ;
3895 pp = peer->procptr ;
3896 up = pp->unitptr ;
3900 if ( up->linediscipline == LDISC_RAW ) {
3901 pBuf = up->sTextBuf ;
3902 iLen = up->iTextBufLen ;
3904 pBuf = pp->a_lastcode ;
3905 iLen = pp->lencode ;
3908 if ( iLen == 2 && strncmp( pBuf, "OK" , 2 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_OK ; }
3909 else if ( iLen == 7 && strncmp( pBuf, "CONNECT" , 7 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_CONNECT ; }
3910 else if ( iLen == 4 && strncmp( pBuf, "RING" , 4 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_RING ; }
3911 else if ( iLen == 10 && strncmp( pBuf, "NO CARRIER" , 10 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_NO_CARRIER ; }
3912 else if ( iLen == 5 && strncmp( pBuf, "ERROR" , 5 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_ERROR ; }
3913 else if ( iLen >= 8 && strncmp( pBuf, "CONNECT " , 8 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_CONNECT_X ; }
3914 else if ( iLen == 11 && strncmp( pBuf, "NO DAILTONE", 11 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_NO_DAILTONE ; }
3915 else if ( iLen == 4 && strncmp( pBuf, "BUSY" , 4 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_BUSY ; }
3916 else if ( iLen == 9 && strncmp( pBuf, "NO ANSWER" , 9 ) == 0 ) { up->iModemEvent = MODEM_EVENT_RESP_NO_ANSWER ; }
3917 else { up->iModemEvent = MODEM_EVENT_RESP_UNKNOWN ; }
3923 iCopyLen = ( iLen <= sizeof(sResp)-1 ? iLen : sizeof(sResp)-1 ) ;
3924 strncpy( sResp, pBuf, iLen <= sizeof(sResp)-1 ? iLen : sizeof(sResp)-1 ) ;
3926 printf ( "refclock_jjy.c : modem_receive : iLen=%zu pBuf=[%s] iModemEvent=%d\n", iCopyLen, sResp, up->iModemEvent ) ;
3929 modem_control ( peer, pp, up ) ;
3942 struct jjyunit *up ;
3944 pp = peer->procptr ;
3945 up = pp->unitptr ;
3949 if ( iModemSilentTimeout[up->iModemState] != 0 ) {
3950 up->iModemSilentTimer++ ;
3951 if ( iModemSilentTimeout[up->iModemState] <= up->iModemSilentTimer ) {
3952 up->iModemEvent = MODEM_EVENT_SILENT ;
3953 modem_control ( peer, pp, up ) ;
3957 if ( iModemStateTimeout[up->iModemState] != 0 ) {
3958 up->iModemStateTimer++ ;
3959 if ( iModemStateTimeout[up->iModemState] <= up->iModemStateTimer ) {
3960 up->iModemEvent = MODEM_EVENT_TIMEOUT ;
3961 modem_control ( peer, pp, up ) ;
3970 modem_control ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
3978 rc = (*pModemHandler[up->iModemEvent][up->iModemState])( peer, pp, up ) ;
3981 iPostEvent = iModemPostEvent[up->iModemEvent][up->iModemState] ;
3984 printf( "refclock_jjy.c : modem_control : iModemState=%d -> %d iPostEvent=%d\n",
3985 up->iModemState, iModemNextState[up->iModemEvent][up->iModemState], iPostEvent ) ;
3989 if ( up->iModemState != iModemNextState[up->iModemEvent][up->iModemState] ) {
3990 up->iModemSilentCount = 0 ;
3991 up->iModemStateTimer = 0 ;
3992 up->iModemCommandSeq = 0 ;
3995 up->iModemState = iModemNextState[up->iModemEvent][up->iModemState] ;
3999 up->iModemEvent = iPostEvent ;
4000 modem_control ( peer, pp, up ) ;
4003 up->iModemEvent = MODEM_EVENT_NULL ;
4009 modem_disc_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4020 modem_disc_init ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4031 modem_init_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4042 modem_init_start ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4047 up->iModemCommandSeq = 0 ;
4055 return modem_init_resp00( peer, pp, up ) ;
4061 modem_init_resp00 ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4072 up->iModemCommandSeq++ ;
4074 switch ( up->iModemCommandSeq ) {
4085 if ( ( pp->sloppyclockflag & CLK_FLAG3 ) == 0 ) {
4094 if ( ( pp->sloppyclockflag & CLK_FLAG4 ) == 0 ) {
4123 if ( ( pp->sloppyclockflag & CLK_FLAG2 ) == 0 ) {
4136 /* Hn = Hook 0:Hook-On ( Disconnect ) 1:Hook-Off ( Connect ) */
4155 if ( write( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) {
4169 modem_init_resp04 ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4174 return modem_init_resp00( peer, pp, up ) ;
4180 modem_init_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4196 modem_dial_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4207 modem_dial_dialout ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4217 if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) {
4230 if ( write( pp->io.fd, sCmd, iCmdLen ) != iCmdLen ) {
4242 modem_dial_escape ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4252 return modem_conn_escape( peer, pp, up ) ;
4258 modem_dial_connect ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4269 modem_dial_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4279 modem_esc_disc( peer, pp, up ) ;
4287 modem_conn_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4298 modem_conn_escape ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4309 modem_esc_ignore ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4320 modem_esc_escape ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4333 if ( write( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) {
4345 modem_esc_data ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4350 up->iModemSilentTimer = 0 ;
4358 modem_esc_silent ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4363 up->iModemSilentCount ++ ;
4365 if ( up->iModemSilentCount < iModemStateTimeout[up->iModemState] / iModemSilentTimeout[up->iModemState] ) {
4371 modem_esc_escape( peer, pp, up ) ;
4372 up->iModemSilentTimer = 0 ;
4381 return modem_esc_disc( peer, pp, up ) ;
4386 modem_esc_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
4399 if ( write( pp->io.fd, pCmd, iCmdLen ) != iCmdLen ) {
4430 pMark = "--> " ;
4433 pMark = "<-- " ;
4436 pMark = "--- " ;
4442 pMark = "-W- " ;
4445 pMark = "-X- " ;
4458 printableString( sLog+iMarkLen, sizeof(sLog)-iMarkLen, pData, iDataLen ) ;
4465 record_clock_stats( &peer->srcadr, sLog ) ;
4510 OutputLen - j ) ;
4515 snprintf( sOutput + j, OutputLen - j, "<x%X>",
4521 sOutput[min(j, (size_t)iOutputLen - 1)] = '\0' ;