⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 check.cpp

📁 Dialogic D41/E语音卡 的一个应用源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include "check.h"

#define TID_1 5

#define PASS_WORD	"05170"     /*用于port[].msi_no*/
//#define B_SERIAL  	"DJ090012"
#define B_SERIAL  	"EM005646"
char path_f[30];

TN_GEN tngen;
DV_TPT tpt[5];
DX_IOTT iott;

long scts,scts1,scts2;
CONFID mconfid[8]={0};
int numfh;
/*struct 
{
	int addr;
	int len;
}seek[20];
*/
extern long errcaseno;

extern RETCODE init_odbc(),close_odbc(),connect_as400b();
extern int get_user(char *,int);
extern int get_bank(char *);
extern int check_last(int);
extern int get_last(int);
extern int change_pass(int);

extern void g_time();

void print_state();
int play_num(int,char *);

void process_port(int channel,int event)
   {
      int errcode;           /* exit to DOS with errcode      */
	  if(event==TM_TONE)
	  {
	   if(ATDX_HOOKST(port[channel].devhandle)!=DX_ONHOOK)
	   {
		if (dx_sethook(port[channel].devhandle,DX_ONHOOK,EV_ASYNC)==-1)
		 {
			printf("error set onhook on channel %d\n",channel);
		 }
	   }
		return;
	  }
	 printf("\nport[%d].state:%d",channel,port[channel].state);
	 port[channel].state=curr_state(channel,event);
     errcode = next_state(channel);
     if (errcode != 0)
      {
       printf("error on channel %d, state %d, return code %d\n",
                   channel,port[channel].state,errcode);
      }

    }

/****************************************************************
*        NAME : init_proc()
* DESCRIPTION : start d/4x system, set cst parameters, put line on
*             : hook and open vox files.
*       INPUT : d4xint = hardware interrupt level.
*      OUTPUT : none.
*     RETURNS : none.
*    CAUTIONS : none.
****************************************************************/
void sys_init()
{
	int i,channel;
	char d4xname[20],string[20];
	int mode,parm[11];
	int numvoxdev = 0;
	FILE *stream;
	int  dev;
	char serial[10];
	if(sr_getboardcnt(DEV_CLASS_VOICE,&numvoxdev)==-1)
	{
	   printf("error sr_getboardcnt");
	   exit(0);
	}
   /* open the board device */
   if ((dev=dx_open("dxxxB1",0 )) == -1) {
      printf("Error opening dxxxB1\n");
      exit(1);
   }
   /* get the board serial number and display it */
   if (dx_gtsernum(dev, GS_SN, serial) == 0) 
   {
		//printf("dxxxB1: %s\n", serial);
		if(strcmp(B_SERIAL,serial)!=0)
		{
			printf("Error board serial_no system exit", ATDV_LASTERR(dev), ATDV_ERRMSGP(dev));
			dx_close(dev);
			exit(0);
		}
   } 
   else 
   {
		printf("Error %d, %s\n", ATDV_LASTERR(dev), ATDV_ERRMSGP(dev));
   }
   dx_close(dev);

	if( numvoxdev < 1 ){
       printf("No boards found");
       //MessageBox(hWnd,"No boards found", "Program Message        ", MB_OK);
	   exit(1);
	}
    numfh=dx_fileopen("c:\\yy\\num.vox",O_RDONLY|O_BINARY);
	if(numfh<=0)
	{
		printf("error open num.vox");
	   exit(1);
	}
    //boxfh=fopen("c:\\yy\\num.box","rb");
	/*boxfh = fopen("c:\\yy\\num.box","r+");
    if(boxfh<=0)
	{
		printf("error open num.box");
	   exit(1);
    }
	else
	{
		for (j=0;j<12;j++)
		{
			fscanf(boxfh,"%d %d\n",&off,&len);
			seek[j].addr=off;
			seek[j].len=len;
		}

	}*/

	stream = fopen( "c:\\check\\file\\cptone.out", "r" );
   if( stream == NULL )
      {
	   printf( "the system file cptone.out was not find\n" );
	   exit (0);
      }
   else
   {
    for(i=0;i<10;i++)
     {
      /* Read data back from file: */
	  fscanf(stream,"%s%d",string,&parm[i]);
	  printf("Line %d:%-9s   %d\n",i,string,parm[i]);
	 }
   }
	fclose(stream);
	  mode=SR_POLLMODE;
      sr_setparm(SRL_DEVICE,SR_MODEID,&mode);

	  for(channel=1;channel<=MAX_CHAN;channel++)
	  { 
		 printf(".");
		 sprintf(d4xname,"dxxxB1C%d",channel);
		 port[channel].devhandle=dx_open(d4xname,0);
		 if(port[channel].devhandle==-1)
		 {
		  printf("error open vox");
		  exit(0);
		 }
       if (dx_sethook(port[channel].devhandle,DX_ONHOOK,EV_ASYNC)==-1)
		 {
			printf("error set onhook on channel %d\n",channel);
		 }

		 port[channel].state = ST_WTRING;
         port[channel].msg_fh=0;
		 if(dx_setevtmsk(port[channel].devhandle,DM_LCREV|DM_RINGS)==-1)
			 printf("error setevtmsk\n");
         if (dx_deltones(port[channel].devhandle) == -1)
		 {
	       printf("error deltones");
         }

       // build tone templet for desconnect supervision
//         if (dx_blddtcad(TID_1,400,25,0,0,35,3,35,3,1)==-1)
         if (dx_blddtcad(TID_1,parm[1],parm[2],parm[3],parm[4],parm[5],parm[6],parm[7],parm[8],parm[9])==-1)
	     {
	       printf("error buliding tone templet");
         }

         if (dx_addtone(port[channel].devhandle,0,0) ==-1)
		 {
	       printf("error dx_addtone");
         }

         if (dx_distone(port[channel].devhandle,TID_1,DM_TONEON|DM_TONEOFF) ==-1)
		 {
	       printf("error dx_disbtone");
         }

		 if(dx_setrings(port[channel].devhandle,MAXRING)==-1)
		 {
			printf("error setrings \n");
		 }

      }
	init_odbc();
   printf("init_odbc ok!");
   errcaseno=0;
    }

void sys_exit()
{
	int chan;
	printf("\nexit lsi program now...\n");
	for(chan=1;chan<=MAX_CHAN;chan++)
	{
		dx_close(port[chan].devhandle);
		printf(".");
	}
	printf("\nclose vox ok!");
	dx_fileclose(numfh);
	close_odbc();
	
	exit(0);
}
/****************************************************************************
* Name:   process_event
* Input:  int channel number
* output: returns a voice event
* Des:    It retreives voice events on a channel by calling sr_getevttype()
*                 sr_getevtdatap() and returns it to the wait_event()
*
*
*****************************************************************************/
int process_event(int channel)
{
   
   int event;
   long bitmask;

   DX_CST *cstp;
   
   /*Process the Event and Save the Next Channel State  */
	 
   event = sr_getevttype();

   switch(event){
      
      case TDX_SETHOOK:
	    cstp = (DX_CST *) sr_getevtdatap();
	    return( cstp->cst_event );

      case TDX_CST:
	    cstp = (DX_CST *) sr_getevtdatap();
	    if(cstp->cst_event==DE_RINGS)
		{
			port[channel].state=ST_WTRING;
			return( USER_RINGS );
		}
        else
			return( cstp->cst_event );
      
      case TDX_PLAYTONE:           /* Playtone Completed   */    
      case TDX_RECORD:             /* Record Completed     */
      case TDX_PLAY:               /* Play Completed       */
      case TDX_GETDIG:             /* Get Digits Completed */
	   
	  bitmask = ATDX_TERMMSK( port[ channel ].devhandle);
	  /* If a Loop Current Drop was Detected goto ON-HOOK state */
	  if ( bitmask & TM_LCOFF ) 
	     return( TM_LCOFF );
		
	  if ( bitmask & TM_MAXDTMF ) 
	     return( TM_MAXDTMF );
	  
	  if ( bitmask & TM_EOD ) 
	     return( TM_EOD );
	  
	  if ( bitmask & TM_MAXTIME) 
	     return( TM_MAXTIME );
	  
	  if ( bitmask & TM_USRSTOP)
	     return(TM_USRSTOP);
	  
	  if ( bitmask & TM_TONE)
	     return(TM_TONE);

	  if ( bitmask & TM_DIGIT)
	     return(TM_DIGIT);
    default:
      return(DX_ONHOOK);
	  
   }  // end switch
}   
/********************************
* lsi event process
********************************/

/****************************************************************
*        NAME : main(argc,argv[])
* DESCRIPTION : entry point to application.
*       INPUT : argc = argument count.
*             : argv = array of pointers to arguments.
*      OUTPUT : none.
*     RETURNS : none.
*    CAUTIONS : none.
****************************************************************/
      
main()
{
int aa=0,chdev,channel,event,cc,board;
//HWND my_hwnd=0;
//while((my_hwnd=GetActiveWindow())==NULL)
//	  ;
//printf("my_hwnd:%d",my_hwnd);
	sys_init();
	printf("\naaaaaaaaaaa");
	while(1)
	{
		while(sr_waitevt(50)==-1)
		{
			switch(aa++)
			{
			case 0:
				//get_play();
				break;
			case 1:
				//get_dial();
				break;
			case 2:
				if(_kbhit())
				{
					if ((cc=_getch())==0)
					{
						cc=_getch();
						if(cc==0x6b)    //ALT+F4
							sys_exit();
						//cc=_getch();
					}
					else
						if (cc==0x20)  //Spacebar
							;
						if (cc==0x1b)  //Esc
						{
							print_state();
						}
				}
			aa=0;
			break;
			}
		}
		chdev = sr_getevtdev();
		channel=1;
		while ( channel <= MAX_CHAN )
		{
			if ( port[ channel ].devhandle == chdev ) 
			{
				board=1;
				break;
			}
			else  channel++;
		}
		if (channel>MAX_CHAN) 
		{
			printf("error chandev get");
			continue;
		}
		switch(board)
		{
		case 1:
		   event=process_event(channel);
		   printf("\nEVENT:%x",event);
		   process_port(channel,event);
		   break;
		default:
			printf("no find channel of handle");
		break;
		}	 
	}
  return 0;
}

/****************************************************************
*        NAME : curr_state(channel,evtcode,board)
* DESCRIPTION : complete processing of the current state
*             : identify the next state to be entered
*       INPUT : channel = channel number
*             : evtcode = termination event code
*      OUTPUT : none
*     RETURNS : next channel state
*    CAUTIONS : none
****************************************************************/
int curr_state(int channel,int event)
{
	//int errcode,i,j;
	//int confid;
	//char call[14];
	//if ((port[channel].msg_fh!=0)&&(port[channel].state!=ST_CONNECT)&&(port[channel].state!=ST_WAIT))
	if (port[channel].msg_fh!=0)
    {
        printf("close handle:%d",port[channel].msg_fh);
        dx_fileclose(port[channel].msg_fh);
        port[channel].msg_fh=0;
    }

	switch (port[channel].state) 
	{
		case ST_WTRING:
			if (dx_enbtone(port[channel].devhandle,TID_1,DM_TONEON) ==-1)
			{
				printf("error dx_enbtone");
			}
			if(event==USER_RINGS)
			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -