www.pudn.com > RecDemo6.0.rar > D.cpp


 
#include "stdafx.h" 
#include "D.h" 
#include "tc08a32.h" 
#include "resource.h" 
#include "NewSig.h" 
#include "mydefines.h" 
extern int TotalLine; 
extern HWND hGWnd; 
 
extern LINESTRUCT  *Lines; 
char VoicePath[100]; 
 
void WINAPI new_yzDrawState( int trkno ) 
{	 
	char state[100]; ; 
	char tmpstr[20] ; 
 
	switch( Lines[trkno].State )  
	{ 
	case CH_FREE:		 
		strcpy(state,"空闲");  
		break ; 
	case CH_RECEIVEID: 
		strcpy(state,"接收主叫号码"); 
		break; 
	case CH_WAITSECONDRING: 
		strcpy(state,"等待第二次振铃"); 
		break; 
				 
	case CH_WELCOME: 
		strcpy(state,"这里是东进电话银行演示系统"); 
		break ; 
				 
	case CH_ACCOUNT: 
	case CH_ACCOUNT1: 
		strcpy(state,"请输入8位帐号") ; 
		break ; 
	case CH_PASSWORD: 
	case CH_PASSWORD1: 
		strcpy(state,"请输入6位密码"); 
		break; 
	case CH_SELECT: 
	case CH_SELECT1: 
		strcpy(state,"选择功能"); 
		break; 
	case CH_RECORDFILE: 
		strcpy(state,"录制留言"); 
		break; 
	case CH_PLAYRESULT: 
		strcpy(state,"播放查询结果"); 
		break; 
	case CH_PLAYRECORD: 
		strcpy(state,"播放留言"); 
		break; 
	case CH_OFFHOOK: 
		strcpy(state,"摘机"); 
		break; 
	case CH_WAITUSERONHOOK: 
		strcpy(state,"等待内线挂机"); 
		break; 
	} 
	 
	ListView_GetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 2, tmpstr, 19 ) ; 
	if ( strcmp(state,tmpstr )!=0)  
		ListView_SetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 2, state ); 
 
	strcpy(state, Lines[trkno].CallerID) ; 
 
	ListView_GetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 3, tmpstr, 19 ) ; 
	if ( strcmp(state,tmpstr )!=0)  
		ListView_SetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 3, state ); 
 
	strcpy(state,Lines[trkno].Dtmf); 
 
	ListView_GetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 4, tmpstr, 19 ) ; 
	if ( strcmp(state,tmpstr )!=0)  
		ListView_SetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 4, state ); 
 
} 
void yzResetChannel(int channelID) 
{ 
	if(Lines[channelID].nType==CHTYPE_TRUNK) 
	{ 
		StartSigCheck(channelID); 
		HangUp(channelID); 
		//Sig_ResetCheck(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';//转换成ASCII码 
	} 
	return c; 
} 
 
#define	USER_DEFINE_TIMER	5 
 
void WINAPI yzDoWork(int i) 
{ 
	char FileName[200]; 
    short int code; 
	int len; 
 
   // for(int i=0;i 5000 )		// no ring for 5 second 
					{ 
						Lines[i].State = CH_FREE; 
					} 
				} 
 
				// 处理摘机 
				if ( DRec_OffHookDetect(i) == 1 ) {		// user OffHook 
					Lines[i].State = CH_OFFHOOK; 
					int a=GetCallerIDStr (i,Lines[i].CallerID); 
					if(a==4) 
					{ 
						strcpy(Lines[i].CallerID,"校验错"); 
					} 
				} 
				} 
				break; 
			 
			case CH_OFFHOOK:		// start record 
				wsprintf ( FileName, "TmpRec.%d.pcm", i ); 
				StartRecordFile ( i, FileName, 8000L*60 ); 
				Lines[i].State = CH_WAITUSERONHOOK; 
				break; 
			case CH_WAITUSERONHOOK: 
				if ( DRec_OffHookDetect(i) == 0 ) {		// user OffHook 
					StopRecordFile ( i ); 
					Lines[i].State = CH_FREE; 
				} 
				break; 
			} // end of switch 
		//	continue; 
			return ; 
		} 
		// end of record module 
 
        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) 
            { 
				strcpy(Lines[i].CallerID,"校验错"); 
                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,"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\\"); 
} 
void WINAPI yzExitSystem() 
{ 
	 
}