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

📄 d.cpp

📁 语音卡IVR示例程序,银行查询的示例程序,可以多线程接听用户查询
💻 CPP
字号:
#include <windows.h>
#include <commdlg.h>
#include <commctrl.h>
#include <windowsx.h>

#include "D.h"
#include "..\\..\\..\\..\\inc\\tc08a32.h"
#include "resource.h"
#include "..\\..\\..\\..\\inc\\NewSig.h"

WORD TotalLine;
extern HWND hGWnd;
long DriverOpenFlag;
LINESTRUCT *Lines;
char VoicePath[100];
char sTmp[128];
extern HINSTANCE hInst;

//#pragma argsused
BOOL WINAPI yzInitSystem()
{
	int i;
	GetVoicePath();
	DriverOpenFlag = LoadDRV ( );
	if ( DriverOpenFlag ) {
		MessageBox ( hGWnd, "Load driver FAIL", "Message", MB_OK );
		return FALSE;
	}

	TotalLine = CheckValidCh();
	if ( EnableCard(TotalLine,1024*8) != (long)0) {
		FreeDRV();
		MessageBox ( hGWnd, "Enable Board FAIL", "Message", MB_OK );
		return FALSE;
	}

	Lines=new LINESTRUCT[TotalLine];
	SetBusyPara(350);
	for(i=0;i<TotalLine;i++)
	{
        Lines[i].nType=CheckChTypeNew(i);
		strcpy(Lines[i].CallerID,"");
		strcpy(Lines[i].Dtmf,"");
		Lines[i].State = CH_FREE;
	}

	Sig_Init(0);

	static int ColumnWidth[60] = {66, 78, 200, 72, 72, 100, 50, 150};
	char dig[10];

	LV_COLUMN lvc;
	lvc.mask =  LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

	lvc.iSubItem = 0;
	LoadString(hInst, IDS_CHANNEL_NO, sTmp, 128);
	lvc.pszText = sTmp ;
	lvc.cx = ColumnWidth[0];
	ListView_InsertColumn(GetDlgItem(hGWnd,IDC_STATELIST),0,&lvc);

	lvc.iSubItem = 1;
	LoadString(hInst, IDS_CHANNEL_TYPE, sTmp, 128);
	lvc.pszText = sTmp ;
	lvc.cx = ColumnWidth[1];
	ListView_InsertColumn(GetDlgItem(hGWnd,IDC_STATELIST),1,&lvc);
	
	lvc.iSubItem = 2;
	LoadString(hInst, IDS_FLOW, sTmp, 128);
	lvc.pszText = sTmp ;
	lvc.cx = ColumnWidth[2];
	ListView_InsertColumn(GetDlgItem(hGWnd,IDC_STATELIST),2,&lvc);

	lvc.iSubItem = 3;
	LoadString(hInst, IDS_CALLER_ID, sTmp, 128);
	lvc.pszText = sTmp ;
	lvc.cx = ColumnWidth[3];
	ListView_InsertColumn(GetDlgItem(hGWnd,IDC_STATELIST),3,&lvc);

	lvc.iSubItem = 4;
	lvc.pszText = "DTMF" ;
	lvc.cx = ColumnWidth[4];
	ListView_InsertColumn(GetDlgItem(hGWnd,IDC_STATELIST),4,&lvc);

	LV_ITEM lvi;
	for(i = 0; i < TotalLine; i++)	
	{
		lvi.mask = LVIF_TEXT;
		lvi.iItem = i;
		lvi.iSubItem = 0;
		itoa( i, dig, 10 ) ; 
		lvi.pszText = dig;
		ListView_InsertItem(GetDlgItem(hGWnd,IDC_STATELIST),&lvi);
	}
	for(i=0;i<TotalLine;i++)
	{
		if(Lines[i].nType==CHTYPE_TRUNK)
		{
			LoadString(hInst, IDS_TRUNK, sTmp, 128);
			ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), i, 1, sTmp);
		}
		else if(Lines[i].nType==CHTYPE_USER)
		{
			LoadString(hInst, IDS_USER, sTmp, 128);
			ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), i, 1, sTmp);
		}
		else if(Lines[i].nType==CHTYPE_RECORD)
		{
			LoadString(hInst, IDS_RECORD, sTmp, 128);
			ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), i, 1, sTmp);
		}
		else if(Lines[i].nType==CHTYPE_EMPTY)
		{
			LoadString(hInst, IDS_EMPTY, sTmp, 128);
			ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), i, 1, sTmp);
		}
	}
	return TRUE;
}
void WINAPI yzExitSystem()
{
	DisableCard();
	FreeDRV();
	delete Lines;
}
void WINAPI yzDrawState( int trkno )
{	
	char state[100]; ;
	char tmpstr[100] ;

	switch( Lines[trkno].State ) 
	{
	case CH_FREE:		
		LoadString(hInst, IDS_CH_FREE, state, 100);
		break ;
	case CH_RECEIVEID:
		LoadString(hInst, IDS_CH_RECEIVEID, state, 100);
		break;
	case CH_WAITSECONDRING:
		LoadString(hInst, IDS_CH_WAITSECONDRING, state, 100);
		break;
				
	case CH_WELCOME:
		LoadString(hInst, IDS_CH_WELCOME, state, 100);
		break ;
				
	case CH_ACCOUNT:
	case CH_ACCOUNT1:
		LoadString(hInst, IDS_CH_ACCOUNT, state, 100);
		break ;
	case CH_PASSWORD:
	case CH_PASSWORD1:
		LoadString(hInst, IDS_CH_PINNUMBER, state, 100);
		break;
	case CH_SELECT:
	case CH_SELECT1:
		LoadString(hInst, IDS_CH_SELECT, state, 100);
		break;
	case CH_RECORDFILE:
		LoadString(hInst, IDS_CH_LEAVEMSG, state, 100);
		break;
	case CH_PLAYRESULT:
		LoadString(hInst, IDS_CH_PLAYRESULT, state, 100);
		break;
	case CH_PLAYRECORD:
		LoadString(hInst, IDS_CH_PLAYRECORD, state, 100);
		break;
	case CH_OFFHOOK:
		LoadString(hInst, IDS_CH_OFFHOOK, state, 100);
		break;
	case CH_WAITUSERONHOOK:
		LoadString(hInst, IDS_CH_WAITUSERONHOOK, state, 100);
		break;
	}
	
	ListView_GetItemText(GetDlgItem(hGWnd,IDC_STATELIST), trkno, 2, tmpstr, 99 ) ;
	if ( strcmp(state,tmpstr )!=0) 
		ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), trkno, 2, state );

	strcpy(state, Lines[trkno].CallerID) ;

	ListView_GetItemText(GetDlgItem(hGWnd,IDC_STATELIST), trkno, 3, tmpstr, 99 ) ;
	if ( strcmp(state,tmpstr )!=0) 
		ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), trkno, 3, state );

	strcpy(state,Lines[trkno].Dtmf);

	ListView_GetItemText(GetDlgItem(hGWnd,IDC_STATELIST), trkno, 4, tmpstr, 99 ) ;
	if ( strcmp(state,tmpstr )!=0) 
		ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), trkno, 4, state );

}
void yzResetChannel(int channelID)
{
	if(Lines[channelID].nType==CHTYPE_TRUNK)
	{
		HangUp(channelID);
		Sig_ResetCheck(channelID);
		StartSigCheck(channelID);
		//StopSigCheck(channelID);
	}
	Lines[channelID].Dtmf[0]=0;
	Lines[channelID].CallerID[0]=0;
	Lines[channelID].State = CH_FREE;
}
char yzConvertDtmf(int ch)
{
	char c;

	switch(ch)
    {
		case 10:
			c = '0';
			break;
		case 11:
			c = '*';
			break;
		case 12:
			c = '#';
			break;
        case 13:
        case 14:
        case 15:
            c=ch-13+'a';
            break;
        case 0:
            c='d';
            break;
		default:
			c = ch + '0';//change DTMF from number to ASCII
	}
	return c;
}

void WINAPI yzDoWork()
{
	char FileName[200];
    short int code;
	int len;
	PUSH_PLAY();
	FeedSigFunc();
    for(int i=0;i<TotalLine;i++)
    {
        yzDrawState(i);

        switch(Lines[i].State)
        {
        case CH_FREE:
            if(RingDetect(i))
            {
                if(Lines[i].nType==CHTYPE_USER)
					Lines[i].State=CH_OFFHOOK;
				else 
				{
					Lines[i].State=CH_RECEIVEID;
					ResetCallerIDBuffer(i);
					Lines[i].nTimeElapse=0;
				}
            }
            break;
        case CH_RECEIVEID:
		{
            bool bOffHook=false;
            if(Lines[i].nTimeElapse>2000 && RingDetect(i)) 
				bOffHook=true;
            if(Lines[i].nTimeElapse>7000) 
				bOffHook=true;
            int a=GetCallerIDStr (i,Lines[i].CallerID);
            if(a==3)
            {
                bOffHook=true;
            }
            else if(a==4)
            {
				LoadString(hInst, IDS_CallerID_ERROR, Lines[i].CallerID, 32);
                bOffHook=true;
            }
            if(bOffHook)
            {
                OffHook(i);
                StartSigCheck(i);
                Lines[i].State=CH_OFFHOOK;
            }
            Lines[i].nTimeElapse+=50;
		}
            break;
        case CH_WAITSECONDRING:
            if(RingDetect(i))
            {
                OffHook(i);
                StartSigCheck(i);
                Lines[i].State=CH_OFFHOOK;
            }
            break;
        case CH_OFFHOOK:
			strcpy(FileName,VoicePath);
			strcat(FileName,"bank.001");
			InitDtmfBuf(i);
			StartPlayFile(i,FileName,0L);
			Lines[i].State = CH_WELCOME;
			break;
		case CH_WELCOME:
			code=GetDtmfCode(i);
			if(code!=-1)
			{
				StopPlayFile(i);
				Lines[i].Dtmf[0]=yzConvertDtmf(code);
				Lines[i].Dtmf[1]=0;
				Lines[i].State=CH_ACCOUNT1;
				break;
			}
			if(CheckPlayEnd(i))
			{
				StopPlayFile(i);
				strcpy(FileName,VoicePath);
				strcat(FileName,"bank.002");
				StartPlayFile(i,FileName,0L);
				Lines[i].State=CH_ACCOUNT;
			}
			break;
		case CH_ACCOUNT:
			code=GetDtmfCode(i);
			if(code!=-1)
			{
				StopPlayFile(i);
				Lines[i].Dtmf[0]=yzConvertDtmf(code);
				Lines[i].Dtmf[1]=0;
				Lines[i].State=CH_ACCOUNT1;
				break;
			}
			if(CheckPlayEnd(i))
			{
				StopPlayFile(i);					
				Lines[i].State=CH_ACCOUNT1;
			}
			break;
		case CH_ACCOUNT1:
			len=strlen(Lines[i].Dtmf);
			while((code=GetDtmfCode(i))!=-1)
			{
				Lines[i].Dtmf[len++]=yzConvertDtmf(code);
			}
			Lines[i].Dtmf[len]=0;
			if(len>=8)
			{
//				code=GetDtmfCode(i);
				Lines[i].Dtmf[0]=0;
				strcpy(FileName,VoicePath);
				strcat ( FileName,"bank.003" );
				StartPlayFile(i,FileName,0L);
				Lines[i].State = CH_PASSWORD;
			}
			break;
		case CH_PASSWORD:
			code=GetDtmfCode(i);
			if(code!=-1)
			{
				StopPlayFile(i);
				Lines[i].Dtmf[0]=yzConvertDtmf(code);
				Lines[i].Dtmf[1]=0;
				Lines[i].State=CH_PASSWORD1;
				break;
			}
			if(CheckPlayEnd(i))
			{
				StopPlayFile(i);					
				Lines[i].State=CH_PASSWORD1;
			}
			break;
		case CH_PASSWORD1:
			len=strlen(Lines[i].Dtmf);
			while((code=GetDtmfCode(i))!=-1)
			{
				Lines[i].Dtmf[len++]=yzConvertDtmf(code);
			}
			Lines[i].Dtmf[len]=0;
			if(len>=6)
			{
				Lines[i].Dtmf[0]=0;
				strcpy(FileName,VoicePath);
				strcat ( FileName,"bank.004");
				StartPlayFile(i,FileName,0L);
				Lines[i].State = CH_SELECT;
			}
			break;
		case CH_SELECT:
			code=GetDtmfCode(i);
			if(code!=-1)
			{
				Lines[i].Dtmf[0]=yzConvertDtmf(code);
				Lines[i].Dtmf[1]=0;
				switch(Lines[i].Dtmf[0])
				{
				case '1':
					StopPlayFile(i);
					RsetIndexPlayFile(i);
					strcpy(FileName,VoicePath);
					strcat ( FileName, "bank.005");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"d5");
					AddIndexPlayFile(i,FileName);

/*					strcpy(FileName,VoicePath);
					strcat(FileName,"d12");
					AddIndexPlayFile(i,FileName);
*/
					strcpy(FileName,VoicePath);
					strcat(FileName,"d8");
					AddIndexPlayFile(i,FileName);

/*					strcpy(FileName,VoicePath);
					strcat(FileName,"d11");
					AddIndexPlayFile(i,FileName);
*/
					strcpy(FileName,VoicePath);
					strcat(FileName,"d9");
					AddIndexPlayFile(i,FileName);
/*
					strcpy(FileName,VoicePath);
					strcat(FileName,"d10");
					AddIndexPlayFile(i,FileName);
*/
					strcpy(FileName,VoicePath);
					strcat(FileName,"d6");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"d15");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"d8");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"bank.008");
					AddIndexPlayFile(i,FileName);
					StartIndexPlayFile(i);
					Lines[i].State = CH_PLAYRESULT;
					break;

				case '2':
					StopPlayFile(i);
					RsetIndexPlayFile(i);
					strcpy(FileName,VoicePath);
					strcat(FileName,"bank.006");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"d0");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"d15");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"d4");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"d8");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"bank.008");
					AddIndexPlayFile(i,FileName);
					StartIndexPlayFile(i);
					Lines[i].State = CH_PLAYRESULT;
					break;

				case '3':
					StopPlayFile(i);
					RsetIndexPlayFile(i);
					strcpy(FileName,VoicePath);
					strcat(FileName,"bank.007");
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"d3");
					AddIndexPlayFile(i,FileName);

/*					strcpy(FileName,VoicePath);
					strcat(FileName,"d13");
					AddIndexPlayFile(i,FileName);
*/
					strcpy(FileName,VoicePath);
					strcat(FileName,"d7");
					AddIndexPlayFile(i,FileName);
/*
					strcpy(FileName,VoicePath);
					strcat(FileName,"d12");
					AddIndexPlayFile(i,FileName);
*/
					strcpy(FileName,VoicePath);
					strcat(FileName,"d0");
					AddIndexPlayFile(i,FileName);
					AddIndexPlayFile(i,FileName);

					strcpy(FileName,VoicePath);
					strcat(FileName,"bank.008");
					AddIndexPlayFile(i,FileName);
					StartIndexPlayFile(i);
					Lines[i].State = CH_PLAYRESULT;
					break;
				default:
					break;
				}
			}
			break;
		case CH_PLAYRESULT:
			if(CheckIndexPlayFile(i))
			{
				StopIndexPlayFile(i);
				if(Lines[i].nType==CHTYPE_TRUNK) yzResetChannel(i);
				else 
				{
					StartPlaySignal(i,SIG_BUSY1);
					Lines[i].State=CH_WAITUSERONHOOK;
				}
			}
			break;
		case CH_WAITUSERONHOOK:
			if(!RingDetect(i))
			{
				StartPlaySignal(i,SIG_STOP);
				yzResetChannel(i);
			}
			break;
		}//end switch

		if(Lines[i].nType==CHTYPE_TRUNK && Lines[i].State!=CH_FREE)
		{
			//WORD wSigCheckResult=ReadCheckResult(i,PLAY_CHECK);
			//if(wSigCheckResult==R_BUSY)
			if (Sig_CheckBusy(i))
			{
				switch(Lines[i].State)
				{
                   
				case CH_WELCOME:
				case CH_ACCOUNT:
				case CH_PASSWORD:
				case CH_SELECT:
					StopPlayFile(i);
					break;
				case CH_PLAYRESULT:
					StopIndexPlayFile(i);
					break;
				}
				yzResetChannel(i);
			}
		}
		else if(Lines[i].nType==CHTYPE_USER && Lines[i].State!=CH_FREE)
		{
			if(!RingDetect(i))
			{
				switch(Lines[i].State)
				{
                   
				case CH_WELCOME:
				case CH_ACCOUNT:
				case CH_PASSWORD:
				case CH_SELECT:
					StopPlayFile(i);
					break;
				case CH_PLAYRESULT:
					StopIndexPlayFile(i);
					break;
				}
				yzResetChannel(i);
			}
		}
	}//end for
}

void GetVoicePath()
{
	char FileName[100];
	GetWindowsDirectory(FileName,100);
	strcat(FileName,"\\tc08a-v.ini");
	GetPrivateProfileString("SYSTEM","InstallDir",NULL,VoicePath,100,FileName);
	strcat(VoicePath,"voc\\");
}

⌨️ 快捷键说明

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