]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
driver40.html, refclock_jjy.c, driver40-ja.html, ChangeLog:
authorTakao Abe <abe@ntp.org>
Tue, 21 Jan 2020 12:49:14 +0000 (12:49 +0000)
committerTakao Abe <abe@ntp.org>
Tue, 21 Jan 2020 12:49:14 +0000 (12:49 +0000)
  refclock_jjy: TS-JJY0x can skip time sync depending on the STUS reply.

bk: 5e26f34aMwjpV9EcOO9QYN-9NrqGng

ChangeLog
html/drivers/driver40-ja.html
html/drivers/driver40.html
ntpd/refclock_jjy.c

index 9ff845c81028eeecbd72fd587d28555bc5f781e5..9bce224af36aae1ef45f5c7548e3254ddcf515f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+* [Bug 3639] refclock_jjy: TS-JJY0x can skip time sync depending on the STUS reply. <abe@ntp.org>
+  - applied patch by Takao Abe
+
 ---
 (4.2.8p13) 2019/03/07 Released by Harlan Stenn <stenn@ntp.org>
 
index 99ca4827dfa170c5ce20a6920900402c3570bf3d..8b24fdc9b1c1472ccf3d82f75a95cd9ca28139e0 100644 (file)
                                                <dl>
                                                        <dt>server &nbsp; 127.127.40.X &nbsp; mode 1</dt>
                                                        <dd><br></dd>
-                                                       <dt>fudge &nbsp; 127.127.40.X &nbsp; time1 0.NNN &nbsp; flag1 0|1</dt>
+                                                       <dt>fudge &nbsp; 127.127.40.X &nbsp; time1 0.NNN &nbsp; flag1 0|1 &nbsp; flag2 0|1 &nbsp; time2 H</dt>
                                                        <dd>
                                                                <p>Time1 は、受信機からの時刻に加算する調整時間を、固定小数点形式の秒で設定します。<br>
                                                                この受信機には、数10ミリ秒 ( 0.0NN秒 ) から百数10ミリ秒 ( 0.1NN秒 ) の調整時間を設定すると良いでしょう。</p>
-                                                               <p>Flag1 は、時刻同期には無関係です。Flag1 を 1 に設定すると、状態を問い合わせるコマンドを DATE コマンドと STIM コマンドの前に発行して、応答を clockstats ファイルに記録します。</p>
+                                                               <p>Time2 は、STUSコマンドの応答が adjusted ではなくなってからの猶予時間を時単位で指定します。<br>
+                                                               この猶予時間は、flag1 と flag2 を共に 1 に設定したときに有効です。</p>
+                                                               <p>Flag1 は、flag2 を 1 に設定しない限り、時刻同期には無関係です。Flag1 を 1 に設定すると、状態を問い合わせるコマンドを DATE コマンドと STIM コマンドの前に発行して、応答を clockstats ファイルに記録します。</p>
                                                                <table border="1" summary="fudge flag1">
                                                                        <tr><td>0 (Default)</td><td>DCST と STUS コマンドは、発行しません。</td></tr>
                                                                        <tr><td>1</td><td>DCST と STUS コマンドを、発行します。</td></tr>
                                                                </table>
+                                                               <p>Flag2 は STUSコマンドの応答が adjusted の時だけ、時刻同期処理を行う指定です。この機能を使うときは、flag1 も同時に 1 に設定する必要があります。</p>
+                                                               <table border="1" summary="fudge flag2">
+                                                                       <tr><td>0 (Default)</td><td>常に、時刻同期処理</td></tr>
+                                                                       <tr><td>1</td><td>adjusted の時だ、け時刻同期委処理</td></tr>
+                                                               </table>
                                                        </dd>
                                                </dl>
                                                <br>
 
                        <li>
                                <p><a name="mode-4">シチズンTIC &nbsp; JJY-200</a> &nbsp; <a href="http://www.tic-citizen.co.jp/">http://www.tic-citizen.co.jp/</a> (日本語)</p><br>
+                               <p>JJY-200 は、2013年に販売終了となりました。</p><br>
                                <dl>
                                        <dt>NTPの設定 ( ntp.conf )</dt>
                                        <dd><br>
index 827aeff4ea19b8722e2999a9a02c15374dd5e215..24ced93c3a7a6a17f4ce180f29e5b186d8bf3d4d 100644 (file)
                                                <dl>
                                                        <dt>server &nbsp; 127.127.40.X &nbsp; mode 1</dt>
                                                        <dd><br></dd>
-                                                       <dt>fudge &nbsp; 127.127.40.X &nbsp; time1 0.NNN &nbsp; flag1 0|1</dt>
+                                                       <dt>fudge &nbsp; 127.127.40.X &nbsp; time1 0.NNN &nbsp; flag1 0|1 &nbsp; flag2 0|1 &nbsp; time2 H</dt>
                                                        <dd>
                                                                <p>Time1 may specify a constant to be added to the time offset for the time from the receiver, a fixed-point decimal number in seconds. You may specify the time offset from several tens of milli-seconds ( 0.0NN seconds ) to a hundred and several tens of milli-seconds  ( 0.1NN seconds ) for this clock.</p>
-                                                               <p>Flag1 has no effect for time synchronization. When flag1 is set to 1, status commands are issued before DATE and STIM commands, and write a response text into the clockstats file.</p>
+                                                               <p>Time2 may specify a grace period in hours after the 'adjusted' reply of the STUS command stopped coming.<br>This hours is effective when both flag1 and flag2 are set to 1.</p>
+                                                               <p>Flag1 has no effect for time synchronization unless flag2 is set to 1.<br>When flag1 is set to 1, status commands are issued before DATE and STIM commands, and write a response text into the clockstats file.</p>
                                                                <table border="1" summary="fudge flag1">
                                                                        <tr><td>0 (Default)</td><td>DCST and STUS commands are not issued</td></tr>
                                                                        <tr><td>1</td><td>DCST and STUS commands are issued</td></tr>
                                                                </table>
+                                                               <p>Flag2 enables the time synchronization only when the reply of the STUS is 'adjusted'. When this functionality is used, flag1 must be set to 1 together.</p>
+                                                               <table border="1" summary="fudge flag2">
+                                                                       <tr><td>0 (Default)</td><td>Always</td></tr>
+                                                                       <tr><td>1</td><td>'adjusted' only</td></tr>
+                                                               </table>
                                                        </dd>
                                                </dl>
                                                <br>
 
                        <li>
                                <p><a name="mode-4">CITIZEN T.I.C. CO.,LTD. &nbsp; JJY-200</a> &nbsp; <a href="http://www.tic-citizen.co.jp/">http://www.tic-citizen.co.jp/</a> (Japanese only)</p><br>
+                               <p>The JJY-200 became the end of sales in 2013.</p><br>
                                <dl>
                                        <dt>NTP configuration ( ntp.conf )</dt>
                                        <dd><br>
index a73cdd88948dcc758bba79033fc1460c9d496e03..0b554fac66744bf7736b7d0ea8fbf9e4d3c08beb 100644 (file)
@@ -4,7 +4,7 @@
 
 /**********************************************************************/
 /*                                                                   */
-/*  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     */
 /*  and its documentation for any purpose is hereby granted          */
 /*             tool. ( The code is harmless and has no bug. )        */
 /*             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
@@ -194,6 +201,10 @@ struct jjyunit {
        char    sTextBuf [ MAX_RAWBUF ] ;
        int     iTextBufLen ;
        char    bSkipCntrlCharOnly ;
+/* TS-JJY01, TS-JJY02 */
+       time_t  tLastAdjustedTimestamp ;
+       char    bStusReplyAdjusted ;
+       char    bStusReplyAdjustedAtLeastOnce ;
 /* Telephone JJY auto measurement of the loopback delay */
        char    bLoopbackMode ;
        short   iLoopbackCount ;
@@ -371,7 +382,7 @@ struct      refclock refclock_jjy = {
  * Local constants definition
  */
 
-#define        MAX_LOGTEXT     100
+#define        MAX_LOGTEXT     200
 
 #ifndef        TRUE
 #define        TRUE    (0==0)
@@ -410,6 +421,7 @@ struct      refclock refclock_jjy = {
 #define        JJY_CLOCKSTATS_MESSAGE_LOOPBACK_DELAY           "* Loopback delay : %d.%03d mSec."
 #define        JJY_CLOCKSTATS_MESSAGE_DELAY_ADJUST             "* Delay adjustment : %d mSec. ( valid=%hd/%d )"
 #define        JJY_CLOCKSTATS_MESSAGE_DELAY_UNADJUST           "* Delay adjustment : None ( valid=%hd/%d )"
+#define        JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED          "* Skip time synchronization : STUS is 'UNADJUSTED' for %.0lf %s"
 
 #define        JJY_CLOCKSTATS_MESSAGE_UNEXPECTED_REPLY         "# Unexpected reply : [%s]"
 #define        JJY_CLOCKSTATS_MESSAGE_INVALID_LENGTH           "# Invalid length : length=%d"
@@ -619,7 +631,7 @@ jjy_receive ( struct recvbuf *rbufp )
                /* To avoid its claim, pass the value BMAX-1. */
 
                /*
-                * Append received charaters to temporary buffer
+                * Append received characters to temporary buffer
                 */
                for ( i = 0 ;
                      i < pp->lencode && up->iRawBufLen < MAX_RAWBUF - 2 ;
@@ -703,7 +715,7 @@ jjy_receive ( struct recvbuf *rbufp )
                                iBreakPosition = up->iRawBufLen - 1 ;
                        }
 
-                       /* Copy charaters from temporary buffer to process buffer */
+                       /* Copy characters from temporary buffer to process buffer */
                        up->iLineBufLen = up->iTextBufLen = 0 ;
                        for ( i = iReadRawBuf ; i <= iBreakPosition ; i ++ ) {
 
@@ -926,7 +938,7 @@ jjy_poll ( int unit, struct peer *peer )
        up->iRawBufLen = 0 ;
 
        switch ( up->unittype ) {
-       
+
        case UNITTYPE_TRISTATE_JJY01 :
                jjy_poll_tristate_jjy01  ( unit, peer ) ;
                break ;
@@ -991,7 +1003,7 @@ jjy_timer ( int unit, struct peer *peer )
        }
 
        switch ( up->unittype ) {
-       
+
        case UNITTYPE_TELEPHONE :
                jjy_timer_telephone ( unit, peer ) ;
                break ;
@@ -1020,8 +1032,8 @@ jjy_synctime ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
        pp->second = up->second ;
        pp->nsec   = up->msecond * 1000000 ;
 
-       /* 
-        * JST to UTC 
+       /*
+        * JST to UTC
         */
        pp->hour -= 9 ;
        if ( pp->hour < 0 ) {
@@ -1070,7 +1082,7 @@ jjy_synctime ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
        case 5 : cStatus = '#' ; pStatus = "Selected"  ; break ;
        case 6 : cStatus = '*' ; pStatus = "Sys.Peer"  ; break ;
        case 7 : cStatus = 'o' ; pStatus = "PPS.Peer"  ; break ;
-       default : break ; 
+       default : break ;
        }
 
        snprintf ( sLog, sizeof(sLog),
@@ -1151,6 +1163,9 @@ jjy_start_tristate_jjy01 ( int unit, struct peer *peer, struct jjyunit *up )
        up->linespeed = SPEED232_TRISTATE_JJY01 ;
        up->linediscipline = LDISC_CLK ;
 
+       time( &(up->tLastAdjustedTimestamp) ) ;
+       up->bStusReplyAdjustedAtLeastOnce = FALSE ;
+
        return 0 ;
 
 }
@@ -1164,10 +1179,12 @@ jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp )
        struct refclockproc *pp ;
        struct peer         *peer;
 
-       char *          pBuf ;
-       char            sLog [ 100 ] ;
-       int             iLen ;
-       int             rc ;
+       char *  pBuf ;
+       char    sLog [ MAX_LOGTEXT ] ;
+       int     iLen ;
+       int     rc ;
+       time_t  now ;
+       double  fSeconds ;
 
        const char *    pCmd ;
        int             iCmdLen ;
@@ -1269,11 +1286,17 @@ jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp )
        case TS_JJY01_COMMAND_NUMBER_STUS :
 
                if ( strncmp( pBuf, TS_JJY01_REPLY_STUS_ADJUSTED,
-                            TS_JJY01_REPLY_LENGTH_STUS_ADJUSTED ) == 0
-                 || strncmp( pBuf, TS_JJY01_REPLY_STUS_UNADJUSTED,
-                            TS_JJY01_REPLY_LENGTH_STUS_UNADJUSTED ) == 0 ) {
-                       /* Good */
+                            TS_JJY01_REPLY_LENGTH_STUS_ADJUSTED ) == 0 ) {
+                       /* STUS reply : adjusted */
+                       up->bStusReplyAdjusted = TRUE ;
+                       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 {
+                       /* Bad reply */
                        snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
                                  pBuf ) ;
                        jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sLog ) ;
@@ -1286,11 +1309,12 @@ jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp )
        case TS_JJY01_COMMAND_NUMBER_DCST :
 
                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,
-                            TS_JJY01_REPLY_LENGTH_DCST_INVALID ) == 0 ) {
-                       /* Good */
+                             TS_JJY01_REPLY_LENGTH_DCST_INVALID ) == 0 ) {
+                       /* Valid reply */
                } else {
+                       /* Bad reply */
                        snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
                                  pBuf ) ;
                        jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sLog ) ;
@@ -1300,7 +1324,7 @@ jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp )
 
                break ;
 
-       default : /*  Unexpected reply */
+       default : /* Unexpected reply */
 
                snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
                          pBuf ) ;
@@ -1313,9 +1337,27 @@ jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp )
        if ( up->iTimestampCount == 2 ) {
                /* Process date and time */
 
-               if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0]
-                 && up->iTimestamp[0]     <= up->iTimestamp[1] ) {
-                       /* 3 commands (time,date,stim) was excuted in two seconds */
+               time( &now ) ;
+               fSeconds = difftime( now, up->tLastAdjustedTimestamp ) ;
+
+               if ( ( pp->sloppyclockflag & CLK_FLAG2 ) != 0
+                 && ( ! up->bStusReplyAdjusted )
+                 && ( fSeconds >= ( pp->fudgetime2 * 3600 ) || ( ! up->bStusReplyAdjustedAtLeastOnce ) ) ) {
+                       /* STUS is not ADJUSTED */
+                       if ( fSeconds < 60 ) {
+                               snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds, "seconds" ) ;
+                       } else if ( fSeconds < 3600 ) {
+                               snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 60, "minutes" ) ;
+                       } else if ( fSeconds < 86400 ) {
+                               snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 3600, "hours" ) ;
+                       } else {
+                               snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_STUS_UNADJUSTED, fSeconds / 86400, "days" ) ;
+                       }
+                       jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_INFORMATION, 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 seconds */
                        jjy_synctime( peer, pp, up ) ;
                        return JJY_RECEIVE_DONE ;
                } else if ( up->iTimestamp[0] > up->iTimestamp[1] ) {
@@ -1385,6 +1427,8 @@ jjy_poll_tristate_jjy01  ( int unit, struct peer *peer )
                up->iLineCount = 2 ;
        }
 
+       up->bStusReplyAdjusted = FALSE ;
+
 #ifdef DEBUG
        if ( debug ) {
                printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCount=%d\n",
@@ -1421,7 +1465,7 @@ jjy_poll_tristate_jjy01  ( int unit, struct peer *peer )
 /*                                                                                                */
 /*  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        */
 /*                                                                                                */
 /*################################################################################################*/
 
@@ -1461,7 +1505,7 @@ jjy_receive_cdex_jst2000 ( struct recvbuf *rbufp )
        struct refclockproc *pp ;
        struct peer         *peer ;
 
-       char    *pBuf, sLog [ 100 ] ;
+       char    *pBuf, sLog [ MAX_LOGTEXT ] ;
        int     iLen ;
        int     rc ;
 
@@ -1946,8 +1990,8 @@ jjy_poll_citizentic_jjy200 ( int unit, struct peer *peer )
 /*################################################################################################*/
 /*################################################################################################*/
 /*                                                                                                */
-/*  This clock has NMEA mode and command/respose mode.                                            */
-/*  When this jjy driver are used, set to command/respose mode of this clock                      */
+/*  This clock has NMEA mode and command/response mode.                                           */
+/*  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.                               */
 /*  Other than this JJY driver, the refclock driver type 20, generic NMEA driver,                 */
 /*  works with the NMEA mode of this clock.                                                       */
@@ -2022,7 +2066,7 @@ jjy_receive_tristate_gpsclock01 ( struct recvbuf *rbufp )
        struct peer         *peer;
 
        char *          pBuf ;
-       char            sLog [ 100 ] ;
+       char            sLog [ MAX_LOGTEXT ] ;
        int             iLen ;
        int             rc ;
 
@@ -2189,7 +2233,7 @@ jjy_receive_tristate_gpsclock01 ( struct recvbuf *rbufp )
 
                if ( up->iTimestamp[1] - 2 <= up->iTimestamp[0]
                  && 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 seconds */
                        jjy_synctime( peer, pp, up ) ;
                        return JJY_RECEIVE_DONE ;
                } else if ( up->iTimestamp[0] > up->iTimestamp[1] ) {
@@ -2344,7 +2388,7 @@ jjy_receive_seiko_tsys_tdc_300 ( struct recvbuf *rbufp )
        struct refclockproc     *pp ;
        struct jjyunit          *up ;
 
-       char    *pBuf, sLog [ 100 ] ;
+       char    *pBuf, sLog [ MAX_LOGTEXT ] ;
        int     iLen, i ;
        int     rc, iWeekday ;
        time_t  now ;
@@ -3402,7 +3446,7 @@ teljjy_conn_data ( struct peer *peer, struct refclockproc *pp, struct jjyunit *u
 
        char    *pBuf ;
        int     iLen, rc ;
-       char    sLog [ 80 ] ;
+       char    sLog [ MAX_LOGTEXT ] ;
        char    bAdjustment ;