📄 ecudce.c
字号:
/* #define USE_S7 *//*+------------------------------------------------------------------------- ecuDCE.c - ECU DCE dialing and management wht@n4hgf.Mt-Park.GA.US Defined functions: DCE_autoanswer() DCE_dial() DCE_get_result(msec_to_wait) DCE_get_sreg_value(regnum) DCE_hangup() DCE_modem_init() DCE_now_on_hook() DCE_read_modem_init() DCE_redial(arg,argc) DCE_report_iv_set(varnum) DCE_send_cmd(cmd) DCE_set_sreg(regnum,value) check_queued_sigint() process_modem_init(str) show_modem_init_error(erc,iesd)Lothar Hirschbiegel <emory!tmcsys.uucp!lothar> added the ability tospecify a modem acknowledgement string other than "OK".Example use:#+-----------------------------------------------------------------# tty1a.mi - Microcom QX/V.32c#------------------------------------------------------------------init_default:sceondial_default:dpok_string:!--------------------------------------------------------------------------*//*+:EDITS:*//*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 *//*:09-05-1992-14:17-wht@n4hgf-was starting rcvr process too early on connect *//*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA *//*:04-19-1992-03:21-jhpb@sarto.budd-lake.nj.us-3.18.37 has ESIX SVR4 *//*:02-16-1992-01:41-wht@n4hgf-turn off xterm_title *//*:02-04-1992-04:49-wht@n4hgf-fix bug in kill_rcvr_process logic *//*:01-17-1992-15:32-wht@n4hgf-.credit open to public *//*:11-07-1991-16:54-tmcsys!lothar-alternate OK string for built-in dialer *//*:08-28-1991-14:07-wht@n4hgf2-SVR4 cleanup by aega84!lh *//*:07-25-1991-12:55-wht@n4hgf-ECU release 3.10 *//*:07-17-1991-07:04-wht@n4hgf-avoid SCO UNIX nap bug *//*:06-29-1991-15:42-wht@n4hgf-if WHT and xterm, play with title bar *//*:06-16-1991-23:24-wht@n4hgf-ensure hangup since proc could fail connected *//*:06-07-1991-04:09-wht@n4hgf-remove unnecessary naps after kill_rcvr_process *//*:05-20-1991-00:56-wht@n4hgf-fix/upgrade auto fkey load *//*:01-09-1991-22:31-wht@n4hgf-ISC port *//*:01-09-1991-21:23-wht@n4hgf-fix statement not reached *//*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller *//*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */#include "ecu.h"#include "ecukey.h"#include "esd.h"#include "var.h"#include "ecupde.h"#include "ecuerror.h"#include "relop.h"char *get_elapsed_time();char *make_char_graphic();void DCE_hangup();extern int proctrace;extern ulong colors_current;extern char kbdintr;int mi_line;char mi_name[64];char last_dial_result[64];#define MI_MAX_LEN 65char Lmodem_init[MI_MAX_LEN] = ""; /* modem init string w/o trailing CR */char Lmodem_dial[MI_MAX_LEN] = ""; /* modem dialing prefix */char Lmodem_autoans[MI_MAX_LEN] = ""; /* modem autoanswer */char Lmodem_okstring[MI_MAX_LEN] = ""; /* modem ok_answer */char *interrupted_string = "!Interrupted";/*+------------------------------------------------------------------------- check_queued_sigint()--------------------------------------------------------------------------*/intcheck_queued_sigint(){ while(ttyrdchk()) { if((uchar)ttygetc(1) == (uchar)kbdintr) { sigint = 1; return(1); } } return(0);} /* end of check_queued_sigint *//*+------------------------------------------------------------------------- show_modem_init_error(erc,iesd)--------------------------------------------------------------------------*/voidshow_modem_init_error(erc,iesd)int erc;ESD *iesd;{ register itmp; pputs(mi_name); pprintf(" line %d: ",mi_line); proc_error(erc); pputs(iesd->pb); pputc(NL); itmp = iesd->old_index; while(itmp--) pputc(' '); pputs("^\n\n");} /* end of show_modem_init_error *//*+----------------------------------------------------------------------- process_modem_init(str)sample /usr/lib/ecu/tty??.mi lines:init_9600:ATS11=47X4S0=0S7=30\Q0\X0\N0init_>2400:ATS11=47X4S0=0S7=30\Q0\X0\N0init_<=2400:ATS11=47X4S0=0S7=30\Q1\X1\N3ATDTreturn 0 if entire list read, else 1 if error (error msg in errmsg)------------------------------------------------------------------------*/voidprocess_modem_init(str)char *str;{#define MI_INIT 1#define MI_DIAL 2#define MI_AUTOANS 3#define MI_OKSTRING 4 int erc; ESD sesd; char typestr[32]; int relop; int truth = 0; int type; long test_baud; sesd.pb = str; sesd.cb = strlen(str); sesd.maxcb = strlen(str); sesd.index = 0; sesd.old_index = 0; if(get_alpha_zstr(&sesd,typestr,sizeof(typestr))) { erc = eSyntaxError; goto SHOW_ERROR; } if(ulindex(typestr,"init_") == 0) type = MI_INIT; else if(ulindex(typestr,"dial_") == 0) type = MI_DIAL; else if(!strcmpi(typestr,"autoanswer")) type = MI_AUTOANS; else if(!strcmpi(typestr,"ok_string")) type = MI_OKSTRING; else { erc = eSyntaxError; goto SHOW_ERROR; }/* test for default ... if none, check baud rate */ if((type == MI_AUTOANS) || (type == MI_OKSTRING)) truth = 1; else if(ulindex(typestr,"_default") > 0) { truth = !( ((type == MI_INIT) && Lmodem_init[0]) || ((type == MI_DIAL) && Lmodem_dial[0])); } else { /* get optional operator */ if(get_relop(&sesd,&relop)) relop = OP_EQ; if(erc = gint_constant(&sesd,&test_baud)) goto SHOW_ERROR; truth = test_truth_int((long)shm->Lbaud,relop,test_baud); }/* if no match, skip this one */ if(!truth) return;/* skip over colon */ if(erc = skip_colon(&sesd)) goto SHOW_ERROR;/* make sure init or dial string not empty or too long */ if((erc = skip_cmd_break(&sesd)) && (type != MI_AUTOANS)) goto SHOW_ERROR; if((sesd.cb - sesd.index) > (MI_MAX_LEN - 1)) { erc = eBufferTooSmall; goto SHOW_ERROR; } erc = eDuplicateMatch; /* in case of show error in switch */ switch(type) { case MI_INIT: if(Lmodem_init[0]) goto SHOW_ERROR; strcpy(Lmodem_init,sesd.pb + sesd.index); break; case MI_DIAL: if(Lmodem_dial[0]) goto SHOW_ERROR; strcpy(Lmodem_dial,sesd.pb + sesd.index); break; case MI_AUTOANS: if(Lmodem_autoans[0]) goto SHOW_ERROR; if(!sesd.cb) strcpy(Lmodem_autoans,"!null!"); else strcpy(Lmodem_autoans,sesd.pb + sesd.index); break; case MI_OKSTRING: if(Lmodem_okstring[0]) goto SHOW_ERROR; strcpy(Lmodem_okstring,sesd.pb + sesd.index); break; } return; /* <<<<====== done */SHOW_ERROR: show_modem_init_error(erc,&sesd);} /* end of process_modem_init *//*+----------------------------------------------------------------------- DCE_read_modem_init()0123456789/dev/ttyxx------------------------------------------------------------------------*/voidDCE_read_modem_init(){ char *cptr; register FILE *fp_modem; char *skip_ld_break(); char buffer[128];/* zap init information */ Lmodem_init[0] = 0; Lmodem_dial[0] = 0;/* build filename */ sprintf(mi_name,"%s/%s.mi",ECULIBDIR,shm->Lline + 5);/* read modem initialization */ if(!(fp_modem = fopen(mi_name,"r"))) pperror(mi_name); else { mi_line = 0; while((!Lmodem_init[0] || !Lmodem_dial[0] || !Lmodem_okstring[0]) && fgets(buffer,sizeof(buffer),fp_modem)) { mi_line++; buffer[strlen(buffer) - 1] = 0; cptr = skip_ld_break(buffer); /* skip comments and null lines */ if(!strlen(cptr) || (*cptr == '#')) continue; process_modem_init(cptr); } fclose(fp_modem); }/* default */ if(!Lmodem_init[0]) { strcpy(Lmodem_init,"ATE1Q0V1"); pputs("modem init string not found (using default '"); pputs(Lmodem_init); pputs("')\n"); } if(!Lmodem_dial[0]) { strcpy(Lmodem_dial,"ATDT"); pputs("modem dial string not found (using default '"); pputs(Lmodem_dial); pputs("')\n"); } if(!Lmodem_autoans[0]) { strcpy(Lmodem_autoans,"ATQ1S0=1");#ifdef INUSE pputs("modem autoanswer string not found (using default '"); pputs(Lmodem_autoans); pputs("')\n");#endif } if(!Lmodem_okstring[0]) { strcpy(Lmodem_okstring,"OK");#ifdef notdef pputs("modem ok_string not found (using default '"); pputs(Lmodem_okstring); pputs("')\n");#endif } else if(!strcmp(Lmodem_autoans,"!null!")) Lmodem_autoans[0] = 0; if(proctrace > 1) { pprintf("init: '%s'\n",Lmodem_init); pprintf("dial: '%s'\n",Lmodem_dial); pprintf("autoanswer: '%s'\n",Lmodem_autoans); pprintf("okstring: '%s'\n",Lmodem_okstring); }} /* end of DCE_read_modem_init *//*+------------------------------------------------------------------------- DCE_get_result(msec_to_wait)return pointer to static buf containing result code--------------------------------------------------------------------------*/char *DCE_get_result(msec_to_wait)long msec_to_wait;{ static char s32[32]; LRWT lr; if(sigint) return("!Interrupted"); s32[0] = 0; lr.to1 = msec_to_wait; lr.to2 = 200L; lr.raw_flag = 0x80; /* allow interrupts */ lr.buffer = s32; lr.bufsize = sizeof(s32); lr.delim = (char *)0; lr.echo_flag = 0; lgets_timeout(&lr); if(sigint) return("!Interrupted"); return(lr.buffer);} /* end of DCE_get_result *//*+------------------------------------------------------------------------- DCE_modem_init()--------------------------------------------------------------------------*/DCE_modem_init(){ register itmp; int retries = 0; char *cmd; char *cptr; int old_ttymode = get_ttymode(); if(shm->Lmodem_already_init) return(0); DCE_read_modem_init(); ttymode(2); lputs_paced(0,"\b\b\b\b\b\b\b\b\b"); (void)Nap(200L); lflush(0); while(!shm->Lmodem_already_init) {INIT_LOOP: if(retries > 3) goto ERROR_RETURN; if(sigint) goto ERROR_RETURN; if(retries) { lflash_dtr(); lputs_paced(0,"AT\r"); (void)Nap(400L); lputs_paced(0,"ATQ0V1E1\r"); (void)Nap(400L); } lflush(0); cmd = Lmodem_init; itmp = 0;#ifdef NEUROTIC while(*cmd) { lputc_paced(0,*cmd++); if(++itmp < 2) (void)Nap(40L); if((itmp = lgetc_timeout(500L)) < 0) { if(sigint) goto ERROR_RETURN; retries++; goto INIT_LOOP; } pputc(itmp); }#else lputs(cmd); pputs(cmd);#endif pputc(NL); lputc_paced(0,CRET); itmp = 0; while(itmp != CRET) { if((itmp = lgetc_timeout(500L)) < 0) { if(sigint) goto ERROR_RETURN; pputs("missed expected carriage return\n"); pprintf("got: %x\n",itmp); retries++; goto INIT_LOOP; } } if(strcmp(cptr = DCE_get_result(1200L),Lmodem_okstring)) { if(!strcmp(cptr,interrupted_string)) { sigint = 1; goto ERROR_RETURN; } pprintf("unexpected result: '%s'\n",cptr); retries++; continue; } shm->Lmodem_already_init = 1; } ttymode(old_ttymode); return(0);ERROR_RETURN: ttymode(old_ttymode); return(-1);} /* end of DCE_modem_init *//*+------------------------------------------------------------------------- DCE_send_cmd(cmd)--------------------------------------------------------------------------*/intDCE_send_cmd(cmd)register char *cmd;{ register itmp; DCE_modem_init(); (void)Nap(600L); lflush(0);#ifdef NEUROTIC while(*cmd) { lputc_paced(20,*cmd++); if(++char_count < 2) (void)Nap(40L); if((itmp = lgetc_timeout(500L)) < 0) return(-1); pputc(itmp); }#else lputs(cmd); pputs(cmd);#endif pputc(NL); lputc_paced(20,CRET); itmp = 0; if(sigint || check_queued_sigint()) return(-1); while(itmp != CRET) { if((itmp = lgetc_timeout(1000L)) < 0) { pputs("missed expected carriage return\n"); return(-1); } if(sigint || check_queued_sigint()) return(-1); } return(0);} /* end of DCE_send_cmd *//*+------------------------------------------------------------------------- DCE_report_iv_set(varnum)--------------------------------------------------------------------------*/voidDCE_report_iv_set(varnum)int varnum;{ if(proctrace) pprintf("modem handler set $i%02d = %ld\n",varnum,iv[varnum]);} /* end of DCE_report_iv_set *//*+----------------------------------------------------------------------- DCE_dial() - dial a remote or connect All shm->L... variables have been set up and are used to drive the dialing sequence returns 0 on success (CONNECT), eConnectFailed if failure
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -