~ubuntu-branches/ubuntu/oneiric/ntp/oneiric

« back to all changes in this revision

Viewing changes to ntpd/refclock_jjy.c

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-04-08 16:24:42 UTC
  • mfrom: (34.4.5 lucid)
  • Revision ID: james.westby@ubuntu.com-20100408162442-we41i5fzehptyhvu
Tags: 1:4.2.4p8+dfsg-1ubuntu2
debian/apparmor-profile: allow reading of /var/lib/ntp/ntp.conf.dhcp
(LP: #517701)

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
/*    [Fix]    C-DEX JST2000                                          */
75
75
/*             Thanks to Hideo Kuramatsu for the patch                */
76
76
/*                                                                    */
 
77
/*  2009/04/05                                                        */
 
78
/*    [Add]    Support the CITIZEN T.I.C JJY-200 receiver             */
 
79
/*                                                                    */
77
80
/**********************************************************************/
78
81
 
79
82
#ifdef HAVE_CONFIG_H
131
134
/*                 <SUB>                    Second signal             */
132
135
/*                                                                    */
133
136
/**********************************************************************/
 
137
/*                                                                    */
 
138
/*  The CITIZEN T.I.C CO., LTD. JJY receiver JJY200                   */
 
139
/*                                                                    */
 
140
/*  Command        Response                 Remarks                   */
 
141
/*  ------------   ----------------------   ---------------------     */
 
142
/*                 'XX YY/MM/DD W HH:MM:SS<CR>                        */
 
143
/*                                          XX: OK|NG|ER              */
 
144
/*                                          W:  0(Monday)-6(Sunday)   */
 
145
/*                                                                    */
 
146
/**********************************************************************/
134
147
 
135
148
/*
136
149
 * Interface definitions
137
150
 */
138
151
#define DEVICE          "/dev/jjy%d"    /* device name and unit */
139
152
#define SPEED232        B9600           /* uart speed (9600 baud) */
 
153
#define SPEED232_TRISTATE_JJY01         B9600   /* UART speed (9600 baud) */
 
154
#define SPEED232_CDEX_JST2000           B9600   /* UART speed (9600 baud) */
 
155
#define SPEED232_ECHOKEISOKUKI_LT2000   B9600   /* UART speed (9600 baud) */
 
156
#define SPEED232_CITIZENTIC_JJY200      B4800   /* UART speed (4800 baud) */
140
157
#define REFID           "JJY"           /* reference ID */
141
158
#define DESCRIPTION     "JJY Receiver"
142
159
#define PRECISION       (-3)           /* precision assumed (about 100 ms) */
149
166
    short   operationmode ;     /* Echo Keisokuki LT-2000 : 1 or 2 */
150
167
        short   version ;
151
168
        short   linediscipline ;        /* LDISC_CLK or LDISC_RAW */
 
169
    char    bPollFlag ;         /* Set by jjy_pool and Reset by jjy_receive */
152
170
        int     linecount ;
153
171
        int     lineerror ;
154
172
        int     year, month, day, hour, minute, second, msecond ;
164
182
#define UNITTYPE_TRISTATE_JJY01 1
165
183
#define UNITTYPE_CDEX_JST2000   2
166
184
#define UNITTYPE_ECHOKEISOKUKI_LT2000   3
 
185
#define UNITTYPE_CITIZENTIC_JJY200      4
167
186
 
168
187
/*
169
188
 * Function prototypes
174
193
static  void    jjy_poll_tristate_jjy01     P((int, struct peer *));
175
194
static  void    jjy_poll_cdex_jst2000       P((int, struct peer *));
176
195
static  void    jjy_poll_echokeisokuki_lt2000    P((int, struct peer *));
 
196
static  void    jjy_poll_citizentic_jjy200          P((int, struct peer *));
177
197
static  void    jjy_receive                 P((struct recvbuf *));
178
198
static  int     jjy_receive_tristate_jjy01  P((struct recvbuf *));
179
199
static  int     jjy_receive_cdex_jst2000    P((struct recvbuf *));
180
200
static  int     jjy_receive_echokeisokuki_lt2000 P((struct recvbuf *));
 
201
static  int     jjy_receive_citizentic_jjy200       P((struct recvbuf *));
181
202
 
182
203
/*
183
204
 * Transfer vector
217
238
        int     fd ;
218
239
        char    *pDeviceName ;
219
240
        short   iDiscipline ;
 
241
        int     iSpeed232 ;
220
242
 
221
243
#ifdef DEBUG
222
244
        if ( debug ) {
238
260
         */
239
261
        switch ( peer->ttl ) {
240
262
        case 0 :
241
 
        case 1 : iDiscipline = LDISC_CLK ; break ;
242
 
        case 2 : iDiscipline = LDISC_RAW ; break ;
243
 
        case 3 : iDiscipline = LDISC_CLK ; break ;
 
263
    case 1 :
 
264
        iDiscipline = LDISC_CLK ;
 
265
        iSpeed232   = SPEED232_TRISTATE_JJY01 ;
 
266
        break ;
 
267
    case 2 :
 
268
        iDiscipline = LDISC_RAW ;
 
269
        iSpeed232   = SPEED232_CDEX_JST2000   ;
 
270
        break ;
 
271
    case 3 :
 
272
        iDiscipline = LDISC_CLK ;
 
273
        iSpeed232   = SPEED232_ECHOKEISOKUKI_LT2000 ;
 
274
        break ;
 
275
    case 4 :
 
276
        iDiscipline = LDISC_CLK ;
 
277
        iSpeed232   = SPEED232_CITIZENTIC_JJY200 ;
 
278
        break ;
244
279
        default :
245
280
                msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode",
246
281
                          ntoa(&peer->srcadr), peer->ttl ) ;
248
283
                return RC_START_ERROR ;
249
284
        }
250
285
 
251
 
        if ( ! ( fd = refclock_open ( pDeviceName, SPEED232, iDiscipline ) ) ) {
 
286
        if ( ! ( fd = refclock_open ( pDeviceName, iSpeed232, iDiscipline ) ) ) {
252
287
                free ( (void*) pDeviceName ) ;
253
288
                return RC_START_ERROR ;
254
289
        }
299
334
                        break ;
300
335
                }
301
336
                break ;
 
337
    case 4 :
 
338
        up->unittype = UNITTYPE_CITIZENTIC_JJY200 ;
 
339
        up->lineexpect = 1 ;
 
340
        up->charexpect[0] = 23 ; /* 'XX YY/MM/DD W HH:MM:SS<CR> */
 
341
        break ;
302
342
        default :
303
343
                msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode",
304
344
                          ntoa(&peer->srcadr), peer->ttl ) ;
434
474
                rc = jjy_receive_echokeisokuki_lt2000 ( rbufp ) ;
435
475
                break ;
436
476
 
 
477
    case UNITTYPE_CITIZENTIC_JJY200 :
 
478
        rc = jjy_receive_citizentic_jjy200 ( rbufp ) ;
 
479
        break ;
 
480
 
437
481
        default :
438
482
                rc = 0 ;
439
483
                break ;
453
497
 
454
498
        if ( rc == 0 ) return ;
455
499
 
 
500
    up->bPollFlag = 0 ;
 
501
 
456
502
        if ( up->lineerror != 0 ) {
457
503
                refclock_report ( peer, CEVNT_BADREPLY ) ;
458
504
                strcpy  ( sLogText, "BAD REPLY [" ) ;
866
912
}
867
913
 
868
914
/**************************************************************************************************/
 
915
 
 
916
static int
 
917
jjy_receive_citizentic_jjy200 ( struct recvbuf *rbufp )
 
918
{
 
919
 
 
920
    static  char    *sFunctionName = "jjy_receive_citizentic_jjy200" ;
 
921
 
 
922
    struct jjyunit      *up ;
 
923
    struct refclockproc *pp ;
 
924
    struct peer         *peer;
 
925
 
 
926
    char    *pBuf ;
 
927
    int     iLen ;
 
928
    int     rc ;
 
929
    char    cApostrophe, sStatus[3] ;
 
930
    int     iWeekday ;
 
931
 
 
932
    /*
 
933
     * Initialize pointers and read the timecode and timestamp
 
934
     */
 
935
    peer = (struct peer *) rbufp->recv_srcclock ;
 
936
    pp = peer->procptr ;
 
937
    up = (struct jjyunit *) pp->unitptr ;
 
938
 
 
939
    if ( up->linediscipline == LDISC_RAW ) {
 
940
        pBuf = up->rawbuf ;
 
941
        iLen = up->charcount ;
 
942
    } else {
 
943
        pBuf = pp->a_lastcode ;
 
944
        iLen = pp->lencode ;
 
945
    }
 
946
 
 
947
    /*
 
948
     * JJY-200 sends a timestamp every second.
 
949
     * So, a timestamp is ignored unless it is right after polled.
 
950
     */
 
951
    if ( ! up->bPollFlag ) return 0 ;
 
952
 
 
953
    switch ( up->linecount ) {
 
954
 
 
955
    case 1 : /* 'XX YY/MM/DD W HH:MM:SS<CR> */
 
956
 
 
957
        if ( iLen != 23 ) {
 
958
#ifdef DEBUG
 
959
            if ( debug >= 2 ) {
 
960
                printf ( "%s (refclock_jjy.c) : Reply length error ( iLen=%d )\n", sFunctionName, iLen ) ;
 
961
            }
 
962
#endif
 
963
            up->lineerror = 1 ;
 
964
            break ;
 
965
        }
 
966
 
 
967
        rc = sscanf ( pBuf, "%c%2s %2d/%2d/%2d %1d %2d:%2d:%2d",
 
968
                      &cApostrophe, sStatus, 
 
969
                      &up->year, &up->month, &up->day, &iWeekday, &up->hour, &up->minute, &up->second ) ;
 
970
        sStatus[2] = 0 ;
 
971
        if ( rc != 9 || cApostrophe != '\'' || strcmp( sStatus, "OK" ) != 0
 
972
          || up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31
 
973
          || iWeekday > 6
 
974
          || up->hour > 23 || up->minute > 59 || up->second > 60 ) {
 
975
#ifdef DEBUG
 
976
            if ( debug >= 2 ) {
 
977
                printf ( "%s (refclock_jjy.c) : Time error (rc=%d) [ %c %2s %02d %02d %02d %d %02d %02d %02d ]\n", sFunctionName,
 
978
                         rc, cApostrophe, sStatus, up->year, up->month, up->day, iWeekday, up->hour, up->minute, up->second ) ;
 
979
            }
 
980
#endif
 
981
            up->lineerror = 1 ;
 
982
            break ;
 
983
        }
 
984
 
 
985
        up->year += 2000 ;
 
986
        up->msecond = 0 ;
 
987
 
 
988
        break ;
 
989
 
 
990
    default : /* Unexpected reply */
 
991
 
 
992
        up->lineerror = 1 ;
 
993
        break ;
 
994
 
 
995
    }
 
996
 
 
997
    return 1 ;
 
998
 
 
999
}
 
1000
 
 
1001
/**************************************************************************************************/
869
1002
/*  jjy_poll - called by the transmit procedure                                                   */
870
1003
/**************************************************************************************************/
871
1004
static void
893
1026
 
894
1027
        pp->polls ++ ;
895
1028
 
 
1029
    up->bPollFlag = 1 ;
896
1030
        up->linecount = 0 ;
897
1031
        up->lineerror = 0 ;
898
1032
        up->charcount = 0 ;
911
1045
                jjy_poll_echokeisokuki_lt2000 ( unit, peer ) ;
912
1046
                break ;
913
1047
 
 
1048
    case UNITTYPE_CITIZENTIC_JJY200 :
 
1049
        jjy_poll_citizentic_jjy200 ( unit, peer ) ;
 
1050
        break ;
 
1051
 
914
1052
        default :
915
1053
                break ;
916
1054
 
1006
1144
 
1007
1145
}
1008
1146
 
 
1147
/**************************************************************************************************/
 
1148
 
 
1149
static void
 
1150
jjy_poll_citizentic_jjy200 ( int unit, struct peer *peer )
 
1151
{
 
1152
 
 
1153
    /* Do nothing ( up->bPollFlag is set by the jjy_poll ) */
 
1154
 
 
1155
}
 
1156
 
1009
1157
#else
1010
1158
int refclock_jjy_bs ;
1011
1159
#endif /* REFCLOCK */