📄 atimets.ec.bak
字号:
/* lwj update at 2003/06/09 11:20 */
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/locking.h>
#include <string.h>
#include <signal.h>
#include <sys/termio.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#define OPERAT 02
#define TRAFFIC 03
#define MINCHAR 13
#define C_SIZE 86
#define L_SIZE 128
#define RPLEN 32
#define PLEN 10
#define MAX_CLOCK 20 /* max on time num*/
#define MAX_PH 120 /* max on time phone num*/
#define CONFIGLEN sizeof(struct configst)
#define MAX_PORT_NO 16
#define FLASHCLOCK "11:52"
#define PATH "/u/informix"
#define CONFIGFILE "/u/informix/datashare/config"
#define CLOCKFILE "/u/informix/datashare/clockf.h"
#define NUMFILE "/u/informix/datashare/phnumf.h"
struct configst {
char office_name[6];
char exchport[6];
char omcport[7];
char iogtype[9];
unsigned short speed;
unsigned short cstop;
unsigned short paraenb;
unsigned short bit_len;
char send_char;
char connect_char;
char release_char;
char prompts_char;
unsigned short data_type;
char ver[10];
char apz[17];
unsigned short trfcode;
};
char resul[2];
char tjtime[25];
int mapfd,port;
struct configst conf[MAX_PORT_NO];
char portname[20];
int succ_old;
char scjm[15];
char str[4],stri[10];
struct clockstru
{
char clocktime[L_SIZE];
char clockcomm[L_SIZE];
int clockok;
};
struct clockstru clockrec[MAX_CLOCK];
char phonenum[MAX_PH][PLEN];
char comm[L_SIZE];
char phone[PLEN];
int clocklen,phnumlen;
int old_day,sysday,syshour,sysmin,istimeok;
char PASSUSER[8][9]={"PW0009\n","PW0002\n","PW0003\n","PW0004\n","PW0005\n","PW0006\n","PW0007\n","PW0008\n"};
/******************************************************************************/
main(argc,argv)
int argc;
char *argv[];
{
int fp;
int i,j,r,t,resul;
printf("make by lwj 2003/06/09 11:20 start exec *******************\n");
old_day=0;
getclock();
strcpy(scjm,"GXYLTS");
printf("start exec *******************\n");
signal(SIGCLD,SIG_IGN);
if((fp=initport())<=0) exit(0);
for(;;)
{
getsystime();
istime(FLASHCLOCK);
if(istimeok==1)
getclock();
for(i=0;i<clocklen;i++)
{
istime(clockrec[i].clocktime);
if(istimeok==1 && clockrec[i].clockok==0)
{
clockrec[i].clockok=1;
printf("time %s is OK OK OK\n",clockrec[i].clocktime);
strcpy(comm,clockrec[i].clockcomm);
printf("auto time( %s )comm is ( %s ) ! \n",clockrec[i].clocktime,comm);
exec_comm(fp,comm);
} /* if */
} /* for clocken */
} /* for ;; */
} /* main */
/******************************************************************************/
getsystime()
{int i;
long time(),lg;
struct tm *localtime(),*tim;
lg=time(&lg);
tim=localtime(&lg);
sysday=tim->tm_mday;
syshour=tim->tm_hour;
sysmin=tim->tm_min;
if(tim->tm_mday!=old_day)
{
for(i=0;i<clocklen;i++)
clockrec[i].clockok=0;
old_day=tim->tm_mday;
}
printf("current time is day=%d ,hour=%d ,minuter=%d ,second=%d !!!!\n",sysday,syshour,sysmin,tim->tm_sec);
}
/*************************************************************************/
istime(char *clock)
{int hh,mm;
sscanf(clock,"%d:%d",&hh,&mm);
if(hh==syshour && mm==sysmin) istimeok=1;
else istimeok=0;
}
/*************************************************************************/
getnum()
{ FILE *fp;
char buff[L_SIZE];
int i;
if((fp=fopen(NUMFILE,"r"))==NULL)
{printf("open numfile error ! \n");
fclose(fp);
return(-1);
}
i=0;
while(!feof(fp))
{ fgets(buff,L_SIZE,fp);
strcpy(phonenum[i],buff);
i++;
}
phnumlen=i;
fclose(fp);
return(0);
}
/*************************************************************************/
getclock()
{ FILE *fp;
char buff[L_SIZE];
int i;
if((fp=fopen(CLOCKFILE,"r"))==NULL)
{printf("open clockfile error ! \n");
fclose(fp);
return(-1);
}
i=0;
while(!feof(fp))
{ fgets(buff,L_SIZE,fp);
strcpy(clockrec[i].clocktime,buff);
fgets(buff,L_SIZE,fp);
strcpy(clockrec[i].clockcomm,buff);
clockrec[i].clockok=0;
printf("auto time( %s )comm is ( %s ) ! \n",clockrec[i].clocktime,clockrec[i].clockcomm);
i++;
}
clocklen=i;
fclose(fp);
return(0);
}
/******************************************************************************/
initport()
{
struct termio t;
int p,i;
int nn;
int fdd;
int n;
char c,str[80];
FILE *confd;
char porttype[5][20]={"TRAFFIC","TRAFFIC","OPERATION","TRAFFIC","TRAFFIC"};
int porttype_no;
if ((confd=fopen(CONFIGFILE,"rb"))==NULL){
perror("config open");
exit(1);
}
if((n=fread(conf,CONFIGLEN,MAX_PORT_NO,confd))<0){
perror("fread");
exit(0);
}
if(n==0){
printf("there is no defined port!\n");
exit(0);
}
fclose(confd);
for(;;){
system("clear");
printf("\n S1240 PORT LIST \n");
printf("\n lwj update at 2003/06/09 11:20 \n");
printf(" ========================\n");
printf("\n\n");
for(port=0;port<n;port++){
porttype_no=conf[port].data_type;
for(i=0,p=1;i<=(port%4);i++) p=p*2;
printf(" %d%d : %s %s (%s::%dE71) \n",port/10,port%10,conf[port].office_name,conf[port].omcport,conf[port].iogtype,p*600);
}
printf("\n please press 0 - %d to select exchange port(or q to exit) :",n-1);
scanf("%s",str);
if(strlen(str)==0)continue;
if(str[0]=='q'||str[0]=='Q') {
system("clear");
system("stty sane");
exit(0);
}
sscanf(str,"%d",&port);
if(port>=0&&port<n)
{
if(conf[port].data_type!=OPERAT)
{
printf("this is not operation port!!\n");
printf("you should change to operat type,reactive COMIR and INFPHD!!\n");
sleep(1);
continue;
}
else break;
}
else {
printf("out of range !!!\n");
sleep(1);
continue;
}
}
system("clear");
setbuf(stdout,(char *)0);
system("stty -echo -isig -icanon");
system("stty min 1");
sprintf(portname,"/dev/%s",conf[port].omcport);
if((fdd=open(portname,O_RDWR))<0) { perror("Open"); return(-1); }
if((nn=ioctl(fdd,TCGETA,&t))<0) {
perror("Ioctl"); close(fdd); return(-1);
}
t.c_lflag=0;
/*
t.c_cflag = B1200 | CS7 | CREAD | CLOCAL | PARENB ;
*/
t.c_cflag=conf[port].speed | conf[port].bit_len | conf[port].paraenb | CREAD | CLOCAL;
t.c_iflag=BRKINT | BRKINT | IGNPAR | IGNCR | IXON | IXOFF | IXANY ;
t.c_oflag=0;
t.c_line=0;
t.c_cc[7]=255;
t.c_cc[4]=1;
t.c_cc[5]=0;
if((nn=ioctl(fdd,TCSETA,&t))<0) {
perror("Ioctl");
close(fdd);
return(-1);
}
c=0x1b;
write(fdd,&c,1);
return(fdd);
}
/****************************************************************/
send_file(int spc,char *comm)
{
char send_char;
int i,len;
printf("send_file==>%s",comm);
len=strlen(comm);
for(i=0;i<len;i++)
{
send_char=comm[i];
if(send_char==0x0a) send_char=0x0d;
write(spc,&send_char,1);
if(send_char==0x0d)nap(100);
else nap(50);
nap(1);
} /* for i<len */
}
/****************************************************************/
init()
{
setbuf(stdout,(char *)0);
system("stty -echo -isig -icanon");
system("stty min 1");
if ((mapfd=open("/dev/vga",O_RDWR))<0){
perror("Fault");
exit(0);
}
/* ch_mod(mapfd); */
}
/****************************************************************/
exec_comm(int fd1,char *comm)
{int i,t,passnum,resul;
char c;
passnum=0;
star:
t=0;
resul=0;
while(resul<=0 && t<10)
{
resul=justsend(">",0);
if(resul<0 || t>1)
{
c=0x1b;
write(fd1,&c,1);
nap(1000);
}
send_file(fd1,"mm\n");
nap(1000);
resul=justsend("USERID:",0)+justsend("<",0);
/* printf("scan userid or < is==%d\n",resul);*/
i=0;
while(resul==0 && i<5)
{
i++;
nap(1000);
/* printf("scan USERID or < ==%d time /n",i); */
resul=justsend("USERID:",0)+justsend("<",0);
}
t++;
} /* send mm to connect the SWITCH */
if(resul==0) return(0);
resul=justsend("USERID:",0);
if(resul>0)
{
send_file(fd1,PASSUSER[passnum]);
nap(1000);
resul=justsend("PASSWORD:",0);
i=0;
while(resul==0 && i<10)
{
i++;
nap(1000);
/* printf("scan USERID or < ==%d time /n",i); */
resul=justsend("PASSWORD:",0);
}
if(resul>0) send_file(fd1,PASSUSER[passnum]);
else goto star;
nap(1000);
} /*** sent userid and password ***/
resul=justsend("<",0);
i=0;
while(resul==0 && i<10)
{
i++;
nap(1000);
resul=justsend("ALREADY LOGGED ON !",1);
if(resul>0)
{
passnum++;
if(passnum>=8) passnum=0;
goto star;
}
resul=justsend("<",0);
}
if(resul>0)
{
send_file(fd1,comm);
nap(3000);
i=0;
resul=0;
while(resul==0 && i<10)
{
i++;
nap(2000);
resul=justsend(">",0);
}
return(1);
}
else goto star;
}
/****************************************************************/
justsend(str,mod)
char *str;
int mod;
{char buff[L_SIZE],endbuff[L_SIZE],portname[6];
int resul;
FILE *fp;
char fname[50];
long time(),lg;
struct tm *localtime(),*tim;
lg=time(&lg);
tim=localtime(&lg);
strcpy(portname,conf[port].omcport);
sprintf(fname,"%s/data/%sO%s_%d%d%d%d%d",PATH,conf[port].office_name,&portname[3],tim->tm_year,(tim->tm_mon+1)/10,(tim->tm_mon+1)%10,tim->tm_mday/10,tim->tm_mday%10);
/*
printf("%s\n",fname);
*/
if((fp=fopen(fname,"r"))==NULL)
{printf("open rawfile error ! \n");
fclose(fp);
nap(30000);
return(-1);
}
fgets(endbuff,L_SIZE,fp);
while(!feof(fp))
{
strcpy(buff,endbuff);
fgets(endbuff,L_SIZE,fp);
}
fclose(fp);
printf("*******scan %s********************************\n",str);
printf("raw buff:%s\n",buff);
printf("raw endbuff:%s\n\n",endbuff);
if(mod==1) strcpy(endbuff,buff);
resul=sub_str(endbuff,str);
/* printf("sub_str(%s,%s)=%d)\n",endbuff,str,resul); */
if(resul>=0)
return(1);
else
return(0);
}
/****************************************************************/
scanok(char *teleno)
{char portname[6],rawbuff[RPLEN][L_SIZE];
FILE *fp;
char fname[50],hour[6];
long time(),lg;
struct tm *localtime(),*tim;
int i,lastok,succok,teleok;
int yy,mm,dd;
char mon_name[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
lg=time(&lg);
tim=localtime(&lg);
strcpy(portname,conf[port].omcport);
sprintf(fname,"%s/data/%sO%s_%d%d%d%d%d",PATH,conf[port].office_name,&portname[3],tim->tm_year,(tim->tm_mon+1)/10,(tim->tm_mon+1)%10,tim->tm_mday/10,tim->tm_mday%10);
printf("now scan ok %s\n",fname);
if((fp=fopen(fname,"r"))==NULL)
{printf("open rawfile error ! \n");
fclose(fp);
nap(30000);
return(-1);
}
for(i=0;i<RPLEN;i++)
if(!feof(fp))
fgets(rawbuff[i],L_SIZE,fp);
else
break;
for(;!feof(fp);)
{
for(i=1;i<RPLEN;i++)
strcpy(rawbuff[i-1],rawbuff[i]);
if(!feof(fp)) fgets(rawbuff[RPLEN-1],L_SIZE,fp);
}
fclose(fp);
for(i=0;i<RPLEN;i++)
printf("%s",rawbuff[i]);
lastok=0;
teleok=0;
succok=0;
delblank(teleno);
for(i=0;i<RPLEN;i++)
{ if(sub_str(rawbuff[i],"LAST REPORT")>0) lastok=1;
if(sub_str(rawbuff[i],teleno)>0) teleok=1;
if(sub_str(rawbuff[i],"SUCCESSFUL")>0)
{
succok=1;
if(sub_str(rawbuff[i],"NOT SUCCESSFUL")>0) succok=2;
}
if(sub_str(rawbuff[i],scjm)>0)
{sscanf(rawbuff[i],"%*s %4d-%2d-%2d %8s",&yy,&mm,&dd,hour);
sprintf(tjtime,"%d %s %d %8s",yy,mon_name[mm-1],dd,hour);
}
}
printf("lastok=%d,teleok=%d,succok=%d,time=%s\n",lastok,teleok,succok,tjtime);
/****1 is success,2 is not success,3 is can't know */
if(lastok==1&&teleok==1&&succok==1)
{
strcpy(resul,"1");
return(1);
}
else
if(lastok==1&&teleok==1&&succok==2)
{
strcpy(resul,"2");
return(2);
}
else
{
strcpy(resul,"3");
return(3);
}
}
/****************************************************************/
sub_str(str1,str2)
char *str1,*str2;
{
int l1,l2,i;
l1=strlen(str1);
l2=strlen(str2);
if(l1<l2) return(-1);
for(i=0;i<l1;i++) {
if(l1-i<l2) return(-1);
if(!strncmp(str1+i,str2,l2)) return(i);
}
return(-1);
}
/****************************************************************/
cha_str(str,strold,strnew)
char *str,*strold,*strnew;
{ char buff[L_SIZE];
int l1,l2,i,i0;
l1=strlen(strold);
l2=strlen(strnew);
i0=sub_str(str,strold);
strcpy(buff,str+i0+l1);
for(i=0;i<l2;i++) str[i0+i]=strnew[i];
l1=strlen(buff);
for(i=0;i<=l1;i++) str[i0+l2+i]=buff[i];
}
/****************************************************************/
delblank(char *str)
{int len;
len=sub_str(str," ");
if(len>0) str[len]='\0';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -