📄 refclock_jjy.c
字号:
} pp->lastref = pp->lastrec; refclock_receive(peer);}/**************************************************************************************************/static intjjy_receive_tristate_jjy01 ( struct recvbuf *rbufp ){ static char *sFunctionName = "jjy_receive_tristate_jjy01" ; struct jjyunit *up ; struct refclockproc *pp ; struct peer *peer; char *pBuf ; int iLen ; int rc ; /* * Initialize pointers and read the timecode and timestamp */ peer = (struct peer *) rbufp->recv_srcclock ; pp = peer->procptr ; up = (struct jjyunit *) pp->unitptr ; if ( up->linediscipline == LDISC_RAW ) { pBuf = up->rawbuf ; iLen = up->charcount ; } else { pBuf = pp->a_lastcode ; iLen = pp->lencode ; } switch ( up->linecount ) { case 1 : /* YYYY/MM/DD WWW */ if ( iLen != 14 ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : Reply length error ( up->linecount=%d iLen=%d )\n", sFunctionName, up->linecount, iLen ) ; }#endif up->lineerror = 1 ; break ; } rc = sscanf ( pBuf, "%4d/%2d/%2d", &up->year, &up->month, &up->day ) ; if ( rc != 3 || up->year < 2000 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : Date error ( up->linecount=%d )\n", sFunctionName, up->linecount ) ; }#endif up->lineerror = 1 ; break ; } /*** Start of modification on 2004/10/31 */ /* * Following codes are moved from the function jjy_poll_tristate_jjy01 in this source. * The Tristate JJY-01 ( Firmware version 1.01 ) accepts "time" and "stim" commands without any delay. * But the JJY-01 ( Firmware version 2.01 ) does not accept these commands continuously, * so this driver issues the second command "stim" after the reply of the first command "date". */ /* * Send "stim<CR><LF>" or "time<CR><LF>" command */ if ( up->version >= 100 ) {#ifdef DEBUG if ( debug ) { printf ( "%s (refclock_jjy.c) : send 'stim<CR><LF>'\n", sFunctionName ) ; }#endif if ( write ( pp->io.fd, "stim\r\n",6 ) != 6 ) { refclock_report ( peer, CEVNT_FAULT ) ; } } else {#ifdef DEBUG if ( debug ) { printf ( "%s (refclock_jjy.c) : send 'time<CR><LF>'\n", sFunctionName ) ; }#endif if ( write ( pp->io.fd, "time\r\n",6 ) != 6 ) { refclock_report ( peer, CEVNT_FAULT ) ; } } /*** End of modification ***/ return 0 ; case 2 : /* HH:MM:SS */ if ( iLen != 8 ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : Reply length error ( up->linecount=%d iLen=%d )\n", sFunctionName, up->linecount, iLen ) ; }#endif up->lineerror = 1 ; break ; } rc = sscanf ( pBuf, "%2d:%2d:%2d", &up->hour, &up->minute, &up->second ) ; if ( rc != 3 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : Time error ( up->linecount=%d )\n", sFunctionName, up->linecount ) ; }#endif up->lineerror = 1 ; break ; } up->msecond = 0 ; if ( up->hour == 0 && up->minute == 0 && up->second <= 2 ) { /* * The command "date" and "time" ( or "stim" ) were sent to the JJY receiver continuously. * But the JJY receiver replies a date and time separately. * Just after midnight transitions, we ignore this time. */ return 0 ; } break ; default : /* Unexpected reply */ up->lineerror = 1 ; break ; } return 1 ;}/**************************************************************************************************/static intjjy_receive_cdex_jst2000 ( struct recvbuf *rbufp ){ static char *sFunctionName = "jjy_receive_cdex_jst2000" ; struct jjyunit *up ; struct refclockproc *pp ; struct peer *peer; char *pBuf ; int iLen ; int rc ; /* * Initialize pointers and read the timecode and timestamp */ peer = (struct peer *) rbufp->recv_srcclock ; pp = peer->procptr ; up = (struct jjyunit *) pp->unitptr ; if ( up->linediscipline == LDISC_RAW ) { pBuf = up->rawbuf ; iLen = up->charcount ; } else { pBuf = pp->a_lastcode ; iLen = pp->lencode ; } switch ( up->linecount ) { case 1 : /* JYYMMDD HHMMSSS */ if ( iLen != 15 ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : Reply length error ( iLen=%d )\n", sFunctionName, iLen ) ; }#endif up->lineerror = 1 ; break ; } rc = sscanf ( pBuf, "J%2d%2d%2d%*1d%2d%2d%2d%1d", &up->year, &up->month, &up->day, &up->hour, &up->minute, &up->second, &up->msecond ) ; if ( rc != 7 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : Time error (rc=%d) [ %02d %02d %02d * %02d %02d %02d.%1d ]\n", sFunctionName, rc, up->year, up->month, up->day, up->hour, up->minute, up->second, up->msecond ) ; }#endif up->lineerror = 1 ; break ; } up->year += 2000 ; up->msecond *= 100 ; break ; default : /* Unexpected reply */ up->lineerror = 1 ; break ; } return 1 ;}/**************************************************************************************************/static intjjy_receive_echokeisokuki_lt2000 ( struct recvbuf *rbufp ){ static char *sFunctionName = "jjy_receive_echokeisokuki_lt2000" ; struct jjyunit *up ; struct refclockproc *pp ; struct peer *peer; char *pBuf ; int iLen ; int rc ; int i, ibcc, ibcc1, ibcc2 ; /* * Initialize pointers and read the timecode and timestamp */ peer = (struct peer *) rbufp->recv_srcclock ; pp = peer->procptr ; up = (struct jjyunit *) pp->unitptr ; if ( up->linediscipline == LDISC_RAW ) { pBuf = up->rawbuf ; iLen = up->charcount ; } else { pBuf = pp->a_lastcode ; iLen = pp->lencode ; } switch ( up->linecount ) { case 1 : /* YYMMDDWHHMMSS<BCC1><BCC2> or YYMMDDWHHMMSS<ST1><ST2><ST3><ST4> */ if ( ( up->operationmode == 1 && iLen != 15 ) || ( up->operationmode == 2 && iLen != 17 ) ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : Reply length error ( iLen=%d )\n", sFunctionName, iLen ) ; }#endif if ( up->operationmode == 1 ) {#ifdef DEBUG if ( debug ) { printf ( "%s (refclock_jjy.c) : send '#'\n", sFunctionName ) ; }#endif if ( write ( pp->io.fd, "#",1 ) != 1 ) { refclock_report ( peer, CEVNT_FAULT ) ; } } up->lineerror = 1 ; break ; } if ( up->operationmode == 1 ) { for ( i = ibcc = 0 ; i < 13 ; i ++ ) ibcc ^= pBuf[i] ; ibcc1 = 0x30 | ( ( ibcc >> 4 ) & 0xF ) ; ibcc2 = 0x30 | ( ( ibcc ) & 0xF ) ; if ( pBuf[13] != ibcc1 || pBuf[14] != ibcc2 ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : BCC error ( Recv=%02X,%02X / Calc=%02X,%02X)\n", sFunctionName, pBuf[13]&0xFF, pBuf[14]&0xFF, ibcc1, ibcc2 ) ; }#endif up->lineerror = 1 ; break ; } } rc = sscanf ( pBuf, "%2d%2d%2d%*1d%2d%2d%2d", &up->year, &up->month, &up->day, &up->hour, &up->minute, &up->second ) ; if ( rc != 6 || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31 || up->hour > 23 || up->minute > 59 || up->second > 60 ) {#ifdef DEBUG if ( debug >= 2 ) { printf ( "%s (refclock_jjy.c) : Time error (rc=%d) [ %02d %02d %02d * %02d %02d %02d ]\n", sFunctionName, rc, up->year, up->month, up->day, up->hour, up->minute, up->second ) ; }#endif up->lineerror = 1 ; break ; } up->year += 2000 ; if ( up->operationmode == 2 ) { /* A time stamp comes on every 0.5 seccond in the mode 2 of the LT-2000. */ up->msecond = 500 ; pp->second -- ; if ( pp->second < 0 ) { pp->second = 59 ; pp->minute -- ; if ( pp->minute < 0 ) { pp->minute = 59 ; pp->hour -- ; if ( pp->hour < 0 ) { pp->hour = 23 ; pp->day -- ; if ( pp->day < 1 ) { pp->year -- ; pp->day = ymd2yd ( pp->year, 12, 31 ) ; } } } } /* Switch from mode 2 to mode 1 in order to restraint of useless time stamp. */#ifdef DEBUG if ( debug ) { printf ( "%s (refclock_jjy.c) : send '#'\n", sFunctionName ) ; }#endif if ( write ( pp->io.fd, "#",1 ) != 1 ) { refclock_report ( peer, CEVNT_FAULT ) ; } } break ; default : /* Unexpected reply */#ifdef DEBUG if ( debug ) { printf ( "%s (refclock_jjy.c) : send '#'\n", sFunctionName ) ; }#endif if ( write ( pp->io.fd, "#",1 ) != 1 ) { refclock_report ( peer, CEVNT_FAULT ) ; } up->lineerror = 1 ; break ; } return 1 ;}/**************************************************************************************************//* jjy_poll - called by the transmit procedure *//**************************************************************************************************/static voidjjy_poll ( int unit, struct peer *peer ){ struct jjyunit *up; struct refclockproc *pp; pp = peer->procptr; up = (struct jjyunit *) pp->unitptr ; if ( pp->polls > 0 && up->linecount == 0 ) { /* * No reply for last command */ refclock_report ( peer, CEVNT_TIMEOUT ) ; }#ifdef DEBUG if ( debug ) { printf ( "jjy_poll (refclock_jjy.c) : %ld\n", pp->polls ) ; }#endif pp->polls ++ ; up->linecount = 0 ; up->lineerror = 0 ; up->charcount = 0 ; switch ( up->unittype ) { case UNITTYPE_TRISTATE_JJY01 : jjy_poll_tristate_jjy01 ( unit, peer ) ; break ; case UNITTYPE_CDEX_JST2000 : jjy_poll_cdex_jst2000 ( unit, peer ) ; break ; case UNITTYPE_ECHOKEISOKUKI_LT2000 : jjy_poll_echokeisokuki_lt2000 ( unit, peer ) ; break ; default : break ; }}/**************************************************************************************************/static voidjjy_poll_tristate_jjy01 ( int unit, struct peer *peer ){ struct refclockproc *pp; pp = peer->procptr; /* * Send "date<CR><LF>" command */#ifdef DEBUG if ( debug ) { printf ( "jjy_poll_tristate_jjy01 (refclock_jjy.c) : send 'date<CR><LF>'\n" ) ; }#endif if ( write ( pp->io.fd, "date\r\n",6 ) != 6 ) { refclock_report ( peer, CEVNT_FAULT ) ; }}/**************************************************************************************************/static voidjjy_poll_cdex_jst2000 ( int unit, struct peer *peer ){ struct refclockproc *pp; pp = peer->procptr; /* * Send "<ENQ>1J<ETX>" command */#ifdef DEBUG if ( debug ) { printf ( "jjy_poll_cdex_jst2000 (refclock_jjy.c) : send '<ENQ>1J<ETX>'\n" ) ; }#endif if ( write ( pp->io.fd, "\0051J\003", 4 ) != 4 ) { refclock_report ( peer, CEVNT_FAULT ) ; }}/**************************************************************************************************/static voidjjy_poll_echokeisokuki_lt2000 ( int unit, struct peer *peer ){ struct jjyunit *up; struct refclockproc *pp; char sCmd[2] ; pp = peer->procptr; up = (struct jjyunit *) pp->unitptr ; /* * Send "T" or "C" command */ switch ( up->operationmode ) { case 1 : sCmd[0] = 'T' ; break ; case 2 : sCmd[0] = 'C' ; break ; } sCmd[1] = 0 ;#ifdef DEBUG if ( debug ) { printf ( "jjy_poll_echokeisokuki_lt2000 (refclock_jjy.c) : send '%s'\n", sCmd ) ; }#endif if ( write ( pp->io.fd, sCmd, 1 ) != 1 ) { refclock_report ( peer, CEVNT_FAULT ) ; }}#elseint refclock_jjy_bs ;#endif /* REFCLOCK */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -