1/* 2 * refclock_jjy - clock driver for JJY receivers 3 */ 4 5/**********************************************************************/ 6/* */ 7/* Copyright (C) 2001-2015, Takao Abe. All rights reserved. */ 8/* */ --- 135 unchanged lines hidden (view full) --- 144#define DESCRIPTION "JJY Receiver" 145#define PRECISION (-3) /* precision assumed (about 100 ms) */ 146 147/* 148 * JJY unit control structure 149 */ 150 151struct jjyRawDataBreak { |
152 const char * pString ; 153 int iLength ; |
154} ; 155 156#define MAX_TIMESTAMP 6 157#define MAX_RAWBUF 100 158#define MAX_LOOPBACK 5 159 160struct jjyunit { 161/* Set up by the function "jjy_start_xxxxxxxx" */ --- 460 unchanged lines hidden (view full) --- 622 } else { 623 624 pp->lencode = refclock_gtlin ( rbufp, pp->a_lastcode, BMAX, &tRecvTimestamp ) ; 625 626 } 627#ifdef DEBUG 628 printf( "\nrefclock_jjy.c : %s : Len=%d ", sFunctionName, pp->lencode ) ; 629 for ( i = 0 ; i < pp->lencode ; i ++ ) { |
630 if ( iscntrl( (u_char)(pp->a_lastcode[i] & 0x7F) ) ) { |
631 printf( "<x%02X>", pp->a_lastcode[i] & 0xFF ) ; 632 } else { 633 printf( "%c", pp->a_lastcode[i] ) ; 634 } 635 } 636 printf( "\n" ) ; 637#endif 638 --- 58 unchanged lines hidden (view full) --- 697 up->iLineBufLen = up->iTextBufLen = 0 ; 698 for ( i = iReadRawBuf ; i <= iBreakPosition ; i ++ ) { 699 700 /* Copy all characters */ 701 up->sLineBuf[up->iLineBufLen] = up->sRawBuf[i] ; 702 up->iLineBufLen ++ ; 703 704 /* Copy printable characters */ |
705 if ( ! iscntrl( (u_char)up->sRawBuf[i] ) ) { |
706 up->sTextBuf[up->iTextBufLen] = up->sRawBuf[i] ; 707 up->iTextBufLen ++ ; 708 } 709 710 } 711 up->sLineBuf[up->iLineBufLen] = 0 ; 712 up->sTextBuf[up->iTextBufLen] = 0 ; 713#ifdef DEBUG --- 435 unchanged lines hidden (view full) --- 1149 1150static int 1151jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp ) 1152{ 1153 struct jjyunit *up ; 1154 struct refclockproc *pp ; 1155 struct peer *peer; 1156 |
1157 char * pBuf ; 1158 char sLog [ 100 ] ; 1159 int iLen ; 1160 int rc ; |
1161 |
1162 const char * pCmd ; 1163 int iCmdLen ; |
1164 1165 /* Initialize pointers */ 1166 1167 peer = rbufp->recv_peer ; 1168 pp = peer->procptr ; 1169 up = pp->unitptr ; 1170 1171 if ( up->linediscipline == LDISC_RAW ) { --- 183 unchanged lines hidden (view full) --- 1355{ 1356#ifdef DEBUG 1357 static const char *sFunctionName = "jjy_poll_tristate_jjy01" ; 1358#endif 1359 1360 struct refclockproc *pp ; 1361 struct jjyunit *up ; 1362 |
1363 const char * pCmd ; 1364 int iCmdLen ; |
1365 1366 pp = peer->procptr; 1367 up = pp->unitptr ; 1368 1369 up->bLineError = FALSE ; 1370 up->iTimestampCount = 0 ; 1371 1372 if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) { --- 633 unchanged lines hidden (view full) --- 2006#ifdef DEBUG 2007 static const char *sFunctionName = "jjy_receive_tristate_gpsclock01" ; 2008#endif 2009 2010 struct jjyunit *up ; 2011 struct refclockproc *pp ; 2012 struct peer *peer; 2013 |
2014 char * pBuf ; 2015 char sLog [ 100 ] ; 2016 int iLen ; 2017 int rc ; |
2018 |
2019 const char * pCmd ; 2020 int iCmdLen ; |
2021 2022 /* Initialize pointers */ 2023 2024 peer = rbufp->recv_peer ; 2025 pp = peer->procptr ; 2026 up = pp->unitptr ; 2027 2028 if ( up->linediscipline == LDISC_RAW ) { --- 207 unchanged lines hidden (view full) --- 2236{ 2237#ifdef DEBUG 2238 static const char *sFunctionName = "jjy_poll_tristate_gpsclock01" ; 2239#endif 2240 2241 struct refclockproc *pp ; 2242 struct jjyunit *up ; 2243 |
2244 const char * pCmd ; 2245 int iCmdLen ; |
2246 2247 pp = peer->procptr ; 2248 up = pp->unitptr ; 2249 2250 up->iTimestampCount = 0 ; 2251 2252 if ( ( pp->sloppyclockflag & CLK_FLAG1 ) == 0 ) { 2253 /* Skip "stus" command */ --- 319 unchanged lines hidden (view full) --- 2573static int teljjy_conn_send ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ; 2574static int teljjy_conn_data ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ; 2575static int teljjy_conn_silent ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ; 2576static int teljjy_conn_error ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ; 2577static int teljjy_bye_ignore ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ; 2578static int teljjy_bye_disc ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ; 2579static int teljjy_bye_modem ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ; 2580 |
2581static int ( *pTeljjyHandler [ ] [ 5 ] ) ( struct peer *, struct refclockproc *, struct jjyunit *) = |
2582{ /*STATE_IDLE STATE_DAILOUT STATE_LOGIN STATE_CONNECT STATE_BYE */ 2583/* NULL */ { teljjy_idle_ignore , teljjy_dial_ignore, teljjy_login_ignore, teljjy_conn_ignore, teljjy_bye_ignore }, 2584/* START */ { teljjy_idle_dialout, teljjy_dial_ignore, teljjy_login_ignore, teljjy_conn_ignore, teljjy_bye_ignore }, 2585/* CONNECT */ { teljjy_idle_ignore , teljjy_dial_login , teljjy_login_ignore, teljjy_conn_ignore, teljjy_bye_ignore }, 2586/* DISCONNECT */ { teljjy_idle_ignore , teljjy_dial_disc , teljjy_login_disc , teljjy_conn_disc , teljjy_bye_disc }, 2587/* COMMAND */ { teljjy_idle_ignore , teljjy_dial_ignore, teljjy_login_ignore, teljjy_conn_ignore, teljjy_bye_modem }, 2588/* LOGIN */ { teljjy_idle_ignore , teljjy_dial_ignore, teljjy_login_login , teljjy_conn_error , teljjy_bye_ignore }, 2589/* PROMPT */ { teljjy_idle_ignore , teljjy_dial_ignore, teljjy_login_conn , teljjy_conn_send , teljjy_bye_ignore }, --- 122 unchanged lines hidden (view full) --- 2712 if ( sys_phone[1] != NULL ) { 2713 msyslog( LOG_ERR, "refclock_jjy.c : jjy_start_telephone : phone in the ntpd.conf should be only one." ) ; 2714 up->bInitError = TRUE ; 2715 return 1 ; 2716 } 2717 2718 iNumberOfDigitsOfPhoneNumber = iCommaCount = iCommaPosition = iFirstThreeDigitsCount = 0 ; 2719 for ( i = 0 ; i < strlen( sys_phone[0] ) ; i ++ ) { |
2720 if ( isdigit( (u_char)sys_phone[0][i] ) ) { |
2721 if ( iFirstThreeDigitsCount < sizeof(sFirstThreeDigits)-1 ) { |
2722 sFirstThreeDigits[iFirstThreeDigitsCount++] = sys_phone[0][i] ; |
2723 } 2724 iNumberOfDigitsOfPhoneNumber ++ ; |
2725 } else if ( sys_phone[0][i] == ',' ) { |
2726 iCommaCount ++ ; 2727 if ( iCommaCount > 1 ) { 2728 msyslog( LOG_ERR, "refclock_jjy.c : jjy_start_telephone : phone in the ntpd.conf should be zero or one comma." ) ; 2729 up->bInitError = TRUE ; 2730 return 1 ; 2731 } 2732 iFirstThreeDigitsCount = 0 ; 2733 iCommaPosition = i ; |
2734 } else if ( sys_phone[0][i] != '-' ) { |
2735 msyslog( LOG_ERR, "refclock_jjy.c : jjy_start_telephone : phone in the ntpd.conf should be a number or a hyphen." ) ; 2736 up->bInitError = TRUE ; 2737 return 1 ; 2738 } 2739 } 2740 sFirstThreeDigits[iFirstThreeDigitsCount] = 0 ; 2741 2742 if ( iCommaCount == 1 ) { --- 467 unchanged lines hidden (view full) --- 3210 3211} 3212 3213/******************************/ 3214static int 3215teljjy_login_login ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up ) 3216{ 3217 |
3218 const char * pCmd ; 3219 int iCmdLen ; |
3220 3221 DEBUG_TELJJY_PRINTF( "teljjy_login_login" ) ; 3222 3223 /* Send a guest user ID */ 3224 pCmd = "TJJY\r" ; 3225 3226 /* Send login ID */ 3227 iCmdLen = strlen( pCmd ) ; --- 59 unchanged lines hidden (view full) --- 3287 3288} 3289 3290/******************************/ 3291static int 3292teljjy_conn_send ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up ) 3293{ 3294 |
3295 const char * pCmd ; 3296 int i, iLen, iNextClockState ; |
3297 3298 DEBUG_TELJJY_PRINTF( "teljjy_conn_send" ) ; 3299 3300 if ( up->iClockCommandSeq > 0 3301 && teljjy_command_sequence[up->iClockCommandSeq].command == NULL ) { 3302 /* Command sequence has been completed */ 3303 return TELJJY_CHANGE_CLOCK_STATE ; 3304 } --- 219 unchanged lines hidden (view full) --- 3524 3525} 3526 3527/******************************/ 3528static int 3529teljjy_conn_silent ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up ) 3530{ 3531 |
3532 const char * pCmd ; |
3533 3534 DEBUG_TELJJY_PRINTF( "teljjy_conn_silent" ) ; 3535 3536 if ( up->iClockCommandSeq >= 1 3537 && up->iClockCommandSeq < TELJJY_COMMAND_START_SKIP_LOOPBACK ) { 3538 /* Loopback */ 3539#ifdef DEBUG 3540 if ( debug ) { --- 121 unchanged lines hidden (view full) --- 3662static int modem_conn_ignore ( struct peer *, struct refclockproc *, struct jjyunit * ) ; 3663static int modem_conn_escape ( struct peer *, struct refclockproc *, struct jjyunit * ) ; 3664static int modem_esc_ignore ( struct peer *, struct refclockproc *, struct jjyunit * ) ; 3665static int modem_esc_escape ( struct peer *, struct refclockproc *, struct jjyunit * ) ; 3666static int modem_esc_data ( struct peer *, struct refclockproc *, struct jjyunit * ) ; 3667static int modem_esc_silent ( struct peer *, struct refclockproc *, struct jjyunit * ) ; 3668static int modem_esc_disc ( struct peer *, struct refclockproc *, struct jjyunit * ) ; 3669 |
3670static int ( *pModemHandler [ ] [ 5 ] ) ( struct peer *, struct refclockproc *, struct jjyunit * ) = |
3671{ /*STATE_DISCONNECT STATE_INITIALIZE STATE_DAILING STATE_CONNECT STATE_ESCAPE */ 3672/* NULL */ { modem_disc_ignore, modem_init_ignore, modem_dial_ignore , modem_conn_ignore, modem_esc_ignore }, 3673/* INITIALIZE */ { modem_disc_init , modem_init_start , modem_dial_ignore , modem_conn_ignore, modem_esc_ignore }, 3674/* DIALOUT */ { modem_disc_ignore, modem_init_ignore, modem_dial_dialout, modem_conn_ignore, modem_esc_ignore }, 3675/* DISCONNECT */ { modem_disc_ignore, modem_init_disc , modem_dial_escape , modem_conn_escape, modem_esc_escape }, 3676/* RESP: 0: OK */ { modem_disc_ignore, modem_init_resp00, modem_dial_ignore , modem_conn_ignore, modem_esc_data }, 3677/* RESP: 1: CONNECT */ { modem_disc_ignore, modem_init_ignore, modem_dial_connect, modem_conn_ignore, modem_esc_data }, 3678/* RESP: 2: RING */ { modem_disc_ignore, modem_init_ignore, modem_dial_ignore , modem_conn_ignore, modem_esc_data }, --- 311 unchanged lines hidden (view full) --- 3990 3991} 3992 3993/******************************/ 3994static int 3995modem_init_resp00 ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up ) 3996{ 3997 |
3998 const char * pCmd ; 3999 char cBuf [ 46 ] ; 4000 int iCmdLen ; 4001 int iErrorCorrection, iSpeakerSwitch, iSpeakerVolume ; 4002 int iNextModemState = STAY_MODEM_STATE ; |
4003 4004 DEBUG_MODEM_PRINTF( "modem_init_resp00" ) ; 4005 4006 up->iModemCommandSeq++ ; 4007 4008 switch ( up->iModemCommandSeq ) { 4009 4010 case 1 : --- 18 unchanged lines hidden (view full) --- 4029 /* fudge 127.127.40.n flag4 0 */ 4030 iSpeakerVolume = 1 ; 4031 } else { 4032 /* fudge 127.127.40.n flag4 1 */ 4033 iSpeakerVolume = 2 ; 4034 } 4035 4036 pCmd = cBuf ; |
4037 snprintf( cBuf, sizeof(cBuf), "ATM%dL%d\r\n", iSpeakerSwitch, iSpeakerVolume ) ; |
4038 break ; 4039 4040 case 3 : 4041 /* &Kn = Flow control 4:XON/XOFF */ 4042 pCmd = "AT&K4\r\n" ; 4043 break ; 4044 4045 case 4 : --- 12 unchanged lines hidden (view full) --- 4058 /* fudge 127.127.40.n flag2 0 */ 4059 iErrorCorrection = 0 ; 4060 } else { 4061 /* fudge 127.127.40.n flag2 1 */ 4062 iErrorCorrection = 3 ; 4063 } 4064 4065 pCmd = cBuf ; |
4066 snprintf( cBuf, sizeof(cBuf), "AT\\N%d\r\n", iErrorCorrection ) ; |
4067 break ; 4068 4069 case 7 : 4070 /* Hn = Hook 0:Hook-On ( Disconnect ) 1:Hook-Off ( Connect ) */ 4071 pCmd = "ATH1\r\n" ; 4072 break ; 4073 4074 case 8 : --- 174 unchanged lines hidden (view full) --- 4249 4250} 4251 4252/******************************/ 4253static int 4254modem_esc_escape ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up ) 4255{ 4256 |
4257 const char * pCmd ; 4258 int iCmdLen ; |
4259 4260 DEBUG_MODEM_PRINTF( "modem_esc_escape" ) ; 4261 4262 /* Escape command ( Go to command mode ) */ 4263 pCmd = "+++" ; 4264 4265 /* Send command */ 4266 iCmdLen = strlen( pCmd ) ; --- 48 unchanged lines hidden (view full) --- 4315 return modem_esc_disc( peer, pp, up ) ; 4316 4317} 4318/******************************/ 4319static int 4320modem_esc_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up ) 4321{ 4322 |
4323 const char * pCmd ; 4324 int iCmdLen ; |
4325 4326 DEBUG_MODEM_PRINTF( "modem_esc_disc" ) ; 4327 4328 /* Disconnect */ 4329 pCmd = "ATH0\r\n" ; 4330 4331 /* Send command */ 4332 iCmdLen = strlen( pCmd ) ; --- 14 unchanged lines hidden (view full) --- 4347/*## ##*/ 4348/*################################################################################################*/ 4349/*################################################################################################*/ 4350 4351static void 4352jjy_write_clockstats ( struct peer *peer, int iMark, const char *pData ) 4353{ 4354 |
4355 char sLog [ 100 ] ; 4356 const char * pMark ; 4357 int iMarkLen, iDataLen ; |
4358 4359 switch ( iMark ) { 4360 case JJY_CLOCKSTATS_MARK_JJY : 4361 pMark = "JJY " ; 4362 break ; 4363 case JJY_CLOCKSTATS_MARK_SEND : 4364 pMark = "--> " ; 4365 break ; --- 95 unchanged lines hidden --- |