refclock_jjy.c (ntp-4.2.8p14) | : | refclock_jjy.c (ntp-4.2.8p15) | ||
---|---|---|---|---|
/* | /* | |||
* refclock_jjy - clock driver for JJY receivers | * refclock_jjy - clock driver for JJY receivers | |||
*/ | */ | |||
/**********************************************************************/ | /**********************************************************************/ | |||
/* */ | /* */ | |||
/* Copyright (C) 2001-2015, Takao Abe. All rights reserved. */ | /* Copyright (C) 2001-2020, Takao Abe. All rights reserved. */ | |||
/* */ | /* */ | |||
/* Permission to use, copy, modify, and distribute this software */ | /* Permission to use, copy, modify, and distribute this software */ | |||
/* and its documentation for any purpose is hereby granted */ | /* and its documentation for any purpose is hereby granted */ | |||
/* without fee, provided that the following conditions are met: */ | /* without fee, provided that the following conditions are met: */ | |||
/* */ | /* */ | |||
/* One retains the entire copyright notice properly, and both the */ | /* One retains the entire copyright notice properly, and both the */ | |||
/* copyright notice and this license. in the documentation and/or */ | /* copyright notice and this license. in the documentation and/or */ | |||
/* other materials provided with the distribution. */ | /* other materials provided with the distribution. */ | |||
/* */ | /* */ | |||
/* This software and the name of the author must not be used to */ | /* This software and the name of the author must not be used to */ | |||
skipping to change at line 118 | skipping to change at line 118 | |||
/* */ | /* */ | |||
/* 2016/05/08 */ | /* 2016/05/08 */ | |||
/* [Fix] C-DEX JST2000 */ | /* [Fix] C-DEX JST2000 */ | |||
/* Thanks to Mr. Kuramatsu for the report and the patch. */ | /* Thanks to Mr. Kuramatsu for the report and the patch. */ | |||
/* */ | /* */ | |||
/* 2017/04/30 */ | /* 2017/04/30 */ | |||
/* [Change] Avoid a wrong report of the coverity static analysis */ | /* [Change] Avoid a wrong report of the coverity static analysis */ | |||
/* tool. ( The code is harmless and has no bug. ) */ | /* tool. ( The code is harmless and has no bug. ) */ | |||
/* teljjy_conn_send() */ | /* teljjy_conn_send() */ | |||
/* */ | /* */ | |||
/* 2020/01/19 */ | ||||
/* [Change] Handling TS-JJY01/02 status of the the STUS reply. */ | ||||
/* Time synchronization can be skipped by the settings of */ | ||||
/* the flag2 when the status of the reply is UNADJUSTED. */ | ||||
/* [Change] Quiet compilation for the GCC 9.2.0. */ | ||||
/* [Fix] Correct typos in comment lines */ | ||||
/* */ | ||||
/**********************************************************************/ | /**********************************************************************/ | |||
#ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | |||
#include <config.h> | #include <config.h> | |||
#endif | #endif | |||
#if defined(REFCLOCK) && defined(CLOCK_JJY) | #if defined(REFCLOCK) && defined(CLOCK_JJY) | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <ctype.h> | #include <ctype.h> | |||
skipping to change at line 197 | skipping to change at line 204 | |||
/* LDISC_RAW only */ | /* LDISC_RAW only */ | |||
char sRawBuf [ MAX_RAWBUF ] ; | char sRawBuf [ MAX_RAWBUF ] ; | |||
int iRawBufLen ; | int iRawBufLen ; | |||
struct jjyRawDataBreak *pRawBreak ; | struct jjyRawDataBreak *pRawBreak ; | |||
char bWaitBreakString ; | char bWaitBreakString ; | |||
char sLineBuf [ MAX_RAWBUF ] ; | char sLineBuf [ MAX_RAWBUF ] ; | |||
int iLineBufLen ; | int iLineBufLen ; | |||
char sTextBuf [ MAX_RAWBUF ] ; | char sTextBuf [ MAX_RAWBUF ] ; | |||
int iTextBufLen ; | int iTextBufLen ; | |||
char bSkipCntrlCharOnly ; | char bSkipCntrlCharOnly ; | |||
/* TS-JJY01, TS-JJY02 */ | ||||
time_t tLastAdjustedTimestamp ; | ||||
char bStusReplyAdjusted ; | ||||
char bStusReplyAdjustedAtLeastOnce ; | ||||
/* Telephone JJY auto measurement of the loopback delay */ | /* Telephone JJY auto measurement of the loopback delay */ | |||
char bLoopbackMode ; | char bLoopbackMode ; | |||
short iLoopbackCount ; | short iLoopbackCount ; | |||
struct timeval sendTime[MAX_LOOPBACK], delayTime[MAX_LOOPBACK] ; | struct timeval sendTime[MAX_LOOPBACK], delayTime[MAX_LOOPBACK] ; | |||
char bLoopbackTimeout[MAX_LOOPBACK] ; | char bLoopbackTimeout[MAX_LOOPBACK] ; | |||
short iLoopbackValidCount ; | short iLoopbackValidCount ; | |||
/* Telephone JJY timer */ | /* Telephone JJY timer */ | |||
short iTeljjySilentTimer ; | short iTeljjySilentTimer ; | |||
short iTeljjyStateTimer ; | short iTeljjyStateTimer ; | |||
/* Telephone JJY control finite state machine */ | /* Telephone JJY control finite state machine */ | |||
skipping to change at line 374 | skipping to change at line 385 | |||
/* | /* | |||
* Start up driver return code | * Start up driver return code | |||
*/ | */ | |||
#define RC_START_SUCCESS 1 | #define RC_START_SUCCESS 1 | |||
#define RC_START_ERROR 0 | #define RC_START_ERROR 0 | |||
/* | /* | |||
* Local constants definition | * Local constants definition | |||
*/ | */ | |||
#define MAX_LOGTEXT 100 | #define MAX_LOGTEXT 200 | |||
#ifndef TRUE | #ifndef TRUE | |||
#define TRUE (0==0) | #define TRUE (0==0) | |||
#endif | #endif | |||
#ifndef FALSE | #ifndef FALSE | |||
#define FALSE (!TRUE) | #define FALSE (!TRUE) | |||
#endif | #endif | |||
/* Local constants definition for the return code of the jjy_receive_xxxxxxxx */ | /* Local constants definition for the return code of the jjy_receive_xxxxxxxx */ | |||
skipping to change at line 413 | skipping to change at line 424 | |||
/* Local constants definition for the clockstats messages */ | /* Local constants definition for the clockstats messages */ | |||
#define JJY_CLOCKSTATS_MESSAGE_ECHOBACK "* Echoback" | #define JJY_CLOCKSTATS_MESSAGE_ECHOBACK "* Echoback" | |||
#define JJY_CLOCKSTATS_MESSAGE_IGNORE_REPLY "* Ignore replay : [%s]" | #define JJY_CLOCKSTATS_MESSAGE_IGNORE_REPLY "* Ignore replay : [%s]" | |||
#define JJY_CLOCKSTATS_MESSAGE_OVER_MIDNIGHT_2 "* Over midnight : timestamp=%d, %d" | #define JJY_CLOCKSTATS_MESSAGE_OVER_MIDNIGHT_2 "* Over midnight : timestamp=%d, %d" | |||
#define JJY_CLOCKSTATS_MESSAGE_OVER_MIDNIGHT_3 "* Over midnight : timestamp=%d, %d, %d" | #define JJY_CLOCKSTATS_MESSAGE_OVER_MIDNIGHT_3 "* Over midnight : timestamp=%d, %d, %d" | |||
#define JJY_CLOCKSTATS_MESSAGE_TIMESTAMP_UNSURE "* Unsure timesta mp : %s" | #define JJY_CLOCKSTATS_MESSAGE_TIMESTAMP_UNSURE "* Unsure timesta mp : %s" | |||
#define JJY_CLOCKSTATS_MESSAGE_LOOPBACK_DELAY "* Loopback delay : %d.%03d mSec." | #define JJY_CLOCKSTATS_MESSAGE_LOOPBACK_DELAY "* Loopback delay : %d.%03d mSec." | |||
#define JJY_CLOCKSTATS_MESSAGE_DELAY_ADJUST "* Delay adjustme nt : %d mSec. ( valid=%hd/%d )" | #define JJY_CLOCKSTATS_MESSAGE_DELAY_ADJUST "* Delay adjustme nt : %d mSec. ( valid=%hd/%d )" | |||
#define JJY_CLOCKSTATS_MESSAGE_DELAY_UNADJUST "* Delay adjustme nt : None ( valid=%hd/%d )" | #define JJY_CLOCKSTATS_MESSAGE_DELAY_UNADJUST "* Delay adjustme nt : None ( valid=%hd/%d )" | |||
#define JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED "* Skip time sync hronization : STUS is 'UNADJUSTED' for %.0lf %s" | ||||
#define JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY "# Unexpected rep ly : [%s]" | #define JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY "# Unexpected rep ly : [%s]" | |||
#define JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH "# Invalid length : length=%d" | #define JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH "# Invalid length : length=%d" | |||
#define JJY_CLOCKSTATS_MESSAGE_TOO_MANY_REPLY "# Too many reply : count=%d" | #define JJY_CLOCKSTATS_MESSAGE_TOO_MANY_REPLY "# Too many reply : count=%d" | |||
#define JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY "# Invalid reply : [%s]" | #define JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY "# Invalid reply : [%s]" | |||
#define JJY_CLOCKSTATS_MESSAGE_SLOW_REPLY_2 "# Slow reply : t imestamp=%d, %d" | #define JJY_CLOCKSTATS_MESSAGE_SLOW_REPLY_2 "# Slow reply : t imestamp=%d, %d" | |||
#define JJY_CLOCKSTATS_MESSAGE_SLOW_REPLY_3 "# Slow reply : t imestamp=%d, %d, %d" | #define JJY_CLOCKSTATS_MESSAGE_SLOW_REPLY_3 "# Slow reply : t imestamp=%d, %d, %d" | |||
#define JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATE "# Invalid date : rc=%d year=%d month=%d day=%d" | #define JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATE "# Invalid date : rc=%d year=%d month=%d day=%d" | |||
#define JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME "# Invalid time : rc=%d hour=%d minute=%d second=%d" | #define JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_TIME "# Invalid time : rc=%d hour=%d minute=%d second=%d" | |||
#define JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME "# Invalid time : rc=%d year=%d month=%d day=%d hour=%d minute=%d second=%d" | #define JJY_CLOCKSTATS_MESSAGE_SSCANF_INVALID_DATETIME "# Invalid time : rc=%d year=%d month=%d day=%d hour=%d minute=%d second=%d" | |||
skipping to change at line 622 | skipping to change at line 634 | |||
* Get next input line | * Get next input line | |||
*/ | */ | |||
if ( up->linediscipline == LDISC_RAW ) { | if ( up->linediscipline == LDISC_RAW ) { | |||
pp->lencode = refclock_gtraw ( rbufp, pp->a_lastcode, BMAX-1, &t RecvTimestamp ) ; | pp->lencode = refclock_gtraw ( rbufp, pp->a_lastcode, BMAX-1, &t RecvTimestamp ) ; | |||
/* 3rd argument can be BMAX, but the coverity scan tool claim "Me mory - corruptions (OVERRUN)" */ | /* 3rd argument can be BMAX, but the coverity scan tool claim "Me mory - corruptions (OVERRUN)" */ | |||
/* "a_lastcode" is defined as "char a_lastcode[BMAX]" in the ntp_ refclock.h */ | /* "a_lastcode" is defined as "char a_lastcode[BMAX]" in the ntp_ refclock.h */ | |||
/* To avoid its claim, pass the value BMAX-1. */ | /* To avoid its claim, pass the value BMAX-1. */ | |||
/* | /* | |||
* Append received charaters to temporary buffer | * Append received characters to temporary buffer | |||
*/ | */ | |||
for ( i = 0 ; | for ( i = 0 ; | |||
i < pp->lencode && up->iRawBufLen < MAX_RAWBUF - 2 ; | i < pp->lencode && up->iRawBufLen < MAX_RAWBUF - 2 ; | |||
i ++ , up->iRawBufLen ++ ) { | i ++ , up->iRawBufLen ++ ) { | |||
up->sRawBuf[up->iRawBufLen] = pp->a_lastcode[i] ; | up->sRawBuf[up->iRawBufLen] = pp->a_lastcode[i] ; | |||
} | } | |||
up->sRawBuf[up->iRawBufLen] = 0 ; | up->sRawBuf[up->iRawBufLen] = 0 ; | |||
} else { | } else { | |||
skipping to change at line 705 | skipping to change at line 717 | |||
break ; | break ; | |||
} else { | } else { | |||
/* Temporary buffer is full */ | /* Temporary buffer is full */ | |||
iBreakPosition = up->iRawBufLen - 1 ; | iBreakPosition = up->iRawBufLen - 1 ; | |||
} | } | |||
} | } | |||
} else { | } else { | |||
iBreakPosition = up->iRawBufLen - 1 ; | iBreakPosition = up->iRawBufLen - 1 ; | |||
} | } | |||
/* Copy charaters from temporary buffer to process buffer */ | /* Copy characters from temporary buffer to process buffe r */ | |||
up->iLineBufLen = up->iTextBufLen = 0 ; | up->iLineBufLen = up->iTextBufLen = 0 ; | |||
for ( i = iReadRawBuf ; i <= iBreakPosition ; i ++ ) { | for ( i = iReadRawBuf ; i <= iBreakPosition ; i ++ ) { | |||
/* Copy all characters */ | /* Copy all characters */ | |||
up->sLineBuf[up->iLineBufLen] = up->sRawBuf[i] ; | up->sLineBuf[up->iLineBufLen] = up->sRawBuf[i] ; | |||
up->iLineBufLen ++ ; | up->iLineBufLen ++ ; | |||
/* Copy printable characters */ | /* Copy printable characters */ | |||
if ( ! iscntrl( (u_char)up->sRawBuf[i] ) ) { | if ( ! iscntrl( (u_char)up->sRawBuf[i] ) ) { | |||
up->sTextBuf[up->iTextBufLen] = up->sRawB uf[i] ; | up->sTextBuf[up->iTextBufLen] = up->sRawB uf[i] ; | |||
skipping to change at line 1153 | skipping to change at line 1165 | |||
static int | static int | |||
jjy_start_tristate_jjy01 ( int unit, struct peer *peer, struct jjyunit *up ) | jjy_start_tristate_jjy01 ( int unit, struct peer *peer, struct jjyunit *up ) | |||
{ | { | |||
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: Tristate Ltd. TS-JJY01, TS-JJY02" ) ; | jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, "Refclock: Tristate Ltd. TS-JJY01, TS-JJY02" ) ; | |||
up->unittype = UNITTYPE_TRISTATE_JJY01 ; | up->unittype = UNITTYPE_TRISTATE_JJY01 ; | |||
up->linespeed = SPEED232_TRISTATE_JJY01 ; | up->linespeed = SPEED232_TRISTATE_JJY01 ; | |||
up->linediscipline = LDISC_CLK ; | up->linediscipline = LDISC_CLK ; | |||
time( &(up->tLastAdjustedTimestamp) ) ; | ||||
up->bStusReplyAdjustedAtLeastOnce = FALSE ; | ||||
return 0 ; | return 0 ; | |||
} | } | |||
/******************************************************************************* *******************/ | /******************************************************************************* *******************/ | |||
static int | static int | |||
jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp ) | jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp ) | |||
{ | { | |||
struct jjyunit *up ; | struct jjyunit *up ; | |||
struct refclockproc *pp ; | struct refclockproc *pp ; | |||
struct peer *peer; | struct peer *peer; | |||
char * pBuf ; | char * pBuf ; | |||
char sLog [ 100 ] ; | char sLog [ MAX_LOGTEXT ] ; | |||
int iLen ; | int iLen ; | |||
int rc ; | int rc ; | |||
time_t now ; | ||||
double fSeconds ; | ||||
const char * pCmd ; | const char * pCmd ; | |||
int iCmdLen ; | int iCmdLen ; | |||
/* Initialize pointers */ | /* Initialize pointers */ | |||
peer = rbufp->recv_peer ; | peer = rbufp->recv_peer ; | |||
pp = peer->procptr ; | pp = peer->procptr ; | |||
up = pp->unitptr ; | up = pp->unitptr ; | |||
skipping to change at line 1271 | skipping to change at line 1288 | |||
up->iTimestampCount++ ; | up->iTimestampCount++ ; | |||
up->msecond = 0 ; | up->msecond = 0 ; | |||
break ; | break ; | |||
case TS_JJY01_COMMAND_NUMBER_STUS : | case TS_JJY01_COMMAND_NUMBER_STUS : | |||
if ( strncmp( pBuf, TS_JJY01_REPLY_STUS_ADJUSTED, | if ( strncmp( pBuf, TS_JJY01_REPLY_STUS_ADJUSTED, | |||
TS_JJY01_REPLY_LENGTH_STUS_ADJUSTED ) == 0 | TS_JJY01_REPLY_LENGTH_STUS_ADJUSTED ) == 0 ) { | |||
|| strncmp( pBuf, TS_JJY01_REPLY_STUS_UNADJUSTED, | /* STUS reply : adjusted */ | |||
TS_JJY01_REPLY_LENGTH_STUS_UNADJUSTED ) == 0 ) { | up->bStusReplyAdjusted = TRUE ; | |||
/* Good */ | up->bStusReplyAdjustedAtLeastOnce = TRUE ; | |||
time( &(up->tLastAdjustedTimestamp) ) ; | ||||
} else if ( strncmp( pBuf, TS_JJY01_REPLY_STUS_UNADJUSTED, | ||||
TS_JJY01_REPLY_LENGTH_STUS_UNADJUSTED ) == 0 | ||||
) { | ||||
/* STUS reply : unadjusted */ | ||||
up->bStusReplyAdjusted = FALSE ; | ||||
} else { | } else { | |||
/* Bad reply */ | ||||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_IN VALID_REPLY, | snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_IN VALID_REPLY, | |||
pBuf ) ; | pBuf ) ; | |||
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sL og ) ; | jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sL og ) ; | |||
up->bLineError = TRUE ; | up->bLineError = TRUE ; | |||
return JJY_RECEIVE_ERROR ; | return JJY_RECEIVE_ERROR ; | |||
} | } | |||
break ; | break ; | |||
case TS_JJY01_COMMAND_NUMBER_DCST : | case TS_JJY01_COMMAND_NUMBER_DCST : | |||
if ( strncmp( pBuf, TS_JJY01_REPLY_DCST_VALID, | if ( strncmp( pBuf, TS_JJY01_REPLY_DCST_VALID, | |||
TS_JJY01_REPLY_LENGTH_DCST_VALID ) == 0 | TS_JJY01_REPLY_LENGTH_DCST_VALID ) == 0 | |||
|| strncmp( pBuf, TS_JJY01_REPLY_DCST_INVALID, | || strncmp( pBuf, TS_JJY01_REPLY_DCST_INVALID, | |||
TS_JJY01_REPLY_LENGTH_DCST_INVALID ) == 0 ) { | TS_JJY01_REPLY_LENGTH_DCST_INVALID ) == 0 ) { | |||
/* Good */ | /* Valid reply */ | |||
} else { | } else { | |||
/* Bad reply */ | ||||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_IN VALID_REPLY, | snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_IN VALID_REPLY, | |||
pBuf ) ; | pBuf ) ; | |||
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sL og ) ; | jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sL og ) ; | |||
up->bLineError = TRUE ; | up->bLineError = TRUE ; | |||
return JJY_RECEIVE_ERROR ; | return JJY_RECEIVE_ERROR ; | |||
} | } | |||
break ; | break ; | |||
default : /* Unexpected reply */ | default : /* Unexpected reply */ | |||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_RE PLY, | snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_RE PLY, | |||
pBuf ) ; | pBuf ) ; | |||
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sLog ) ; | jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sLog ) ; | |||
up->bLineError = TRUE ; | up->bLineError = TRUE ; | |||
return JJY_RECEIVE_ERROR ; | return JJY_RECEIVE_ERROR ; | |||
} | } | |||
if ( up->iTimestampCount == 2 ) { | if ( up->iTimestampCount == 2 ) { | |||
/* Process date and time */ | /* Process date and time */ | |||
if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0] | time( &now ) ; | |||
&& up->iTimestamp[0] <= up->iTimestamp[1] ) { | fSeconds = difftime( now, up->tLastAdjustedTimestamp ) ; | |||
/* 3 commands (time,date,stim) was excuted in two seconds | ||||
*/ | if ( ( pp->sloppyclockflag & CLK_FLAG2 ) != 0 | |||
&& ( ! up->bStusReplyAdjusted ) | ||||
&& ( fSeconds >= ( pp->fudgetime2 * 3600 ) || ( ! up->bStusRepl | ||||
yAdjustedAtLeastOnce ) ) ) { | ||||
/* STUS is not ADJUSTED */ | ||||
if ( fSeconds < 60 ) { | ||||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_ME | ||||
SSAGE_STUS_UNADJUSTED, fSeconds, "seconds" ) ; | ||||
} else if ( fSeconds < 3600 ) { | ||||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_ME | ||||
SSAGE_STUS_UNADJUSTED, fSeconds / 60, "minutes" ) ; | ||||
} else if ( fSeconds < 86400 ) { | ||||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_ME | ||||
SSAGE_STUS_UNADJUSTED, fSeconds / 3600, "hours" ) ; | ||||
} else { | ||||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_ME | ||||
SSAGE_STUS_UNADJUSTED, fSeconds / 86400, "days" ) ; | ||||
} | ||||
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_INFORMATI | ||||
ON, sLog ) ; | ||||
return JJY_RECEIVE_SKIP ; | ||||
} else if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0] | ||||
&& up->iTimestamp[0] <= up->iTimestamp[1] ) { | ||||
/* 3 commands (time,date,stim) was executed in two second | ||||
s */ | ||||
jjy_synctime( peer, pp, up ) ; | jjy_synctime( peer, pp, up ) ; | |||
return JJY_RECEIVE_DONE ; | return JJY_RECEIVE_DONE ; | |||
} else if ( up->iTimestamp[0] > up->iTimestamp[1] ) { | } else if ( up->iTimestamp[0] > up->iTimestamp[1] ) { | |||
/* Over midnight, and date is unsure */ | /* Over midnight, and date is unsure */ | |||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_OV ER_MIDNIGHT_2, | snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_OV ER_MIDNIGHT_2, | |||
up->iTimestamp[0], up->iTimestamp[1] ) ; | up->iTimestamp[0], up->iTimestamp[1] ) ; | |||
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_INFORMATI ON, sLog ) ; | jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_INFORMATI ON, sLog ) ; | |||
return JJY_RECEIVE_SKIP ; | return JJY_RECEIVE_SKIP ; | |||
} else { | } else { | |||
/* Slow reply */ | /* Slow reply */ | |||
skipping to change at line 1387 | skipping to change at line 1429 | |||
up->bLineError = FALSE ; | up->bLineError = FALSE ; | |||
up->iTimestampCount = 0 ; | up->iTimestampCount = 0 ; | |||
if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) { | if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) { | |||
/* Skip "dcst" and "stus" commands */ | /* Skip "dcst" and "stus" commands */ | |||
up->iCommandSeq = 2 ; | up->iCommandSeq = 2 ; | |||
up->iLineCount = 2 ; | up->iLineCount = 2 ; | |||
} | } | |||
up->bStusReplyAdjusted = FALSE ; | ||||
#ifdef DEBUG | #ifdef DEBUG | |||
if ( debug ) { | if ( debug ) { | |||
printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCo unt=%d\n", | printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCo unt=%d\n", | |||
sFunctionName, pp->sloppyclockflag, CLK_FLAG1, | sFunctionName, pp->sloppyclockflag, CLK_FLAG1, | |||
up->iLineCount ) ; | up->iLineCount ) ; | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* Send a first command | * Send a first command | |||
skipping to change at line 1423 | skipping to change at line 1467 | |||
/*## ##*/ | /*## ##*/ | |||
/*## The C-DEX Co. Ltd. JJY receiver JST2000 ##*/ | /*## The C-DEX Co. Ltd. JJY receiver JST2000 ##*/ | |||
/*## ##*/ | /*## ##*/ | |||
/*## server 127.127.40.X mode 2 ##*/ | /*## server 127.127.40.X mode 2 ##*/ | |||
/*## ##*/ | /*## ##*/ | |||
/*############################################################################## ##################*/ | /*############################################################################## ##################*/ | |||
/*############################################################################## ##################*/ | /*############################################################################## ##################*/ | |||
/* */ | /* */ | |||
/* Command Response Remarks */ | /* Command Response Remarks */ | |||
/* -------------------- ---------------------------------------- ------------ ---------------- */ | /* -------------------- ---------------------------------------- ------------ ---------------- */ | |||
/* <ENQ>1J<ETX> <STX>JYYMMDD HHMMSSS<ETX> J is a fixed character */ | /* <ENQ>1J<ETX> <STX>JYYMMDDWHHMMSSS<ETX> J is a fixed character */ | |||
/* */ | /* */ | |||
/*############################################################################## ##################*/ | /*############################################################################## ##################*/ | |||
static struct jjyRawDataBreak cdex_jst2000_raw_break [ ] = | static struct jjyRawDataBreak cdex_jst2000_raw_break [ ] = | |||
{ | { | |||
{ "\x03", 1 }, { NULL, 0 } | { "\x03", 1 }, { NULL, 0 } | |||
} ; | } ; | |||
/******************************************************************************* *******************/ | /******************************************************************************* *******************/ | |||
skipping to change at line 1463 | skipping to change at line 1507 | |||
/******************************************************************************* *******************/ | /******************************************************************************* *******************/ | |||
static int | static int | |||
jjy_receive_cdex_jst2000 ( struct recvbuf *rbufp ) | jjy_receive_cdex_jst2000 ( struct recvbuf *rbufp ) | |||
{ | { | |||
struct jjyunit *up ; | struct jjyunit *up ; | |||
struct refclockproc *pp ; | struct refclockproc *pp ; | |||
struct peer *peer ; | struct peer *peer ; | |||
char *pBuf, sLog [ 100 ] ; | char *pBuf, sLog [ MAX_LOGTEXT ] ; | |||
int iLen ; | int iLen ; | |||
int rc ; | int rc ; | |||
/* Initialize pointers */ | /* Initialize pointers */ | |||
peer = rbufp->recv_peer ; | peer = rbufp->recv_peer ; | |||
pp = peer->procptr ; | pp = peer->procptr ; | |||
up = pp->unitptr ; | up = pp->unitptr ; | |||
if ( up->linediscipline == LDISC_RAW ) { | if ( up->linediscipline == LDISC_RAW ) { | |||
skipping to change at line 1947 | skipping to change at line 1991 | |||
/*############################################################################## ##################*/ | /*############################################################################## ##################*/ | |||
/*############################################################################## ##################*/ | /*############################################################################## ##################*/ | |||
/*## ##*/ | /*## ##*/ | |||
/*## The Tristate Ltd. GPS clock TS-GPS01 ##*/ | /*## The Tristate Ltd. GPS clock TS-GPS01 ##*/ | |||
/*## ##*/ | /*## ##*/ | |||
/*## server 127.127.40.X mode 5 ##*/ | /*## server 127.127.40.X mode 5 ##*/ | |||
/*## ##*/ | /*## ##*/ | |||
/*############################################################################## ##################*/ | /*############################################################################## ##################*/ | |||
/*############################################################################## ##################*/ | /*############################################################################## ##################*/ | |||
/* */ | /* */ | |||
/* This clock has NMEA mode and command/respose mode. | /* This clock has NMEA mode and command/response mode. | |||
*/ | */ | |||
/* When this jjy driver are used, set to command/respose mode of this clock | /* When this jjy driver are used, set to command/response mode of this clock | |||
*/ | */ | |||
/* by the onboard switch SW4, and make sure the LED-Y is tured on. */ | /* by the onboard switch SW4, and make sure the LED-Y is tured on. */ | |||
/* Other than this JJY driver, the refclock driver type 20, generic NMEA driver , */ | /* Other than this JJY driver, the refclock driver type 20, generic NMEA driver , */ | |||
/* works with the NMEA mode of this clock. */ | /* works with the NMEA mode of this clock. */ | |||
/* */ | /* */ | |||
/* Command Response Remarks */ | /* Command Response Remarks */ | |||
/* -------------------- ---------------------------------------- ------------ ---------------- */ | /* -------------------- ---------------------------------------- ------------ ---------------- */ | |||
/* stus<CR><LF> *R|*G|*U|+U<CR><LF> */ | /* stus<CR><LF> *R|*G|*U|+U<CR><LF> */ | |||
/* date<CR><LF> YY/MM/DD<CR><LF> */ | /* date<CR><LF> YY/MM/DD<CR><LF> */ | |||
/* time<CR><LF> HH:MM:SS<CR><LF> */ | /* time<CR><LF> HH:MM:SS<CR><LF> */ | |||
/* */ | /* */ | |||
skipping to change at line 2023 | skipping to change at line 2067 | |||
{ | { | |||
#ifdef DEBUG | #ifdef DEBUG | |||
static const char *sFunctionName = "jjy_receive_tristate_gpsclock01 " ; | static const char *sFunctionName = "jjy_receive_tristate_gpsclock01 " ; | |||
#endif | #endif | |||
struct jjyunit *up ; | struct jjyunit *up ; | |||
struct refclockproc *pp ; | struct refclockproc *pp ; | |||
struct peer *peer; | struct peer *peer; | |||
char * pBuf ; | char * pBuf ; | |||
char sLog [ 100 ] ; | char sLog [ MAX_LOGTEXT ] ; | |||
int iLen ; | int iLen ; | |||
int rc ; | int rc ; | |||
const char * pCmd ; | const char * pCmd ; | |||
int iCmdLen ; | int iCmdLen ; | |||
/* Initialize pointers */ | /* Initialize pointers */ | |||
peer = rbufp->recv_peer ; | peer = rbufp->recv_peer ; | |||
pp = peer->procptr ; | pp = peer->procptr ; | |||
skipping to change at line 2190 | skipping to change at line 2234 | |||
up->bLineError = TRUE ; | up->bLineError = TRUE ; | |||
return JJY_RECEIVE_ERROR ; | return JJY_RECEIVE_ERROR ; | |||
} | } | |||
if ( up->iTimestampCount == 2 ) { | if ( up->iTimestampCount == 2 ) { | |||
/* Process date and time */ | /* Process date and time */ | |||
if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0] | if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0] | |||
&& up->iTimestamp[0] <= up->iTimestamp[1] ) { | && up->iTimestamp[0] <= up->iTimestamp[1] ) { | |||
/* 3 commands (time,date,stim) was excuted in two seconds */ | /* 3 commands (time,date,stim) was executed in two second s */ | |||
jjy_synctime( peer, pp, up ) ; | jjy_synctime( peer, pp, up ) ; | |||
return JJY_RECEIVE_DONE ; | return JJY_RECEIVE_DONE ; | |||
} else if ( up->iTimestamp[0] > up->iTimestamp[1] ) { | } else if ( up->iTimestamp[0] > up->iTimestamp[1] ) { | |||
/* Over midnight, and date is unsure */ | /* Over midnight, and date is unsure */ | |||
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_OV ER_MIDNIGHT_2, | snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_OV ER_MIDNIGHT_2, | |||
up->iTimestamp[0], up->iTimestamp[1] ) ; | up->iTimestamp[0], up->iTimestamp[1] ) ; | |||
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_INFORMATI ON, sLog ) ; | jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_INFORMATI ON, sLog ) ; | |||
return JJY_RECEIVE_SKIP ; | return JJY_RECEIVE_SKIP ; | |||
} else { | } else { | |||
/* Slow reply */ | /* Slow reply */ | |||
skipping to change at line 2345 | skipping to change at line 2389 | |||
/******************************************************************************* *******************/ | /******************************************************************************* *******************/ | |||
static int | static int | |||
jjy_receive_seiko_tsys_tdc_300 ( struct recvbuf *rbufp ) | jjy_receive_seiko_tsys_tdc_300 ( struct recvbuf *rbufp ) | |||
{ | { | |||
struct peer *peer; | struct peer *peer; | |||
struct refclockproc *pp ; | struct refclockproc *pp ; | |||
struct jjyunit *up ; | struct jjyunit *up ; | |||
char *pBuf, sLog [ 100 ] ; | char *pBuf, sLog [ MAX_LOGTEXT ] ; | |||
int iLen, i ; | int iLen, i ; | |||
int rc, iWeekday ; | int rc, iWeekday ; | |||
time_t now ; | time_t now ; | |||
struct tm *pTime ; | struct tm *pTime ; | |||
/* Initialize pointers */ | /* Initialize pointers */ | |||
peer = rbufp->recv_peer ; | peer = rbufp->recv_peer ; | |||
pp = peer->procptr ; | pp = peer->procptr ; | |||
up = pp->unitptr ; | up = pp->unitptr ; | |||
skipping to change at line 3403 | skipping to change at line 3447 | |||
} | } | |||
/******************************/ | /******************************/ | |||
static int | static int | |||
teljjy_conn_data ( struct peer *peer, struct refclockproc *pp, struct jjyunit *u p ) | teljjy_conn_data ( struct peer *peer, struct refclockproc *pp, struct jjyunit *u p ) | |||
{ | { | |||
char *pBuf ; | char *pBuf ; | |||
int iLen, rc ; | int iLen, rc ; | |||
char sLog [ 80 ] ; | char sLog [ MAX_LOGTEXT ] ; | |||
char bAdjustment ; | char bAdjustment ; | |||
DEBUG_TELJJY_PRINTF( "teljjy_conn_data" ) ; | DEBUG_TELJJY_PRINTF( "teljjy_conn_data" ) ; | |||
if ( up->linediscipline == LDISC_RAW ) { | if ( up->linediscipline == LDISC_RAW ) { | |||
pBuf = up->sTextBuf ; | pBuf = up->sTextBuf ; | |||
iLen = up->iTextBufLen ; | iLen = up->iTextBufLen ; | |||
} else { | } else { | |||
pBuf = pp->a_lastcode ; | pBuf = pp->a_lastcode ; | |||
iLen = pp->lencode ; | iLen = pp->lencode ; | |||
End of changes. 24 change blocks. | ||||
30 lines changed or deleted | 81 lines changed or added |