head 3.1; access oasisa; symbols ; locks oasisa:3.1; strict; comment @ * @; 3.1 date 2001.06.19.13.15.10; author oasisa; state Exp; branches ; next 3.0; 3.0 date 99.05.12.10.11.28; author bobh; state Exp; branches ; next 2.9; 2.9 date 98.08.24.13.45.56; author bobh; state Exp; branches ; next 2.8; 2.8 date 98.03.17.11.11.43; author bobh; state Exp; branches ; next 2.7; 2.7 date 97.09.09.09.52.48; author bobh; state Exp; branches ; next 1.5; 1.5 date 94.01.17.11.07.42; author hebo; state Exp; branches ; next 1.4; 1.4 date 92.06.22.14.48.11; author hebo; state Exp; branches ; next 1.3; 1.3 date 92.06.22.10.20.22; author hebo; state Exp; branches ; next 1.2; 1.2 date 92.05.29.09.13.14; author hebo; state Exp; branches ; next 1.1; 1.1 date 92.03.16.15.44.43; author hebo; state Rel; branches 1.1.1.1; next 1.0; 1.0 date 92.03.12.13.59.22; author hebo; state Rel; branches ; next ; 1.1.1.1 date 92.03.30.14.40.34; author hebo; state Exp; branches ; next ; desc @Program to download OASIS data via Packet Radio TNC @ 3.1 log @Periodic Update 6/19/2001 (klh) @ text @/****************************************************************************/ /* Copyright 1992 MBARI */ /****************************************************************************/ /* $Header: getoasis.c,v 3.0 99/05/12 10:11:28 bobh Exp $ */ /* Summary : Program to download OASIS data */ /* Filename : getoasis.c */ /* Author : Robert Herlien (rah) */ /* Project : OASIS Mooring */ /* $Revision: 3.0 $ */ /* Created : 02/22/92 */ /* */ /* MBARI provides this documentation and code "as is", with no warranty, */ /* express or implied, of its quality or consistency. It is provided without*/ /* support and without obligation on the part of the Monterey Bay Aquarium */ /* Research Institute to assist in its use, correction, modification, or */ /* enhancement. This information should not be published or distributed to */ /* third parties without specific written permission from MBARI. */ /* */ /****************************************************************************/ /* Modification History: */ /* 22feb92 rah - created, from gps.c */ /* $Log: getoasis.c,v $ * Revision 3.0 99/05/12 10:11:28 10:11:28 bobh (Bob Herlien) * Added tstring, misc changes * * Revision 2.9 98/08/24 13:45:56 13:45:56 bobh (Bob Herlien) * Archiving sources after M2/M3 & Eqpac deployments of 1998 * * Revision 2.8 98/03/17 11:11:43 11:11:43 bobh (Bob Herlien) * Archiving sources prior to porting to DOS/Windows * * Revision 2.7 97/09/09 09:52:48 09:52:48 bobh (Bob Herlien) * Archiving various changes * * Revision 1.5 94/01/17 11:07:42 11:07:42 hebo (Bob Herlien) * Misc changes * * Revision 1.4 92/06/22 14:48:11 14:48:11 hebo (Bob Herlien) * Fixed timeout bug in wait_for_prompt() that caused early abort. * * Revision 1.3 92/06/22 10:20:22 10:20:22 hebo (Bob Herlien) * Fixed bug in tnc_cmd_mode. Added error message if release_port() fails. * * Revision 1.2 92/05/29 09:13:14 09:13:14 hebo (Bob Herlien) * Changed restore parameters to delete "M OFF", add "EC ON" * Deleted #define _HPUX_SOURCE. It's now defined in Makefile. * * Revision 1.1 92/03/16 15:44:43 15:44:43 hebo (Bob Herlien) * First working version * * Revision 1.0 92/03/12 13:59:22 13:59:22 hebo (Bob Herlien) * Initial revision */ /****************************************************************************/ #include /* Standard I/O */ #include /* For exit() */ #include /* For FD_ISSET, etc */ #include /* MBARI type definitions */ #include /* MBARI constants */ #include /* For timeout */ #include /* For terminal I/O stuff */ #include /* For open() stuff */ #include /* For signal() */ #include /* For ioctl() */ #include /* For NOFILE */ #include /* For toupper() */ #include /* For strchr() */ #include "decode.h" /* For LogStruct */ #define TNC_DEV "tnc" /* Default radio TNC device file */ #define BUFSIZE 1023 /* Size of line buffer */ #define TNC_ADDR "mbari-3" /* Dflt TNC to connect to */ #define OPROMPT "OASIS>" /* OASIS prompt */ #define CAN_NAME "m1a" /* Can name */ #define NCMDS 10 /* Nmbr usr cmds supported */ #define ARG_ERR 1 /* Bad command line arg exit() code */ #define PORT_ERR 2 /* Serial port error exit() code */ #define CONNECT_ERR 3 /* Can't connect exit() code */ #define DOWNLOAD_ERR 4 /* Download error exit() code */ #define ABORT_ERR 5 /* Aborted exit() code */ /********************************/ /* External Functions */ /********************************/ /* From port.c */ Extern MBool set_baud( struct termio *tp, Int baud ); Extern Int get_port( char *name, Int mode, struct termio *setup, struct termio *save ); Extern Status release_port( char *name, Int fd, struct termio *parms ); Extern Void rcdInit( LogStruct *lp ); Extern MBool readRcd( char *can, LogStruct *lp ); Extern MBool getMissingRcd( LogStruct *lp, Nat32 lognum, Nat32 last, RcdRange *rcd ); /********************************/ /* External Data */ /********************************/ Extern char *optarg; /* Option argument from getopt() */ Extern Int optind; /* Option index from getopt() */ Extern Int opterr; /* getopt() error flag */ Extern char *rcdfile; /* File of record numbers */ /********************************/ /* Module Local Data */ /********************************/ MLocal char *tncfile = TNC_DEV; /* Radio TNC device file */ MLocal char *tncaddr = TNC_ADDR; /* TNC address to connect to */ MLocal time_t timeout = 660; /* 11 minute timeout by default */ MLocal MBool get_rcds = FALSE; /* TRUE to get missing records */ MLocal Int32 tfd = ERROR; /* TNC file descriptor */ MLocal MBool echo = FALSE; /* TRUE to echo tnc reads to stdout */ MLocal MBool aborted = FALSE; /* Set from signal handler */ MLocal char rbuf[BUFSIZE+1]; /* Read line buffer */ MLocal Nat32 rcnt = 0; /* # chars in rbuf */ MLocal LogStruct logs; /* Which records have been read */ MLocal char *can_name = CAN_NAME; /* Can name */ MLocal Nat32 nusrcmds = 0; MLocal char *usrcmds[NCMDS]; /* User commands */ MLocal struct termio tnc_term = /* Termio characteristics for TNC */ { IGNPAR, /* c_iflag */ 0, /* c_oflag */ B9600 | CS8 | CREAD | CLOCAL, /* c_cflag */ NOFLSH, /* c_lflag */ 0, /* c_line, HP has no line disciplines*/ {0, 0, 0, 0, 0, 10, 0, 0} /* control chars (1 second timeout) */ }; MLocal struct termio tnc_save; /* Place to save terminal charac. */ MLocal char *setup_tnc[] = { "NO OFF\r", "EC OFF\r", "RET 15\r", "CH 6\r", "M OFF\r" }; MLocal char *restore_tnc[] = { "EC ON\r" }; /********************************/ /* Forward Declarations */ /********************************/ MBool process_command_line ( Int argc, char **argv ); Void use_msg( char *s ); Status connect_tnc( Void ); Status disconnect_tnc( Void ); Status write_tnc( char *s ); Status send_tnc_cmds( char *cmds[], Int num ); Status get_missing_records( Void ); Status get_data( Void ); Status send_usr_cmds( Void ); Void quit( Int sig ); /************************************************************************/ /* Function : main */ /* Purpose : Main routine */ /* Inputs : argc, argv */ /* Outputs : none */ /************************************************************************/ Void main( Int argc, char **argv ) { Int rtn; /* exit() code */ printf("OASIS download program $Revision: 3.0 $\n"); if ( !process_command_line(argc, argv) ) { use_msg(argv[0]); exit( ARG_ERR ); } signal(SIGTERM, quit); /* Catch terminate signals */ signal(SIGHUP, quit); signal(SIGINT, quit); signal(SIGQUIT, quit); if ( (tfd = get_port(tncfile, O_RDWR, &tnc_term, &tnc_save)) == ERROR ) { printf( "Couln't acquire serial port %s\n", tncfile ); exit( PORT_ERR ); } printf("Acquired serial port %s\n", tncfile); if ( send_tnc_cmds(setup_tnc, sizeof(setup_tnc)/sizeof(char *)) == ERROR ) printf( "Failed to setup TNC commands\n" ); if ( connect_tnc() == OK ) { rtn = wait_for_prompt(); /* Look for initial prompt*/ if ( rtn == OK ) rtn = send_usr_cmds(); if ( rtn == OK ) rtn = get_data(); if ( get_rcds && (rtn == OK) ) rtn = get_missing_records(); write_tnc( "quit\r" ); sleep( 3 ); } else { printf( "Couldn't establish radio communication\n" ); rtn = CONNECT_ERR; } disconnect_tnc(); send_tnc_cmds( restore_tnc, sizeof(restore_tnc)/sizeof(char *) ); sleep( 1 ); printf("\n"); if ( release_port(tncfile, tfd, &tnc_save) == ERROR ) printf( "Error in releasing serial port %s\n", tncfile ); exit( aborted ? ABORT_ERR : rtn ); } /* main() */ /************************************************************************/ /* Function : use_msg */ /* Purpose : Print Usage Message */ /* Inputs : Name of program */ /* Outputs : None */ /************************************************************************/ Void use_msg( char *s ) { fprintf( stderr, "Usage: %s [-a tnc_address] [-b baud] [-c can] [-p port] ", s ); fprintf( stderr, "[-r rcd_file] [-t timeout]\n"); } /* use_msg() */ /************************************************************************/ /* Function : process_command_line */ /* Purpose : Read the arguments from the command line */ /* Inputs : argc, argv from main() routine */ /* Outputs : TRUE if arguments OK, else FALSE */ /************************************************************************/ MBool process_command_line ( Int argc, char **argv ) { Int i, baud; while ( (i = getopt(argc, argv, "a:b:c:p:r:t:u:")) != EOF ) switch( i ) { case 'a': tncaddr = optarg; break; case 'b': if ( !set_baud(&tnc_term, atoi(optarg)) ) return( FALSE ); break; case 'c': can_name = optarg; get_rcds = TRUE; break; case 'p': tncfile = optarg; break; case 'r': rcdfile = optarg; get_rcds = TRUE; break; case 't': timeout = 60 * atoi(optarg); break; case 'u': usrcmds[nusrcmds++] = optarg; break; default: return( FALSE ); } return( TRUE ); } /* process_command_line() */ /****************************************************************************/ /* Function : find_str */ /* Purpose : Find target string embedded in source string, case insens */ /* Inputs : Source string ptr, Target string ptr */ /* Outputs : NULL if strings don't match, else ptr to next char of source*/ /****************************************************************************/ char * find_str( char *src, char *tgt ) { Reg char *p, *p1, *q; for ( p1 = src; *p1; p1++ ) { for( p = p1, q = tgt; ; p++, q++ ) { if ( *q == '\0' ) return( p ); if ( *p == '\0' ) return( NULL ); if ( toupper(*p) != toupper(*q) ) break; } } return( NULL ); } /* find_str() */ /************************************************************************/ /* Function : gets_tnc_tmout */ /* Purpose : Read one line from TNC with timeout */ /* Inputs : Buffer, length, timeout (seconds) */ /* Outputs : Number of characters read, or ERROR */ /* Comment : Needs a buffer of length len+1 (for '\0') */ /************************************************************************/ Int gets_tnc_tmout( char *buf, Int len, Int tmout ) { time_t start, curtime; Int i, rtn; char c; time( &start ); /* Get start time */ for ( rtn = 0; rtn < len; ) { if ( (i = read(tfd, &buf[rtn], 1)) < 0 ) /* Read one character */ break; if ( i > 0 ) /* If got character, */ { c = buf[rtn++]; /* increment char count */ if ( c == '\n' ) /* look for end of line */ break; if ( c == '\r' ) { /* If CR, */ buf[rtn++] = '\n'; /* insert LF */ break; } } time( &curtime ); /* Get time */ if ( curtime > start + tmout ) /* If timed out, return */ break; } buf[rtn] = '\0'; /* Insert EOS */ if ( rtn > 0 ) { /* Echo to stdout */ printf( "%s", buf ); fflush( stdout ); } return( rtn ); /* Return # chars */ } /* gets_tnc_tmout() */ /************************************************************************/ /* Function : write_tnc */ /* Purpose : Write a line to the TNC, echo to stdout */ /* Inputs : String to write */ /* Outputs : OK or ERROR */ /************************************************************************/ Status write_tnc( char *s ) { Reg Nat32 rtn; Reg char *p, *q; rtn = write( tfd, s, strlen(s) ); if ( (p = strdup(s)) != NULL ) { while ( (q = strchr(p, '\r')) != NULL ) *q = '\n'; printf( "%s", p ); fflush( stdout ); free(p); } return( (rtn == strlen(s)) ? OK : ERROR ); } /* write_tnc() */ /************************************************************************/ /* Function : tnc_cmd_mode */ /* Purpose : Send ^C to TNC to go into command mode */ /* Inputs : None */ /* Outputs : OK or ERROR */ /************************************************************************/ Status tnc_cmd_mode( Void ) { Int32 i; if ( write_tnc("\003\r") != OK ) /* Send ctrl-C to TNC */ return( ERROR ); for ( i = 0; i < 10; i++ ) /* Wait for "cmd:" prompt*/ { if ( gets_tnc_tmout(rbuf, 4, 10) <= 0 ) return( ERROR ); if ( find_str(rbuf, "cmd:") != NULL ) return( OK ); } return( ERROR ); } /* tnc_cmd_mode() */ /************************************************************************/ /* Function : send_tnc_cmds */ /* Purpose : Send commands to the TNC */ /* Inputs : Ptr to cmds, number of cmds */ /* Outputs : OK or ERROR */ /************************************************************************/ Status send_tnc_cmds( char *cmds[], Int num ) { Int i; Status rtn; rtn = tnc_cmd_mode(); /* Go into command mode */ for ( i = 0; i < num; i++ ) /* Send commands to TNC */ { write_tnc( cmds[i] ); gets_tnc_tmout( rbuf, BUFSIZE, 1 ); /* Discard any replys */ } return( OK ); } /* send_tnc_cmds() */ /************************************************************************/ /* Function : tnc_status */ /* Purpose : Get STATus message from TNC */ /* Inputs : None */ /* Outputs : Status of TNC, or ERROR */ /* Comment : Leaves TNC in command mode */ /************************************************************************/ Int tnc_status( Void ) { char *p; Int res; write_tnc( "STAT\r" ); /* Ask for status */ res = -1; /* Initialize result */ while ( gets_tnc_tmout(rbuf, BUFSIZE, 10) != ERROR ) if ( (p = find_str(rbuf, "STAT")) != NULL ) if ( (p = strchr(p, '$')) != NULL ) if ( sscanf(p+1, "%x", &res) == 1 ) break; gets_tnc_tmout( rbuf, BUFSIZE, 10 ); /* Clear tnc buffer */ return( res ); } /* tnc_status() */ /************************************************************************/ /* Function : disconnect_tnc */ /* Purpose : Break TNC connection */ /* Inputs : None */ /* Outputs : OK or ERROR */ /************************************************************************/ Status disconnect_tnc( Void ) { Int i; Status rtn; rtn = tnc_cmd_mode(); /* Go into command mode */ if ( write_tnc("D\r") != OK ) /* Make sure we're */ return( ERROR ); /* disconnected */ for ( i = 10; i; i-- ) { if ( tnc_status() == 0 ) return( rtn ); sleep( 2 ); } return( ERROR ); } /* disconnect_tnc() */ /************************************************************************/ /* Function : connect_tnc */ /* Purpose : Put TNC into converse mode */ /* Inputs : None */ /* Outputs : OK or ERROR */ /************************************************************************/ Status connect_tnc( Void ) { time_t start, curtime; disconnect_tnc(); /* Make sure disconnected*/ time( &start ); /* Get time */ sprintf(rbuf, "C %s\r", tncaddr); /* Send connect message */ if ( write_tnc(rbuf) != OK ) return( ERROR ); while ( time(&curtime) < start + timeout ) /* Loop until connect */ { /* or timeout */ if ( aborted ) /* If program aborted, */ return( ERROR ); /* return ERROR */ gets_tnc_tmout( rbuf, BUFSIZE, timeout - (curtime - start) ); if ( find_str(rbuf, "DISCONNECTED") != NULL ) { sprintf(rbuf, "C %s\r", tncaddr); if ( write_tnc(rbuf) != OK ) return( ERROR ); } else if ( find_str(rbuf, "CONNECTED") != NULL ) return( OK ); } return( ERROR ); /* Timed out. Error */ } /* connect_tnc() */ /************************************************************************/ /* Function : wait_for_prompt */ /* Purpose : Wait for OASIS prompt or "DISCONNECTED" message */ /* Inputs : None */ /* Outputs : OK or ERROR */ /* Comments : Error if "DISCONNECTED" or no data for timeout seconds */ /************************************************************************/ Status wait_for_prompt( Void ) { time_t datatime, curtime; Int i, j; char c; time( &datatime ); /* Get start time */ j = 0; while ( !aborted && (time(&curtime) <= datatime + timeout) ) { if ( (i = read(tfd, &c, 1)) > 0 ) /* Read one character */ { /* If got character, */ rbuf[j++] = c; /* Store it */ rbuf[j] = '\0'; /* Mark end of string */ if ( c != '\r' ) putchar( c ); /* Echo it to stdout */ datatime = curtime; /* Save time of last data*/ if ( find_str(rbuf, OPROMPT) != NULL ) { /* Look for prompt */ while ( read(tfd, &c, 1) > 0 ) /* If got it, throw away*/ ; /* extra chars (spaces)*/ return( OK ); /* and return OK */ } if ( find_str(rbuf, "DISCONNECTED") != NULL ) return( DOWNLOAD_ERR ); /* Look for DISCON msg */ if ( (c == '\r') || (c == '\n') || (j > BUFSIZE) ) { j = 0; fflush(stdout); } } /* if */ } /* while */ return( DOWNLOAD_ERR ); } /* wait_for_prompt() */ /************************************************************************/ /* Function : get_data */ /* Purpose : Get data from mooring, copy to stdout */ /* Inputs : None */ /* Outputs : Return code for exit() */ /************************************************************************/ Status get_data( Void ) { if ( write_tnc("logs\r") != OK ) /* Send "logs" command */ return( DOWNLOAD_ERR ); if ( wait_for_prompt() != OK ) /* Wait for end of "logs"*/ return( DOWNLOAD_ERR ); printf("\n"); /* Echo newline to output*/ if ( write_tnc("getdata\r") != OK ) /* Send "getdata" command*/ return( DOWNLOAD_ERR ); if ( wait_for_prompt() != OK ) /* Wait for end of data */ return( DOWNLOAD_ERR ); return( OK ); } /* get_data() */ /************************************************************************/ /* Function : send_usr_cmds */ /* Purpose : Send User commands, if any */ /* Inputs : None */ /* Outputs : Return code for exit() */ /************************************************************************/ Status send_usr_cmds( Void ) { Reg Nat32 cnt; for (cnt = 0; cnt < nusrcmds; cnt++ ) { sprintf(rbuf, "%s\r", usrcmds[cnt]); if ( write_tnc(rbuf) != OK ) /* Send user command */ return( DOWNLOAD_ERR ); if ( wait_for_prompt() != OK ) /* Wait for response */ return( DOWNLOAD_ERR ); printf("\n"); /* Echo newline to output*/ } return( OK ); } /* send_usr_cmds() */ /************************************************************************/ /* Function : get_missing_records */ /* Purpose : Look for and download missing data records */ /* Inputs : None */ /* Outputs : Return code for exit() */ /************************************************************************/ Status get_missing_records( Void ) { Reg Int32 lognum; Reg Nat32 rcd; RcdRange range; MBool changedToBin; rcdInit( &logs ); /* Init LogStructs */ if ( !readRcd(can_name, &logs) ) /* Read record file */ return( OK ); changedToBin = FALSE; for ( lognum = logs.firstLog; lognum < logs.nLogs; lognum++ ) for (rcd = 0; getMissingRcd(&logs, lognum, rcd, &range); ) { if ( !changedToBin ) { printf("\n"); if ( write_tnc("parm ascii 0\r") != OK ) return( DOWNLOAD_ERR ); if ( wait_for_prompt() != OK ) return( DOWNLOAD_ERR ); changedToBin = TRUE; } printf("\n"); /* Echo newline to output*/ sprintf(rbuf, "getlog %d %d %d\r", lognum, range.min, range.max - range.min +1); if ( write_tnc(rbuf) != OK ) return( DOWNLOAD_ERR ); if ( wait_for_prompt() != OK ) return( DOWNLOAD_ERR ); rcd = range.max + 1; } return( OK ); } /* get_missing_records() */ /************************************************************************/ /* Function : tnc_read */ /* Purpose : SIGIO handler */ /* Inputs : Signal number received */ /* Outputs : None */ /************************************************************************/ Void tnc_read( Void ) { Int32 nbytes; char c; if ( (nbytes = read(tfd, &c, 1)) > 0 ) { rbuf[rcnt++] = c; if ( echo && (c != '\r') ) putchar( c ); if ( rcnt > BUFSIZE ) rcnt = 0; rbuf[rcnt] = '\0'; } else if ( nbytes == -1 ) { aborted = TRUE; perror( "Read error in SIGIO handler\n" ); } } /************************************************************************/ /* Function : quit */ /* Purpose : SIGTERM handler */ /* Inputs : Signal number received */ /* Outputs : None */ /************************************************************************/ Void quit( Int sig ) { aborted = TRUE; } /* quit() */ @ 3.0 log @Added tstring, misc changes @ text @d4 1 a4 1 /* $Header: getoasis.c,v 2.9 98/08/24 13:45:56 bobh Exp $ */ d9 1 a9 1 /* $Revision: 2.9 $ */ d11 8 d23 3 d76 1 d124 2 d138 2 a139 1 MLocal char *setup_tnc[] = { "NO OFF\r", "EC OFF\r", "RET 15\r", "M OFF\r" }; d156 1 d171 1 a171 1 printf("OASIS download program $Revision: 2.9 $\n"); d199 3 d257 1 a257 1 while ( (i = getopt(argc, argv, "a:b:c:p:r:t:")) != EOF ) d287 4 d623 28 @ 2.9 log @Archiving sources after M2/M3 & Eqpac deployments of 1998 @ text @d4 1 a4 1 /* $Header: getoasis.c,v 2.8 98/03/17 11:11:43 bobh Exp $ */ d9 1 a9 1 /* $Revision: 2.8 $ */ d15 3 d155 1 a155 1 printf("OASIS download program $Revision: 2.8 $\n"); @ 2.8 log @Archiving sources prior to porting to DOS/Windows @ text @d4 1 a4 1 /* $Header: getoasis.c,v 2.7 97/09/09 09:52:48 bobh Exp $ */ d9 1 a9 1 /* $Revision: 2.7 $ */ d15 3 d45 2 a46 2 #include /* MBARI type definitions */ #include /* MBARI constants */ d152 1 a152 1 printf("OASIS download program $Revision: 2.7 $\n"); d179 3 a184 3 if ( rtn == OK ) rtn = get_data(); d186 1 a186 1 sleep( 5 ); d197 1 a197 1 sleep( 2 ); d358 2 a359 2 Reg Int rtn; Reg char *p; d362 8 a369 4 while ( (p = strchr(s, '\r')) != NULL ) *p = '\n'; printf( "%s", s ); fflush( stdout ); d397 2 d560 1 d562 2 d584 1 a584 1 if ( wait_for_prompt() == ERROR ) /* Wait for end of "logs"*/ d591 1 a591 1 if ( wait_for_prompt() == ERROR ) /* Wait for end of data */ d608 2 a609 1 Reg Nat32 lognum, rcd; d629 1 a629 1 if ( wait_for_prompt() == ERROR ) d639 1 a639 1 if ( wait_for_prompt() == ERROR ) @ 2.7 log @Archiving various changes @ text @d4 1 a4 1 /* $Header: getoasis.c,v 1.5 94/01/17 11:07:42 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.5 $ */ d15 3 d108 1 a108 1 { IGNPAR | IXON, /* c_iflag */ d118 1 a118 1 MLocal char *setup_tnc[] = { "NO ON\r", "EC OFF\r", "RET 15\r", "M OFF\r" }; d120 1 a120 1 MLocal char *restore_tnc[] = { "NO OFF\r", "EC ON\r" }; d131 1 d149 1 a149 1 printf("OASIS download program $Revision: 1.5 $\n"); d167 2 d182 1 a182 1 write( tfd, "quit\r", 5 ); d301 3 a303 3 /* Function : gets_tmout */ /* Purpose : Read one line from a file descriptor with timeout */ /* Inputs : File descriptor, buffer, length, timeout (seconds) */ d308 1 a308 1 gets_tmout( Int fd, char *buf, Int len, Int tmout ) d317 1 a317 1 if ( (i = read(fd, &buf[rtn], 1)) < 0 ) /* Read one character */ d322 1 a322 1 if ( (c == '\r') || (c == '\n') ) /* look for end of line */ d324 5 d336 5 d343 1 a343 1 } /* gets_tmout() */ d347 22 d379 1 a379 1 if ( write(tfd, "\003\r", 2) != 2 ) /* Send ctrl-C to TNC */ d384 1 a384 1 if ( gets_tmout(tfd, rbuf, 4, 10) <= 0 ) d409 2 a410 2 write(tfd, cmds[i], strlen(cmds[i])); gets_tmout( tfd, rbuf, BUFSIZE, 1 ); /* Discard any replys */ d431 1 a431 1 write( tfd, "STAT\r", 5); /* Ask for status */ d434 1 a434 1 while ( gets_tmout(tfd, rbuf, BUFSIZE, 10) != ERROR ) d440 1 a440 1 gets_tmout( tfd, rbuf, BUFSIZE, 10 ); /* Clear tnc buffer */ d461 1 a461 1 if ( write(tfd, "D\r", 2) != 2 ) /* Make sure we're */ d490 4 d499 3 a501 1 switch( tnc_status() ) /* Check if we're connected*/ d503 2 a504 3 case 0: /* If no conn in progress*/ sprintf(rbuf, "C %s\r", tncaddr); /* Send connect message */ if ( write(tfd, rbuf, strlen(rbuf)) != strlen(rbuf) ) a505 12 break; case 1: /* Connection in progress*/ case 3: /* Just wait */ break; case 4: /* Connected */ case 6: if (write(tfd, "K\r", 2) == 2) /* Go to converse mode */ return( OK ); /* and return OK */ else return( ERROR ); d507 2 a508 1 sleep( 1 ); /* Wait 2 seconds each loop*/ d569 1 a569 1 if ( write(tfd, "logs\r", 5) != 5 ) /* Send "logs" command */ d576 1 a576 1 if ( write(tfd, "getdata\r", 8) != 8 ) /* Send "getdata" command*/ d614 1 a614 1 if ( write(tfd, "parm ascii 0\r", 13) != 13 ) d624 1 a624 1 if ( write(tfd, rbuf, strlen(rbuf)) != strlen(rbuf) ) @ 1.5 log @Misc changes @ text @d4 1 a4 1 /* $Header: getoasis.c,v 1.4 92/06/22 14:48:11 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.4 $ */ d15 3 d49 1 d53 1 a53 1 #define TNC_ADDR "mbari-4 v mbari-2" /* Dflt TNC to connect to */ d55 1 a56 1 #define OK_RTN 0 /* Good exit() code */ a62 1 typedef int Status; /* Status rtn, normally OK or ERROR */ a63 1 d68 1 a68 1 Extern Boolean set_baud( struct termio *tp, Int baud ); d73 4 d85 1 d95 8 a102 3 MLocal Int tfd = ERROR; /* TNC file descriptor */ MLocal Boolean aborted = FALSE; /* Set from signal handler */ MLocal char rwbuf[BUFSIZE+1]; /* Read/write line buffer */ d115 1 a115 2 MLocal char *setup_tnc[] = { "NO ON\r", "EC OFF\r", "RET 15\r", "M OFF\r", "MY MBARI-1" }; d124 1 a124 1 Boolean process_command_line ( Int argc, char **argv ); d129 1 d145 1 a145 1 printf("OASIS download program $Revision: 1.4 $\n"); d168 8 a175 1 rtn = get_data(); d209 2 a210 2 "Usage: %s [-a tnc_address] [-b baud] [-p port] ", s ); fprintf( stderr, "[-t timeout]\n"); d221 1 a221 1 Boolean d226 1 a226 1 while ( (i = getopt(argc, argv, "a:b:p:t:")) != EOF ) d238 5 d247 5 d346 1 a346 1 if ( gets_tmout(tfd, rwbuf, 4, 10) <= 0 ) d348 1 a348 1 if ( find_str(rwbuf, "cmd:") != NULL ) d372 1 a372 1 gets_tmout( tfd, rwbuf, BUFSIZE, 1 ); /* Discard any replys */ d396 2 a397 2 while ( gets_tmout(tfd, rwbuf, BUFSIZE, 10) != ERROR ) if ( (p = find_str(rwbuf, "STAT")) != NULL ) d402 1 a402 1 gets_tmout( tfd, rwbuf, BUFSIZE, 10 ); /* Clear tnc buffer */ d460 2 a461 2 sprintf(rwbuf, "C %s\r", tncaddr); /* Send connect message */ if ( write(tfd, rwbuf, strlen(rwbuf)) != strlen(rwbuf) ) d505 2 a506 2 rwbuf[j++] = c; /* Store it */ rwbuf[j] = '\0'; /* Mark end of string */ d510 1 a510 1 if ( find_str(rwbuf, OPROMPT) != NULL ) d516 2 a517 2 if ( find_str(rwbuf, "DISCONNECTED") != NULL ) return( ERROR ); /* Look for DISCON msg */ d523 1 a523 1 return( ERROR ); d530 1 a530 1 /* Purpose : Get data from input file, copy to stdout */ d534 1 a534 1 Int a536 3 if ( wait_for_prompt() == ERROR ) /* Look for initial prompt*/ return( DOWNLOAD_ERR ); d550 1 a550 1 return( OK_RTN ); d554 79 @ 1.4 log @Fixed timeout bug in wait_for_prompt() that caused early abort. @ text @d4 1 a4 1 /* $Header: getoasis.c,v 1.3 92/06/22 10:20:22 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.3 $ */ d15 3 d87 1 a87 1 MLocal time_t timeout = 600; /* 10 minute timeout by default */ d103 2 a104 1 MLocal char *setup_tnc[] = { "NO ON\r", "EC OFF\r", "RET 15\r", "M OFF\r" }; d133 1 a133 1 printf("OASIS download program $Revision: 1.3 $\n"); d169 1 d447 1 a447 1 sleep( 2 ); /* Wait 2 seconds each loop*/ @ 1.3 log @Fixed bug in tnc_cmd_mode. Added error message if release_port() fails. @ text @d4 1 a4 1 /* $Header: getoasis.c,v 1.2 92/05/29 09:13:14 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.2 $ */ d15 3 d129 1 a129 1 printf("OASIS download program $Revision: 1.2 $\n"); d460 1 a460 1 time_t start, curtime; d464 1 a464 1 time( &start ); /* Get start time */ d467 1 a467 1 while ( !aborted && (time(&curtime) <= start + timeout) ) d469 1 a469 1 if ( (i = read(tfd, &rwbuf[j], 1)) > 0 ) /* Read one character */ d471 1 a471 1 c = rwbuf[j++]; /* store it */ d475 1 d486 2 a487 2 } } @ 1.2 log @Changed restore parameters to delete "M OFF", add "EC ON" Deleted #define _HPUX_SOURCE. It's now defined in Makefile. @ text @d4 1 a4 1 /* $Header: getoasis.c,v 1.2 92/05/26 11:31:39 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.1 $ */ d15 4 d139 2 d142 1 a161 2 release_port( tncfile, tfd, &tnc_save ); d164 3 d302 2 d307 1 a307 1 while ( TRUE ) /* Wait for "cmd:" prompt*/ d309 1 a309 1 if ( gets_tmout(tfd, rwbuf, 4, 10) == ERROR ) @ 1.1 log @First working version @ text @d4 1 a4 1 /* $Header: getoasis.c,v 1.0 92/03/12 13:59:22 hebo Exp $ */ d9 1 a9 1 /* $Revision: 1.0 $ */ d15 3 a22 2 #define _HPUX_SOURCE /* termio.h (at least) needs this */ d95 1 a95 1 MLocal char *restore_tnc[] = { "NO OFF\r", "M ON\r" }; d103 1 a103 1 Void use_msg( Void ); d122 1 a122 1 printf("OASIS download program $Revision: 1.0 $\n"); d125 1 a125 1 use_msg(); d167 1 a167 1 /* Inputs : None */ d171 1 a171 1 use_msg( Void ) d174 1 a174 1 "Usage: oasis_download [-a tnc_address] [-b baud] [-p port] " ); @ 1.1.1.1 log @Wait til OASIS about to listen, save time of connect to file "oasis.time" @ text @d4 1 a4 1 /* $Header: getoasis.c,v 1.2 92/03/30 14:34:35 hebo Rel $ */ d9 1 a9 1 /* $Revision: 1.2 $ */ a14 3 * Revision 1.1 92/03/16 15:44:43 15:44:43 hebo (Bob Herlien) * First working version * a39 1 #define TIME_FILE "oasis.time" /* File name to write connect time */ a75 1 MLocal time_t cycle_time = 600; /* 10 minute timeout by default */ d120 2 a121 4 FILE *tfp; /* FILE ptr for connect time */ time_t conntime, curtime; printf("OASIS download program $Revision: 1.2 $\n"); d134 1 a134 1 exit( PORT_ERR ); /* Get serial lock file */ d139 5 a143 12 if ( (tfp = fopen(TIME_FILE, "r+")) == (FILE *)NULL ) tfp = fopen(TIME_FILE, "w"); else /* Read connect_time file,*/ { /* sleep until OASIS wakes*/ if ( fscanf(tfp, "%lx", &conntime) == 1 ) { time( &curtime ); while ( conntime < curtime ) /* Look for next time to */ conntime += cycle_time; /* connect */ if ( conntime - 60 > curtime ) /* Wait til OASIS wakes up*/ sleep( conntime - curtime - 60 ); } d145 2 a146 17 if ( connect_tnc() == OK ) /* Connect to OASIS */ { /* Connected. */ if ( tfp != (FILE *)NULL ) /* If have a conn_time file*/ { time( &curtime ); /* Write new connect time */ rewind( tfp ); fprintf( tfp, "%lx %s", curtime, ctime(&curtime) ); fclose( tfp ); } rtn = get_data(); /* Get OASIS data */ write( tfd, "quit\r", 5 ); /* Log off OASIS */ sleep( 5 ); /* Wait for disconnect */ } else /* If couldn't connect, */ { /* print error message */ d151 1 a151 1 disconnect_tnc(); /* Disconn, just to make sure*/ d155 1 a155 1 release_port( tncfile, tfd, &tnc_save ); /* Release lock file */ d173 2 a174 2 "Usage: get_oasis [-a tnc_address] [-b baud] [-c cycle_time] " ); fprintf( stderr, "[-p port] [-t timeout]\n"); d190 1 a190 1 while ( (i = getopt(argc, argv, "a:b:c:p:t:")) != EOF ) a201 4 case 'c': cycle_time = atoi(optarg); break; d392 1 a392 1 /* Purpose : Connect local TNC to remote TNC */ @ 1.0 log @Initial revision @ text @d4 1 a4 1 /* $Header$ */ d9 1 a9 1 /* $Revision$ */ d14 3 a16 1 /* $Log$ d38 1 a38 1 #define TNC_ADDR "mbari-4" /* Dflt TNC to connect to */ a77 1 MLocal Boolean echo = FALSE; /* Echo serial output to stdout */ d82 1 a82 1 { IGNPAR | ICRNL | IXON, /* c_iflag */ d92 1 a92 1 MLocal char *setup_tnc[] = { "NO ON\r", "EC OFF\r", "RET 10\r", "M OFF\r" }; d121 1 a121 1 printf("OASIS download program $Revision$\n"); a252 1 /* Side Effects: Copies the read data to stdout if echo TRUE */ a278 2 if ( echo ) fwrite( buf, 1, rtn, stdout ); /* Echo it to stdout */ d447 2 d451 1 d455 6 a460 2 if ( gets_tmout(tfd, rwbuf, BUFSIZE, 10) != ERROR ) { d462 5 a466 1 return( OK ); d468 3 a470 1 return( ERROR ); a487 1 echo = TRUE; /* Start echoing output */ a502 2 echo = FALSE; @