131
134
/* <SUB> Second signal */
133
136
/**********************************************************************/
138
/* The CITIZEN T.I.C CO., LTD. JJY receiver JJY200 */
140
/* Command Response Remarks */
141
/* ------------ ---------------------- --------------------- */
142
/* 'XX YY/MM/DD W HH:MM:SS<CR> */
144
/* W: 0(Monday)-6(Sunday) */
146
/**********************************************************************/
136
149
* Interface definitions
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 */
151
168
short linediscipline ; /* LDISC_CLK or LDISC_RAW */
169
char bPollFlag ; /* Set by jjy_pool and Reset by jjy_receive */
154
172
int year, month, day, hour, minute, second, msecond ;
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 *));
183
204
* Transfer vector
239
261
switch ( peer->ttl ) {
241
case 1 : iDiscipline = LDISC_CLK ; break ;
242
case 2 : iDiscipline = LDISC_RAW ; break ;
243
case 3 : iDiscipline = LDISC_CLK ; break ;
264
iDiscipline = LDISC_CLK ;
265
iSpeed232 = SPEED232_TRISTATE_JJY01 ;
268
iDiscipline = LDISC_RAW ;
269
iSpeed232 = SPEED232_CDEX_JST2000 ;
272
iDiscipline = LDISC_CLK ;
273
iSpeed232 = SPEED232_ECHOKEISOKUKI_LT2000 ;
276
iDiscipline = LDISC_CLK ;
277
iSpeed232 = SPEED232_CITIZENTIC_JJY200 ;
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 ;
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 ;
338
up->unittype = UNITTYPE_CITIZENTIC_JJY200 ;
340
up->charexpect[0] = 23 ; /* 'XX YY/MM/DD W HH:MM:SS<CR> */
303
343
msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode",
304
344
ntoa(&peer->srcadr), peer->ttl ) ;
868
914
/**************************************************************************************************/
917
jjy_receive_citizentic_jjy200 ( struct recvbuf *rbufp )
920
static char *sFunctionName = "jjy_receive_citizentic_jjy200" ;
923
struct refclockproc *pp ;
929
char cApostrophe, sStatus[3] ;
933
* Initialize pointers and read the timecode and timestamp
935
peer = (struct peer *) rbufp->recv_srcclock ;
937
up = (struct jjyunit *) pp->unitptr ;
939
if ( up->linediscipline == LDISC_RAW ) {
941
iLen = up->charcount ;
943
pBuf = pp->a_lastcode ;
948
* JJY-200 sends a timestamp every second.
949
* So, a timestamp is ignored unless it is right after polled.
951
if ( ! up->bPollFlag ) return 0 ;
953
switch ( up->linecount ) {
955
case 1 : /* 'XX YY/MM/DD W HH:MM:SS<CR> */
960
printf ( "%s (refclock_jjy.c) : Reply length error ( iLen=%d )\n", sFunctionName, iLen ) ;
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 ) ;
971
if ( rc != 9 || cApostrophe != '\'' || strcmp( sStatus, "OK" ) != 0
972
|| up->month < 1 || up->month > 12 || up->day < 1 || up->day > 31
974
|| up->hour > 23 || up->minute > 59 || up->second > 60 ) {
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 ) ;
990
default : /* Unexpected reply */
1001
/**************************************************************************************************/
869
1002
/* jjy_poll - called by the transmit procedure */
870
1003
/**************************************************************************************************/